Skip to content

Commit

Permalink
breaking-change: merge instrument/rig and convert rig to List[Optiona…
Browse files Browse the repository at this point in the history
…l[]]
  • Loading branch information
dbirman committed Jan 14, 2025
1 parent 4fa9607 commit 5bceb2c
Show file tree
Hide file tree
Showing 8 changed files with 264 additions and 884 deletions.
510 changes: 0 additions & 510 deletions examples/aibs_smartspim_instrument.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,35 @@
AdditionalImagingDevice,
Detector,
Filter,
ImagingInstrumentType,
Laser,
MotorizedStage,
Objective,
OpticalTable,
ScanningStage,
)
from aind_data_schema.core.instrument import Com, Instrument
from aind_data_schema_models.modalities import Modality
from aind_data_schema.core.rig import Com, Rig

inst = Instrument(
instrument_id="440_SmartSPIM2_20231004",
modification_date=datetime.date(2023, 10, 4),
instrument_type="SmartSPIM",
manufacturer=Organization.LIFECANVAS,
objectives=[
Objective(
name="TLX Objective",
numerical_aperture=0.2,
magnification=3.6,
immersion="multi",
manufacturer=Organization.THORLABS,
model="TL4X-SAP",
notes="Thorlabs TL4X-SAP with LifeCanvas dipping cap and correction optics.",
),
],
detectors=[
Detector(
objective = Objective(
name="TLX Objective",
numerical_aperture=0.2,
magnification=3.6,
immersion="multi",
manufacturer=Organization.THORLABS,
model="TL4X-SAP",
notes="Thorlabs TL4X-SAP with LifeCanvas dipping cap and correction optics.",
)
camera1 = Detector(
name="Camera 1",
detector_type="Camera",
data_interface="USB",
cooling="Air",
manufacturer=Organization.HAMAMATSU,
model="C14440-20UP",
serial_number="001107",
),
],
light_sources=[
Laser(
)
laser1 = Laser(
name="Ex_488",
device_type="Laser",
coupling="Single-mode fiber",
Expand All @@ -55,8 +47,8 @@
manufacturer=Organization.VORTRAN,
model="Stradus",
notes="All lasers controlled via Vortran VersaLase System",
),
Laser(
)
laser2 = Laser(
name="Ex_561",
device_type="Laser",
coupling="Single-mode fiber",
Expand All @@ -66,8 +58,8 @@
manufacturer=Organization.COHERENT_SCIENTIFIC,
model="Obis",
notes="All lasers controlled via Vortran VersaLase System",
),
Laser(
)
laser3 = Laser(
name="Ex_647",
device_type="Laser",
coupling="Single-mode fiber",
Expand All @@ -77,90 +69,70 @@
manufacturer=Organization.VORTRAN,
model="Stradus",
notes="All lasers controlled via Vortran VersaLase System",
),
],
motorized_stages=[
MotorizedStage(
)
stage0 = MotorizedStage(
name="Focus stage",
model="LS-100",
manufacturer=Organization.ASI,
travel=100,
),
MotorizedStage(
)
stage1 = MotorizedStage(
name="Cylindrical lens #1",
model="L12-20F-4",
manufacturer=Organization.IR_ROBOT_CO,
travel=41,
),
MotorizedStage(
)
stage2 = MotorizedStage(
name="Cylindrical lens #2",
model="L12-20F-4",
manufacturer=Organization.IR_ROBOT_CO,
travel=41,
),
MotorizedStage(
)
stage3 = MotorizedStage(
name="Cylindrical lens #3",
model="L12-20F-4",
manufacturer=Organization.IR_ROBOT_CO,
travel=41,
),
MotorizedStage(
)
stage4 = MotorizedStage(
name="Cylindrical lens #4",
model="L12-20F-4",
manufacturer=Organization.IR_ROBOT_CO,
travel=41,
),
],
scanning_stages=[
ScanningStage(
)
scan_stage1 = ScanningStage(
name="Sample stage Z",
model="LS-50",
manufacturer=Organization.ASI,
stage_axis_direction="Detection axis",
stage_axis_name="Z",
travel=50,
),
ScanningStage(
)
scan_stage2 = ScanningStage(
name="Sample stage X",
model="LS-50",
manufacturer=Organization.ASI,
stage_axis_direction="Illumination axis",
stage_axis_name="X",
travel=50,
),
ScanningStage(
)
scan_stage3 = ScanningStage(
name="Sample stage Y",
model="LS-50",
manufacturer=Organization.ASI,
stage_axis_direction="Perpendicular axis",
stage_axis_name="Y",
travel=50,
),
],
optical_tables=[
OpticalTable(
)
table = OpticalTable(
name="Table",
model="CleanTop", # model="VIS2424-IG2-125A", # ~3 months
length=35, # length=24,
width=29, # width=24,
vibration_control=True,
manufacturer=Organization.TMC,
)
],
temperature_control=False,
com_ports=[
Com(
hardware_name="Laser Launch",
com_port="COM3",
),
Com(
hardware_name="ASI Tiger",
com_port="COM5",
),
Com(hardware_name="MightyZap", com_port="COM4"),
],
fluorescence_filters=[
Filter(
filter0 = Filter(
name="Em_525",
filter_type="Band pass",
manufacturer=Organization.SEMROCK,
Expand All @@ -169,8 +141,8 @@
thickness_unit=SizeUnit.MM,
model="FF03-525/50-25",
filter_wheel_index=0,
),
Filter(
)
filter1 = Filter(
name="Em_600",
filter_type="Band pass",
manufacturer=Organization.SEMROCK,
Expand All @@ -179,8 +151,8 @@
thickness_unit=SizeUnit.MM,
model="FF01-600/52-25",
filter_wheel_index=1,
),
Filter(
)
filter2 = Filter(
name="Em_690",
filter_type="Band pass",
manufacturer=Organization.CHROMA,
Expand All @@ -189,29 +161,67 @@
thickness_unit=SizeUnit.MM,
model="ET690/50m",
filter_wheel_index=2,
),
],
additional_devices=[
AdditionalImagingDevice(
)
lens1 = AdditionalImagingDevice(
name="Lens 1",
imaging_device_type="Tunable lens",
manufacturer=Organization.OPTOTUNE,
model="EL-16-40-TC",
),
AdditionalImagingDevice(
)
lens2 = AdditionalImagingDevice(
name="Lens 2",
imaging_device_type="Tunable lens",
manufacturer=Organization.OPTOTUNE,
model="EL-16-40-TC",
),
AdditionalImagingDevice(
)
lens3 = AdditionalImagingDevice(
name="Sample chamber",
imaging_device_type="Sample Chamber",
manufacturer=Organization.LIFECANVAS,
model="Large-uncoated-glass",
)

inst = Rig(
rig_id="440_SmartSPIM2_20231004",
modification_date=datetime.date(2023, 10, 4),
instrument_type=ImagingInstrumentType.SMARTSPIM,
modalities=[Modality.SPIM],
manufacturer=Organization.LIFECANVAS,
temperature_control=False,
components=[
objective,
camera1,
laser1,
laser2,
laser3,
stage0,
stage1,
stage2,
stage3,
stage4,
scan_stage1,
scan_stage2,
scan_stage3,
table,
filter0,
filter1,
filter2,
lens1,
lens2,
lens3,
],
com_ports=[
Com(
hardware_name="Laser Launch",
com_port="COM3",
),
Com(
hardware_name="ASI Tiger",
com_port="COM5",
),
Com(hardware_name="MightyZap", com_port="COM4"),
],
)
serialized = inst.model_dump_json()
deserialized = Instrument.model_validate_json(serialized)
deserialized = Rig.model_validate_json(serialized)
deserialized.write_standard_file(prefix="aibs_smartspim")
30 changes: 30 additions & 0 deletions examples/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from typing import Annotated, List, Union
from pydantic import BaseModel, Field


class TypeA(BaseModel):
item_type: str = "TypeA"
value: int


class TypeB(BaseModel):
item_type: str = "TypeB"
value: str


class TypeC(BaseModel):
item_type: str = "TypeC"
value: float


class MyModel(BaseModel):
items: List[Annotated[Union[TypeA, TypeB, TypeC], Field(discriminator="item_type")]]


# Example usage:
data = MyModel(items=[TypeA(value=42), TypeB(value="string"), TypeC(value=3.14)])
print(data)

# Example: Providing only a subset
data_subset = MyModel(items=[TypeA(value=42), TypeC(value=3.14)])
print(data_subset)
4 changes: 1 addition & 3 deletions src/aind_data_schema/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ def default_filename(cls):
"""
Returns standard filename in snakecase
"""
parent_classes = [
base_class for base_class in cls.__bases__ if base_class.__name__ != DataCoreModel.__name__
]
parent_classes = [base_class for base_class in cls.__bases__ if base_class.__name__ != DataCoreModel.__name__]

name = cls.__name__

Expand Down
5 changes: 1 addition & 4 deletions src/aind_data_schema/components/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class Device(DataModel):
default=None, title="Path to CAD diagram", description="For CUSTOM manufactured devices"
)
port_index: Optional[str] = Field(default=None, title="Port index")
additional_settings: GenericModelType = Field(GenericModel(), title="Additional parameters")
additional_settings: Optional[GenericModelType] = Field(default=None, title="Additional parameters")
notes: Optional[str] = Field(default=None, title="Notes")


Expand Down Expand Up @@ -933,6 +933,3 @@ class MyomatrixArray(Device):

device_type: Literal["Myomatrix Array"] = "Myomatrix Array"
array_type: MyomatrixArrayType = Field(..., title="Array type")


LIGHT_SOURCES = Annotated[Union[Laser, LightEmittingDiode, Lamp], Field(discriminator="device_type")]
Loading

0 comments on commit 5bceb2c

Please sign in to comment.