Skip to content

Commit

Permalink
Merge pull request #1122 from AllenNeuralDynamics/1091-evaluate-diffi…
Browse files Browse the repository at this point in the history
…cult-of-converting-units-to-_unit-with-global-validator

Refactor _unit fields to rely on a validator instead of always being set
  • Loading branch information
dbirman authored Dec 12, 2024
2 parents 89063e0 + a2c4f1a commit 7ee0989
Show file tree
Hide file tree
Showing 35 changed files with 301 additions and 132 deletions.
21 changes: 20 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,29 @@ There are several libraries used to run linters and check documentation. We've i
```
**NOTE**: Please note that these linters are automatically run in github actions when a PR is opened. These linters must pass for a PR to merge.
### Units
Unit types (i.e. anything from [aind_data_schema_models.units](https://github.com/AllenNeuralDynamics/aind-data-schema-models/blob/main/src/aind_data_schema_models/units.py)) should always be paired with a variable in one of two patterns.
When you have a single `variable` with a unit, you should add the `_unit` suffix on the name of the unit:
```python
variable: type = Field(...)
variable_unit: XUnit = Field(...)
```
If the variable is `Optional[]` the unit should also be marked as optional.
If you have multiple variables that map onto a single unit type, start each `variable` with the same prefix. The prefix should be unique within the class (watch out for inherited fields).
```python
fov_width: type = Field(...)
fov_height: type = Field(...)
fov_unit: XUnit = Field(...)
```
## Documentation and Style Guide
Documentation is required for contributing to this project. We have settled on using Numpy's conventions as a default: [Numpy docstring standards](https://numpydoc.readthedocs.io/en/latest/format.html)


## Pull Requests
For internal members, please create a branch. For external members, please fork the repo and open a pull request from the fork. We'll primarily use [Angular](https://github.com/angular/angular/blob/main/CONTRIBUTING.md#commit) style for commit messages. Roughly, they should follow the pattern:
```
Expand Down
2 changes: 1 addition & 1 deletion examples/aibs_smartspim_instrument.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"cooling": "Air",
"computer_name": null,
"frame_rate": null,
"frame_rate_unit": "hertz",
"frame_rate_unit": null,
"immersion": null,
"chroma": null,
"sensor_width": null,
Expand Down
4 changes: 4 additions & 0 deletions examples/aibs_smartspim_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import datetime

from aind_data_schema_models.organizations import Organization
from aind_data_schema_models.units import SizeUnit

from aind_data_schema.components.devices import (
AdditionalImagingDevice,
Expand Down Expand Up @@ -166,6 +167,7 @@
manufacturer=Organization.SEMROCK,
diameter=25,
thickness=2.0,
thickness_unit=SizeUnit.MM,
model="FF03-525/50-25",
filter_wheel_index=0,
),
Expand All @@ -175,6 +177,7 @@
manufacturer=Organization.SEMROCK,
diameter=25,
thickness=2.0,
thickness_unit=SizeUnit.MM,
model="FF01-600/52-25",
filter_wheel_index=1,
),
Expand All @@ -184,6 +187,7 @@
manufacturer=Organization.CHROMA,
diameter=25,
thickness=2.0,
thickness_unit=SizeUnit.MM,
model="ET690/50m",
filter_wheel_index=2,
),
Expand Down
2 changes: 1 addition & 1 deletion examples/aind_smartspim_instrument.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"cooling": "Air",
"computer_name": null,
"frame_rate": null,
"frame_rate_unit": "hertz",
"frame_rate_unit": null,
"immersion": null,
"chroma": null,
"sensor_width": null,
Expand Down
7 changes: 7 additions & 0 deletions examples/aind_smartspim_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import datetime

from aind_data_schema_models.organizations import Organization
from aind_data_schema_models.units import SizeUnit

