Skip to content

Commit

Permalink
add: new data_type for PointByPointScanData, "spec_motor_absolute"
Browse files Browse the repository at this point in the history
The new data type makes it possible to get a MapConfig for an EDD
dataset which does not have a .par file (like alignment scans).
  • Loading branch information
keara-soloway committed Mar 5, 2024
1 parent c2d721e commit 675e060
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
22 changes: 16 additions & 6 deletions CHAP/common/models/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ class PointByPointScanData(BaseModel):
"""
label: constr(min_length=1)
units: constr(strip_whitespace=True, min_length=1)
data_type: Literal['spec_motor', 'scan_column', 'smb_par', 'expression']
data_type: Literal['spec_motor', 'spec_motor_absolute', 'scan_column',
'smb_par', 'expression']
name: constr(strip_whitespace=True, min_length=1)

@validator('label')
Expand Down Expand Up @@ -383,7 +384,9 @@ def get_value(
requested.
:rtype: float
"""
if self.data_type == 'spec_motor':
if 'spec_motor' in self.data_type:
if 'absolute' in self.data_type:
relative = False
return get_spec_motor_value(spec_scans.spec_file,
scan_number,
scan_step_index,
Expand Down Expand Up @@ -911,6 +914,8 @@ def validate_attrs(cls, value, values):
value['dataset_id'] = cls.get_smb_par_attr(values, 'dataset_id')
axes_labels = {1: 'fly_labx', 2: 'fly_laby', 3: 'fly_labz',
4: 'fly_ometotal'}
if value['scan_type'] is None:
return value
if value['scan_type'] != 0:
value['fly_axis_labels'] = [
axes_labels[cls.get_smb_par_attr(values, 'fly_axis0')]]
Expand All @@ -932,7 +937,7 @@ def validate_map_type(cls, map_type, values):
:rtype: str
"""
dims = {}
attrs = values['attrs']
attrs = values.get('attrs', {})
scan_type = attrs.get('scan_type', -1)
fly_axis_labels = attrs.get('fly_axis_labels', [])
spec_scans = values['spec_scans']
Expand Down Expand Up @@ -992,9 +997,14 @@ def get_smb_par_attr(class_fields, label, units='-', name=None):
for scans in class_fields.get('spec_scans'):
for scan_number in scans.scan_numbers:
scanparser = scans.get_scanparser(scan_number)
for index in range(scanparser.spec_scan_npts):
values.append(
scalar_data.get_value(scans, scan_number, index))
try:
values.append(scanparser.pars[name])
except:
print(
f'Warning: No value found for .par file value "{name}"'
+ f' on scan {scan_number} in spec file '
+ f'{scans.spec_file}.')
values.append(None)
values = list(set(values))
if len(values) != 1:
raise ValueError(f'More than one {name} in map not allowed '
Expand Down
4 changes: 2 additions & 2 deletions CHAP/utils/scanparsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1209,8 +1209,8 @@ def get_spec_scan_motor_vals(self, relative=True):
# workflows, obtain them from relevant values available in
# the .par file, and defer implementation for absolute
# motor postions to later.
# return super().get_spec_scan_motor_vals(relative=True)
raise NotImplementedError('Only relative motor values are available.')
return super().get_spec_scan_motor_vals(relative=True)
# raise NotImplementedError('Only relative motor values are available.')
if self.spec_macro in ('flymesh', 'mesh', 'flydmesh', 'dmesh'):
mot_vals_axis0 = np.linspace(self.pars['fly_axis0_start'],
self.pars['fly_axis0_end'],
Expand Down

0 comments on commit 675e060

Please sign in to comment.