Skip to content
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

[WIP] DKI ODF redux #2304

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open

[WIP] DKI ODF redux #2304

wants to merge 28 commits into from

Conversation

arokem
Copy link
Contributor

@arokem arokem commented Dec 4, 2020

This revisits the old #685, which I think we should incorporate.

@pep8speaks
Copy link

pep8speaks commented Dec 4, 2020

Hello @arokem, Thank you for updating !

Line 786:1: E305 expected 2 blank lines after class or function definition, found 1
Line 786:3: E227 missing whitespace around bitwise or shift operator
Line 786:7: E225 missing whitespace around operator
Line 799:3: E225 missing whitespace around operator
Line 799:5: E225 missing whitespace around operator
Line 799:7: E225 missing whitespace around operator
Line 801:1: E302 expected 2 blank lines, found 1
Line 920:1: E305 expected 2 blank lines after class or function definition, found 0
Line 920:7: E225 missing whitespace around operator
Line 920:18: E211 whitespace before '('

Comment last updated at 2021-10-07 18:28:52 UTC

@arokem
Copy link
Contributor Author

arokem commented Dec 4, 2020

I think I got it all this time! 😅

@skoudoro
Copy link
Member

skoudoro commented Dec 4, 2020

Hi @arokem,

Do you plan to clean a bit this PR before a review? is it still WIP? After a really quick look, I saw some fvtk so I suppose it might have some old function too. Let us know when it is ready for review!

@skoudoro skoudoro changed the title DKI ODF redux [WIP] DKI ODF redux Dec 4, 2020
@skoudoro skoudoro modified the milestone: 1.4 Dec 4, 2020
@arokem
Copy link
Contributor Author

arokem commented Dec 4, 2020 via email

@arokem
Copy link
Contributor Author

arokem commented Mar 19, 2021

OK - this is no longer WIP - ready for a review!

Copy link
Member

@skoudoro skoudoro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @arokem,

Here a quick first review. I still need to render locally the example, run the tests, and look deeper at the code.

Thanks!

The DKI-ODF is calculated in the vertices of this input.
alpha : float, optional
radial weighting power. Default is 4 according to [Jen2014]_ and
[Raf2015]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing the underscore [Raf2015]_

normalize_peaks=False, npeaks=3, gtol=1e-5):
""" Estimation of fiber directions based on diffusion kurtosis imaging
(DKI). Fiber directions are estimated as the maxima of the DKI
orientation distribution function [Jen2014]. This function is based on
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing the underscore [Jen2014]_

Comment on lines 2137 to 2141
return dki_directions(self.model_params, sphere, alpha=4,
relative_peak_threshold=0.1,
min_separation_angle=20, mask=None,
return_odf=False, normalize_peaks=False,
npeaks=3, gtol=1e-5)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a problem here. alpha=alpha, relative_peak_threshold=relative_peak_threshold, etc... instead

kODF = np.zeros((len(kt), len(V)))

# select non-zero voxels
# (when #677 is merged replace this code lines by function _positive_evals)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is merged so this comment can be removed

normalize_peaks=False, npeaks=3, gtol=1e-5):
""" Estimation of fiber direction based on diffusion kurtosis imaging
(DKI). Fiber directions are estimated as the maxima of the orientation
distribution function [Jen2014]. This function is based on the work done by
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing underscore [Jen2014]_

relative_peak_threshold : float, optional
Only return peaks greater than ``relative_peak_threshold * m`` where m
is the largest peak.
min_separation_angle : float in [0, 90], optinal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo, optional

affine = img.affine