from aind_data_schema.components.devices import Filter, Laser, MotorizedStage, OpticalTable, ScanningStage
from aind_data_schema.core.instrument import Com, Detector, Instrument, Objective
Expand Down Expand Up @@ -106,6 +107,7 @@
manufacturer=Organization.SEMROCK,
diameter=25,
thickness=2.0,
thickness_unit=SizeUnit.MM,
model="FF01-469/35-25",
filter_wheel_index=0,
serial_number="Unknown-0",
Expand All @@ -116,6 +118,7 @@
manufacturer=Organization.SEMROCK,
diameter=25,
thickness=2.0,
thickness_unit=SizeUnit.MM,
model="FF01-525/45-25",
filter_wheel_index=1,
serial_number="Unknown-1",
Expand All @@ -126,6 +129,7 @@
manufacturer=Organization.SEMROCK,
diameter=25,
thickness=2.0,
thickness_unit=SizeUnit.MM,
model="FF01-593/40-25",
filter_wheel_index=2,
serial_number="Unknown-2",
Expand All @@ -136,6 +140,7 @@
manufacturer=Organization.SEMROCK,
diameter=25,
thickness=2.0,
thickness_unit=SizeUnit.MM,
model="FF01-624/40-25",
filter_wheel_index=3,
serial_number="Unknown-3",
Expand All @@ -146,6 +151,7 @@
manufacturer=Organization.CHROMA,
diameter=25,
thickness=2.0,
thickness_unit=SizeUnit.MM,
model="ET667/30m",
filter_wheel_index=4,
serial_number="Unknown-4",
Expand All @@ -156,6 +162,7 @@
manufacturer=Organization.THORLABS,
diameter=25,
thickness=2.0,
thickness_unit=SizeUnit.MM,
model="FELH0700",
filter_wheel_index=5,
serial_number="Unknown-5",
Expand Down
4 changes: 2 additions & 2 deletions examples/bergamo_ophys_session.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@
"frame_rate_unit": "hertz",
"coupled_fov_index": null,
"power": null,
"power_unit": "percent",
"power_unit": null,
"power_ratio": null,
"scanfield_z": null,
"scanfield_z_unit": "micrometer",
"scanfield_z_unit": null,
"scanimage_roi_index": null,
"notes": null
}
Expand Down
2 changes: 2 additions & 0 deletions examples/bergamo_ophys_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import datetime, timezone

from aind_data_schema_models.modalities import Modality
from aind_data_schema_models.units import FrequencyUnit

from aind_data_schema.components.stimulus import PhotoStimulation, PhotoStimulationGroup
from aind_data_schema.core.session import (
Expand Down Expand Up @@ -64,6 +65,7 @@
magnification="1x",
fov_scale_factor=1.5,
frame_rate=20,
frame_rate_unit=FrequencyUnit.HZ,
),
],
),
Expand Down
18 changes: 9 additions & 9 deletions examples/ephys_rig.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"height": null,
"size_unit": "millimeter",
"thickness": null,
"thickness_unit": "millimeter",
"thickness_unit": null,
"filter_wheel_index": null,
"cut_off_wavelength": null,
"cut_on_wavelength": null,
Expand Down Expand Up @@ -232,7 +232,7 @@
"height": null,
"size_unit": "millimeter",
"thickness": null,
"thickness_unit": "millimeter",
"thickness_unit": null,
"filter_wheel_index": null,
"cut_off_wavelength": null,
"cut_on_wavelength": null,
Expand Down Expand Up @@ -386,7 +386,7 @@
"additional_settings": {},
"notes": null,
"focal_length": null,
"focal_length_unit": "millimeter",
"focal_length_unit": null,
"size": null,
"lens_size_unit": "inch",
"optimized_wavelength_range": null,
Expand Down Expand Up @@ -464,7 +464,7 @@
"additional_settings": {},
"notes": null,
"focal_length": null,
"focal_length_unit": "millimeter",
"focal_length_unit": null,
"size": null,
"lens_size_unit": "inch",
"optimized_wavelength_range": null,
Expand Down Expand Up @@ -542,7 +542,7 @@
"additional_settings": {},
"notes": null,
"focal_length": null,
"focal_length_unit": "millimeter",
"focal_length_unit": null,
"size": null,
"lens_size_unit": "inch",
"optimized_wavelength_range": null,
Expand Down Expand Up @@ -620,7 +620,7 @@
"additional_settings": {},
"notes": null,
"focal_length": null,
"focal_length_unit": "millimeter",
"focal_length_unit": null,
"size": null,
"lens_size_unit": "inch",
"optimized_wavelength_range": null,
Expand Down Expand Up @@ -815,7 +815,7 @@
"port": null,
"channel_index": null,
"sample_rate": null,
"sample_rate_unit": "hertz",
"sample_rate_unit": null,
"event_based_sampling": null
},
{
Expand All @@ -825,7 +825,7 @@
"port": null,
"channel_index": null,
"sample_rate": null,
"sample_rate_unit": "hertz",
"sample_rate_unit": null,
"event_based_sampling": null
},
{
Expand All @@ -835,7 +835,7 @@
"port": null,
"channel_index": null,
"sample_rate": null,
"sample_rate_unit": "hertz",
"sample_rate_unit": null,
"event_based_sampling": null
}
],
Expand Down
15 changes: 14 additions & 1 deletion examples/ephys_rig.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from aind_data_schema_models.harp_types import HarpDeviceType
from aind_data_schema_models.modalities import Modality
from aind_data_schema_models.organizations import Organization
from aind_data_schema_models.units import FrequencyUnit, SizeUnit

