Skip to content

Commit

Permalink
adjust set_probe tests
Browse files Browse the repository at this point in the history
  • Loading branch information
magland committed Nov 28, 2023
1 parent 9afd9a9 commit 46f592d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def set_aligned_segment_starting_times(self, aligned_segment_starting_times: Lis
]
self.set_aligned_segment_timestamps(aligned_segment_timestamps=aligned_segment_timestamps)

def set_probe(self, probe, *, group_mode: Literal["by_shank", "by_probe"]):
def set_probe(self, probe, group_mode: Literal["by_shank", "by_probe"]):
"""
Set the probe information via a ProbeInterface object.
Expand Down
37 changes: 4 additions & 33 deletions src/neuroconv/tools/testing/data_interface_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
from neuroconv.datainterfaces.ecephys.basesortingextractorinterface import (
BaseSortingExtractorInterface,
)
from neuroconv.datainterfaces.ecephys.intan.intandatainterface import (
IntanRecordingInterface,
)
from neuroconv.datainterfaces.ophys.baseimagingextractorinterface import (
BaseImagingExtractorInterface,
)
Expand All @@ -30,7 +27,7 @@
)
from neuroconv.utils import NWBMetaDataEncoder

interfaces_for_testing_probe = [IntanRecordingInterface]
from .mock_probes import generate_mock_probe


class DataInterfaceTestMixin:
Expand Down Expand Up @@ -114,10 +111,11 @@ 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 = self.data_interface_cls in interfaces_for_testing_probe
do_set_probe = isinstance(self.interface, BaseRecordingExtractorInterface)
if do_set_probe:
assert isinstance(self.interface, BaseRecordingExtractorInterface)
self.interface.set_probe(
_create_mock_probe(num_channels=self.interface.recording_extractor.get_num_channels()),
generate_mock_probe(num_channels=self.interface.recording_extractor.get_num_channels()),
group_mode="by_shank",
)
self.check_metadata_schema_valid()
Expand All @@ -131,33 +129,6 @@ def test_conversion_as_lone_interface(self):
self.run_custom_checks()


def _create_mock_probe(*, num_channels: int):
import probeinterface as pi

# The shank ids will be 0, 0, 0, ..., 1, 1, 1, ..., 2, 2, 2, ...
shank_ids: List[int] = []
positions = np.zeros((num_channels, 2))
num_shanks = 3
# ceil division
channels_per_shank = (num_channels + num_shanks - 1) // num_shanks
for i in range(num_shanks):
# x0, y0 is the position of the first electrode in the shank
x0 = 0
y0 = i * 200
for j in range(channels_per_shank):
if len(shank_ids) == num_channels:
break
shank_ids.append(i)
x = x0 + j * 10
y = y0 + (j % 2) * 10
positions[len(shank_ids) - 1] = x, y
probe = pi.Probe(ndim=2, si_units="um")
probe.set_contacts(positions=positions, shapes="circle", shape_params={"radius": 5})
probe.set_device_channel_indices(np.arange(num_channels))
probe.set_shank_ids(shank_ids)
return probe


class TemporalAlignmentMixin:
"""
Generic class for testing temporal alignment methods.
Expand Down
28 changes: 28 additions & 0 deletions src/neuroconv/tools/testing/mock_probes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from typing import List
import numpy as np


def generate_mock_probe(num_channels: int, num_shanks: int = 3):
import probeinterface as pi

# The shank ids will be 0, 0, 0, ..., 1, 1, 1, ..., 2, 2, 2, ...
shank_ids: List[int] = []
positions = np.zeros((num_channels, 2))
# ceil division
channels_per_shank = (num_channels + num_shanks - 1) // num_shanks
for i in range(num_shanks):
# x0, y0 is the position of the first electrode in the shank
x0 = 0
y0 = i * 200
for j in range(channels_per_shank):
if len(shank_ids) == num_channels:
break
shank_ids.append(i)
x = x0 + j * 10
y = y0 + (j % 2) * 10
positions[len(shank_ids) - 1] = x, y
probe = pi.Probe(ndim=2, si_units="um")
probe.set_contacts(positions=positions, shapes="circle", shape_params={"radius": 5})
probe.set_device_channel_indices(np.arange(num_channels))
probe.set_shank_ids(shank_ids)
return probe
2 changes: 1 addition & 1 deletion tests/test_on_data/test_recording_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def check_extracted_metadata(self, metadata: dict):
assert len(metadata["Ecephys"]["Device"]) == 1
assert metadata["Ecephys"]["Device"][0]["name"] == "Neuronexus-32"
assert metadata["Ecephys"]["Device"][0]["description"] == "The ecephys device for the MEArec recording."
assert len(metadata["Ecephys"]["ElectrodeGroup"]) == 1
# assert len(metadata["Ecephys"]["ElectrodeGroup"]) == 1 # do not test this condition because in the test we are setting a mock probe
assert metadata["Ecephys"]["ElectrodeGroup"][0]["device"] == "Neuronexus-32"
assert metadata["Ecephys"]["ElectricalSeries"]["description"] == (
'{"angle_tol": 15, "bursting": false, "chunk_duration": 0, "color_noise_floor": 1, '
Expand Down

0 comments on commit 46f592d

Please sign in to comment.