Closed alexk101 closed 9 months ago
Another note, this behavior is also present in the function
With half of the peak spectral power matrix being empty (0). The looping structure is the same as in the previously mentioned window sci function
@alexk101 thanks for the thorough analysis, sounds like you're right. And also like our tests are not complete enough. A bunch of zeros appearing in the output should probably should have started failing!
@alexk101 are you up for making a PR to take a stab at fixing this?
@larsoner The changes have been made and are correct (afaik). CI is failing on some other unrelated things though.
Describe the bug
This bug has to do with upstream changes in the MNE package that were never propagated to this project in the function.
https://github.com/mne-tools/mne-nirs/blob/3ba42cd47bb4f5e6bc6c15d4677bb2b2177cb6ae/mne_nirs/preprocessing/_scalp_coupling_segmented.py#L16
I believe that when this function was originally written ~3 years ago, that some assumptions were made about the order of channel names which no longer hold true, or perhaps never did, though I am not sure. Looking at a similar function which does this in the main MNE package at the overall channel level (ie not windowed), the method by which channels are looped over is quite different, with the non-windowed function looping this way
https://github.com/mne-tools/mne-python/blob/195a2cc8009160fd125e355b0280e903a941c874/mne/preprocessing/nirs/_scalp_coupling_index.py#L63
and the broken windowed function looping this way
https://github.com/mne-tools/mne-nirs/blob/3ba42cd47bb4f5e6bc6c15d4677bb2b2177cb6ae/mne_nirs/preprocessing/_scalp_coupling_segmented.py#L95
The reason I say that this is broken is because when using this function to calculate the windowed sci for my data, half of the matrix is empty. Looking at this initially, I thought that my channels may just be really bad, but looking at the signal by hand, I can see a very clear heartbeat, but a zero in every entry for that channel in sci. Looking even more closely, the channels which are empty are never visited during the previously mentioned loop.
I rewrote this function to be in line with the non-windowed sci function in the main mne repo, and it fully populates the matrix, though I am unsure of the correctness. I can open a pull request with that change if the maintainers would like.
Steps to reproduce
2024-01-19_007.snirf.zip
Expected results
The score matrix should be fully populated for all channels.
Actual results
Half of the score matrix is 0, having never been visited during the traversal of channels in
scalp_coupling_index_windowed