Skip to content

Commit

Permalink
feat: added attributes to map_config (for EDD right now)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfverberg committed Feb 6, 2024
1 parent 77e603d commit 353eaea
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion CHAP/common/models/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,7 @@ class MapConfig(BaseModel):
dwell_time_actual: Optional[DwellTimeActual]
postsample_intensity: Optional[PostsampleIntensity]
map_type: Optional[Literal['structured', 'unstructured']] = 'structured'
attrs: Optional[dict] = {}
_coords: dict = PrivateAttr()
_dims: tuple = PrivateAttr()
_scan_step_indices: list = PrivateAttr()
Expand Down Expand Up @@ -879,7 +880,7 @@ def validate_map_type(cls, map_type, values):
@validator('experiment_type')
def validate_experiment_type(cls, value, values):
"""Ensure values for the station and experiment_type fields are
compatible
compatible.
"""
station = values.get('station')
if station == 'id1a3':
Expand All @@ -897,6 +898,34 @@ def validate_experiment_type(cls, value, values):
f'Supplied experiment type {value} is not allowed.')
return value

@validator('attrs', always=True)
def validate_attrs(cls, value, values):
"""Read any additional attributes depending on the values for
the station and experiment_type fields.
"""
# Get the map's scan_type for EDD experiments
station = values.get('station')
experiment_type = values.get('experiment_type')
if station in ['id1a3', 'id3a'] and experiment_type == 'EDD':
scan_type = PointByPointScanData(
label='scan_type', data_type='smb_par', units='-',
name='scan_type')
scan_types = []
for scans in values.get('spec_scans'):
for scan_number in scans.scan_numbers:
scanparser = scans.get_scanparser(scan_number)
scan_step_index_range = range(scanparser.spec_scan_npts)
for index in scan_step_index_range:
scan_types.append(
scan_type.get_value(scans, scan_number, index))
scan_types = list(set(scan_types))
if len(scan_types) != 1:
raise ValueError('More than one scan_type in map not allowed '
f'({scan_types})')
scan_type = scan_types[0]
value['scan_type'] = scan_type
return value

@property
def all_scalar_data(self):
"""Return a list of all instances of `PointByPointScanData`
Expand Down

0 comments on commit 353eaea

Please sign in to comment.