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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions neo/rawio/maxwellrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ 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.

channel_ids = np.array(mapping["channel"])
electrode_ids = np.array(mapping["electrode"])
else:
channel_ids = np.array(h5file["wells"][stream_id][self.rec_name]["groups"]["routed"]["channels"])
electrode_ids = np.array(mapping["electrode"])
channel_ids = channel_ids[channel_ids >= 0]
routed_channel_ids_mask = np.isin(np.array(mapping["channel"]), channel_ids)
unique_channel_ids_mask = np.unique(mapping["channel"][routed_channel_ids_mask],
return_index=True)[1]
return channel_ids, electrode_ids[unique_channel_ids_mask]


def _parse_header(self):
import h5py
Expand Down Expand Up @@ -175,11 +189,7 @@ def _parse_header(self):
}
self._stream_buffer_slice[stream_id] = slice(None)

channel_ids = np.array(mapping["channel"])
electrode_ids = np.array(mapping["electrode"])
mask = channel_ids >= 0
channel_ids = channel_ids[mask]
electrode_ids = electrode_ids[mask]
channel_ids, electrode_ids = self._get_ids_and_electrodes(version, stream_id, h5file, mapping)

for i, chan_id in enumerate(channel_ids):
elec_id = electrode_ids[i]
Expand Down