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

ENH: Add a script to plot the signal estimated by the GP #228

Merged
merged 3 commits into from
Oct 26, 2024

Conversation

jhlegarreta
Copy link
Collaborator

@jhlegarreta jhlegarreta commented Sep 26, 2024

  • ENH: Add a script to plot the signal estimated by the GP
  • STYLE: Rename the error analysis script to honor better its purpose
  • STYLE: Rename the EddyMotionGPR instance to honor better its classname

@jhlegarreta
Copy link
Collaborator Author

pyhon /path/to/eddymotion/scripts/dwi_estimation_plot.py \ 
  60 1000 100 \
  --evals1 0.0015 0.0003 0.0003 \
  --snr 20

gives the below result (with the caveat mentioned in #228 (comment))

@jhlegarreta jhlegarreta force-pushed the AddGPPredictionPlotScript branch 2 times, most recently from c102c22 to 9358298 Compare September 29, 2024 21:52
Copy link

codecov bot commented Sep 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.18%. Comparing base (796c501) to head (8835e63).
Report is 9 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #228   +/-   ##
=======================================
  Coverage   66.18%   66.18%           
=======================================
  Files          19       19           
  Lines         905      905           
  Branches      112      112           
=======================================
  Hits          599      599           
  Misses        264      264           
  Partials       42       42           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jhlegarreta
Copy link
Collaborator Author

jhlegarreta commented Sep 29, 2024

After 9358298 the script is able to simulate accept one, or two or three crossing fibers, e.g.

One fiber:

pyhon /path/to/eddymotion/scripts/dwi_estimation_plot.py \ 
  60 1000 100 \
  --angles 0 0 \
  --evals 0.0015 0.0003 0.0003 \
  --snr 20

Two fibers:

pyhon /path/to/eddymotion/scripts/dwi_estimation_plot.py \ 
  60 1000 100 \ 
  --angles 0 0 90 0 \
  --evals 0.0015 0.0003 0.0003 0.0015 0.0003 0.0003 \
  --snr 20

Three fibers:

pyhon /path/to/eddymotion/scripts/dwi_estimation_plot.py \ 
  60 1000 100 \
  --angles 0 0 90 0 90 90 \
  --evals 0.0015 0.0003 0.0003 0.0015 0.0003 0.0003 0.0015 0.0003 0.0003 \
  --snr 20

Plot for two fibers (made the colormap solid and changed the opacity value only):

Plot for three fibers:

@jhlegarreta
Copy link
Collaborator Author

jhlegarreta commented Oct 25, 2024

A few notes:

  • I have tested the error analysis and plot scripts and they work as intended (or at least as they were working prior to this commit).

    • The std dev is monotonically increasing only after the 10-fold CV in my experiments (happens in the main branch as well: @oesteban you may want to check this; if we conclude that there is something wrong, I'd rather try to fix that in a separate PR).
  • Pending to create the predicted surface on more vectors than those used to generate the synthetic signal (xref ENH: Add a script to plot the signal estimated by the GP #228 (comment)). That requires reformatting the script, as we do not save the gp parameters or the fitted object in the error analysis script.

  • I would set the seed in dwi_gp_estimation_error_analysis.py to a fixed value for the sake of reproducibility. @oesteban do you prefer to keep the randomness through a flag to the script?

  • We may want to remove the evals parameter from the dwi_gp_estimation_error_analysis.py script, and rely entirely on random values, as it is not feasible to provide N different values for each voxels, and even less so for multi-fiber cases (xref PR ENH: Allow simulating multi-fiber voxels #247) It will be easier to handle towards generalizing this to a synthetic dataset with voxels having multiple fibers.

  • Checking the overlap between/merging eddymotion.testing.simulations.create_random_polar_coordinates and eddymotion.testing.simulations.create_random_polar_angles is left for a separate PR.

@jhlegarreta jhlegarreta marked this pull request as ready for review October 25, 2024 01:16
Add a script to plot the signal estimated by the GP as well as the error
data generated by the error analysis script.

Add the necessary helper functions to the signal visualization module to
plot the estimated signal as a surface.

Modify the signal visualization error plotting method to optionally
accept the color the figure size parameters.

Add methods to the the signal simulation module in order to serialize
the dMRI data.

Refactor the the the signal simulation module to:
- Allow the dMRI signal generation method to generate evals randomly if
  not provided.
- Allow reusing the polar random angle generation utility.
- Allow the single tensor method to accept a random generator for the
  sake of reproducibility.
- Set the `zip` function `strict` parameter to `True` as we want all
  iterables to have the same length.
- Create a method to simulate a single-fiber multivoxel signal given the
  gradient table and the rest of the necessary parameters.

Modify the error analysis script to:
- Reuse the `EddyMotionGPR` instance: factor it out from the CV
  function, as the instance does not change across folds and repeats.
- Save the simulated signal and gtab.
- Predict and save the signal of the GP estimation.
- Save the simulated SNR to the CV scores data file. Since `None`
  indicates no noise, modify the `pandas` serialization method arguments
  so that `None` is not considered as a missing value.

Take advantage of the commit to rename the `evals1` argument to `evals`
in the error analysis script.
Rename the error analysis script to honor better its purpose.
Rename the `EddyMotionGPR` instance to honor better its classname.
@oesteban oesteban merged commit 33992b6 into nipreps:main Oct 26, 2024
8 checks passed
@jhlegarreta jhlegarreta deleted the AddGPPredictionPlotScript branch October 26, 2024 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants