Skip to content

MaxwellIO: Fix issue due to disparity between routed and mapped channels #1703

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

LeMuellerGuy
Copy link

As mentioned in #1702, there can be a potential disparity between the list of mapped channels and routed channels when using stimulation electrodes. This PR attempts to fix this by ignoring the additional electrodes since they have no data associated to them/ neo can currently only pull data from the routed group. I don't know if there can be additional groups in the data though.

Update mask to only allow unique electrodes to pass in addition to filtering out non-routed electrodes
Copy link
Contributor

@zm711 zm711 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @LeMuellerGuy!

I have a couple more stylistic comments to go through. And also a general preference to use channel_ids and electrode_ids here in the function to be explicit as possible.

Otherwise I ran testing so we will make sure this current iteration doesn't break on our test files.

Is there anyway you can generate a really small test file (<10MB that can be junk data) that we could add to our test suite to make sure your fix works?

@@ -65,6 +65,19 @@ def __init__(self, filename="", rec_name=None):

def _source_name(self):
return self.filename

def _get_ids_and_electrodes(self, version, stream_id, h5file, mapping):
if int(version) == 20160704:
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you document where this version number comes from in a comment? Was this dev docs etc. I think knowing magic numbers at all times.

Copy link
Author

Choose a reason for hiding this comment

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

I took the version number from the existing code. My best guess is that it is actually the release date of the first file version, where the structure was a little different. Our lab works with the MaxTwo device which was released later on so I assume that it never used this version because it needs additional fields to correctly represent the multiple wells of the MaxTwo device. There is also an option for legacy data formats in the software supplied by maxwell, so I assume it must be that.

else:
ids = np.array(h5file["wells"][stream_id][self.rec_name]["groups"]["routed"]["channels"])
els = np.array(mapping["electrode"])
ids = ids[ids >= 0]
Copy link
Contributor

Choose a reason for hiding this comment

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

what does an id < 0 mean in this case ?
I see we do the same thing in the old code, but since I don't work on this reader much I would love to know what this means.

Copy link
Author

Choose a reason for hiding this comment

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

This was also taken from the existing code and I can only guess what it means. I know that the spike files can contain negative timestamps relative to the starting time so I wouldn't put it beyond them to also have negative channel numbers in some scenarios, but I personally haven't encountered them yet. Maybe that is also something occuring in the older data format.

ids = np.array(h5file["wells"][stream_id][self.rec_name]["groups"]["routed"]["channels"])
els = np.array(mapping["electrode"])
ids = ids[ids >= 0]
mask = np.unique(mapping["channel"][np.isin(np.array(mapping["channel"]), ids)],
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer to break this up into a couple lines because it is really hard to follow the logic when everything is chained together.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not highlighting the line I wanted it to. I meant for line 77 it is really chained logic.

Copy link
Author

Choose a reason for hiding this comment

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

Totally understandable, I tried to split it into two. Maybe you have a more expressive variable name for the masks created.

@zm711 zm711 changed the title Fix issue due to disparity between routed and mapped channels MaxwellIO: Fix issue due to disparity between routed and mapped channels May 10, 2025
@zm711
Copy link
Contributor

zm711 commented May 10, 2025

The PR name change was just because it is easier for me to make our release notes if I can quickly glance to see which IOs have been worked on :)

Stylistic cleanup
@LeMuellerGuy
Copy link
Author

Hi Zach,
I tried to answer your comments and improve the style of the code a little. I'm pretty new to creating PRs on public repos so I'm guessing that I didn't use the review feature correctly and just commited a new file version. I hope you can still see the changes.

You're also on the probeinterface team right? Because I noticed that this issue propagates to probeinterface as well so I'll open a similar PR there too.

I'll try and "filet" a piece out of the dataset. I think it should be possible.

@LeMuellerGuy
Copy link
Author

Hey again,

I created a data slice that basically represent a single well, single segment recording that contains the mismatch between routed channels and mapped channels. It's only 100 datapoints long, but I can make it longer if you like.
If you inspect the file using https://myhdf5.hdfgroup.org/ (or any tool of your choice) and navigate into the data_store/data0000/routed/raw group you can see that the channels array has 998 entries but data_store/data0000/settings/mapping is actually 1000 entries long due to 2 duplicate channels.

data_slice.raw.h5.zip

@LeMuellerGuy
Copy link
Author

LeMuellerGuy commented May 11, 2025

Hey again,

I had the time to do some further investigation on my file. It seems to be the case that the issue always takes the form that two channels can be mapped to the same two electrodes. There can also be more than one pair of these duplicates per recording segment.

Initially I thought that this would be physically impossible for the device but after looking into the data, I am not quite sure about this anymore so it is be possible that the mapping file is indeed correct. I'm not sure how neo would navigate a surjective mapping of channels to electrodes since that is usually not a very useful situation.

I'll do some further digging once I get back to the lab tomorrow but for now I'd put this PR on ice until I found the source of this issue in the device and can give more insight into how to navigate the situation. Maybe this results in a more meaningful error message for future users.

@zm711
Copy link
Contributor

zm711 commented May 11, 2025

Sounds good @LeMuellerGuy thanks for checking on that. It does seem a bit strange unless it really is a recording electrode and a stimulating electrode being associated with the same channel. But even then we would expect the need to unpack the two different information streams in order to be useful. Just ping us when you have some more info!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants