From bc258f225431ffc36044b4e800180b5c767badd3 Mon Sep 17 00:00:00 2001 From: CodyCBakerPhD Date: Wed, 7 Jun 2023 01:50:59 +0000 Subject: [PATCH] sorting and icephys fixes --- .../ecephys/baserecordingextractorinterface.py | 6 +++--- .../tools/testing/data_interface_mixins.py | 16 ++++++++-------- tests/test_on_data/test_gin_icephys.py | 8 ++++---- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/neuroconv/datainterfaces/ecephys/baserecordingextractorinterface.py b/src/neuroconv/datainterfaces/ecephys/baserecordingextractorinterface.py index 5f8bcb764..86c0ea6c9 100644 --- a/src/neuroconv/datainterfaces/ecephys/baserecordingextractorinterface.py +++ b/src/neuroconv/datainterfaces/ecephys/baserecordingextractorinterface.py @@ -170,7 +170,7 @@ def set_aligned_timestamps(self, aligned_timestamps: np.ndarray): self.recording_extractor.set_times(times=aligned_timestamps) - def align_segment_timestamps(self, aligned_segment_timestamps: List[np.ndarray]): + def set_aligned_segment_timestamps(self, aligned_segment_timestamps: List[np.ndarray]): """ Replace all timestamps for all segments in this interface with those aligned to the common session start time. @@ -197,7 +197,7 @@ def align_starting_time(self, starting_time: float): if self._number_of_segments == 1: self.set_aligned_timestamps(aligned_timestamps=self.get_timestamps() + starting_time) else: - self.align_segment_timestamps( + self.set_aligned_segment_timestamps( aligned_segment_timestamps=[ segment_timestamps + starting_time for segment_timestamps in self.get_timestamps() ] @@ -225,7 +225,7 @@ def align_segment_starting_times(self, segment_starting_times: List[float]): segment_timestamps + segment_starting_time for segment_timestamps, segment_starting_time in zip(self.get_timestamps(), segment_starting_times) ] - self.align_segment_timestamps(aligned_segment_timestamps=aligned_segment_timestamps) + self.set_aligned_segment_timestamps(aligned_segment_timestamps=aligned_segment_timestamps) def align_by_interpolation( self, diff --git a/src/neuroconv/tools/testing/data_interface_mixins.py b/src/neuroconv/tools/testing/data_interface_mixins.py index d5849116a..4e56e2019 100644 --- a/src/neuroconv/tools/testing/data_interface_mixins.py +++ b/src/neuroconv/tools/testing/data_interface_mixins.py @@ -323,7 +323,7 @@ def check_interface_set_aligned_timestamps(self): ] self.interface.set_aligned_timestamps(aligned_timestamps=all_aligned_segment_timestamps) - def check_interface_align_segment_timestamps(self): + def check_interface_set_aligned_segment_timestamps(self): self.setUpFreshInterface() random_number_generator = np.random.default_rng(seed=0) @@ -333,7 +333,7 @@ def check_interface_align_segment_timestamps(self): all_aligned_segment_timestamps = [ unaligned_timestamps + 1.23 + random_number_generator.random(size=unaligned_timestamps.shape) ] - self.interface.align_segment_timestamps(aligned_segment_timestamps=all_aligned_segment_timestamps) + self.interface.set_aligned_segment_timestamps(aligned_segment_timestamps=all_aligned_segment_timestamps) retrieved_aligned_timestamps = self.interface.get_timestamps() assert_array_equal(x=retrieved_aligned_timestamps, y=all_aligned_segment_timestamps[0]) @@ -343,7 +343,7 @@ def check_interface_align_segment_timestamps(self): unaligned_timestamps + 1.23 + random_number_generator.random(size=unaligned_timestamps.shape) for unaligned_timestamps in all_unaligned_timestamps ] - self.interface.align_segment_timestamps(aligned_segment_timestamps=all_aligned_segment_timestamps) + self.interface.set_aligned_segment_timestamps(aligned_segment_timestamps=all_aligned_segment_timestamps) all_retrieved_aligned_timestamps = self.interface.get_timestamps() for retrieved_aligned_timestamps, aligned_segment_timestamps in zip( @@ -438,7 +438,7 @@ def test_interface_alignment(self): self.check_interface_get_original_timestamps() self.check_interface_get_timestamps() self.check_interface_set_aligned_timestamps() - self.check_interface_align_segment_timestamps() + self.check_interface_set_aligned_segment_timestamps() self.check_shift_timestamps_by_start_time() self.check_shift_segment_timestamps_by_starting_times() self.check_interface_original_timestamps_inmutability() @@ -473,7 +473,7 @@ def check_read_nwb(self, nwbfile_path: str): ) check_sortings_equal(SX1=sorting_renamed, SX2=nwb_sorting) - def check_interface_align_segment_timestamps(self): + def check_interface_set_aligned_segment_timestamps(self): self.setUpFreshInterface() if self.interface.sorting_extractor.has_recording(): @@ -484,7 +484,7 @@ def check_interface_align_segment_timestamps(self): all_aligned_segment_timestamps = [ unaligned_timestamps + 1.23 + random_number_generator.random(size=unaligned_timestamps.shape) ] - self.interface.align_segment_timestamps(aligned_segment_timestamps=all_aligned_segment_timestamps) + self.interface.set_aligned_segment_timestamps(aligned_segment_timestamps=all_aligned_segment_timestamps) retrieved_aligned_timestamps = self.interface.get_timestamps() assert_array_equal(x=retrieved_aligned_timestamps, y=all_aligned_segment_timestamps[0]) @@ -494,7 +494,7 @@ def check_interface_align_segment_timestamps(self): unaligned_timestamps + 1.23 + random_number_generator.random(size=unaligned_timestamps.shape) for unaligned_timestamps in all_unaligned_timestamps ] - self.interface.align_segment_timestamps(aligned_segment_timestamps=all_aligned_segment_timestamps) + self.interface.set_aligned_segment_timestamps(aligned_segment_timestamps=all_aligned_segment_timestamps) all_retrieved_aligned_timestamps = self.interface.get_timestamps() for retrieved_aligned_timestamps, aligned_segment_timestamps in zip( @@ -544,7 +544,7 @@ def test_interface_alignment(self): # Skip get_original_timestamps() checks since unsupported self.check_interface_get_timestamps() self.check_interface_set_aligned_timestamps() - self.check_interface_align_segment_timestamps() + self.check_interface_set_aligned_segment_timestamps() self.check_shift_timestamps_by_start_time() self.check_shift_segment_timestamps_by_starting_times() diff --git a/tests/test_on_data/test_gin_icephys.py b/tests/test_on_data/test_gin_icephys.py index 8aaa573bf..fb460e1b6 100644 --- a/tests/test_on_data/test_gin_icephys.py +++ b/tests/test_on_data/test_gin_icephys.py @@ -65,10 +65,10 @@ class TestIcephysNwbConversions(unittest.TestCase): def check_align_starting_time(self): # TODO - use the mixin class in the future fresh_interface = self.data_interface_cls(file_paths=self.file_paths) - global_starting_time = 1.23 + starting_time = 1.23 relative_segment_starting_times = [[0.1]] fresh_interface.align_segment_starting_times(segment_starting_times=relative_segment_starting_times) - fresh_interface.align_global_starting_time(global_starting_time=global_starting_time) + fresh_interface.align_starting_time(starting_time=starting_time) neo_reader_starting_times = [reader._t_starts for reader in fresh_interface.readers_list] expecting_starting_times = [[1.33]] @@ -116,8 +116,8 @@ class TestConverter(NWBConverter): # Test number of traces = n_electrodes * n_segments npt.assert_equal(len(nwbfile.acquisition), n_electrodes * n_segments) - self.check_align_global_starting_time() - self.check_align_starting_times() + self.check_align_starting_time() + self.check_align_segment_starting_times() if __name__ == "__main__":