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: Don't require specific order for fNIRS #10642

Merged
merged 8 commits into from
May 23, 2022
Merged

Conversation

larsoner
Copy link
Member

@larsoner larsoner commented May 17, 2022

  • Push commit that should be green that does some refactoring to use zip(picks[::2], picks[1::2])
  • Change _check_channels_ordered to return picks even if they aren't in matched pairs
  • Add tests that operating on reordered channels is the same as original order:
    • optical density
    • SCI
    • TDDR
    • beer_lambert

cc @rob-luke I'll ping you when this is ready to go

@larsoner
Copy link
Member Author

Okay @rob-luke I think this one is ready. I still think we could do some better refactoring of _check_channels_ordered, _channel_frequencies, _channel_chromophore, and _validate_nirs_info -- I think eventually ideally unifying within just _validate_nirs_info -- but for now this is probably good enough.

@rob-luke
Copy link
Member

Wow!! That was quick @larsoner

I'm currently in transit to the US and won't be able to review this for a few days. When's the 1.1 release scheduled for? I'd love to review, but will I be holding things up?

@larsoner
Copy link
Member Author

Tentatively the end of the month but we haven't really discussed it, so this week or next should work!

@larsoner
Copy link
Member Author

Argh I removed a bunch of the nominal channel stuff and it broke hitachi... I'll have to fix it.

@larsoner
Copy link
Member Author

@rob-luke this one is good to go

Copy link
Member

@rob-luke rob-luke left a comment

Choose a reason for hiding this comment

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

This is amazing @larsoner, thanks for tackling this.

Something we will want to support in the future is NIRS data with more than two frequencies of light. This is beyond the scope of this PR. But I wanted to raise it in advance incase it would change any of your design decisions here. I read the code with this in mind and nothing appears to block future extension.

With this PR can we now remove the following documentation?

.. note:: To provide a consistent interface across different measurement
devices and file types, MNE-Python uses a standard ordering of
channels. MNE-Python internally orders channels by ascending source
number. When there are multiple channels with the same source number,
they are ordered by ascending detector number. The ordering of
channels is done automatically when data is imported. Therefore,
the ordering of channels within MNE-Python may be different to what
was provided by the hardware vendor.

# .. warning:: The channels must be ordered in haemoglobin pairs, such that for
# a single channel all the types are in subsequent indices. The
# type order must be 'hbo' then 'hbr'.
# The data below is already in the correct order and may be
# used as a template for how data must be stored.
# If the order that your data is stored is different to the
# mandatory formatting, then you must first read the data with
# channel naming according to the data structure, then reorder
# the channels to match the required format.

mne/preprocessing/nirs/_beer_lambert_law.py Outdated Show resolved Hide resolved
@@ -59,19 +59,16 @@ def short_channels(info, threshold=0.01):
return source_detector_distances(info) < threshold


def _channel_frequencies(info, nominal=False):
def _channel_frequencies(info, *, throw_errors=True):
Copy link
Member

Choose a reason for hiding this comment

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

This argument is introduced but not used. I assume it is from an earlier implementation version and should be removed?

Suggested change
def _channel_frequencies(info, *, throw_errors=True):
def _channel_frequencies(info, *):

mne/preprocessing/nirs/nirs.py Outdated Show resolved Hide resolved
@larsoner
Copy link
Member Author

Something we will want to support in the future is NIRS data with more than two frequencies of light. This is beyond the scope of this PR. But I wanted to raise it in advance incase it would change any of your design decisions here. I read the code with this in mind and nothing appears to block future extension.

I think in the long term we should abandon the channel-name-based stuff altogether. It occurred to me while making this PR that we currently only use 9 entries in ch['loc'] (right?), so we could maybe use the last three entries to store the pairing (somehow) and the frequency. Or maybe better (less redundant) we could probably use np.allclose on a scipy.spatial.pdist of the [ch['loc'][:9] for ch in chs] to pair automatically based on locations, then all we need to store is the frequencies in ch['loc'][9] or something.

But yes I think this is future compatible in the sense that this moves us toward one centralized place where pairings are identified and returned in a way that you can just operate on zip(picks[::2], picks[1::2]) and be operating on pairs. 👍

I'll push a commit to hopefully take care of the above comments then merge when green!

@larsoner
Copy link
Member Author

Not enough sleep this weekend apparently... we already store the frequency, so maybe my next PR should be this automatic pairing based on chs['loc'] to avoid using channel names completely. Then people can name channels however they want in the future, which would be nice.

@larsoner larsoner merged commit f435846 into mne-tools:main May 23, 2022
@larsoner
Copy link
Member Author

In it goes, thanks for the quick review @rob-luke ! There might be some adjustments necessary at the MNE-NIRS end, do you have time to look there?

@larsoner larsoner deleted the order2 branch May 23, 2022 21:22
@rob-luke
Copy link
Member

There might be some adjustments necessary at the MNE-NIRS end, do you have time to look there?

I do, will do today.

On another note @larsoner, NIRx have changed the way they store triggers in their latest software version. I have been sent a file with their new format. I will open a PR today for this too, so that we can get this in for 1.1.

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