-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix fnirs channel name cropping in topomap combination #11138
base: main
Are you sure you want to change the base?
Conversation
Hello! 👋 Thanks for opening your first pull request here! ❤️ We will try to get back to you soon. 🚴🏽♂️ |
mne/viz/topomap.py
Outdated
@@ -167,6 +167,7 @@ def _average_fnirs_overlaps(info, ch_type, sphere): | |||
# first listed channel is the one to be replaced with merge | |||
overlapping_set = [chs[i]['ch_name'] for i in | |||
np.where(overlapping_mask[chan_idx])[0]] | |||
overlapping_set = np.array(overlapping_set).astype('>U20') |
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 would even use lists here to avoid issues cause 20 might be too small too for some people
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.
agree that the better fix is to keep overlapping_set
as a list until after the insertion (list.insert()
ought to work right?), and only then cast to array (if casting to array is even necessary?)
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.
Agree with this. I had been thinking the same thing, but had aimed to keep things as close as possible to original code.
Have updated the PR, now it aggregates a list in the loop, and converts to an array after the loop is finished.
committing @drammock's suggested change Co-authored-by: Daniel McCloy <[email protected]>
@JohnGriffiths looks reasonable, just two small remaining things:
I'll push a quick commit for these so that we can get this change into 1.2, which we're releasing imminently |
@JohnGriffiths can you check the "allow edits by maintainers" box? Then I can push my commit and we can merge |
(or fetch my branch and upstream, locally merge / rebase with |
@larsoner please merge this with |
... let's get this in early 1.3 rather than last minute 1.2. No need to hold up the release process I think |
(we can always backport easily to a 1.2.1) |
Reference issue
Resolves a bug discovered whilst reviewing #11064
@rob-luke @larsoner
What does this implement/fix?
Explain your changes.
While testing out the #11064 I was having a recurrent issue that was quite subtle and tricky to pin down:
Essentially, it looks like this line
mne-python/mne/viz/topomap.py
Line 170 in aef4966
will lead to a cropping of the added channel name, if it is longer than the channel names of the other ones in the list, and consequently than the numpy array datatype will permit.
To properly reproduce this you would need to add a breakpoint at the above line, run the function, and monitor for when it attempts to combine channel names with differing lengths as described above. I don't have an example for that full use case, but here is the plain numpy for the scenario I have encountered, using the same variable names as the linked code:
Additional information
Not sure if the fix proposed is the ideal; setting datatype to '<U20' is just something relatively minimal that appears to work.
TBH the fact that numpy insert will mess with element contents like it does above seems pretty brittle and surprising to me.