Skip to content

Commit

Permalink
recording extractor interface tests
Browse files Browse the repository at this point in the history
  • Loading branch information
magland committed Nov 28, 2023
1 parent e2298fa commit 69e5d94
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,17 @@ def set_probe(self, probe, group_mode: Literal["by_shank", "by_probe"]):
# But neuroconv allows "group_name" property to override spike interface "group" value
self.recording_extractor.set_property("group_name", self.recording_extractor.get_property("group").astype(str))

def has_probe(self) -> bool:
"""
Check if the recording extractor has probe information.
Returns
-------
has_probe : bool
True if the recording extractor has probe information.
"""
return self.recording_extractor.has_probe()

def align_by_interpolation(
self,
unaligned_timestamps: np.ndarray,
Expand Down
32 changes: 25 additions & 7 deletions src/neuroconv/tools/testing/data_interface_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,6 @@ def test_conversion_as_lone_interface(self):
self.case = num
self.test_kwargs = kwargs
self.interface = self.data_interface_cls(**self.test_kwargs)
do_set_probe = isinstance(self.interface, BaseRecordingExtractorInterface)
if do_set_probe:
assert isinstance(self.interface, BaseRecordingExtractorInterface)
self.interface.set_probe(
generate_mock_probe(num_channels=self.interface.recording_extractor.get_num_channels()),
group_mode="by_shank",
)
self.check_metadata_schema_valid()
self.check_conversion_options_schema_valid()
self.check_metadata()
Expand Down Expand Up @@ -476,6 +469,31 @@ def test_interface_alignment(self):

self.check_nwbfile_temporal_alignment()

def test_conversion_as_lone_interface(self):
interface_kwargs = self.interface_kwargs
if isinstance(interface_kwargs, dict):
interface_kwargs = [interface_kwargs]
for num, kwargs in enumerate(interface_kwargs):
with self.subTest(str(num)):
self.case = num
self.test_kwargs = kwargs
self.interface = self.data_interface_cls(**self.test_kwargs)
assert isinstance(self.interface, BaseRecordingExtractorInterface)
if not self.interface.has_probe():
self.interface.set_probe(
generate_mock_probe(num_channels=self.interface.recording_extractor.get_num_channels()),
group_mode="by_shank",
)
self.check_metadata_schema_valid()
self.check_conversion_options_schema_valid()
self.check_metadata()
self.nwbfile_path = str(self.save_directory / f"{self.__class__.__name__}_{num}.nwb")
self.run_conversion(nwbfile_path=self.nwbfile_path)
self.check_read_nwb(nwbfile_path=self.nwbfile_path)

# Any extra custom checks to run
self.run_custom_checks()


class SortingExtractorInterfaceTestMixin(DataInterfaceTestMixin, TemporalAlignmentMixin):
data_interface_cls: BaseSortingExtractorInterface
Expand Down

0 comments on commit 69e5d94

Please sign in to comment.