Skip to content

Commit 51bd96b

Browse files
authored
compare daq names (#982)
* compare daq names * checks subset instead of 1:1 match
1 parent 14ecd53 commit 51bd96b

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

src/aind_data_schema/components/devices.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
SpeedUnit,
1616
TemperatureUnit,
1717
UnitlessUnit,
18-
VoltageUnit
18+
VoltageUnit,
1919
)
2020
from pydantic import Field, ValidationInfo, field_validator, model_validator
2121
from typing_extensions import Annotated
@@ -694,8 +694,9 @@ class PockelsCell(Device):
694694
"""Description of a Pockels Cell"""
695695

696696
device_type: Literal["Pockels cell"] = "Pockels cell"
697-
polygonal_scanner: Optional[str] = Field(default=None, title="Polygonal scanner",
698-
description="Must match name of Polygonal scanner")
697+
polygonal_scanner: Optional[str] = Field(
698+
default=None, title="Polygonal scanner", description="Must match name of Polygonal scanner"
699+
)
699700
on_time: Optional[Decimal] = Field(default=None, title="On time (fraction of cycle)")
700701
off_time: Optional[Decimal] = Field(default=None, title="Off time (fraction of cycle)")
701702
time_setting_unit: UnitlessUnit = Field(default=UnitlessUnit.FC, title="Time setting unit")

src/aind_data_schema/utils/compatibility_check.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,21 @@ def _compare_mouse_platform_name(self) -> Optional[ValueError]:
2828
f"does not match the rig's {self.rig.mouse_platform.name}"
2929
)
3030

31+
def _compare_daq_names(self) -> Optional[ValueError]:
32+
"""Compares daq names"""
33+
session_daqs = [
34+
daq for stream in getattr(self.session, "data_streams", []) for daq in getattr(stream, "daq_names", [])
35+
]
36+
rig_daqs = [getattr(daq, "name", None) for daq in getattr(self.rig, "daqs", [])]
37+
if not set(session_daqs).issubset(set(rig_daqs)):
38+
return ValueError(
39+
f"daq names in session do not match daq names in rig. "
40+
f"session_daqs: {set(session_daqs)} rig_daqs: {set(rig_daqs)}"
41+
)
42+
3143
def run_compatibility_check(self) -> None:
3244
"""Runs compatibility check.Creates a dictionary of fields and whether it matches in rig and session."""
33-
comparisons = [self._compare_rig_id(), self._compare_mouse_platform_name()]
45+
comparisons = [self._compare_rig_id(), self._compare_mouse_platform_name(), self._compare_daq_names()]
3446
error_messages = [str(error) for error in comparisons if error]
3547
if error_messages:
3648
raise ValueError(error_messages)

tests/test_examples_generator.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,4 @@ def test_generate_example(self, mocked_run_path):
2323
"C:/Users/mae.moninghoff/Documents/GitHub/aind-data-schema/examples/subject.py"
2424
)
2525

26-
ExamplesGenerator().generate_example(
27-
"fake/path/to/example.py"
28-
)
26+
ExamplesGenerator().generate_example("fake/path/to/example.py")

tests/test_rig_session_compatibility.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""Tests rig session compatibility check"""
22
import unittest
33

4-
from aind_data_schema.components.devices import MousePlatform
4+
from aind_data_schema.components.devices import MousePlatform, DAQDevice
55
from aind_data_schema.core.rig import Rig
6-
from aind_data_schema.core.session import Session
6+
from aind_data_schema.core.session import Session, Stream
77
from aind_data_schema.utils.compatibility_check import RigSessionCompatibility
88

99

@@ -12,12 +12,18 @@ class TestRigSessionCompatibility(unittest.TestCase):
1212

1313
# TODO: use example rig and session once examples are synced
1414
mouse_platform = MousePlatform.model_construct(name="some_mouse_platform")
15-
rig = Rig.model_construct(rig_id="some_rig_id", mouse_platform=mouse_platform)
16-
compatible_session = Session.model_construct(rig_id="some_rig_id", mouse_platform_name="some_mouse_platform")
15+
stream1 = Stream.model_construct(daq_names=["daq1", "daq2"])
16+
stream2 = Stream.model_construct(daq_names=["daq3", "daq4"])
17+
daq1 = DAQDevice.model_construct(name="daq1")
18+
daq2 = DAQDevice.model_construct(name="daq2")
19+
daq3 = DAQDevice.model_construct(name="daq3")
20+
rig = Rig.model_construct(rig_id="some_rig_id", mouse_platform=mouse_platform, daqs=[daq1, daq2, daq3])
21+
compatible_session = Session.model_construct(
22+
rig_id="some_rig_id", mouse_platform_name="some_mouse_platform", data_streams=[stream1, stream1]
23+
)
1724
noncompatible_session = Session.model_construct(
18-
rig_id="some_other_rig_id", mouse_platform_name="some_other_mouse_platform"
25+
rig_id="some_other_rig_id", mouse_platform_name="some_other_mouse_platform", data_streams=[stream1, stream2]
1926
)
20-
2127
checker = RigSessionCompatibility(rig=rig, session=compatible_session)
2228
noncompatible_checker = RigSessionCompatibility(rig=rig, session=noncompatible_session)
2329

@@ -31,6 +37,11 @@ def test_compare_mouse_platform_name(self):
3137
self.assertIsNone(self.checker._compare_mouse_platform_name())
3238
self.assertIsInstance(self.noncompatible_checker._compare_mouse_platform_name(), ValueError)
3339

40+
def test_compare_daq_names(self):
41+
"""Tests compare daq names"""
42+
self.assertIsNone(self.checker._compare_daq_names())
43+
self.assertIsInstance(self.noncompatible_checker._compare_daq_names(), ValueError)
44+
3445
def test_run_compatibility_check(self):
3546
"""Tests compatibility check"""
3647
self.assertIsNone(self.checker.run_compatibility_check())

0 commit comments

Comments
 (0)