Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING CHANGE: Refactoring to CoordinateSystem, Coordinate, and RelativePosition #1311

Draft
wants to merge 27 commits into
base: release-v2.0.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
25b4126
feat: defining coordinates for v2
dbirman Mar 6, 2025
83c9b38
fix: small tweaks to coordinates v2
dbirman Mar 6, 2025
a8a5e3e
refactor: first pass modifying code to use new coordinate patterns
dbirman Mar 6, 2025
4e728b6
refactor: refactor to match discussion with David
dbirman Mar 6, 2025
48ee71c
feat: working on adding to_matrix functions for transforms
dbirman Mar 7, 2025
81989a2
fix: changing title string
dbirman Mar 7, 2025
8bf2701
refactor: use optional scipy dependency in Rotation
dbirman Mar 11, 2025
327a8b4
Merge branch 'release-v2.0.0' into breaking-atlas-refactor-v2
dbirman Mar 11, 2025
dbeb29e
refactor: procedures refactored to accept new coordinate systems
dbirman Mar 11, 2025
ae97e1b
refactor: ephys coordinates
dbirman Mar 11, 2025
aec9462
chore: lint
dbirman Mar 11, 2025
bd3b63d
chore: typo
dbirman Mar 11, 2025
8bd953e
refactor: adding atlas to acquisition, starting to repair examples
dbirman Mar 11, 2025
6a41204
refactor: working on ManipulatorConfig
dbirman Mar 11, 2025
a9c862e
fix: functional compose and test coverage
dbirman Mar 11, 2025
0f5bbb3
refactor: multiply_matrices -> np.matmul
dbirman Mar 11, 2025
a2ebd13
chore: lint
dbirman Mar 11, 2025
596257f
feat: add validator for atlas axes
dbirman Mar 11, 2025
b04b794
refactor: working on changing examples to new pattern
dbirman Mar 11, 2025
4a659ac
refactor: fixing example instrument
dbirman Mar 11, 2025
dcb2912
refactor: continuing to fix examples
dbirman Mar 11, 2025
72efd06
chore: minor
dbirman Mar 11, 2025
459aa79
refactor: instrument refactors
dbirman Mar 11, 2025
4f7e44e
refactor: remove rotation_direction, continue refactoring examples
dbirman Mar 12, 2025
4dcaa66
refactor: fix occurrences of NanojectInjection, fix some coordinates
dbirman Mar 12, 2025
1ec1e35
refactor: replace bregma_to_lambda with measured_coordinates
dbirman Mar 12, 2025
2f9a382
refactor: use new coordinate pattern
dbirman Mar 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/source/example_workflow/example_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from aind_data_schema.core.data_description import Funding, RawDataDescription
from aind_data_schema.core.procedures import (
NanojectInjection,
BrainInjection,
Perfusion,
Procedures,
Surgery,
Expand Down Expand Up @@ -99,7 +99,7 @@
ethics_review_id=ethics_review_id,
experimenters=[experimenter],
procedures=[
NanojectInjection(
BrainInjection(
protocol_id=protocol,
injection_materials=[
ViralMaterial(
Expand Down
15 changes: 15 additions & 0 deletions examples/aibs_smartspim_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
)
from aind_data_schema_models.modalities import Modality
from aind_data_schema.core.instrument import Com, Instrument
from aind_data_schema.components.coordinates import (
Axis,
AxisName,
CoordinateSystem,
Direction,
Origin,
)

objective = Objective(
name="TLX Objective",
Expand Down Expand Up @@ -182,6 +189,14 @@
instrument_id="440_SmartSPIM2_20231004",
modification_date=datetime.date(2023, 10, 4),
instrument_type=ImagingInstrumentType.SMARTSPIM,
coordinate_system=CoordinateSystem(
origin=Origin.BREGMA,
axes=[
Axis(name=AxisName.AP, direction=Direction.AP),
Axis(name=AxisName.ML, direction=Direction.LR),
Axis(name=AxisName.SI, direction=Direction.SI),
],
),
modalities=[Modality.SPIM],
manufacturer=Organization.LIFECANVAS,
temperature_control=False,
Expand Down
15 changes: 15 additions & 0 deletions examples/aind_smartspim_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
)
from aind_data_schema.core.instrument import Com, Detector, Instrument, Objective
from aind_data_schema_models.modalities import Modality
from aind_data_schema.components.coordinates import (
Axis,
AxisName,
CoordinateSystem,
Direction,
Origin,
)

objective_1 = Objective(
name="TLX Objective 1",
Expand Down Expand Up @@ -248,6 +255,14 @@
instrument_type=ImagingInstrumentType.SMARTSPIM,
manufacturer=Organization.LIFECANVAS,
modification_date=date(2023, 10, 4),
coordinate_system=CoordinateSystem(
origin=Origin.BREGMA,
axes=[
Axis(name=AxisName.AP, direction=Direction.AP),
Axis(name=AxisName.ML, direction=Direction.LR),
Axis(name=AxisName.SI, direction=Direction.SI),
],
),
modalities=[Modality.SPIM],
components=[
*objectives,
Expand Down
203 changes: 104 additions & 99 deletions examples/ephys_acquisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,111 @@
SubjectDetails,
)
from aind_data_schema.components.configs import (
CcfCoords,
Coordinates3d,
DomeModule,
ManipulatorModule,
ManipulatorConfig,
StimulusModality,
)
from aind_data_schema.components.coordinates import Coordinate, FloatAxis, AxisName
from aind_data_schema.components.stimulus import VisualStimulation
from aind_data_schema_models.brain_atlas import CCFStructure

bonsai_software = Software(name="Bonsai", version="2.7")


ephys_config_a = ManipulatorConfig(
rotation_angle=0,
arc_angle=5.2,
module_angle=8,
atlas_coordinates=[
Coordinate(
position=[
FloatAxis(value=8150, axis=AxisName.ML),
FloatAxis(value=3250, axis=AxisName.AP),
FloatAxis(value=7800, axis=AxisName.SI),
]
),
],
device_name="Ephys_assemblyA",
coordinate_transform="behavior/calibration_info_np2_2023_04_24.npy",
primary_targeted_structure=CCFStructure.LGD,
manipulator_axis_position=[
Coordinate(
position=[
FloatAxis(value=8422, axis=AxisName.ML),
FloatAxis(value=4205, axis=AxisName.AP),
FloatAxis(value=11087.5, axis=AxisName.SI),
]
),
],
calibration_date=datetime(year=2023, month=4, day=25, tzinfo=timezone.utc),
notes=(
"Moved Y to avoid blood vessel, X to avoid edge. Mouse made some noise during the recording"
" with a sudden shift in signals. Lots of motion. Maybe some implant motion."
),
)

ephys_config_b = ManipulatorConfig(
rotation_angle=0,
arc_angle=25,
module_angle=-22,
atlas_coordinates=[
Coordinate(
position=[
FloatAxis(value=8150, axis=AxisName.ML),
FloatAxis(value=3250, axis=AxisName.AP),
FloatAxis(value=7800, axis=AxisName.SI),
]
),
],
device_name="Ephys_assemblyB",
coordinate_transform="behavior/calibration_info_np2_2023_04_24.py",
primary_targeted_structure=CCFStructure.LC,
manipulator_axis_position=[
Coordinate(
position=[
FloatAxis(value=8422, axis=AxisName.ML),
FloatAxis(value=4205, axis=AxisName.AP),
FloatAxis(value=11087.5, axis=AxisName.SI),
]
),
],
calibration_date=datetime(year=2023, month=4, day=25, tzinfo=timezone.utc),
notes=(
"Trouble penetrating. Lots of compression, needed to move probe. Small amount of surface"
" bleeding/bruising. Initial Target: X;10070.3\tY:7476.6"
),
)


stick_config_1 = DomeModule(
rotation_angle=0,
device_name="Stick_assembly_1",
arc_angle=-180,
module_angle=-180,
notes="did not record angles, did not calibrate.",
)
stick_config_2 = DomeModule(
rotation_angle=0,
device_name="Stick_assembly_2",
arc_angle=-180,
module_angle=-180,
notes="Did not record angles, did not calibrate",
)
stick_config_3 = DomeModule(
rotation_angle=0,
device_name="Stick_assembly_3",
arc_angle=-180,
module_angle=-180,
notes="Did not record angles, did not calibrate",
)
stick_config_4 = DomeModule(
rotation_angle=0,
device_name="Stick_assembly_4",
arc_angle=-180,
module_angle=-180,
notes="Did not record angles, did not calibrate",
)

acquisition = Acquisition(
experimenters=[Person(name="John Smith")],
subject_id="664484",
Expand Down Expand Up @@ -89,65 +183,12 @@
"Ephys_assemblyB",
],
configurations=[
DomeModule(
rotation_angle=0,
device_name="Stick_assembly_1",
arc_angle=-180,
module_angle=-180,
notes="did not record angles, did not calibrate.",
),
DomeModule(
rotation_angle=0,
device_name="Stick_assembly_2",
arc_angle=-180,
module_angle=-180,
notes="Did not record angles, did not calibrate",
),
DomeModule(
rotation_angle=0,
device_name="Stick_assembly_3",
arc_angle=-180,
module_angle=-180,
notes="Did not record angles, did not calibrate",
),
DomeModule(
rotation_angle=0,
device_name="Stick_assembly_4",
arc_angle=-180,
module_angle=-180,
notes="Did not record angles, did not calibrate",
),
ManipulatorModule(
targeted_ccf_coordinates=[
CcfCoords(ml=8150, ap=3250, dv=7800),
],
device_name="Ephys_assemblyA",
arc_angle=5.2,
module_angle=8,
coordinate_transform="behavior/calibration_info_np2_2023_04_24.npy",
primary_targeted_structure=CCFStructure.LGD,
manipulator_coordinates=Coordinates3d(x=8422, y=4205, z=11087.5),
calibration_date=datetime(year=2023, month=4, day=25, tzinfo=timezone.utc),
notes=(
"Moved Y to avoid blood vessel, X to avoid edge. Mouse made some noise during the recording"
" with a sudden shift in signals. Lots of motion. Maybe some implant motion."
),
),
ManipulatorModule(
rotation_angle=0,
arc_angle=25,
module_angle=-22,
targeted_ccf_coordinates=[CcfCoords(ml=6637.28, ap=4265.02, dv=10707.35)],
device_name="Ephys_assemblyB",
coordinate_transform="behavior/calibration_info_np2_2023_04_24.py",
primary_targeted_structure=CCFStructure.LC,
manipulator_coordinates=Coordinates3d(x=9015, y=7144, z=13262),
calibration_date=datetime(year=2023, month=4, day=25, tzinfo=timezone.utc),
notes=(
"Trouble penetrating. Lots of compression, needed to move probe. Small amount of surface"
" bleeding/bruising. Initial Target: X;10070.3\tY:7476.6"
),
),
ephys_config_a,
ephys_config_b,
stick_config_1,
stick_config_2,
stick_config_3,
stick_config_4,
],
),
DataStream(
Expand All @@ -162,43 +203,7 @@
"Ephys_assemblyB",
],
configurations=[
DomeModule(
rotation_angle=0,
device_name="Stick_assembly_1",
arc_angle=-180,
module_angle=-180,
notes="did not record angles, did not calibrate.",
),
ManipulatorModule(
rotation_angle=0,
arc_angle=5.2,
module_angle=8,
targeted_ccf_coordinates=[CcfCoords(ml=8150, ap=3250, dv=7800)],
device_name="Ephys_assemblyA",
coordinate_transform="behavior/calibration_info_np2_2023_04_24.npy",
primary_targeted_structure=CCFStructure.LGD,
manipulator_coordinates=Coordinates3d(x=8422, y=4205, z=11087.5),
calibration_date=datetime(year=2023, month=4, day=25, tzinfo=timezone.utc),
notes=(
"Moved Y to avoid blood vessel, X to avoid edge. Mouse made some noise during the recording"
" with a sudden shift in signals. Lots of motion. Maybe some implant motion."
),
),
ManipulatorModule(
rotation_angle=0,
arc_angle=25,
module_angle=-22,
targeted_ccf_coordinates=[CcfCoords(ml=6637.28, ap=4265.02, dv=10707.35)],
device_name="Ephys_assemblyB",
coordinate_transform="behavior/calibration_info_np2_2023_04_24.py",
primary_targeted_structure=CCFStructure.LC,
manipulator_coordinates=Coordinates3d(x=9015, y=7144, z=13262),
calibration_date=datetime(year=2023, month=4, day=25, tzinfo=timezone.utc),
notes=(
"Trouble penetrating. Lots of compression, needed to move probe. Small amount of surface"
" bleeding/bruising. Initial Target: X;10070.3\tY:7476.6"
),
),
stick_config_1,
],
),
],
Expand Down
35 changes: 29 additions & 6 deletions examples/ephys_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
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.coordinates import (
RelativePosition,
AnatomicalRelative,
CoordinateSystem,
Origin,
Axis,
AxisName,
Direction,
)

from aind_data_schema.components.devices import (
Calibration,
Expand Down Expand Up @@ -149,28 +158,32 @@

microscope_1 = CameraAssembly(
name="Stick_assembly_1",
camera_target=CameraTarget.BRAIN_SURFACE, # NEEDS TO BE FILLED OUT
target=CameraTarget.BRAIN,
position=RelativePosition(position=[AnatomicalRelative.SUPERIOR]),
camera=probe_camera_1,
lens=stick_lens,
)

microscope_2 = CameraAssembly(
name="Stick_assembly_2",
camera_target=CameraTarget.BRAIN_SURFACE, # NEEDS TO BE FILLED OUT
target=CameraTarget.BRAIN,
position=RelativePosition(position=[AnatomicalRelative.SUPERIOR]),
camera=probe_camera_2,
lens=stick_lens,
)

microscope_3 = CameraAssembly(
name="Stick_assembly_3",
camera_target=CameraTarget.BRAIN_SURFACE, # NEEDS TO BE FILLED OUT
target=CameraTarget.BRAIN,
position=RelativePosition(position=[AnatomicalRelative.SUPERIOR]),
camera=probe_camera_3,
lens=stick_lens,
)

microscope_4 = CameraAssembly(
name="Stick_assembly_4",
camera_target=CameraTarget.BRAIN_SURFACE, # NEEDS TO BE FILLED OUT
target=CameraTarget.BRAIN,
position=RelativePosition(position=[AnatomicalRelative.SUPERIOR]),
camera=probe_camera_4,
lens=stick_lens,
)
Expand Down Expand Up @@ -228,7 +241,8 @@
camassm1 = CameraAssembly(
name="Face Camera Assembly",
camera=face_camera,
camera_target="Face side left",
target=CameraTarget.FACE,
position=RelativePosition(position=[AnatomicalRelative.LEFT]),
filter=filt,
lens=lens,
)
Expand All @@ -250,8 +264,9 @@

camassm2 = CameraAssembly(
name="Body Camera Assembly",
target=CameraTarget.BODY,
position=RelativePosition(position=[AnatomicalRelative.SUPERIOR]),
camera=body_camera,
camera_target="Body",
filter=filt,
lens=lens,
)
Expand Down Expand Up @@ -279,6 +294,14 @@
instrument_id="323_EPHYS1_20231003",
modification_date=date(2023, 10, 3),
modalities=[Modality.ECEPHYS],
coordinate_system=CoordinateSystem(
origin=Origin.BREGMA,
axes=[
Axis(name=AxisName.AP, direction=Direction.AP),
Axis(name=AxisName.ML, direction=Direction.LR),
Axis(name=AxisName.SI, direction=Direction.SI),
],
),
components=[
ephys_assemblyA,
ephys_assemblyB,
Expand Down
Loading
Loading