Skip to content

Commit

Permalink
Merge pull request #1227 from AllenNeuralDynamics/1225-20-rename-aind…
Browse files Browse the repository at this point in the history
…x-models

refactor: rename AindX classes to show their actual purposes
  • Loading branch information
dbirman authored Jan 14, 2025
2 parents b6be2bb + 19ca120 commit a3668cb
Show file tree
Hide file tree
Showing 24 changed files with 198 additions and 184 deletions.
2 changes: 1 addition & 1 deletion src/aind_data_schema/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" imports for AindModel subclasses
""" imports for DataModel subclasses
"""

__version__ = "2.0.0"
12 changes: 7 additions & 5 deletions src/aind_data_schema/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def has_corrupt_keys(input) -> bool:
return has_corrupt_keys(input_dict)


class AindGeneric(BaseModel, extra="allow"):
class GenericModel(BaseModel, extra="allow"):
"""Base class for generic types that can be used in AIND schema"""

# extra="allow" is needed because BaseModel by default drops extra parameters.
Expand All @@ -91,10 +91,10 @@ def validate_fieldnames(self):
return self


AindGenericType = TypeVar("AindGenericType", bound=AindGeneric)
GenericModelType = TypeVar("GenericModelType", bound=GenericModel)


class AindModel(BaseModel, Generic[AindGenericType]):
class DataModel(BaseModel, Generic[GenericModelType]):
"""BaseModel that disallows extra fields
Also performs validation checks / coercion / upgrades where necessary
Expand Down Expand Up @@ -130,7 +130,7 @@ def unit_validator(cls, values):
return values


class AindCoreModel(AindModel):
class DataCoreModel(DataModel):
"""Generic base class to hold common fields/validators/etc for all basic AIND schema"""

_FILE_EXTENSION = PrivateAttr(default=".json")
Expand All @@ -154,7 +154,9 @@ def default_filename(cls):
"""
Returns standard filename in snakecase
"""
parent_classes = [base_class for base_class in cls.__bases__ if base_class.__name__ != AindCoreModel.__name__]
parent_classes = [
base_class for base_class in cls.__bases__ if base_class.__name__ != DataCoreModel.__name__
]

name = cls.__name__

Expand Down
22 changes: 11 additions & 11 deletions src/aind_data_schema/components/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pydantic import Field
from typing_extensions import Annotated

from aind_data_schema.base import AindModel
from aind_data_schema.base import DataModel


class CcfVersion(str, Enum):
Expand Down Expand Up @@ -45,7 +45,7 @@ class AnatomicalDirection(str, Enum):
OTHER = "Other"


class CoordinateTransform(AindModel):
class CoordinateTransform(DataModel):
"""Generic base class for coordinate transform subtypes"""

type: str = Field(..., title="transformation type")
Expand Down Expand Up @@ -83,15 +83,15 @@ class Affine3dTransform(CoordinateTransform):
)


class Size2d(AindModel):
class Size2d(DataModel):
"""2D size of an object"""

width: int = Field(..., title="Width")
height: int = Field(..., title="Height")
unit: SizeUnit = Field(SizeUnit.PX, title="Size unit")


class Size3d(AindModel):
class Size3d(DataModel):
"""3D size of an object"""

width: int = Field(..., title="Width")
Expand All @@ -100,7 +100,7 @@ class Size3d(AindModel):
unit: SizeUnit = Field(SizeUnit.M, title="Size unit")


class Orientation3d(AindModel):
class Orientation3d(DataModel):
"""3D orientation of an object"""

pitch: Decimal = Field(..., title="Angle pitch", ge=0, le=360)
Expand All @@ -109,15 +109,15 @@ class Orientation3d(AindModel):
unit: AngleUnit = Field(AngleUnit.DEG, title="Angle unit")


class ModuleOrientation2d(AindModel):
class ModuleOrientation2d(DataModel):
"""2D module orientation of an object"""

arc_angle: Decimal = Field(..., title="Arc angle")
module_angle: Decimal = Field(..., title="Module angle")
unit: AngleUnit = Field(AngleUnit.DEG, title="Angle unit")


class ModuleOrientation3d(AindModel):
class ModuleOrientation3d(DataModel):
"""3D module orientation of an object"""

arc_angle: Decimal = Field(..., title="Arc angle")
Expand All @@ -126,7 +126,7 @@ class ModuleOrientation3d(AindModel):
unit: AngleUnit = Field(AngleUnit.DEG, title="Angle unit")


class Coordinates3d(AindModel):
class Coordinates3d(DataModel):
"""Coordinates in a 3D grid"""

x: Decimal = Field(..., title="Position X")
Expand All @@ -135,7 +135,7 @@ class Coordinates3d(AindModel):
unit: SizeUnit = Field(SizeUnit.UM, title="Position unit")


class CcfCoords(AindModel):
class CcfCoords(DataModel):
"""Coordinates in CCF template space"""

ml: Decimal = Field(..., title="ML")
Expand All @@ -145,7 +145,7 @@ class CcfCoords(AindModel):
ccf_version: CcfVersion = Field(CcfVersion.CCFv3, title="CCF version")


class Axis(AindModel):
class Axis(DataModel):
"""Description of an axis"""

name: AxisName = Field(..., title="Axis")
Expand All @@ -168,7 +168,7 @@ class ImageAxis(Axis):
unit: SizeUnit = Field(SizeUnit.UM, title="Axis physical units")


class RelativePosition(AindModel):
class RelativePosition(DataModel):
"""Position and rotation of a device in a rig or instrument"""

device_position_transformations: List[
Expand Down
34 changes: 17 additions & 17 deletions src/aind_data_schema/components/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from pydantic import Field, ValidationInfo, field_validator, model_validator
from typing_extensions import Annotated

from aind_data_schema.base import AindGeneric, AindGenericType, AindModel, AwareDatetimeWithDefault
from aind_data_schema.base import GenericModel, GenericModelType, DataModel, AwareDatetimeWithDefault
from aind_data_schema.components.coordinates import RelativePosition, Size3d
from aind_data_schema.components.reagent import Reagent

Expand Down Expand Up @@ -261,7 +261,7 @@ class MyomatrixArrayType(str, Enum):
SUTURED = "Sutured"


class Device(AindModel):
class Device(DataModel):
"""Generic device"""

device_type: str = Field(..., title="Device type") # Needs to be set by child classes that inherits
Expand All @@ -273,31 +273,31 @@ class Device(AindModel):
default=None, title="Path to CAD diagram", description="For CUSTOM manufactured devices"
)
port_index: Optional[str] = Field(default=None, title="Port index")
additional_settings: AindGenericType = Field(AindGeneric(), title="Additional parameters")
additional_settings: GenericModelType = Field(GenericModel(), title="Additional parameters")
notes: Optional[str] = Field(default=None, title="Notes")


class Software(AindModel):
class Software(DataModel):
"""Description of generic software"""

name: str = Field(..., title="Software name")
version: str = Field(..., title="Software version")
url: Optional[str] = Field(default=None, title="URL to commit being used")
parameters: AindGenericType = Field(AindGeneric(), title="Software parameters")
parameters: GenericModelType = Field(GenericModel(), title="Software parameters")


class Calibration(AindModel):
class Calibration(DataModel):
"""Generic calibration class"""

calibration_date: AwareDatetimeWithDefault = Field(..., title="Date and time of calibration")
device_name: str = Field(..., title="Device name", description="Must match a device name in rig/instrument")
description: str = Field(..., title="Description", description="Brief description of what is being calibrated")
input: AindGenericType = Field(AindGeneric(), description="Calibration input", title="inputs")
output: AindGenericType = Field(AindGeneric(), description="Calibration output", title="outputs")
input: GenericModelType = Field(GenericModel(), description="Calibration input", title="inputs")
output: GenericModelType = Field(GenericModel(), description="Calibration output", title="outputs")
notes: Optional[str] = Field(default=None, title="Notes")


class Maintenance(AindModel):
class Maintenance(DataModel):
"""Generic maintenance class"""

maintenance_date: AwareDatetimeWithDefault = Field(..., title="Date and time of maintenance")
Expand Down Expand Up @@ -444,7 +444,7 @@ def validate_other(cls, value: Optional[str], info: ValidationInfo) -> Optional[
return value


class CameraAssembly(AindModel):
class CameraAssembly(DataModel):
"""Named assembly of a camera and lens (and optionally a filter)"""

# required fields
Expand All @@ -458,7 +458,7 @@ class CameraAssembly(AindModel):
position: Optional[RelativePosition] = Field(default=None, title="Relative position of this assembly")


class DAQChannel(AindModel):
class DAQChannel(DataModel):
"""Named input or output channel on a DAQ device"""

# required fields
Expand Down Expand Up @@ -560,7 +560,7 @@ class Lamp(Device):
temperature_unit: Optional[TemperatureUnit] = Field(default=None, title="Temperature unit")


class ProbePort(AindModel):
class ProbePort(DataModel):
"""Port for a probe connection"""

index: int = Field(..., title="One-based port index")
Expand Down Expand Up @@ -610,7 +610,7 @@ class Patch(Device):
photobleaching_date: Optional[date] = Field(default=None, title="Photobleaching date")


class LaserAssembly(AindModel):
class LaserAssembly(DataModel):
"""Assembly for optogenetic stimulation"""

name: str = Field(..., title="Laser assembly name")
Expand Down Expand Up @@ -638,7 +638,7 @@ class EphysProbe(Device):
headstage: Optional[Headstage] = Field(default=None, title="Headstage for this probe")


class EphysAssembly(AindModel):
class EphysAssembly(DataModel):
"""Module for electrophysiological recording"""

name: str = Field(..., title="Ephys assembly name")
Expand All @@ -659,7 +659,7 @@ class FiberProbe(Device):
length_unit: SizeUnit = Field(default=SizeUnit.MM, title="Length unit")


class FiberAssembly(AindModel):
class FiberAssembly(DataModel):
"""Module for inserted fiber photometry recording"""

name: str = Field(..., title="Fiber assembly name")
Expand Down Expand Up @@ -839,7 +839,7 @@ def validate_other(self):
return self


class RewardDelivery(AindModel):
class RewardDelivery(DataModel):
"""Description of reward delivery system"""

device_type: Literal["Reward delivery"] = "Reward delivery"
Expand All @@ -862,7 +862,7 @@ class ChannelType(Enum):
CARRIER = "Carrier"


class OlfactometerChannel(AindModel):
class OlfactometerChannel(DataModel):
"""description of a Olfactometer channel"""

channel_index: int = Field(..., title="Channel index")
Expand Down
4 changes: 2 additions & 2 deletions src/aind_data_schema/components/reagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from aind_data_schema_models.pid_names import PIDName
from pydantic import Field

from aind_data_schema.base import AindModel
from aind_data_schema.base import DataModel


class Reagent(AindModel):
class Reagent(DataModel):
"""Description of reagent used in procedure"""

name: str = Field(..., title="Name")
Expand Down
26 changes: 13 additions & 13 deletions src/aind_data_schema/components/stimulus.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from aind_data_schema_models.units import ConcentrationUnit, FrequencyUnit, PowerUnit, TimeUnit
from pydantic import Field, model_validator

from aind_data_schema.base import AindGeneric, AindGenericType, AindModel
from aind_data_schema.base import GenericModel, GenericModelType, DataModel


class PulseShape(str, Enum):
Expand All @@ -25,7 +25,7 @@ class FilterType(str, Enum):
OTHER = "Other"


class OptoStimulation(AindModel):
class OptoStimulation(DataModel):
"""Description of opto stimulation parameters"""

stimulus_type: Literal["Opto Stimulation"] = "Opto Stimulation"
Expand All @@ -49,17 +49,17 @@ class OptoStimulation(AindModel):
description="Duration of baseline recording prior to first pulse train",
)
baseline_duration_unit: TimeUnit = Field(default=TimeUnit.S, title="Baseline duration unit")
other_parameters: AindGenericType = Field(AindGeneric(), title="Other parameters")
other_parameters: GenericModelType = Field(GenericModel(), title="Other parameters")
notes: Optional[str] = Field(default=None, title="Notes")


class VisualStimulation(AindModel):
class VisualStimulation(DataModel):
"""Description of visual stimulus parameters. Provides a high level description of stimulus."""

stimulus_type: Literal["Visual Stimulation"] = "Visual Stimulation"
stimulus_name: str = Field(..., title="Stimulus name")
stimulus_parameters: AindGenericType = Field(
AindGeneric(),
stimulus_parameters: GenericModelType = Field(
GenericModel(),
title="Stimulus parameters",
description="Define and list the parameter values used (e.g. all TF or orientation values)",
)
Expand All @@ -71,7 +71,7 @@ class VisualStimulation(AindModel):
notes: Optional[str] = Field(default=None, title="Notes")


class PhotoStimulationGroup(AindModel):
class PhotoStimulationGroup(DataModel):
"""Description of a photostimulation group"""

group_index: int = Field(..., title="Group index")
Expand All @@ -84,11 +84,11 @@ class PhotoStimulationGroup(AindModel):
spiral_duration_unit: TimeUnit = Field(default=TimeUnit.S, title="Spiral duration unit")
inter_spiral_interval: Decimal = Field(..., title="Inter trial interval (s)")
inter_spiral_interval_unit: TimeUnit = Field(default=TimeUnit.S, title="Inter trial interval unit")
other_parameters: AindGenericType = Field(AindGeneric(), title="Other parameters")
other_parameters: GenericModelType = Field(GenericModel(), title="Other parameters")
notes: Optional[str] = Field(default=None, title="Notes")


class PhotoStimulation(AindModel):
class PhotoStimulation(DataModel):
"""Description of a photostimulation session"""

stimulus_type: Literal["Photo Stimulation"] = "Photo Stimulation"
Expand All @@ -97,11 +97,11 @@ class PhotoStimulation(AindModel):
groups: List[PhotoStimulationGroup] = Field(..., title="Groups")
inter_trial_interval: Decimal = Field(..., title="Inter trial interval (s)")
inter_trial_interval_unit: TimeUnit = Field(default=TimeUnit.S, title="Inter trial interval unit")
other_parameters: AindGenericType = Field(AindGeneric(), title="Other parameters")
other_parameters: GenericModelType = Field(GenericModel(), title="Other parameters")
notes: Optional[str] = Field(default=None, title="Notes")


class OlfactometerChannelConfig(AindModel):
class OlfactometerChannelConfig(DataModel):
"""Description of olfactometer channel configurations"""

channel_index: int = Field(..., title="Channel index")
Expand All @@ -111,7 +111,7 @@ class OlfactometerChannelConfig(AindModel):
notes: Optional[str] = Field(default=None, title="Notes")


class OlfactoryStimulation(AindModel):
class OlfactoryStimulation(DataModel):
"""Description of a olfactory stimulus"""

stimulus_type: Literal["Olfactory Stimulation"] = "Olfactory Stimulation"
Expand All @@ -120,7 +120,7 @@ class OlfactoryStimulation(AindModel):
notes: Optional[str] = Field(default=None, title="Notes")


class AuditoryStimulation(AindModel):
class AuditoryStimulation(DataModel):
"""Description of an auditory stimulus"""

stimulus_type: Literal["Auditory Stimulation"] = "Auditory Stimulation"
Expand Down
Loading

0 comments on commit a3668cb

Please sign in to comment.