From 28af3ec63164e0f3df32c661e9612cc6a6015b73 Mon Sep 17 00:00:00 2001 From: hornauerp <57408359+hornauerp@users.noreply.github.com> Date: Mon, 24 Jul 2023 13:12:44 +0200 Subject: [PATCH 1/2] Fixed bug in maxwellrawio.py that shuffled channels Fix for issue https://github.com/SpikeInterface/spikeinterface/issues/1691 that reshuffled channels when selecting and concatenating channels from MaxWell recordings. --- neo/rawio/maxwellrawio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo/rawio/maxwellrawio.py b/neo/rawio/maxwellrawio.py index d014a2b73..6b7993889 100644 --- a/neo/rawio/maxwellrawio.py +++ b/neo/rawio/maxwellrawio.py @@ -185,7 +185,7 @@ def _get_analogsignal_chunk(self, block_index, seg_index, i_start, i_stop, # to be indexed out of order sorted_channel_indexes = np.sort(channel_indexes) resorted_indexes = np.array( - [list(channel_indexes).index(ch) for ch in sorted_channel_indexes]) + [list(sorted_channel_indexes).index(ch) for ch in channel_indexes]) try: if resorted_indexes is None: From d97fe0c0c5007c52082322da2b61f2a9fc91b10c Mon Sep 17 00:00:00 2001 From: hornauerp <57408359+hornauerp@users.noreply.github.com> Date: Mon, 24 Jul 2023 17:38:34 +0200 Subject: [PATCH 2/2] More optimal bug fix --- neo/rawio/maxwellrawio.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/neo/rawio/maxwellrawio.py b/neo/rawio/maxwellrawio.py index 6b7993889..10b0e9819 100644 --- a/neo/rawio/maxwellrawio.py +++ b/neo/rawio/maxwellrawio.py @@ -183,9 +183,10 @@ def _get_analogsignal_chunk(self, block_index, seg_index, i_start, i_stop, if np.array(channel_indexes).size > 1 and np.any(np.diff(channel_indexes) < 0): # get around h5py constraint that it does not allow datasets # to be indexed out of order - sorted_channel_indexes = np.sort(channel_indexes) - resorted_indexes = np.array( - [list(sorted_channel_indexes).index(ch) for ch in channel_indexes]) + order_f = np.argsort(channel_indexes) + sorted_channel_indexes = channel_indexes[order_f] + # use argsort again on order_f to obtain resorted_indexes + resorted_indexes = np.argsort(order_f) try: if resorted_indexes is None: