Skip to content

Commit

Permalink
sorting and icephys fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyCBakerPhD committed Jun 7, 2023
1 parent 0b5b2e7 commit bc258f2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()
]
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions src/neuroconv/tools/testing/data_interface_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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])
Expand All @@ -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(
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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():
Expand All @@ -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])
Expand All @@ -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(
Expand Down Expand Up @@ -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()

Expand Down
8 changes: 4 additions & 4 deletions tests/test_on_data/test_gin_icephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down Expand Up @@ -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__":
Expand Down

0 comments on commit bc258f2

Please sign in to comment.