"""
Having the acquition paramenters of the loaded data, we can define the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo, parameters and acquisition

tensors = tensors.reshape((5, 2, 1, len(sphere.vertices)))
tensors_actor = actor.odf_slicer(tensors, sphere=sphere, scale=0.5)
scene.add(tensors_actor)
window.show(scene)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc generation will block.

if interactive=True:
     window.show(scene)

ODF = ODF.reshape((5, 1, 1, len(sphere.vertices)), order='F')
odf_actor = actor.odf_slicer(ODF, sphere=sphere, scale=0.5)
scene.add(tensors_actor)
window.show(scene)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc generation will block

if interactive=True:
     window.show(scene)

den = img.get_fdata()
else:
den = patch2self(data, gtab.bvals)
nib.save(nib.Nifti1Image(den, affine), 'denoised_cenir_multib.nii.gz')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you use save_nifti function (from dipy.io.image import load_nifti, save_nifti)

@skoudoro
Copy link
Member

Also, could you fix the pep8 issues

@skoudoro skoudoro added this to the 1.5 milestone Mar 22, 2021
@arokem
Copy link
Contributor Author

arokem commented Mar 23, 2021

Thanks for the review @skoudoro ! I think that I've addressed the comments in the recent commit.

@skoudoro
Copy link
Member

Thank you for the update!

@ShreyasFadnavis, Can you check this PR too? thank you

Copy link
Member

@skoudoro skoudoro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @arokem,

  • Can you add your examples in valid_examples.txt and examples_index.rst.
  • Running the tutorial takes all my resources (memory, etc...) and freeze my laptop. It does not seem normal to me. So, it needs further introspection, or do you have an explanation?
  • Furthermore, the tutorial is super long to run! more than 1 hour on my laptop for 1 tutorial. This is really too long. there are 80 tutorials during doc generation. You might want to reduce the data size. I did not check which step take all this time.
  • Concerning the math part, I will let someone else have the last look.

Comment on lines +77 to +78
for v in range(len(five_voxel_angles)):
angles = five_voxel_angles[v]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's be more pythonic by using

for idx, angles in enumerate(five_voxel_angles):
    signal_dki[idx], ....


# convert fiber directions ground truth angles to Cartesian coordinates
gt_dir = np.zeros((5, 1, 2, 3))
for d in range(5):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we do not iterate over five_voxel_angles for more clarity


Parameters
----------
sphere : Sphere class instance, optional
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional to remove

kODFi = kODF[rel_i]

# loop over all relevant voxels
for vox in range(len(kt)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

range(len( is not recommended in general. There are many alternatives more pythonic.


# loop over all directions
sampledODF = np.zeros(len(V))
for i in range(len(V)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above

range(len( is not recommended in general. There are many alternatives more pythonic.

Comment on lines +2647 to +2663
# loop over all relevant voxels
for vox in range(len(kt)):
# Compute dimensionless tensor U
R = evecs[vox]
dt = np.dot(np.dot(R, np.diag(evals[vox])), R.T)
MD = (dt[0, 0] + dt[1, 1] + dt[2, 2]) / 3
U = np.linalg.pinv(dt) * MD

# loop over all directions
sampledODF = np.zeros(len(V))
for i in range(len(V)):
sampledODF[i] = _dki_odf_core(V[i], kt[vox], U, alpha)

kODFi[vox] = sampledODF
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be good to review this block. I think this whole block can be managed more efficiently.

normalize_peaks=False, npeaks=3, gtol=1e-5):
""" Estimation of fiber direction based on diffusion kurtosis imaging
(DKI). Fiber directions are estimated as the maxima of the orientation
distribution function [Jen2014]_. This function is based on the work done by
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pep8: it should stop at done

@skoudoro
Copy link
Member

skoudoro commented Mar 24, 2021

Also, Do you plan to use this opportunity to fix #1773 (option to invert the signal in DKI WMTI)?

@skoudoro skoudoro mentioned this pull request Apr 10, 2021
17 tasks
@skoudoro
Copy link
Member

Hi @arokem,

Do you think you can finalize this for the next release, 1 week from now, or should I move it for the release in June?

@arokem
Copy link
Contributor Author

arokem commented Apr 16, 2021 via email

@skoudoro
Copy link
Member

ok, no problem, thanks!

@skoudoro skoudoro modified the milestones: 1.4.1, 1.5.0 Apr 16, 2021
@Garyfallidis Garyfallidis changed the title DKI ODF redux [WIP] DKI ODF redux Oct 7, 2021
…Wcons which is being revised in PR dipy#677. I am adding here this function to carry with thr dki-odf test. However when the 2 pull requests are merged we have to insure that duplicates of this function are removed
@skoudoro
Copy link
Member

Hi @arokem,

What is the status of this PR? How is your schedule? Do you plan to come back on it?

@arokem arokem mentioned this pull request Mar 4, 2022
2 tasks
@skoudoro skoudoro force-pushed the master branch 7 times, most recently from 1419292 to ca6268a Compare December 8, 2023 22:25
@skoudoro skoudoro force-pushed the master branch 3 times, most recently from 5935e1e to 765963e Compare January 24, 2024 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants