Skip to content

Commit

Permalink
fix icephys
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyCBakerPhD committed Jun 7, 2023
1 parent 3942d24 commit eb035e0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def get_metadata(self) -> dict:

return metadata

def align_starting_time(self, aligned_starting_time: float):
def set_aligned_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):
Expand Down
16 changes: 8 additions & 8 deletions tests/test_on_data/test_gin_behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def setUpClass(cls):
cls.video_files = list((BEHAVIOR_DATA_PATH / "videos" / "CFR").iterdir())
cls.video_files.sort()
cls.number_of_video_files = len(cls.video_files)
cls.segment_starting_times = [0.0, 50.0, 100.0, 150.0, 175.0]
cls.aligned_segment_starting_times = [0.0, 50.0, 100.0, 150.0, 175.0]

def _get_metadata(self):
"""TODO: temporary helper function to fetch new metadata each time; need to debug in follow-up."""
Expand All @@ -153,7 +153,7 @@ def _get_metadata(self):
def test_real_videos(self):
# TODO - merge this with the data mixin in follow-up
for file_index, (file_path, segment_starting_time) in enumerate(
zip(self.video_files, self.segment_starting_times)
zip(self.video_files, self.aligned_segment_starting_times)
):
self.file_index = file_index

Expand All @@ -163,15 +163,15 @@ class VideoTestNWBConverter(NWBConverter):
source_data = dict(Video=dict(file_paths=[file_path]))
self.converter = VideoTestNWBConverter(source_data)
self.interface = self.converter.data_interface_objects["Video"]
self.interface.align_segment_starting_times(
segment_starting_times=[self.segment_starting_times[self.file_index]]
self.interface.set_aligned_segment_starting_times(
aligned_segment_starting_times=[self.aligned_segment_starting_times[self.file_index]]
)

self.check_video_starting_times()
self.check_video_set_aligned_starting_times()
self.check_video_custom_module()
self.check_video_chunking()

def check_video_starting_times(self):
def check_video_set_aligned_starting_times(self):
self._get_metadata()
conversion_options = dict(Video=dict(external_mode=False))
nwbfile_path = OUTPUT_PATH / "check_video_starting_times.nwb"
Expand All @@ -187,9 +187,9 @@ def check_video_starting_times(self):
self.image_series = nwbfile.acquisition[self.image_series_name]

if self.image_series.starting_time is not None:
assert self.segment_starting_times[self.file_index] == self.image_series.starting_time
assert self.aligned_segment_starting_times[self.file_index] == self.image_series.starting_time
else:
assert self.segment_starting_times[self.file_index] == self.image_series.timestamps[0]
assert self.aligned_segment_starting_times[self.file_index] == self.image_series.timestamps[0]

def check_video_custom_module(self):
self._get_metadata()
Expand Down
24 changes: 14 additions & 10 deletions tests/test_on_data/test_gin_icephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,30 @@ class TestIcephysNwbConversions(unittest.TestCase):
)
]

def check_align_starting_time(self): # TODO - use the mixin class in the future
def check_set_aligned_starting_time(self): # TODO - use the mixin class in the future
fresh_interface = self.data_interface_cls(file_paths=self.file_paths)

starting_time = 1.23
aligned_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_starting_time(starting_time=starting_time)
fresh_interface.set_aligned_segment_starting_times(
aligned_segment_starting_times=relative_segment_starting_times
)
fresh_interface.set_aligned_starting_time(aligned_starting_time=aligned_starting_time)

neo_reader_starting_times = [reader._t_starts for reader in fresh_interface.readers_list]
expecting_starting_times = [[1.33]]
self.assertListEqual(list1=neo_reader_starting_times, list2=expecting_starting_times)

def check_align_segment_starting_times(self):
def check_set_aligned_segment_starting_times(self):
fresh_interface = self.data_interface_cls(file_paths=self.file_paths)

segment_starting_times = [[1.2]]
fresh_interface.align_segment_starting_times(segment_starting_times=segment_starting_times)
aligned_segment_starting_times = [[1.2]]
fresh_interface.set_aligned_segment_starting_times(
aligned_segment_starting_times=aligned_segment_starting_times
)

neo_reader_starting_times = [reader._t_starts for reader in fresh_interface.readers_list]
self.assertListEqual(list1=neo_reader_starting_times, list2=segment_starting_times)
self.assertListEqual(list1=neo_reader_starting_times, list2=aligned_segment_starting_times)

@parameterized.expand(input=parameterized_recording_list, name_func=custom_name_func)
def test_convert_abf_to_nwb(self, data_interface, interface_kwargs):
Expand Down Expand Up @@ -116,8 +120,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_starting_time()
self.check_align_segment_starting_times()
self.check_set_aligned_starting_time()
self.check_set_aligned_segment_starting_times()


if __name__ == "__main__":
Expand Down

0 comments on commit eb035e0

Please sign in to comment.