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

MRG: Add initial arguments to vol viz #6046

Merged
merged 10 commits into from
Sep 15, 2019
Merged

Conversation

larsoner
Copy link
Member

@larsoner larsoner commented Mar 11, 2019

When using VolSourceEstimate.plot() I found myself wanting a way to specify the initial time and initial position. This PR thus:

  • Adds support for initial_time (like in surf source est plotting)
  • Adds support for initial_position
  • Adds support for passing a morph instead of SourceSpaces as src (see Notes for details/rationale)
  • Fixes indexing of morphed STC (see example)
  • Speeds up tests a little bit

My particular use case involved replicating a figure someone sent me with initial_time=0.2 and initial_pos=(-0.04, -0.034, -0.002) and now I can script it to give:

3089_0 2_nai

Not ready for merge because there is some bug with indexing the morphed STC.

@codecov
Copy link

codecov bot commented Mar 12, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@9585e93). Click here to learn what that means.
The diff coverage is 93.4%.

@@            Coverage Diff            @@
##             master    #6046   +/-   ##
=========================================
  Coverage          ?   89.62%           
=========================================
  Files             ?      421           
  Lines             ?    76110           
  Branches          ?    12441           
=========================================
  Hits              ?    68211           
  Misses            ?     5100           
  Partials          ?     2799

@jasmainak
Copy link
Member

@larsoner what is the image we are looking at? Is it the max? I remember being confused by this in the beginning. If you click on a certain slice that looks like the max, it does not necessarily give you the max in the time course. Because you are looking at the time course for that particular slice, not the time course for the slice corresponding to the global max. How does the image look when you click at t = 0.16?

@larsoner
Copy link
Member Author

Try the example here morphed to fsaverage in either mode, clicking and the maps/time course should be broken

@larsoner
Copy link
Member Author

@jasmainak why in glass_brain mode are images resampled to the bg_img? I don't understand this bit. (For now I've removed the code for it since it did not seem to be useful.) I don't even see how bg_img would be useful, since in the plot_glass_brain docs it says that the image should be in MNI coords, but we do nothing to guarantee this.

We might want to use the given subject's talxfm to automagically transform the image, or -- probably safer -- add a big warning (with instructions for people on how to do the resampling themselves).

This doesn't really tell us why the morph to fsaverage clicking does not work properly, though, since fsaverage is in MNI space already... more work to be done there still. But at least the non-morphed versions seem to work well with the given changes (which mostly simplify things).

@jasmainak
Copy link
Member

@jasmainak why in glass_brain mode are images resampled to the bg_img? I don't understand this bit. (For now I've removed the code for it since it did not seem to be useful.) I don't even see how bg_img would be useful, since in the plot_glass_brain docs it says that the image should be in MNI coords, but we do nothing to guarantee this.

sorry for this. I will need to dig up a bit to figure out what was the exact reasoning at the time. But from what I seem to remember, the stc image was not in the same coordinate space as the T1, which is why you need to do this. Once you are in the same space as T1, then plot_stat_map and plot_glass_brain become equivalent.

We might want to use the given subject's talxfm to automagically transform the image, or -- probably safer -- add a big warning (with instructions for people on how to do the resampling themselves).

sure. I am always confused about the different coordinate systems. From what I can recall there was an interplay between 3 coordinate systems -- the one that the STC was in, then the T1 and then the one that nilearn expects the images to be in -- which is MNI? So, the talxfm is the transform that takes you from T1 to MNI, and is stored in the metadata of the T1 image?

@larsoner larsoner added the VIZ label Mar 27, 2019
@britta-wstnr
Copy link
Member

@jasmainak and @larsoner I went through quite some transformation matrix and coordinate system fun lately and would be happy to share my 2 cents at the sprint if desired? I also wrote a little snippet to add markers to volume plots (e.g., for marking simulation voxels etc.; however, with plot_stat_map), could be nice to have here, too?

@larsoner
Copy link
Member Author

I went through quite some transformation matrix and coordinate system fun lately and would be happy to share my 2 cents at the sprint if desired

Yes let's figure this out at the sprint after we complete The Great Beamformer Unification of 2019™

@lgtm-com
Copy link

lgtm-com bot commented Apr 27, 2019

This pull request introduces 1 alert when merging e7788e5 into 5d80e26 - view on LGTM.com

new alerts:

  • 1 for Unused import

Comment posted by LGTM.com

@lgtm-com
Copy link

lgtm-com bot commented Sep 5, 2019

This pull request introduces 1 alert and fixes 1 when merging 0a44aa8 into d1730ca - view on LGTM.com

new alerts:

  • 1 for Unused import

fixed alerts:

  • 1 for Wrong name for an argument in a call

@larsoner larsoner force-pushed the initial branch 2 times, most recently from 7f8e9d6 to 998e936 Compare September 5, 2019 20:38
@lgtm-com
Copy link

lgtm-com bot commented Sep 5, 2019

This pull request fixes 1 alert when merging 998e936 into 63e9ad2 - view on LGTM.com

fixed alerts:

  • 1 for Wrong name for an argument in a call

@larsoner larsoner changed the title WIP: Add initial arguments to vol viz MRG: Add initial arguments to vol viz Sep 11, 2019
@larsoner
Copy link
Member Author

larsoner commented Sep 11, 2019

