Skip to content

Commit

Permalink
Merge pull request #1532 from zm711/biocam-slice
Browse files Browse the repository at this point in the history
BiocamRawIO: Fix case where slice is given to `get_analogsignal_chunk`
  • Loading branch information
alejoe91 authored Aug 27, 2024
2 parents ac881dd + a0efaa1 commit 0f770e3
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions neo/rawio/biocamrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,28 +136,36 @@ def _get_analogsignal_chunk(self, block_index, seg_index, i_start, i_stop, strea

# newer style data returns an initial flat array (n_samples * n_channels)
# we iterate through channels rather than slicing
# Due to the fact that Neo and SpikeInterface tend to prefer slices we need to add
# some careful checks around slicing of None in the case we need to iterate through
# channels. First check if None. Then check if slice and only if slice check that it is slice(None)
else:
if channel_indexes is None:
channel_indexes = [ch for ch in range(self._num_channels)]
elif isinstance(channel_indexes, slice):
start = channel_indexes.start or 0
stop = channel_indexes.stop or self._num_channels
step = channel_indexes.step or 1
channel_indexes = [ch for ch in range(start, stop, step)]

sig_chunk = np.zeros((i_stop-i_start, len(channel_indexes)))
sig_chunk = np.zeros((i_stop - i_start, len(channel_indexes)))
# iterate through channels to prevent loading all channels into memory which can cause
# memory exhaustion. See https://github.com/SpikeInterface/spikeinterface/issues/3303
for index, channel_index in enumerate(channel_indexes):
sig_chunk[:, index] = data[channel_index::self._num_channels]
sig_chunk[:, index] = data[channel_index :: self._num_channels]

return sig_chunk


def open_biocam_file_header(filename)-> dict:
def open_biocam_file_header(filename) -> dict:
"""Open a Biocam hdf5 file, read and return the recording info, pick the correct method to access raw data,
and return this to the caller
Parameters
----------
filename: str
The file to be parsed
Returns
-------
dict
Expand Down Expand Up @@ -244,7 +252,7 @@ def open_biocam_file_header(filename)-> dict:
num_channels_x = num_channels_y = int(np.sqrt(num_channels))
else:
raise NeoReadWriteError("No Well found in the file")

if num_channels_x * num_channels_y != num_channels:
raise NeoReadWriteError(f"Cannot determine structure of the MEA plate with {num_channels} channels")
channels = 1 + np.concatenate(np.transpose(np.meshgrid(range(num_channels_x), range(num_channels_y))))
Expand All @@ -268,6 +276,7 @@ def open_biocam_file_header(filename)-> dict:
######################################################################
# Helper functions to obtain the raw data split by Biocam version.


# return the full array for the old datasets
def readHDF5t_100(rf, t0, t1, nch):
return rf["3BData/Raw"][t0:t1]
Expand Down

0 comments on commit 0f770e3

Please sign in to comment.