from aind_data_schema.components.devices import (
Calibration,
Expand Down Expand Up @@ -91,6 +92,7 @@
manufacturer=Organization.FLIR,
computer_name=ephys_computer,
frame_rate=50,
frame_rate_unit=FrequencyUnit.HZ,
sensor_width=1080,
sensor_height=570,
sensor_format="1/2.9",
Expand All @@ -105,6 +107,7 @@
manufacturer=Organization.FLIR,
computer_name=ephys_computer,
frame_rate=50,
frame_rate_unit=FrequencyUnit.HZ,
sensor_width=1080,
sensor_height=570,
sensor_format="1/2.9",
Expand All @@ -119,6 +122,7 @@
manufacturer=Organization.FLIR,
computer_name=ephys_computer,
frame_rate=50,
frame_rate_unit=FrequencyUnit.HZ,
sensor_width=1080,
sensor_height=570,
sensor_format="1/2.9",
Expand All @@ -133,6 +137,7 @@
manufacturer=Organization.FLIR,
computer_name=ephys_computer,
frame_rate=50,
frame_rate_unit=FrequencyUnit.HZ,
sensor_width=1080,
sensor_height=570,
sensor_format="1/2.9",
Expand Down Expand Up @@ -197,7 +202,13 @@
description="850 nm longpass filter",
)

lens = Lens(name="Camera lens", focal_length=15, manufacturer=Organization.EDMUND_OPTICS, max_aperture="f/2")
lens = Lens(
name="Camera lens",
focal_length=15,
focal_length_unit=SizeUnit.MM,
manufacturer=Organization.EDMUND_OPTICS,
max_aperture="f/2",
)

face_camera = Camera(
name="Face Camera",
Expand All @@ -206,6 +217,7 @@
manufacturer=Organization.FLIR,
computer_name=behavior_computer,
frame_rate=50,
frame_rate_unit=FrequencyUnit.HZ,
sensor_width=1080,
sensor_height=570,
sensor_format="1/2.9",
Expand All @@ -228,6 +240,7 @@
manufacturer=Organization.FLIR,
computer_name=behavior_computer,
frame_rate=50,
frame_rate_unit=FrequencyUnit.HZ,
sensor_width=1080,
sensor_height=570,
sensor_format="1/2.9",
Expand Down
8 changes: 4 additions & 4 deletions examples/ephys_session.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"anatomical_coordinates": null,
"anatomical_reference": null,
"surface_z": null,
"surface_z_unit": "micrometer",
"surface_z_unit": null,
"dye": null,
"implant_hole_number": null
},
Expand Down Expand Up @@ -90,7 +90,7 @@
"anatomical_coordinates": null,
"anatomical_reference": null,
"surface_z": null,
"surface_z_unit": "micrometer",
"surface_z_unit": null,
"dye": null,
"implant_hole_number": null
}
Expand Down Expand Up @@ -192,7 +192,7 @@
"anatomical_coordinates": null,
"anatomical_reference": null,
"surface_z": null,
"surface_z_unit": "micrometer",
"surface_z_unit": null,
"dye": null,
"implant_hole_number": null
},
Expand Down Expand Up @@ -225,7 +225,7 @@
"anatomical_coordinates": null,
"anatomical_reference": null,
"surface_z": null,
"surface_z_unit": "micrometer",
"surface_z_unit": null,
"dye": null,
"implant_hole_number": null
}
Expand Down
4 changes: 2 additions & 2 deletions examples/exaspim_acquisition.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"excitation_power_unit": "milliwatt",
"filter_wheel_index": 0,
"dilation": null,
"dilation_unit": "pixel",
"dilation_unit": null,
"description": null
},
"notes": "these are my notes",
Expand Down Expand Up @@ -140,7 +140,7 @@
"excitation_power_unit": "milliwatt",
"filter_wheel_index": 0,
"dilation": null,
"dilation_unit": "pixel",
"dilation_unit": null,
"description": null
},
"notes": "these are my notes",
Expand Down
2 changes: 1 addition & 1 deletion examples/exaspim_instrument.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"cooling": "Air",
"computer_name": null,
"frame_rate": null,
"frame_rate_unit": "hertz",
"frame_rate_unit": null,
"immersion": null,
"chroma": null,
"sensor_width": null,
Expand Down
Loading

0 comments on commit 7ee0989

Please sign in to comment.