This monster is finally done. There were several bugs (see changes/latest.inc), but to summarize:

  • glass_brain plotting assumes your data are in MNI coords, otherwise the overlay is wrong. So we modify img.affine to add an extra transformation to those coords.
  • stc_morph = SourceMorph.apply(stc) had stc_morph.vertices defined improperly (assuming Z, then Y, then X changed most rapidly, i.e. 'C' order, but the MNE-C code defines it using Fortran order)
  • glass_brain MIP picking function needed to make use of the voxel data orientation, which for fsaverage's T1 is LIA for example, to know which i/j/k dimension to look into, set, and display

Ready for review/merge from my end. Modified example showing correct plots for different combinations of stat_map, glass_brain, and passing morph:

https://15223-1301584-gh.circle-artifacts.com/0/dev/auto_examples/inverse/plot_lcmv_beamformer_volume.html#sphx-glr-auto-examples-inverse-plot-lcmv-beamformer-volume-py

@larsoner larsoner added this to the 0.19 milestone Sep 11, 2019
@lgtm-com
Copy link

lgtm-com bot commented Sep 11, 2019

This pull request introduces 3 alerts and fixes 1 when merging 773566a into 13c8e69 - view on LGTM.com

new alerts:

  • 1 for Unused import
  • 1 for Unreachable code
  • 1 for Variable defined multiple times

fixed alerts:

  • 1 for Wrong name for an argument in a call

Copy link
Member

@agramfort agramfort left a comment

Choose a reason for hiding this comment

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

maybe @jasmainak can have a look or test to confirm it works as expected? thanks !

@larsoner
Copy link
Member Author

Glass brain is almost "on fire". Not sure if it's this PR or this was always the case.

MIP can look that way when a lot of the brain is active. Center on the N100 peak and it looks more like what you're probably expecting.

do you think we should fix the ylim for the time series? It would be a bit misleading otherwise. Might be easy to include in this PR while you are already at it.

I can try some heuristic like 0.5 and 99.5th percentile of the data or something. I'll try some stuff and see if I can come up with something reasonable. Eventually we might want a time_ylim or something to allow fixing it manually

@larsoner
Copy link
Member Author

Rebased and pushed a commit to use the same ticks as the colorbar (improved consistency), and fix the ylim while browsing. If people want it to change to something else, they can use plt commands or manually change with the matplotlib interactive tools.

@lgtm-com
Copy link

lgtm-com bot commented Sep 13, 2019

This pull request fixes 1 alert when merging b8c52cb into 9585e93 - view on LGTM.com

fixed alerts:

  • 1 for Wrong name for an argument in a call

@larsoner
Copy link
Member Author

@jasmainak can you have another look?

@jasmainak
Copy link
Member

I'll take a look tomorrow!

@jasmainak
Copy link
Member

The ylim works beautifully but I have this issue on the mac when I try to zoom in:

Screen Shot 2019-09-14 at 8 06 52 PM

The butterfly plot however looks fine when I zoom in.

mne/viz/_3d.py Outdated Show resolved Hide resolved
@larsoner
Copy link
Member Author

Removed the problematic clip_on=False and improved doc description

@lgtm-com
Copy link

lgtm-com bot commented Sep 15, 2019

This pull request fixes 1 alert when merging 5ce5f19 into d9e2788 - view on LGTM.com

fixed alerts:

  • 1 for Wrong name for an argument in a call

stc.copy().crop(0.05, 0.18).plot(
src=morph, subject='fsaverage', subjects_dir=subjects_dir,
mode='stat_map', clim=dict(kind='value', pos_lims=lims),
initial_time=0.1, verbose=True)
Copy link
Member

Choose a reason for hiding this comment

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

why is this so slow compared to the other two plots? Does the morph do some computation on demand? It's a bit hard to interact with the time series on this one, specially if you click on a time point very close to the vertical line (maybe because the samples are far apart?).

That said, this PR is already a big improvement over what exists. So, feel free to merge it. I won't have time to look again the next 2 days.

@agramfort agramfort merged commit 951df43 into mne-tools:master Sep 15, 2019
@agramfort
Copy link
Member

thx @larsoner !

@larsoner larsoner deleted the initial branch September 15, 2019 13:19
alexrockhill pushed a commit to alexrockhill/mne-python that referenced this pull request Oct 1, 2019
* ENH: Add initial arguments to vol viz

* DOC: Links

* FIX: Fix for deprecation

* WIP

* FIX: Fix affine treatment and vertices order

* FIX: Adjust tests

* FIX: Flake

* FIX: Check

* BUG: Fix axis limits

* FIX: Clip and desc
DimitriPapadopoulos added a commit to DimitriPapadopoulos/mne-python that referenced this pull request Mar 22, 2023
`Forward` keys added by:
* 6d84371 / mne-tools#5840 / 2019-01-29

`SourceMorph` keys added by:
* 6d84371 / mne-tools#5840 / 2019-01-29
* b65a045 / mne-tools#6046 / 2019-09-15
DimitriPapadopoulos added a commit to DimitriPapadopoulos/mne-python that referenced this pull request Mar 22, 2023
dictionary key `name` repeated with different values

`Forward` keys added by:
* 6d84371 / mne-tools#5840 / 2019-01-29

`SourceMorph` keys added by:
* 6d84371 / mne-tools#5840 / 2019-01-29
* b65a045 / mne-tools#6046 / 2019-09-15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants