Skip to content

Commit c183ea3

Browse files
authored
refactor: allow instrument_id to be included in device.name fields (#1663)
* refactor: allow instrument_id to be included in device.name fields * test: add coverage for the new instrumentID check * chore: lint * chore: fix bad active devices * tests: ensure that exaspim acq/inst are compatible * tests: fix broken test * chore: lint
1 parent 098a14a commit c183ea3

File tree

7 files changed

+38
-6
lines changed

7 files changed

+38
-6
lines changed

examples/exaspim_acquisition.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@
4949
)
5050

5151
imaging_config = ImagingConfig(
52-
device_name="ExaSPIM",
52+
device_name="exaSPIM1",
5353
channels=[
5454
Channel(
5555
channel_name="488",
5656
intended_measurement="GFP signal",
5757
light_sources=[
5858
LaserConfig(
59-
device_name="LAS_08308",
59+
device_name="LAS-08307",
6060
wavelength=488,
6161
wavelength_unit=SizeUnit.NM,
6262
power=200,
@@ -115,7 +115,7 @@
115115
experimenters=["John Smith"],
116116
specimen_id="123456-123",
117117
subject_id="123456",
118-
instrument_id="###",
118+
instrument_id="exaSPIM1",
119119
maintenance=[
120120
Maintenance(
121121
maintenance_date=t,
@@ -149,8 +149,11 @@
149149
stream_end_time=t,
150150
modalities=[Modality.SPIM],
151151
active_devices=[
152-
"LAS_08308",
152+
"LAS-08307",
153153
"539251",
154+
"Multiband filter",
155+
"PMT_1",
156+
"Sample chamber",
154157
],
155158
configurations=[
156159
imaging_config,

examples/exaspim_instrument.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
detectors = [
3939
Detector(
40-
name="Camera 1",
40+
name="PMT_1",
4141
detector_type="Camera",
4242
data_interface="Coax",
4343
cooling="Air",
@@ -193,6 +193,13 @@
193193
model="L6Cc",
194194
serial_number="L6CC-00513",
195195
),
196+
AdditionalImagingDevice(
197+
name="Sample chamber",
198+
imaging_device_type="Sample Chamber",
199+
manufacturer=Organization.AI,
200+
model="Custom exaspim chamber",
201+
serial_number="01",
202+
),
196203
]
197204

198205
laser_launch = Device(

src/aind_data_schema/core/instrument.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ def get_component_names(self) -> List[str]:
173173
names.extend(recursive_get_all_names(component))
174174
names = [name for name in names if name is not None]
175175

176+
# Include the instrument ID as a valid name
177+
names = names + [self.instrument_id]
178+
176179
return names
177180

178181
@field_validator("modalities", mode="before")

tests/test_acquisition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ def test_datastream_add_with_exaspim_example(self):
550550

551551
self.assertIsNotNone(combined_stream)
552552
self.assertIn(Modality.SPIM, combined_stream.modalities)
553-
self.assertEqual(len(combined_stream.active_devices), 3)
553+
self.assertEqual(len(combined_stream.active_devices), 6)
554554

555555

556556
if __name__ == "__main__":

tests/test_compatibility_check.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
from aind_data_schema.core.instrument import Instrument
99
from aind_data_schema.utils.compatibility_check import InstrumentAcquisitionCompatibility
1010

11+
from examples.exaspim_acquisition import acq
12+
from examples.exaspim_instrument import inst
13+
1114

1215
class TestInstrumentAcquisitionCompatibility(unittest.TestCase):
1316
"""Unit tests for InstrumentAcquisitionCompatibility class."""
@@ -34,6 +37,11 @@ def setUp(self):
3437
self.mock_acquisition.data_streams = [MagicMock(active_devices=["component_1"])]
3538
self.mock_acquisition.stimulus_epochs = [MagicMock(active_devices=["component_2"])]
3639

40+
def test_exaspim_example_compatibility(self):
41+
"""Test compatibility of the exaspim example instrument and acquisition."""
42+
checker = InstrumentAcquisitionCompatibility(inst, acq)
43+
self.assertIsNone(checker.run_compatibility_check())
44+
3745
def test_compare_instrument_id_success(self):
3846
"""Test that instrument IDs match."""
3947
checker = InstrumentAcquisitionCompatibility(self.mock_instrument, self.mock_acquisition)

tests/test_inst_acq_compatibility.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from aind_data_schema.utils.compatibility_check import InstrumentAcquisitionCompatibility
66
from examples.ephys_acquisition import acquisition as ephys_acquisition
77
from examples.ephys_instrument import inst as ephys_instrument
8+
from examples.exaspim_acquisition import acq as exaspim_acquisition
9+
from examples.exaspim_instrument import inst as exaspim_instrument
810
from examples.fip_ophys_instrument import instrument as ophys_instrument
911
from examples.ophys_acquisition import a as ophys_acquisition
1012

@@ -16,6 +18,8 @@ def setUp(self):
1618
"""Set up test data"""
1719
self.ephys_instrument = ephys_instrument.model_copy()
1820
self.ephys_acquisition = ephys_acquisition.model_copy()
21+
self.exaspim_instrument = exaspim_instrument.model_copy()
22+
self.exaspim_acquisition = exaspim_acquisition.model_copy()
1923
self.ophys_instrument = ophys_instrument.model_copy()
2024
self.ophys_acquisition = ophys_acquisition.model_copy()
2125

@@ -27,6 +31,12 @@ def test_check_examples_compatibility(self):
2731
)
2832
self.assertIsNone(example_ephys_check.run_compatibility_check())
2933

34+
# check that exaspim acquisition and instrument are synced
35+
example_exaspim_check = InstrumentAcquisitionCompatibility(
36+
instrument=self.exaspim_instrument, acquisition=self.exaspim_acquisition
37+
)
38+
self.assertIsNone(example_exaspim_check.run_compatibility_check())
39+
3040
# check that ophys acquisition and instrument are synced
3141
example_ophys_check = InstrumentAcquisitionCompatibility(
3242
instrument=self.ophys_instrument, acquisition=self.ophys_acquisition

tests/test_instrument.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ def test_constructors(self):
354354
Instrument()
355355

356356
self.assertIsNotNone(ephys_instrument)
357+
self.assertIn(ephys_instrument.instrument_id, ephys_instrument.get_component_names())
357358

358359
def test_other_camera_target(self):
359360
"""Test that the camera_target being set to Other throws a validation error without notes"""

0 commit comments

Comments
 (0)