From d983d1cc82adce3eb1ec4e2cd81447f157d412ca Mon Sep 17 00:00:00 2001 From: Cody Baker Date: Wed, 7 Jun 2023 14:40:33 -0400 Subject: [PATCH] adjust align_starting_times to set_aligned_starting_times --- .../basetemporalalignmentinterface.py | 6 +- .../behavior/audio/audiointerface.py | 32 ++++----- .../behavior/video/videodatainterface.py | 20 +++--- .../baserecordingextractorinterface.py | 25 +++---- .../ecephys/basesortingextractorinterface.py | 33 ++++++---- .../icephys/abf/abfdatainterface.py | 20 +++--- .../icephys/baseicephysinterface.py | 2 +- .../text/timeintervalsinterface.py | 4 +- .../tools/testing/data_interface_mixins.py | 66 +++++++++++-------- .../test_temporal_alignment_methods.py | 20 +++--- 10 files changed, 126 insertions(+), 102 deletions(-) diff --git a/src/neuroconv/basetemporalalignmentinterface.py b/src/neuroconv/basetemporalalignmentinterface.py index 29108571d..ec77f7fdc 100644 --- a/src/neuroconv/basetemporalalignmentinterface.py +++ b/src/neuroconv/basetemporalalignmentinterface.py @@ -55,7 +55,7 @@ def set_aligned_timestamps(self, aligned_timestamps: np.ndarray): "The protocol for synchronizing the timestamps of this interface has not been specified!" ) - def align_starting_time(self, starting_time: float): + def set_aligned_starting_time(self, aligned_starting_time: float): """ Align the starting time for this interface relative to the common session start time. @@ -63,10 +63,10 @@ def align_starting_time(self, starting_time: float): Parameters ---------- - starting_time : float + aligned_starting_time : float The starting time for all temporal data in this interface. """ - self.set_aligned_timestamps(aligned_timestamps=self.get_timestamps() + starting_time) + self.set_aligned_timestamps(aligned_timestamps=self.get_timestamps() + aligned_starting_time) def align_by_interpolation(self, unaligned_timestamps: np.ndarray, aligned_timestamps: np.ndarray): """ diff --git a/src/neuroconv/datainterfaces/behavior/audio/audiointerface.py b/src/neuroconv/datainterfaces/behavior/audio/audiointerface.py index 2b2c08702..d9134e8a2 100644 --- a/src/neuroconv/datainterfaces/behavior/audio/audiointerface.py +++ b/src/neuroconv/datainterfaces/behavior/audio/audiointerface.py @@ -98,7 +98,7 @@ def get_timestamps(self) -> Optional[np.ndarray]: def set_aligned_timestamps(self, aligned_timestamps: List[np.ndarray]): raise NotImplementedError("The AudioInterface does not yet support timestamps.") - def align_starting_time(self, starting_time: float): + def set_aligned_starting_time(self, aligned_starting_time: float): """ Align all starting times for all audio files in this interface relative to the common session start time. @@ -106,23 +106,23 @@ def align_starting_time(self, starting_time: float): Parameters ---------- - starting_time : float + aligned_starting_time : float The common starting time for all temporal data in this interface. Applies to all segments if there are multiple file paths used by the interface. """ if self._segment_starting_times is None and self._number_of_audio_files == 1: - self._segment_starting_times = [starting_time] + self._segment_starting_times = [aligned_starting_time] elif self._segment_starting_times is not None and self._number_of_audio_files > 1: self._segment_starting_times = [ - segment_starting_time + starting_time for segment_starting_time in self._segment_starting_times + segment_starting_time + aligned_starting_time for segment_starting_time in self._segment_starting_times ] else: raise ValueError( "There are no segment starting times to shift by a common value! " - "Please set them using 'align_segment_starting_times'." + "Please set them using 'set_aligned_segment_starting_times'." ) - def align_segment_starting_times(self, segment_starting_times: List[float]): + def set_aligned_segment_starting_times(self, aligned_segment_starting_times: List[float]): """ Align the individual starting time for each audio file in this interface relative to the common session start time. @@ -130,19 +130,19 @@ def align_segment_starting_times(self, segment_starting_times: List[float]): Parameters ---------- - segment_starting_times : list of floats + aligned_segment_starting_times : list of floats The relative starting times of each audio file (segment). """ - segment_starting_times_length = len(segment_starting_times) - assert isinstance(segment_starting_times, list) and all( - [isinstance(x, float) for x in segment_starting_times] - ), "Argument 'segment_starting_times' must be a list of floats." - assert segment_starting_times_length == self._number_of_audio_files, ( - f"The number of entries in 'segment_starting_times' ({segment_starting_times_length}) must be equal to the number of " - f"audio file paths ({self._number_of_audio_files})." + aligned_segment_starting_times_length = len(aligned_segment_starting_times) + assert isinstance(aligned_segment_starting_times, list) and all( + [isinstance(x, float) for x in aligned_segment_starting_times] + ), "Argument 'aligned_segment_starting_times' must be a list of floats." + assert aligned_segment_starting_times_length == self._number_of_audio_files, ( + f"The number of entries in 'aligned_segment_starting_times' ({aligned_segment_starting_times_length}) " + f"must be equal to the number of audio file paths ({self._number_of_audio_files})." ) - self._segment_starting_times = segment_starting_times + self._segment_starting_times = aligned_segment_starting_times def align_by_interpolation(self, unaligned_timestamps: np.ndarray, aligned_timestamps: np.ndarray): raise NotImplementedError("The AudioInterface does not yet support timestamps.") @@ -200,7 +200,7 @@ def run_conversion( if self._number_of_audio_files > 1 and self._segment_starting_times is None: raise ValueError( "If you have multiple audio files, then you must specify each starting time by calling " - "'.align_segment_starting_times(segment_starting_times=...)'!" + "'.set_aligned_segment_starting_times(...)'!" ) starting_times = self._segment_starting_times or [0.0] diff --git a/src/neuroconv/datainterfaces/behavior/video/videodatainterface.py b/src/neuroconv/datainterfaces/behavior/video/videodatainterface.py index f0a482416..efe92263a 100644 --- a/src/neuroconv/datainterfaces/behavior/video/videodatainterface.py +++ b/src/neuroconv/datainterfaces/behavior/video/videodatainterface.py @@ -157,7 +157,7 @@ def set_aligned_timestamps(self, aligned_timestamps: List[np.ndarray]): ), "If setting both timestamps and starting times, please set the timestamps first so they can be shifted by the starting times." self._timestamps = aligned_timestamps - def align_starting_time(self, starting_time: float, stub_test: bool = False): + def set_aligned_starting_time(self, aligned_starting_time: float, stub_test: bool = False): """ Align all starting times for all videos in this interface relative to the common session start time. @@ -165,7 +165,7 @@ def align_starting_time(self, starting_time: float, stub_test: bool = False): Parameters ---------- - starting_time : float + aligned_starting_time : float The common starting time for all segments of temporal data in this interface. stub_test : bool, default: False If timestamps have not been set to this interface, it will attempt to retrieve them @@ -177,17 +177,17 @@ def align_starting_time(self, starting_time: float, stub_test: bool = False): if self._timestamps is not None: self.set_aligned_timestamps( aligned_timestamps=[ - timestamps + starting_time for timestamps in self.get_timestamps(stub_test=stub_test) + timestamps + aligned_starting_time for timestamps in self.get_timestamps(stub_test=stub_test) ] ) elif self._segment_starting_times is not None: self._segment_starting_times = [ - starting_time + starting_time for starting_time in self._segment_starting_times + segment_starting_time + aligned_starting_time for segment_starting_time in self._segment_starting_times ] else: raise ValueError("There are no timestamps or starting times set to shift by a common value!") - def align_segment_starting_times(self, segment_starting_times: List[float], stub_test: bool = False): + def set_aligned_segment_starting_times(self, aligned_segment_starting_times: List[float], stub_test: bool = False): """ Align the individual starting time for each video (segment) in this interface relative to the common session start time. @@ -204,9 +204,9 @@ def align_segment_starting_times(self, segment_starting_times: List[float], stub To limit that scan to a small number of frames, set `stub_test=True`. """ - segment_starting_times_length = len(segment_starting_times) - assert segment_starting_times_length == self._number_of_files, ( - f"The length of the 'segment_starting_times' list ({segment_starting_times_length}) does not match the " + aligned_segment_starting_times_length = len(aligned_segment_starting_times) + assert aligned_segment_starting_times_length == self._number_of_files, ( + f"The length of the 'aligned_segment_starting_times' list ({aligned_segment_starting_times_length}) does not match the " "number of video files ({self._number_of_files})!" ) if self._timestamps is not None: @@ -214,12 +214,12 @@ def align_segment_starting_times(self, segment_starting_times: List[float], stub aligned_timestamps=[ timestamps + segment_starting_time for timestamps, segment_starting_time in zip( - self.get_timestamps(stub_test=stub_test), segment_starting_times + self.get_timestamps(stub_test=stub_test), aligned_segment_starting_times ) ] ) else: - self._segment_starting_times = segment_starting_times + self._segment_starting_times = aligned_segment_starting_times def align_by_interpolation(self, unaligned_timestamps: np.ndarray, aligned_timestamps: np.ndarray): raise NotImplementedError("The `align_by_interpolation` method has not been developed for this interface yet.") diff --git a/src/neuroconv/datainterfaces/ecephys/baserecordingextractorinterface.py b/src/neuroconv/datainterfaces/ecephys/baserecordingextractorinterface.py index 86c0ea6c9..cb8fb9b4d 100644 --- a/src/neuroconv/datainterfaces/ecephys/baserecordingextractorinterface.py +++ b/src/neuroconv/datainterfaces/ecephys/baserecordingextractorinterface.py @@ -193,17 +193,17 @@ def set_aligned_segment_timestamps(self, aligned_segment_timestamps: List[np.nda times=aligned_segment_timestamps[segment_index], segment_index=segment_index ) - def align_starting_time(self, starting_time: float): + def set_aligned_starting_time(self, aligned_starting_time: float): if self._number_of_segments == 1: - self.set_aligned_timestamps(aligned_timestamps=self.get_timestamps() + starting_time) + self.set_aligned_timestamps(aligned_timestamps=self.get_timestamps() + aligned_starting_time) else: self.set_aligned_segment_timestamps( aligned_segment_timestamps=[ - segment_timestamps + starting_time for segment_timestamps in self.get_timestamps() + segment_timestamps + aligned_starting_time for segment_timestamps in self.get_timestamps() ] ) - def align_segment_starting_times(self, segment_starting_times: List[float]): + def set_aligned_segment_starting_times(self, aligned_segment_starting_times: List[float]): """ Align the starting time for each segment in this interface relative to the common session start time. @@ -211,19 +211,22 @@ def align_segment_starting_times(self, segment_starting_times: List[float]): Parameters ---------- - segment_starting_times : list of floats + aligned_segment_starting_times : list of floats The starting time for each segment of data in this interface. """ - assert ( - len(segment_starting_times) == self._number_of_segments - ), f"The length of the starting_times ({len(segment_starting_times)}) does not match the number of segments ({self._number_of_segments})!" + assert len(aligned_segment_starting_times) == self._number_of_segments, ( + f"The length of the starting_times ({len(aligned_segment_starting_times)}) does not match the " + "number of segments ({self._number_of_segments})!" + ) if self._number_of_segments == 1: - self.align_starting_time(starting_time=segment_starting_times[0]) + self.set_aligned_starting_time(aligned_starting_time=aligned_segment_starting_times[0]) else: aligned_segment_timestamps = [ - segment_timestamps + segment_starting_time - for segment_timestamps, segment_starting_time in zip(self.get_timestamps(), segment_starting_times) + segment_timestamps + aligned_segment_starting_time + for segment_timestamps, aligned_segment_starting_time in zip( + self.get_timestamps(), aligned_segment_starting_times + ) ] self.set_aligned_segment_timestamps(aligned_segment_timestamps=aligned_segment_timestamps) diff --git a/src/neuroconv/datainterfaces/ecephys/basesortingextractorinterface.py b/src/neuroconv/datainterfaces/ecephys/basesortingextractorinterface.py index 0512733c3..cb910b649 100644 --- a/src/neuroconv/datainterfaces/ecephys/basesortingextractorinterface.py +++ b/src/neuroconv/datainterfaces/ecephys/basesortingextractorinterface.py @@ -166,21 +166,21 @@ def set_aligned_segment_timestamps(self, aligned_segment_timestamps: List[np.nda times=aligned_segment_timestamps[segment_index], segment_index=segment_index ) - def align_starting_time(self, starting_time: float): + def set_aligned_starting_time(self, aligned_starting_time: float): if self.sorting_extractor.has_recording(): if self._number_of_segments == 1: - self.set_aligned_timestamps(aligned_timestamps=self.get_timestamps() + starting_time) + self.set_aligned_timestamps(aligned_timestamps=self.get_timestamps() + aligned_starting_time) else: self.set_aligned_segment_timestamps( aligned_timestamps=[ - segment_timestamps + starting_time for segment_timestamps in self.get_timestamps() + segment_timestamps + aligned_starting_time for segment_timestamps in self.get_timestamps() ] ) else: for sorting_segment in self.sorting_extractor._sorting_segments: - sorting_segment._t_start += starting_time + sorting_segment._t_start += aligned_starting_time - def align_segment_starting_times(self, segment_starting_times: List[float]): + def set_aligned_segment_starting_times(self, aligned_segment_starting_times: List[float]): """ Align the starting time for each segment in this interface relative to the common session start time. @@ -188,25 +188,30 @@ def align_segment_starting_times(self, segment_starting_times: List[float]): Parameters ---------- - segment_starting_times : list of floats + aligned_segment_starting_times : list of floats The starting time for each segment of data in this interface. """ - assert ( - len(segment_starting_times) == self._number_of_segments - ), f"The length of the starting_times ({len(segment_starting_times)}) does not match the number of segments ({self._number_of_segments})!" + assert len(aligned_segment_starting_times) == self._number_of_segments, ( + f"The length of the starting_times ({len(aligned_segment_starting_times)}) does not match the number " + f"of segments ({self._number_of_segments})!" + ) if self.sorting_extractor.has_recording(): if self._number_of_segments == 1: - self.set_aligned_timestamps(aligned_timestamps=self.get_timestamps() + segment_starting_times[0]) + self.set_aligned_starting_time(aligned_starting_time=aligned_segment_starting_times[0]) else: aligned_segment_timestamps = [ - segment_timestamps + segment_starting_time - for segment_timestamps, segment_starting_time in zip(self.get_timestamps(), segment_starting_times) + segment_timestamps + aligned_segment_starting_time + for segment_timestamps, aligned_segment_starting_time in zip( + self.get_timestamps(), aligned_segment_starting_times + ) ] self.set_aligned_segment_timestamps(aligned_segment_timestamps=aligned_segment_timestamps) else: - for sorting_segment, starting_time in zip(self.sorting_extractor._sorting_segments, segment_starting_times): - sorting_segment._t_start = starting_time + for sorting_segment, aligned_segment_starting_time in zip( + self.sorting_extractor._sorting_segments, aligned_segment_starting_times + ): + sorting_segment._t_start = aligned_segment_starting_time def subset_sorting(self): max_min_spike_time = max( diff --git a/src/neuroconv/datainterfaces/icephys/abf/abfdatainterface.py b/src/neuroconv/datainterfaces/icephys/abf/abfdatainterface.py index b374c1a3f..9e774c834 100644 --- a/src/neuroconv/datainterfaces/icephys/abf/abfdatainterface.py +++ b/src/neuroconv/datainterfaces/icephys/abf/abfdatainterface.py @@ -144,13 +144,15 @@ def get_metadata(self) -> dict: return metadata - def align_starting_time(self, starting_time: float): + def align_starting_time(self, aligned_starting_time: float): for reader in self.readers_list: number_of_segments = reader.header["nb_segment"][0] for segment_index in range(number_of_segments): - reader._t_starts[segment_index] += starting_time + reader._t_starts[segment_index] += aligned_starting_time - def align_segment_starting_times(self, segment_starting_times: List[List[float]], stub_test: bool = False): + def set_aligned_segment_starting_times( + self, aligned_segment_starting_times: List[List[float]], stub_test: bool = False + ): """ Align the individual starting time for each video in this interface relative to the common session start time. @@ -158,21 +160,23 @@ def align_segment_starting_times(self, segment_starting_times: List[List[float]] Parameters ---------- - segment_starting_times : list of list of floats + aligned_segment_starting_times : list of list of floats The relative starting times of each video. Outer list is over file paths (readers). Inner list is over segments of each recording. """ - number_of_files_from_starting_times = len(segment_starting_times) + number_of_files_from_starting_times = len(aligned_segment_starting_times) assert number_of_files_from_starting_times == len(self.readers_list), ( f"The length of the outer list of 'starting_times' ({number_of_files_from_starting_times}) " "does not match the number of files ({len(self.readers_list)})!" ) - for file_index, (reader, segment_starting_times) in enumerate(zip(self.readers_list, segment_starting_times)): + for file_index, (reader, aligned_segment_starting_times_by_file) in enumerate( + zip(self.readers_list, aligned_segment_starting_times) + ): number_of_segments = reader.header["nb_segment"][0] assert number_of_segments == len( - segment_starting_times + aligned_segment_starting_times_by_file ), f"The length of starting times index {file_index} does not match the number of segments of that reader!" - reader._t_starts = segment_starting_times + reader._t_starts = aligned_segment_starting_times_by_file diff --git a/src/neuroconv/datainterfaces/icephys/baseicephysinterface.py b/src/neuroconv/datainterfaces/icephys/baseicephysinterface.py index 068afcca7..86560664c 100644 --- a/src/neuroconv/datainterfaces/icephys/baseicephysinterface.py +++ b/src/neuroconv/datainterfaces/icephys/baseicephysinterface.py @@ -76,7 +76,7 @@ def get_timestamps(self) -> np.ndarray: def set_aligned_timestamps(self, aligned_timestamps: np.ndarray): raise NotImplementedError("Icephys interfaces do not yet support timestamps.") - def align_starting_time(self, starting_time: float): + def set_aligned_starting_time(self, aligned_starting_time: float): raise NotImplementedError("This icephys interface has not specified the method for aligning starting time.") def align_by_interpolation(self, unaligned_timestamps: np.ndarray, aligned_timestamps: np.ndarray): diff --git a/src/neuroconv/datainterfaces/text/timeintervalsinterface.py b/src/neuroconv/datainterfaces/text/timeintervalsinterface.py index a5e6e8b2a..6f71a8bad 100644 --- a/src/neuroconv/datainterfaces/text/timeintervalsinterface.py +++ b/src/neuroconv/datainterfaces/text/timeintervalsinterface.py @@ -63,11 +63,11 @@ def get_timestamps(self, column: str) -> np.ndarray: return self.dataframe[column].values - def align_starting_time(self, starting_time: float): + def set_aligned_starting_time(self, aligned_starting_time: float): timing_columns = [column for column in self.dataframe.columns if column.endswith("_time")] for column in timing_columns: - self.dataframe[column] += starting_time + self.dataframe[column] += aligned_starting_time def set_aligned_timestamps( self, aligned_timestamps: np.ndarray, column: str, interpolate_other_columns: bool = False diff --git a/src/neuroconv/tools/testing/data_interface_mixins.py b/src/neuroconv/tools/testing/data_interface_mixins.py index 4e56e2019..709cfa0c7 100644 --- a/src/neuroconv/tools/testing/data_interface_mixins.py +++ b/src/neuroconv/tools/testing/data_interface_mixins.py @@ -176,11 +176,11 @@ def check_shift_timestamps_by_start_time(self): self.setUpFreshInterface() unaligned_timestamps = self.interface.get_timestamps() - starting_time = 1.23 - self.interface.align_starting_time(starting_time=starting_time) + aligned_starting_time = 1.23 + self.interface.set_aligned_starting_time(aligned_starting_time=aligned_starting_time) aligned_timestamps = self.interface.get_timestamps() - expected_timestamps = unaligned_timestamps + starting_time + expected_timestamps = unaligned_timestamps + aligned_starting_time assert_array_equal(x=aligned_timestamps, y=expected_timestamps) def check_interface_original_timestamps_inmutability(self): @@ -236,8 +236,8 @@ def check_nwbfile_temporal_alignment(self): interface = self.data_interface_cls(**self.test_kwargs) - starting_time = 1.23 - interface.align_starting_time(starting_time=starting_time) + aligned_starting_time = 1.23 + interface.set_aligned_starting_time(aligned_starting_time=aligned_starting_time) metadata = interface.get_metadata() metadata["NWBFile"].update(session_start_time=datetime.now().astimezone()) @@ -246,7 +246,7 @@ def check_nwbfile_temporal_alignment(self): with NWBHDF5IO(path=nwbfile_path) as io: nwbfile = io.read() - assert nwbfile.acquisition["TwoPhotonSeries"].starting_time == starting_time + assert nwbfile.acquisition["TwoPhotonSeries"].starting_time == aligned_starting_time class SegmentationExtractorInterfaceTestMixin(DataInterfaceTestMixin, TemporalAlignmentMixin): @@ -355,17 +355,17 @@ def check_shift_timestamps_by_start_time(self): self.setUpFreshInterface() all_unaligned_timestamps = self.interface.get_timestamps() - starting_time = 1.23 - self.interface.align_starting_time(starting_time=starting_time) + aligned_starting_time = 1.23 + self.interface.set_aligned_starting_time(aligned_starting_time=aligned_starting_time) if self.interface._number_of_segments == 1: retrieved_aligned_timestamps = self.interface.get_timestamps() - expected_timestamps = all_unaligned_timestamps + starting_time + expected_timestamps = all_unaligned_timestamps + aligned_starting_time assert_array_equal(x=retrieved_aligned_timestamps, y=expected_timestamps) else: all_retrieved_aligned_timestamps = self.interface.get_timestamps() all_expected_timestamps = [ - unaligned_timestamps + starting_time for unaligned_timestamps in all_unaligned_timestamps + unaligned_timestamps + aligned_starting_time for unaligned_timestamps in all_unaligned_timestamps ] for retrieved_aligned_timestamps, expected_timestamps in zip( all_retrieved_aligned_timestamps, all_expected_timestamps @@ -375,24 +375,28 @@ def check_shift_timestamps_by_start_time(self): def check_shift_segment_timestamps_by_starting_times(self): self.setUpFreshInterface() - segment_starting_times = list(np.arange(float(self.interface._number_of_segments)) + 1.23) + aligned_segment_starting_times = list(np.arange(float(self.interface._number_of_segments)) + 1.23) if self.interface._number_of_segments == 1: unaligned_timestamps = self.interface.get_timestamps() - self.interface.align_segment_starting_times(segment_starting_times=segment_starting_times) + self.interface.set_aligned_segment_starting_times( + aligned_segment_starting_times=aligned_segment_starting_times + ) retrieved_aligned_timestamps = self.interface.get_timestamps() - expected_aligned_timestamps = unaligned_timestamps + segment_starting_times[0] + expected_aligned_timestamps = unaligned_timestamps + aligned_segment_starting_times[0] assert_array_equal(x=retrieved_aligned_timestamps, y=expected_aligned_timestamps) else: all_unaligned_timestamps = self.interface.get_timestamps() - self.interface.align_segment_starting_times(segment_starting_times=segment_starting_times) + self.interface.set_aligned_segment_starting_times( + aligned_segment_starting_times=aligned_segment_starting_times + ) all_retrieved_aligned_timestamps = self.interface.get_timestamps() all_expected_aligned_timestamps = [ timestamps + segment_starting_time - for timestamps, segment_starting_time in zip(all_unaligned_timestamps, segment_starting_times) + for timestamps, segment_starting_time in zip(all_unaligned_timestamps, aligned_segment_starting_times) ] for retrieved_aligned_timestamps, expected_aligned_timestamps in zip( all_retrieved_aligned_timestamps, all_expected_aligned_timestamps @@ -505,24 +509,30 @@ def check_interface_set_aligned_segment_timestamps(self): def check_shift_segment_timestamps_by_starting_times(self): self.setUpFreshInterface() - segment_starting_times = list(np.arange(float(self.interface._number_of_segments)) + 1.23) + aligned_segment_starting_times = list(np.arange(float(self.interface._number_of_segments)) + 1.23) if self.interface._number_of_segments == 1: unaligned_timestamps = self.interface.get_timestamps() - self.interface.align_segment_starting_times(segment_starting_times=segment_starting_times) + self.interface.set_aligned_segment_starting_times( + aligned_segment_starting_times=aligned_segment_starting_times + ) retrieved_aligned_timestamps = self.interface.get_timestamps() - expected_aligned_timestamps = unaligned_timestamps + segment_starting_times[0] + expected_aligned_timestamps = unaligned_timestamps + aligned_segment_starting_times[0] assert_array_equal(x=retrieved_aligned_timestamps, y=expected_aligned_timestamps) else: all_unaligned_timestamps = self.interface.get_timestamps() - self.interface.align_segment_starting_times(segment_starting_times=segment_starting_times) + self.interface.set_aligned_segment_starting_times( + aligned_segment_starting_times=aligned_segment_starting_times + ) all_retrieved_aligned_timestamps = self.interface.get_timestamps() all_expected_aligned_timestamps = [ segment_timestamps + segment_starting_time - for segment_timestamps, segment_starting_time in zip(all_unaligned_timestamps, segment_starting_times) + for segment_timestamps, segment_starting_time in zip( + all_unaligned_timestamps, aligned_segment_starting_times + ) ] for retrieved_aligned_timestamps, expected_aligned_timestamps in zip( all_retrieved_aligned_timestamps, all_expected_aligned_timestamps @@ -602,29 +612,29 @@ def check_interface_set_aligned_timestamps(self): def check_shift_timestamps_by_start_time(self): self.setUpFreshInterface() - starting_time = 1.23 + aligned_starting_time = 1.23 self.interface.set_aligned_timestamps(aligned_timestamps=self.interface.get_original_timestamps()) - self.interface.align_starting_time(starting_time=starting_time) + self.interface.set_aligned_starting_time(aligned_starting_time=aligned_starting_time) all_aligned_timestamps = self.interface.get_timestamps() unaligned_timestamps = self.interface.get_original_timestamps() - all_expected_timestamps = [timestamps + starting_time for timestamps in unaligned_timestamps] + all_expected_timestamps = [timestamps + aligned_starting_time for timestamps in unaligned_timestamps] [ assert_array_equal(x=aligned_timestamps, y=expected_timestamps) for aligned_timestamps, expected_timestamps in zip(all_aligned_timestamps, all_expected_timestamps) ] - def check_align_segment_starting_times(self): + def check_set_aligned_segment_starting_times(self): self.setUpFreshInterface() - segment_starting_times = [1.23 * file_path_index for file_path_index in range(len(self.test_kwargs))] - self.interface.align_segment_starting_times(segment_starting_times=segment_starting_times) + aligned_segment_starting_times = [1.23 * file_path_index for file_path_index in range(len(self.test_kwargs))] + self.interface.set_aligned_segment_starting_times(aligned_segment_starting_times=aligned_segment_starting_times) all_aligned_timestamps = self.interface.get_timestamps() unaligned_timestamps = self.interface.get_original_timestamps() all_expected_timestamps = [ timestamps + segment_starting_time - for timestamps, segment_starting_time in zip(unaligned_timestamps, segment_starting_times) + for timestamps, segment_starting_time in zip(unaligned_timestamps, aligned_segment_starting_times) ] for aligned_timestamps, expected_timestamps in zip(all_aligned_timestamps, all_expected_timestamps): assert_array_equal(x=aligned_timestamps, y=expected_timestamps) @@ -663,6 +673,6 @@ def test_interface_alignment(self): self.check_interface_set_aligned_timestamps() self.check_shift_timestamps_by_start_time() self.check_interface_original_timestamps_inmutability() - self.check_align_segment_starting_times() + self.check_set_aligned_segment_starting_times() self.check_nwbfile_temporal_alignment() diff --git a/tests/test_on_data/test_temporal_alignment/test_temporal_alignment_methods.py b/tests/test_on_data/test_temporal_alignment/test_temporal_alignment_methods.py index f5ba1bb83..86fad7457 100644 --- a/tests/test_on_data/test_temporal_alignment/test_temporal_alignment_methods.py +++ b/tests/test_on_data/test_temporal_alignment/test_temporal_alignment_methods.py @@ -438,8 +438,8 @@ def test_alignment_interfaces(self): channel_name="nidq#XA0" # The channel receiving pulses from the DLC system )[0] - self.trial_interface.align_starting_time(starting_time=inferred_aligned_trial_start_time) - self.behavior_interface.align_starting_time(starting_time=inferred_aligned_trial_start_time) + self.trial_interface.set_aligned_starting_time(aligned_starting_time=inferred_aligned_trial_start_time) + self.behavior_interface.set_aligned_starting_time(aligned_starting_time=inferred_aligned_trial_start_time) assert_array_equal(x=self.trial_interface.get_timestamps(column="start_time"), y=self.aligned_trial_start_times) assert_array_equal( @@ -488,9 +488,11 @@ class TestAlignmentConverter(NWBConverter): channel_name="nidq#XA0" # The channel receiving pulses from the DLC system )[0] - converter.data_interface_objects["Trials"].align_starting_time(starting_time=inferred_aligned_trial_start_time) - converter.data_interface_objects["Behavior"].align_starting_time( - starting_time=inferred_aligned_trial_start_time + converter.data_interface_objects["Trials"].set_aligned_starting_time( + aligned_starting_time=inferred_aligned_trial_start_time + ) + converter.data_interface_objects["Behavior"].set_aligned_starting_time( + aligned_starting_time=inferred_aligned_trial_start_time ) nwbfile_path = self.tmpdir / "test_nidq_on_signal_alignment_nwbconverter_direct_modification.nwb" @@ -511,11 +513,11 @@ def __init__(self, source_data: Dict[str, dict], verbose: bool = True): channel_name="nidq#XA0" # The channel receiving pulses from the DLC system )[0] - self.data_interface_objects["Trials"].align_starting_time( - starting_time=inferred_aligned_trial_start_time + self.data_interface_objects["Trials"].set_aligned_starting_time( + aligned_starting_time=inferred_aligned_trial_start_time ) - self.data_interface_objects["Behavior"].align_starting_time( - starting_time=inferred_aligned_trial_start_time + self.data_interface_objects["Behavior"].set_aligned_starting_time( + aligned_starting_time=inferred_aligned_trial_start_time ) source_data = dict(