Skip to content

Commit

Permalink
Merge pull request #430 from sot/read_or_list
Browse files Browse the repository at this point in the history
Update to use read_or_list_full
  • Loading branch information
jeanconn authored Sep 25, 2023
2 parents 44c7c1f + 54d865c commit fb0e448
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
14 changes: 7 additions & 7 deletions starcheck/calc_ccd_temps.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import kadi.commands.states as kadi_states
import xija
from chandra_aca import dark_model
from parse_cm import read_or_list
from parse_cm import read_or_list_full
from chandra_aca.drift import get_aca_offsets
from ska_helpers import chandra_models

Expand Down Expand Up @@ -234,7 +234,7 @@ def get_ccd_temps(oflsdir, outdir='out',
make_check_plots(outdir, states, ccd_times, ccd_temps,
tstart=bs_start.secs, tstop=sched_stop.secs)
intervals = get_obs_intervals(sc_obsids)
obsreqs = None if orlist is None else {obs['obsid']: obs for obs in read_or_list(orlist)}
obsreqs = None if orlist is None else read_or_list_full(orlist)[0]
obstemps = get_interval_data(intervals, ccd_times, ccd_temps, obsreqs)
return json.dumps(obstemps, sort_keys=True, indent=4,
cls=NumpyAwareJSONEncoder)
Expand Down Expand Up @@ -275,12 +275,12 @@ def get_interval_data(intervals, times, ccd_temp, obsreqs=None):
100, interval['tstart'], np.max(ok_temps))
# If we have an OR list, the obsid is in that list, and the OR list has zero-offset keys
if (obsreqs is not None and interval['obsid'] in obsreqs and
'chip_id' in obsreqs[interval['obsid']]):
'zero_offset' in obsreqs[interval['obsid']]):
obsreq = obsreqs[interval['obsid']]
ddy, ddz = get_aca_offsets(obsreq['detector'],
obsreq['chip_id'],
obsreq['chipx'],
obsreq['chipy'],
ddy, ddz = get_aca_offsets(obsreq['zero_offset']['detector'],
obsreq['zero_offset']['chip_id'],
obsreq['zero_offset']['chipx'],
obsreq['zero_offset']['chipy'],
time=ok_times,
t_ccd=ok_temps)
obs['aca_offset_y'] = np.mean(ddy)
Expand Down
22 changes: 11 additions & 11 deletions starcheck/pcad_att_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from Quaternion import Quat
import math

from parse_cm import read_backstop, read_or_list
from parse_cm import read_backstop, read_or_list_full
from Chandra.Time import DateTime
import hopper

Expand Down Expand Up @@ -101,43 +101,43 @@ def run(backstop_file, or_list_file=None, attitude_file=None,
'simpos': simpos,
'simfa_pos': simfa}

or_list = None if or_list_file is None else read_or_list(or_list_file)
if or_list is None:
obsreqs = None if or_list_file is None else read_or_list_full(or_list_file)[0]

if obsreqs is None:
lines.append('ERROR: No OR list provided, cannot check attitudes')
all_ok = False

# If dynamical offsets file is available then load was planned using
# Matlab tools 2016_210 later, which implements the "Cycle 18 aimpoint
# transition plan". This code injects new OR list attributes for the
# dynamical offset.
if dynamic_offsets_file is not None and or_list is not None:
if dynamic_offsets_file is not None and obsreqs is not None:
# Existing OFLS characteristics file is not relevant for post 2016_210.
# Products are planned using the Matlab tools SI align which matches the
# baseline mission align matrix from pre-November 2015.
ofls_characteristics_file = None

lines.append('INFO: using dynamic offsets file {}'.format(dynamic_offsets_file))
or_map = {or_['obsid']: or_ for or_ in or_list}

doffs = Table.read(dynamic_offsets_file, format='ascii.basic', guess=False)
for doff in doffs:
obsid = doff['obsid']
if obsid in or_map:
or_map[obsid]['aca_offset_y'] = doff['aca_offset_y'] / 3600.
or_map[obsid]['aca_offset_z'] = doff['aca_offset_z'] / 3600.
if obsid in obsreqs:
obsreqs[obsid]['aca_offset_y'] = doff['aca_offset_y'] / 3600.
obsreqs[obsid]['aca_offset_z'] = doff['aca_offset_z'] / 3600.

# Check that obsids in dynamic offsets table are all in OR list
if not set(doffs['obsid']).issubset(set(or_map)):
if not set(doffs['obsid']).issubset(set(obsreqs)):
all_ok = False
obsid_mismatch = set(doffs['obsid']) - set(or_map)
obsid_mismatch = set(doffs['obsid']) - set(obsreqs)
lines.append('WARNING: Obsid in dynamic offsets table but missing in OR list {}'
.format(list(obsid_mismatch)))

# Run the commands and populate attributes in `sc`, the spacecraft state.
# In particular sc.checks is a dict of checks by obsid.
# Any state value (e.g. obsid or q_att) has a corresponding plural that
# gives the history of updates as a dict with a `value` and `date` key.
sc = hopper.run_cmds(backstop_file, or_list, ofls_characteristics_file,
sc = hopper.run_cmds(backstop_file, obsreqs, ofls_characteristics_file,
initial_state=initial_state, starcheck=True)

# Make maneuver structure
Expand Down

0 comments on commit fb0e448

Please sign in to comment.