Skip to content

Commit e167f9d

Browse files
committed
Sort and re-sort maxwell indices in case they are not sorted
1 parent 3940b2d commit e167f9d

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

neo/rawio/maxwellrawio.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from urllib.request import urlopen
2424

2525
from .baserawio import (BaseRawIO, _signal_channel_dtype, _signal_stream_dtype,
26-
_spike_channel_dtype, _event_channel_dtype)
26+
_spike_channel_dtype, _event_channel_dtype)
2727

2828
import numpy as np
2929

@@ -76,12 +76,13 @@ def _parse_header(self):
7676
if len(rec_names) > 1:
7777
if self.rec_name is None:
7878
raise ValueError("Detected multiple recordings. Please select a single recording using"
79-
f' the `rec_name` paramter.\nPossible rec_name {rec_names}')
79+
f' the `rec_name` paramter.\nPossible rec_name {rec_names}')
8080
else:
8181
self.rec_name = rec_names[0]
8282
signal_streams.append((stream_id, stream_id))
8383
else:
84-
raise NotImplementedError(f'This version {version} is not supported')
84+
raise NotImplementedError(
85+
f'This version {version} is not supported')
8586
signal_streams = np.array(signal_streams, dtype=_signal_stream_dtype)
8687

8788
# create signal channels
@@ -185,15 +186,25 @@ def _get_analogsignal_chunk(self, block_index, seg_index, i_start, i_stop,
185186
if i_stop is None:
186187
i_stop = sigs.shape[1]
187188

189+
resorted_indexes = None
188190
if channel_indexes is None:
189191
channel_indexes = slice(None)
192+
else:
193+
if np.array(channel_indexes).size > 1 and np.any(np.diff(channel_indexes) < 0):
194+
# get around h5py constraint that it does not allow datasets
195+
# to be indexed out of order
196+
channel_indexes = np.sort(channel_indexes)
197+
resorted_indexes = np.array(
198+
[list(channel_indexes).index(ch) for ch in channel_indexes])
190199

191200
try:
192201
if self._old_format:
193202
sigs = sigs[self._channel_slice, i_start:i_stop]
194203
sigs = sigs[channel_indexes]
195204
else:
196205
sigs = sigs[channel_indexes, i_start:i_stop]
206+
if resorted_indexes is not None:
207+
sigs = sigs[resorted_indexes]
197208
except OSError as e:
198209
print('*' * 10)
199210
print(_hdf_maxwell_error)

0 commit comments

Comments
 (0)