55from enum import Enum
66from typing import List , Literal , Optional
77
8- from pydantic import Field , ValidationInfo , field_validator
8+ from pydantic import Field , ValidationInfo , field_validator , model_validator
99
1010from aind_data_schema .base import AindCoreModel , AindGenericType , AindModel
1111from aind_data_schema .core .procedures import Anaesthetic
@@ -47,13 +47,13 @@ class MRIScan(AindModel):
4747 scan_sequence_type : MriScanSequence = Field (..., title = "Scan sequence" )
4848 rare_factor : Optional [int ] = Field (None , title = "RARE factor" )
4949 echo_time : Decimal = Field (..., title = "Echo time (ms)" )
50- effective_echo_time : Decimal = Field (... , title = "Effective echo time (ms)" )
50+ effective_echo_time : Optional [ Decimal ] = Field (None , title = "Effective echo time (ms)" )
5151 echo_time_unit : TimeUnit = Field (TimeUnit .MS , title = "Echo time unit" )
5252 repetition_time : Decimal = Field (..., title = "Repetition time (ms)" )
5353 repetition_time_unit : TimeUnit = Field (TimeUnit .MS , title = "Repetition time unit" )
5454 # fields required to get correct orientation
55- vc_orientation : Rotation3dTransform = Field (... , title = "Scan orientation" )
56- vc_position : Translation3dTransform = Field (... , title = "Scan position" )
55+ vc_orientation : Optional [ Rotation3dTransform ] = Field (None , title = "Scan orientation" )
56+ vc_position : Optional [ Translation3dTransform ] = Field (None , title = "Scan position" )
5757 subject_position : SubjectPosition = Field (..., title = "Subject position" )
5858 # other fields
5959 voxel_sizes : Scale3dTransform = Field (..., title = "Voxel sizes" , description = "Resolution" )
@@ -77,6 +77,14 @@ def validate_other(cls, value: Optional[str], info: ValidationInfo) -> Optional[
7777 " Describe the scan_sequence_type in the notes field."
7878 )
7979 return value
80+
81+ @model_validator (mode = "after" )
82+ def validate_primary_scan (self ):
83+ if self .primary_scan :
84+ if not self .vc_orientation or not self .vc_position :
85+ raise ValueError (
86+ "Primary scan must have vc_orientation and vc_position"
87+ )
8088
8189
8290class MriSession (AindCoreModel ):
0 commit comments