-
Notifications
You must be signed in to change notification settings - Fork 429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RF] Fix spherical harmonic terminology swap #3086
[RF] Fix spherical harmonic terminology swap #3086
Conversation
Hello @itellaetxe, Thank you for updating !
Comment last updated at 2024-03-08 19:24:55 UTC |
My linter was not showing me the E501 problem. Fixing it. Sorry |
Hi @itellaetxe, We fixed the issue in master, Can you rebase this branch or merge master to this branch? Thanks |
Hi @skoudoro @itellaetxe @ebrahimebrahim, If we do proceed with this change we might want to add a note somewhere in the doc clearly explaining the issue. It looks like the dMRI community have settled on the terminology order and all the papers I came across using CSD reconstruction report the maximum SH order when they talk about This is very confusing and unclear to me why there is a swap between the dMRI literature and wikipedia. I'll also tag @karanphil here who might have something to add. |
It is indeed confusing. I remember being confused at first, coming from a physics background. However, when you read the literature on SH bases and CSD in dMRI (like tournier04, tournier07, descoteaux07 or descoteaux09), they all refer to While Wikipedia follows the inverse terminology, other references such as Brilliant (https://brilliant.org/wiki/spherical-harmonics/) follow the current way of Dipy and the dMRI literature. I think we need to be very careful if changing this. |
Thank you for your feedback @CHrlS98. Indeed, Looking back #2206 reminds me that I have already this question as a comment. @Garyfallidis and @arokem, Can you also give your opinion here? it is important. thank you! maybe @RafaelNH could provide also a feedback |
Hmm this is more confusing than I thought when I opened #2970 Sorry if I opened a can of worms that should have remained closed 😬 (In mrtrix "order" is used for |
Hi @skoudoro, due to the ongoing discussion, I think I will leave it like this until we arrive to a conclusion. I will adapt the code to the final decision. |
@arokem, we would like your feed back please when you have time |
Hi! I think that we should use the terminology that is used in the dMRI papers. I would suggest putting in a Note that explains that this is a choice that we made, so readers of wikipedia and scipy should be careful when relying on these as resources. Does that makes sense? |
Do dMRI papers swap degree and order or do they just use order for |
In Maxime Descoteaux (@mdesco) PhD thesis, there is a chapter on spherical harmonics (section 5.2) where it is said that In Tournier et al, 2004 (https://doi.org/10.1016/j.neuroimage.2004.07.037), they refer to
Actually, even in the DIPY paper from 2014 (https://doi.org/10.3389/fninf.2014.00008),
So, while there appears to be a consensus on |
@desco also used the term "phase factor" in [his seminal 2007 paper]:(https://onlinelibrary.wiley.com/doi/pdf/10.1002/mrm.21277) I think part of the confusion stems from the fact that the words "order" and "degree" are used interchangeably to refer to the highest exponent in a polynomial function (see e.g., here). So, a nomenclature that uses "degree" and "phase factor" is potentially much less confusing. In fact, one could argue that if you ever use "order" that should refer to the variable referred to as In other words, potentially with a lot of explanation, I might suggest to go with |
+1 with this conclusion. Thanks all for the debate / clarification, I think we have a consensus. @itellaetxe, can you go ahead with I plan to release DIPY tomorrow or in 2 days so it will be great if you could update this PR on ASAP. Thank you in advance! ps: it is ok if you can not make it. |
PS: do not forget to fix the conflict and pep8 issues above. Thanks again ! |
24fb046
to
8d07316
Compare
Thanks to everyone that took part in the discussion. Shortly:
I just saw that I made a typo with |
doc/theory/sh_basis.rst
Outdated
NOTE: | ||
The definition of spherical harmonics that DIPY utilizes does not match the one | ||
in Wikipedia and scipy. Instead, DIPY follows the dMRI literature conventions, | ||
like in ``descoteaux07`` and ``tournier07``. | ||
The code in DIPY also follows the following convention: | ||
Let the SH be noted as $Y_{l}^m$. Then, $l$ is referred to as either order or | ||
l_value(s), and $m$ is referred to as either phase factor or m_value(s). | ||
This decisions were made as a result of the PR in https://github.com/dipy/dipy/pull/3086 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect !
I am questioning the change from I understand I also found few places where |
Let's try to be the most accurate as possible but you got a very good point @karanphil @itellaetxe, everytime you change from @deprecated_params('sh_order', 'sh_order_max', since='1.9', until='2.0') see an example: Lines 249 to 250 in 379062e
|
doc/theory/sh_basis.rst
Outdated
The code in DIPY also follows the following convention: | ||
Let the SH be noted as $Y_{l}^m$. Then, $l$ is referred to as either order or | ||
l_value(s), and $m$ is referred to as either phase factor or m_value(s). | ||
This decisions were made as a result of the PR in https://github.com/dipy/dipy/pull/3086 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"This decision was" or "These decisions were"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this PR is cited there, I would also update the section "Main changes" (at the beginning of the PR) to represent the actual final changes. It would be less confusing if someone looks at it in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you both for the suggestions :)
- @karanphil I just updated the beginning of the PR. It should reflect the current changes now.
- @CHrlS98 thanks for the grammar check. I will leave it as "These decisions...". Pushed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @itellaetxe , just a small detail, I think the line "sh_degree_max
is now sh_order_max
" should be "sh_order
is now sh_order_max
", since sh_degree_max
never really existed in Dipy.
Done. It should be good to go now! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noted a couple of places where l/m_value
should be l/m_values
, and where the docstring is incomplete. Other than that, it looks good to me, great job!
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3086 +/- ##
==========================================
+ Coverage 81.76% 81.80% +0.03%
==========================================
Files 150 150
Lines 21238 21284 +46
Branches 3412 3412
==========================================
+ Hits 17365 17411 +46
Misses 3034 3034
Partials 839 839
|
@@ -463,17 +466,17 @@ def estimate_response(gtab, evals, S0): | |||
return single_tensor(gtab, S0, evals, evecs, snr=None) | |||
|
|||
|
|||
def forward_sdt_deconv_mat(ratio, n, r2_term=False): | |||
def forward_sdt_deconv_mat(ratio, l_values, r2_term=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here, it is missing @deprecated_params('n', 'l_values', since='1.9', until='2.0')
@@ -56,18 +57,18 @@ def bandit(f): | |||
return bandit | |||
|
|||
|
|||
def forward_sdeconv_mat(r_rh, n): | |||
def forward_sdeconv_mat(r_rh, l_values): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is missing @deprecated_params('n', 'l_values', since='1.9', until='2.0')
|
||
|
||
def spherical_harmonics(m, n, theta, phi, use_scipy=True): | ||
def spherical_harmonics(m_values, l_values, theta, phi, use_scipy=True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same, it is missing @deprecated_params(['m', 'n',], ['m_values', 'l_values'], since='1.9', until='2.0')
return val | ||
|
||
|
||
@deprecate_with_version('dipy.reconst.shm.real_sph_harm is deprecated, ' | ||
'Please use ' | ||
'dipy.reconst.shm.real_sh_descoteaux_from_index ' | ||
'instead', since='1.3', until='2.0') | ||
def real_sph_harm(m, n, theta, phi): | ||
def real_sph_harm(m_values, l_values, theta, phi): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
|
||
|
||
def real_sh_tournier_from_index(m, n, theta, phi, legacy=True): | ||
def real_sh_tournier_from_index(m_values, l_values, theta, phi, legacy=True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, see above
@skoudoro, I completely overlooked the deprecator decorator in the |
else: | ||
warn(tournier07_legacy_msg, category=PendingDeprecationWarning) | ||
|
||
return real_sh | ||
|
||
|
||
def real_sh_descoteaux_from_index(m, n, theta, phi, legacy=True): | ||
def real_sh_descoteaux_from_index(m_values, l_values, theta, phi, legacy=True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, see above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this great work @itellaetxe.
This PR is almost ready to go. See my additional comments.
is there any additional comments @CHrlS98 ? @karanphil ? @arokem ? @ebrahimebrahim ?
If not, I might edit this PR, let the CI's run and merge it today to be part of the release. |
Ok, all seems ok, merging! Thank you @itellaetxe for this work Thank you @arokem @CHrlS98 @karanphil @ebrahimebrahim for the review/debate |
Thank you @skoudoro for the help with those last decorators! |
Summary
For functions related to spherical harmonics, the terminology "degree" and "order" is often used backwards in docstrings and variable names. This PR ensures consistency when referring to "degree" and "order" in the code. Now instead of "degree", we use "phase factor".
Closes Issue #2970
Main changes
l_value
andm_value
, respectively. In case these are arrays, we usel_values
andm_values
to be more informative of the type of the variable.sh_order
is nowsh_order_max
.