Skip to content

Commit f7792e5

Browse files
authored
Merge pull request #1074 from alejoe91/maxwell_sorting
Sort and re-sort maxwell indices in case they are not sorted
2 parents 94a093b + 66797fa commit f7792e5

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

neo/rawio/maxwellrawio.py

Lines changed: 26 additions & 8 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

@@ -75,13 +75,15 @@ def _parse_header(self):
7575
rec_names = list(h5['wells'][stream_id].keys())
7676
if len(rec_names) > 1:
7777
if self.rec_name is None:
78-
raise ValueError("Detected multiple recordings. Please select a single recording using"
79-
f' the `rec_name` paramter.\nPossible rec_name {rec_names}')
78+
raise ValueError("Detected multiple recordings. Please select a "
79+
"single recording using the `rec_name` paramter. "
80+
f"Possible rec_name {rec_names}")
8081
else:
8182
self.rec_name = rec_names[0]
8283
signal_streams.append((stream_id, stream_id))
8384
else:
84-
raise NotImplementedError(f'This version {version} is not supported')
85+
raise NotImplementedError(
86+
f'This version {version} is not supported')
8587
signal_streams = np.array(signal_streams, dtype=_signal_stream_dtype)
8688

8789
# create signal channels
@@ -185,15 +187,31 @@ def _get_analogsignal_chunk(self, block_index, seg_index, i_start, i_stop,
185187
if i_stop is None:
186188
i_stop = sigs.shape[1]
187189

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

191201
try:
192-
if self._old_format:
193-
sigs = sigs[self._channel_slice, i_start:i_stop]
194-
sigs = sigs[channel_indexes]
202+
if resorted_indexes is None:
203+
if self._old_format:
204+
sigs = sigs[self._channel_slice, i_start:i_stop]
205+
sigs = sigs[channel_indexes]
206+
else:
207+
sigs = sigs[channel_indexes, i_start:i_stop]
195208
else:
196-
sigs = sigs[channel_indexes, i_start:i_stop]
209+
if self._old_format:
210+
sigs = sigs[self._channel_slice, i_start:i_stop]
211+
sigs = sigs[sorted_channel_indexes]
212+
else:
213+
sigs = sigs[sorted_channel_indexes, i_start:i_stop]
214+
sigs = sigs[resorted_indexes]
197215
except OSError as e:
198216
print('*' * 10)
199217
print(_hdf_maxwell_error)

0 commit comments

Comments
 (0)