Skip to content

Commit

Permalink
Merge pull request #28 from LCOGT/update_acquire_strategies
Browse files Browse the repository at this point in the history
do some extra conversions for acquire and ag strategy
  • Loading branch information
jnation3406 committed Jun 12, 2019
2 parents eb9acd3 + 14e6282 commit b71dac9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
22 changes: 15 additions & 7 deletions observation_portal/blocks/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ def pointing_to_target_type(pointing_type, coordinate_type):
return 'ORBITAL_ELEMENTS'


def acquire_mode_from_strategy(ag_strategy):
if 'WCS' in ag_strategy.upper():
return 'WCS'
else:
return 'BRIGHTEST'


def convert_pond_blocks_to_observations(blocks):
if isinstance(blocks, list):
return [convert_pond_block_to_observation(block) for block in blocks]
Expand Down Expand Up @@ -136,7 +143,7 @@ def convert_pond_block_to_observation(block):

ag_extra_params = {}
if molecule.get('ag_strategy'):
ag_extra_params['guide_strategy'] = molecule['ag_strategy']
ag_extra_params['ag_strategy'] = molecule['ag_strategy']

(guide_mode, guide_optional) = pond_ag_mode_to_guiding_mode(molecule.get('ag_mode', 'OPT'))
if block.get('instrument_class').upper() in ['1M0-NRES-SCICAM', '1M0-NRES-COMMISIONING', '2M0-FLOYDS-SCICAM']:
Expand All @@ -151,14 +158,15 @@ def convert_pond_block_to_observation(block):
'extra_params': ag_extra_params
}

acquire_mode = 'OFF'
acquire_mode = molecule.get('acquire_mode', 'OFF')
acquire_extra_params = {}
if not molecule.get('acquire_mode', 'OFF') == 'OFF':
if not acquire_mode == 'OFF':
acquire_mode = molecule['acquire_mode']
if molecule.get('acquire_strategy'):
acquire_extra_params['acquire_strategy'] = molecule['acquire_strategy']
if molecule['acquire_mode'] == 'BRIGHTEST' and molecule.get('acquire_radius_arcsec'):
acquire_extra_params['acquire_radius'] = float(molecule['acquire_radius_arcsec'])
if molecule.get('acquire_strategy') and 'NRES' in block.get('instrument_class').upper():
acquire_extra_params['acquire_strategy'] = molecule['acquire_strategy']
acquire_mode = acquire_mode_from_strategy(molecule.get('ag_strategy'))

acquisition_config = {
'mode': acquire_mode,
Expand Down Expand Up @@ -405,8 +413,8 @@ def convert_observation_to_pond_block(observation):
molecule['args'] = configuration['extra_params']['script_name']
if first_instrument_config['extra_params'].get('defocus'):
molecule['defocus'] = str(first_instrument_config['extra_params']['defocus'])
if configuration['guiding_config']['extra_params'].get('guide_strategy'):
molecule['ag_strategy'] = configuration['guiding_config']['extra_params']['guide_strategy']
if configuration['guiding_config']['extra_params'].get('ag_strategy'):
molecule['ag_strategy'] = configuration['guiding_config']['extra_params']['ag_strategy']
if 'filter' in optical_elements:
molecule['filter'] = optical_elements['filter']
if 'slit' in optical_elements:
Expand Down
24 changes: 17 additions & 7 deletions observation_portal/userrequests/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ def rg_target_type_to_ur(target_type):
return target_type.upper()


def acquire_mode_from_strategies(ag_strategy):
if ag_strategy.upper() == 'WCS':
return 'WCS'
else:
return 'BRIGHTEST'


def validate_userrequest(userrequests):
"""
Call a valhalla instance validate endpoint with the userrequest dict. Raise an error with the error response
Expand Down Expand Up @@ -143,15 +150,15 @@ def convert_userrequest_to_requestgroup(userrequest):
ag_optical_elements['filter'] = molecule['ag_filter']

ag_extra_params = {}
if molecule.get('ag_strategy', ''):
ag_extra_params['ag_strategy'] = molecule['ag_strategy']
ag_optional = False
ag_mode = molecule.get('ag_mode', 'OFF')
if ag_mode == 'OPTIONAL':
ag_mode = 'ON'
ag_optional = True
elif ag_mode == 'ON':
ag_optional = False
if molecule.get('ag_strategy', ''):
ag_mode = molecule['ag_strategy']
ag_extra_params['guide_strategy'] = molecule['ag_strategy']

guiding_config = {
'optical_elements': ag_optical_elements,
Expand All @@ -164,13 +171,16 @@ def convert_userrequest_to_requestgroup(userrequest):
guiding_config['exposure_time'] = molecule['ag_exp_time']

acquire_extra_params = {}
acquire_mode = molecule.get('acquire_mode', 'OFF')
if molecule.get('acquire_strategy', ''):
acquire_extra_params['acquire_strategy'] = molecule['acquire_strategy']
if molecule.get('acquire_mode', '') == 'BRIGHTEST':
acquire_extra_params['acquire_radius'] = molecule['acquire_radius_arcsec']
if molecule.get('acquire_strategy', '') and 'NRES' in molecule.get('instrument_name', '').upper():
acquire_mode = acquire_mode_from_strategies(molecule.get('ag_strategy', ''))

acquisition_config = {
'mode': molecule.get('acquire_mode', 'OFF'),
'mode': acquire_mode,
'extra_params': acquire_extra_params
}

Expand Down Expand Up @@ -238,14 +248,14 @@ def convert_requestgroup_to_userrequest(requestgroup):
'ag_name': configuration['instrument_type'] if configuration['extra_params'].get('self_guiding', False) else '',
'ag_mode': ag_mode,
'ag_filter': configuration['guiding_config']['optical_elements'].get('filter', ''),
'ag_strategy': configuration['guiding_config']['mode'],
'ag_strategy': configuration['guiding_config'].get('extra_params', {}).get('ag_strategy', ''),
'filter': first_inst_config['optical_elements'].get('filter', ''),
'readout_mode': first_inst_config['mode'],
'spectra_lamp': first_inst_config['optical_elements'].get('lamp', ''),
'spectra_slit': first_inst_config['optical_elements'].get('slit', ''),
'acquire_mode': configuration['acquisition_config']['mode'],
'acquire_radius_arcsec': configuration['acquisition_config']['extra_params'].get('acquire_radius', 0.0),
'acquire_strategy': configuration['acquisition_config']['extra_params'].get('acquire_strategy', ''),
'acquire_radius_arcsec': configuration['acquisition_config'].get('extra_params', {}).get('acquire_radius', 0.0),
'acquire_strategy': configuration['acquisition_config'].get('extra_params', {}).get('acquire_strategy', ''),
'acquire_exp_time': configuration['acquisition_config'].get('exposure_time', None),
'expmeter_mode': first_inst_config['extra_params'].get('expmeter_mode', 'OFF'),
'expmeter_snr': first_inst_config['extra_params'].get('expmeter_snr', None),
Expand Down

0 comments on commit b71dac9

Please sign in to comment.