Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #518 from SpikeInterface/fix_h5_sorted
Browse files Browse the repository at this point in the history
Fix h5 unsorted channel_ids in get_traces
  • Loading branch information
alejoe91 authored Dec 8, 2020
2 parents c8a7fb8 + 2946f9b commit c935458
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ def get_sampling_frequency(self):
def get_traces(self, channel_ids=None, start_frame=None, end_frame=None):
if np.array(channel_ids).size > 1:
if np.any(np.diff(channel_ids) < 0):
sorted_idx = np.argsort(channel_ids)
recordings = self._signals[np.sort(channel_ids), start_frame:end_frame]
return (recordings[sorted_idx] * self._lsb).astype('float')
sorted_channel_ids = np.sort(channel_ids)
sorted_idx = np.array([list(sorted_channel_ids).index(ch) for ch in channel_ids])
recordings = (self._signals[sorted_channel_ids, start_frame:end_frame] * self._lsb).astype('float32')
return recordings[sorted_idx]
else:
return (self._signals[np.array(channel_ids), start_frame:end_frame] * self._lsb).astype('float32')
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ def get_traces(self, channel_ids=None, start_frame=None, end_frame=None):

if np.array(channel_idxs).size > 1:
if np.any(np.diff(channel_idxs) < 0):
sorted_idx = np.argsort(channel_idxs)
recordings = stream.get('ChannelData')[np.sort(channel_idxs), start_frame:end_frame]
sorted_channel_ids = np.sort(channel_idxs)
sorted_idx = np.array([list(sorted_channel_ids).index(ch) for ch in channel_idxs])
recordings = stream.get('ChannelData')[sorted_channel_ids, start_frame:end_frame]
return recordings[sorted_idx] * conv
else:
return stream.get('ChannelData')[np.sort(channel_idxs), start_frame:end_frame] * conv
Expand Down
7 changes: 4 additions & 3 deletions spikeextractors/extractors/mea1kextractors/mea1kextractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ def get_sampling_frequency(self):
def get_traces(self, channel_ids=None, start_frame=None, end_frame=None):
if np.array(channel_ids).size > 1:
if np.any(np.diff(channel_ids) < 0):
sorted_idx = np.argsort(channel_ids)
recordings = self._signals[np.sort(channel_ids), start_frame:end_frame]
return recordings[sorted_idx].astype('float')
sorted_channel_ids = np.sort(channel_ids)
sorted_idx = np.array([list(sorted_channel_ids).index(ch) for ch in channel_ids])
recordings = (self._signals[sorted_channel_ids, start_frame:end_frame] * self._lsb).astype('float32')
return recordings[sorted_idx]
else:
return (self._signals[np.array(channel_ids), start_frame:end_frame] * self._lsb).astype('float32')
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@ def get_sampling_frequency(self):
@check_get_traces_args
def get_traces(self, channel_ids=None, start_frame=None, end_frame=None):
if np.any(np.diff(channel_ids) < 0):
sorted_idx = np.argsort(channel_ids)
recordings = self._recordings[start_frame:end_frame, np.sort(channel_ids)]
return np.array(recordings[sorted_idx]).transpose()
sorted_channel_ids = np.sort(channel_ids)
sorted_idx = np.array([list(sorted_channel_ids).index(ch) for ch in channel_ids])
recordings = self._recordings[start_frame:end_frame, sorted_channel_ids]
return np.array(recordings[:, sorted_idx]).T
else:
if sorted(channel_ids) == channel_ids and np.all(np.diff(channel_ids) == 1):
channel_ids = slice(channel_ids[0], channel_ids[0] + len(channel_ids))
return np.array(self._recordings[start_frame:end_frame, channel_ids]).transpose()
return np.array(self._recordings[start_frame:end_frame, channel_ids]).T

@staticmethod
def write_recording(recording, save_path, check_suffix=True):
Expand Down
5 changes: 3 additions & 2 deletions spikeextractors/extractors/nwbextractors/nwbextractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,9 @@ def get_traces(self, channel_ids=None, start_frame=None, end_frame=None):
if np.array(channel_ids).size > 1 and np.any(np.diff(channel_ids) < 0):
# get around h5py constraint that it does not allow datasets
# to be indexed out of order
sorted_idx = np.argsort(channel_inds)
recordings = es.data[start_frame:end_frame, np.sort(channel_inds)].T
sorted_channel_ids = np.sort(channel_ids)
sorted_idx = np.array([list(sorted_channel_ids).index(ch) for ch in channel_ids])
recordings = es.data[start_frame:end_frame, sorted_channel_ids].T
traces = recordings[sorted_idx, :]
else:
traces = es.data[start_frame:end_frame, channel_inds].T
Expand Down

0 comments on commit c935458

Please sign in to comment.