Skip to content

Commit

Permalink
Merge 1d2f5b1 into a2fe3df
Browse files Browse the repository at this point in the history
  • Loading branch information
eheinrich committed Jun 29, 2019
2 parents a2fe3df + 1d2f5b1 commit 070cdbb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
33 changes: 27 additions & 6 deletions observation_portal/common/rise_set_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,28 @@ def filter_out_downtime_from_intervalsets(intervalsets_by_telescope: dict) -> di
return filtered_intervalsets_by_telescope


def get_proper_motion(target_dict):
# The proper motion fields are sometimes not present in HOUR_ANGLE targets
pm = {'pmra': None, 'pmdec': None}
if 'proper_motion_ra' in target_dict and target_dict['proper_motion_ra'] is not None:
pm['pmra'] = ProperMotion(
Angle(
degrees=(target_dict['proper_motion_ra'] / 1000.0 / cos(radians(target_dict['dec']))) / 3600.0,
units='arc'
),
time='year'
)
if 'proper_motion_dec' in target_dict and target_dict['proper_motion_dec'] is not None:
pm['pmdec'] = ProperMotion(
Angle(
degrees=(target_dict['proper_motion_dec'] / 1000.0) / 3600.0,
units='arc'
),
time='year'
)
return pm


def get_rise_set_target(target_dict):
# This is a hack to protect against poorly formatted or empty targets that are submitted directly.
# TODO: Remove this check when target models are updated to handle when there is no target
Expand All @@ -164,14 +186,13 @@ def get_rise_set_target(target_dict):
dec=Angle(degrees=0),
)
if target_dict['type'] in ['ICRS', 'HOUR_ANGLE']:
pmra = (target_dict['proper_motion_ra'] / 1000.0 / cos(radians(target_dict['dec']))) / 3600.0
pmdec = (target_dict['proper_motion_dec'] / 1000.0) / 3600.0
pm = get_proper_motion(target_dict)
if target_dict['type'] == 'ICRS':
return make_ra_dec_target(
ra=Angle(degrees=target_dict['ra']),
dec=Angle(degrees=target_dict['dec']),
ra_proper_motion=ProperMotion(Angle(degrees=pmra, units='arc'), time='year'),
dec_proper_motion=ProperMotion(Angle(degrees=pmdec, units='arc'), time='year'),
ra_proper_motion=pm['pmra'],
dec_proper_motion=pm['pmdec'],
parallax=target_dict['parallax'],
rad_vel=0.0,
epoch=target_dict['epoch']
Expand All @@ -180,8 +201,8 @@ def get_rise_set_target(target_dict):
return make_hour_angle_target(
hour_angle=Angle(degrees=target_dict['hour_angle']),
dec=Angle(degrees=target_dict['dec']),
ra_proper_motion=ProperMotion(Angle(degrees=pmra, units='arc'), time='year'),
dec_proper_motion=ProperMotion(Angle(degrees=pmdec, units='arc'), time='year'),
ra_proper_motion=pm['pmra'],
dec_proper_motion=pm['pmdec'],
parallax=target_dict['parallax'],
epoch=target_dict['epoch']
)
Expand Down
6 changes: 5 additions & 1 deletion observation_portal/requestgroups/duration_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ def get_request_duration(request_dict):
duration += change_overhead

# Now add in the slew time between targets (configurations). Only Sidereal can be calculated based on position.
if not previous_target or 'ra' not in previous_target or 'ra' not in configuration['target']:
if (
not previous_target
or previous_target['type'].upper() != 'ICRS'
or configuration['target']['type'].upper() != 'ICRS'
):
duration += request_overheads['maximum_slew_overhead']
elif previous_target != configuration['target']:
duration += min(max(get_slew_distance(previous_target, configuration['target'], start_time)
Expand Down
17 changes: 9 additions & 8 deletions observation_portal/requestgroups/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,17 +510,10 @@ def validate_configurations(self, value):
if not value:
raise serializers.ValidationError(_('You must specify at least 1 configuration'))

target = value[0]['target']
constraints = value[0]['constraints']
# Set the relative priority of molecules in order
for i, configuration in enumerate(value):
configuration['priority'] = i + 1
# TODO: Remove this once we support multiple targets/constraints
if configuration['target'] != target:
raise serializers.ValidationError(_(
'Currently only a single target per Request is supported. This restriction will be lifted in '
'the future.'
))
if configuration['constraints'] != constraints:
raise serializers.ValidationError(_(
'Currently only a single constraints per Request is supported. This restriction will be '
Expand Down Expand Up @@ -726,12 +719,20 @@ def validate(self, data):
# Don't do any time accounting stuff if it is a directly scheduled observation
return data
else:
# for non-DIRECT observations, don't allow HOUR_ANGLE targets
for request in data['requests']:
target = request['configurations'][0]['target']
for config in request['configurations']:
# for non-DIRECT observations, don't allow HOUR_ANGLE targets
if config['target']['type'] == 'HOUR_ANGLE':
raise serializers.ValidationError(_('HOUR_ANGLE Target type not supported in scheduled observations'))

# For non-DIRECT observations, only allow a single target
# TODO: Remove this check once we support multiple targets/constraints
if config['target'] != target:
raise serializers.ValidationError(_(
'Currently only a single target per Request is supported. This restriction will be lifted '
'in the future.'
))
try:
total_duration_dict = get_total_duration_dict(data)
for tak, duration in total_duration_dict.items():
Expand Down

0 comments on commit 070cdbb

Please sign in to comment.