|
23 | 23 | from urllib.request import urlopen |
24 | 24 |
|
25 | 25 | from .baserawio import (BaseRawIO, _signal_channel_dtype, _signal_stream_dtype, |
26 | | - _spike_channel_dtype, _event_channel_dtype) |
| 26 | + _spike_channel_dtype, _event_channel_dtype) |
27 | 27 |
|
28 | 28 | import numpy as np |
29 | 29 |
|
@@ -75,13 +75,15 @@ def _parse_header(self): |
75 | 75 | rec_names = list(h5['wells'][stream_id].keys()) |
76 | 76 | if len(rec_names) > 1: |
77 | 77 | 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}") |
80 | 81 | else: |
81 | 82 | self.rec_name = rec_names[0] |
82 | 83 | signal_streams.append((stream_id, stream_id)) |
83 | 84 | else: |
84 | | - raise NotImplementedError(f'This version {version} is not supported') |
| 85 | + raise NotImplementedError( |
| 86 | + f'This version {version} is not supported') |
85 | 87 | signal_streams = np.array(signal_streams, dtype=_signal_stream_dtype) |
86 | 88 |
|
87 | 89 | # create signal channels |
@@ -185,15 +187,31 @@ def _get_analogsignal_chunk(self, block_index, seg_index, i_start, i_stop, |
185 | 187 | if i_stop is None: |
186 | 188 | i_stop = sigs.shape[1] |
187 | 189 |
|
| 190 | + resorted_indexes = None |
188 | 191 | if channel_indexes is None: |
189 | 192 | 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]) |
190 | 200 |
|
191 | 201 | 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] |
195 | 208 | 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] |
197 | 215 | except OSError as e: |
198 | 216 | print('*' * 10) |
199 | 217 | print(_hdf_maxwell_error) |
|
0 commit comments