-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix issue where set ylim parameter gets swapped across channel types in plot_evoked_topo #9207
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
Conversation
|
In terms of the failed checks, I don't think it's related to any of the changes I've made in this PR.. |
|
any chance we can test this? |
|
Running the sample code from above on the main branch, back to back in different ipython instances should showcase the bug as it has an alternating pattern of either appearing . |
|
what I have in mind is update a test to check that the axes in the figure
have the correct ylim
for example
In [7]: fig, _ = plt.subplots(2, 2)
In [8]: for ax in fig.axes: print(ax.get_ylim())
(0.0, 1.0)
(0.0, 1.0)
(0.0, 1.0)
(0.0, 1.0)
… |
|
did you check that your fix also works for EEG? any potential simplification to the code will also be appreciated. Most of the set operations can possibly achieved with list comprehensions as well ... might save you the need to reorder post-hoc. Maybe something like: chs_in_layout = [ch_name for ch_name in ch_names if ch_name in layout.names] |
|
EEG works fine. Looks like there was minor bug introduced from PR #9162 for EEG plots. Converting the set operation into a list comprehension reduces the randomness of the bug from a 50:50 to a 1 in 5 chance of occurring. The randomness still seems to turn up from setting types_used . |
Let me try adding a test for this ! |
|
I've tried to simplify the whole zipping and unzipping process involved with ylims in relation to meg data specifically , by removing as much of the zip objects as possible. |
Sorry to be a pain, but does this work for fNIRS data? Similar to MEG with mag/grad there are multiple types for fNIRS hbo/hbr often in the same raw structure. See here for example of how to create this data type...
If you're unable to check then let me know and I'll validate in a few weeks. |
So the fix itself doesn't affect fnirs plotting, but it looks like it has a similar issue of channel swapping arising from the same line of setting types used. For the current PR , I just swapped the limits around if it comes out the wrong way for meg data alone. For my fNIRS testing, I used a combination of hbo and hbr and noticed this issue. Since there are four possible channel types with fNIRS, I might need some clarification over the combination of channel types possible with fNIRS to implement a similar fix for it. |
|
For the different possible fNIRS channel type combinations, I can see hbo and hbr being plotted together from the same raw structure. Can 'fnirs_cw_amplitude', 'fnirs_od'be plotted together and can they be individually used with either hbo or hbr? @rob-luke |
|
Thanks for looking in to this!
Good question. Only hbo and hbr are stored/plotted together. We do not support amplitude and od in the same raw structure. Nor do we support a mix of all 4 types. |
|
In that case, the last commit (34a0e20) should deal with similar random swapping across channel types for fNIRS data as well |
|
Still, needs a test built for checking ylims from the plotted figure. |
|
Cheers! That initial ylim confusion we had during the sprint has really led down a rabbit hole. Thanks for fixing this for the extra types too. |
|
Ahh, I think there's still a couple of issues left in |
|
So I've been trying to build a test for this but can't find a way to unpack the figure object or specifically the axes object from inside the figure object that's returned by fig,ax= plot_topo(evoked,ylim=dict(mag=[-10, 10],grad=[-100,100]))I've tried a couple of approaches like the above with the figure object and even the Any tips on how to unpack the figure object would be helpful! |
|
@ramkpari floated the idea of a however, I propose we keep the ball moving with the following actions in order:
how does that sound to you @agramfort ? |
Co-authored-by: Mainak Jas <jasmainak@users.noreply.github.com>
remove randomness
|
So digging deeper into the source of randomness, it turns out it was the set comprehension that was the root cause of the randomness. From Python 3.3, The current fix replaces the set comprehension with a list comprehension and also the set operations with equivalent lambda based list filter operations. References |
|
great sleuthing @ramkpari if you can clean up this PR to remove the swapping and use list comprehension wherever possible (instead of lambda filtering), I think it's good to go for me |
jasmainak
left a comment
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.
All good by me
I let @larsoner or @agramfort merge
agramfort
left a comment
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.
just a tiny cosmit suggestion.
we give up on a test @jasmainak ?
Co-authored-by: Alexandre Gramfort <alexandre.gramfort@m4x.org>
|
I'm not entirely sure if the ci doc build fails is related to the last commit. |
It's being worked on in #9274 |
for now yes. Let's move on and I suggest we revisit this in a later PR |
|
thanks @ramkpari ! |
* upstream/main: MRG: Return empty list of SSP projectors if no ECG, EOG events were found (mne-tools#9277) Better warning message for EDF files with annotations only (mne-tools#9283) FIX: Link [ci skip] FIX: Prepare for PyVista 0.30.0 (mne-tools#9274) Use info for checking more NIRS metadata, not raw (mne-tools#9282) MRG: Use info for checking NIRS metadata, not raw (mne-tools#9280) Fix issue where set ylim parameter gets swapped across channel types in plot_evoked_topo (mne-tools#9207)
Fixes an issue where ylims could get swapped across meg channel types in
plot_evoked_topo.In the current build, this bug has a 50% of occurring and can be replicated by running the following code back to back .
What does this implement/fix?
Implements an extra check to flip the order inside
types_usedonly if required.Additional information
The specific bug occurs due to the randomness of output from line 717 in
mne/viz/topo.py.The particular line has a 50: 50 chance to output either
[mag,grad]or[grad,mag]for the provided example.Line 727 converts it into a list and flips the order regardless of the order of input for
types_used. The proposed fix adds an additional check to perform the flip only the list is not in the expected order.