sot / starcheck

BSD 3-Clause "New" or "Revised" License
3 stars 0 forks source link

Use kadi dynamic commanded states instead of cmd_states #319

Closed taldcroft closed 5 years ago

taldcroft commented 5 years ago

This runs without error on JUN1019A and JUN1719A and appears to have the desired effect of properly accounting for eclipse times. It needs real testing, of course.

It is based on #318 for convenience and requires https://github.com/sot/kadi/pull/131.

I took the liberty of fixing some PEP8 stuff and simplifying a few things here and there.

jeanconn commented 5 years ago

Awesome! Thanks Tom. This is a great step forward in this code. I probably won't have a chance to give this proper attention before we finish the last eclipse of the season though (is that on day 174?)

taldcroft commented 5 years ago

Understood, no rush. Just a Friday fun project, trying to actually use the tools that I spent so much time developing. It turned out to require a bit more specialized understanding of kadi commands than I would have liked, but so it goes. But at least the new traceback code helps quite a bit, though I ended up testing the new Python code standalone in a notebook. (But now there is opportunity for some unit tests for the starcheck package).

jeanconn commented 5 years ago

Thanks. calc_ccd_temps.py will at least still work somewhat standalone if you give it the oflsdir and json file of an already-run week, so that can be good for coding while testing. What did you have in mind for unit tests and how did you want to run them?

taldcroft commented 5 years ago
from starcheck.calc_ccd_temps import get_bs_cmds, get_telem_values, get_week_states
from Chandra.Time import DateTime

oflsdir ='JUN1719/oflsa/'
bs_cmds = get_bs_cmds(oflsdir)

tstart = DateTime(bs_cmds[0]['date']).secs
tstop = DateTime(bs_cmds[-1]['date']).secs

tlm = get_telem_values(tstop, msids=['aacccdpt'], days=30)

states = get_week_states(tstart, tstop, bs_cmds, tlm)
taldcroft commented 5 years ago

For functional validation testing, running on a non-eclipse-load week should produce the same temperature predictions (to within, say, 0.01 C). Then the starcheck.txt output should be identical. Running on an eclipse-load week should show diffs in temperatures and some of the report outputs.

Good to know about the JSON file, I forgot it is stored and didn't go that next step.

For unit testing, one could examine the states that come out and do some little regression test on that, including eclipse values. The value-added is not huge and not clear if we want to bother.

taldcroft commented 5 years ago

@jeanconn - requested some reviews just because I found the open tabs, but not an immediate priority.

taldcroft commented 5 years ago

This needs some sanity checking that the available cmds are sufficient. For JUN2419 I ran without updating my local ska data and got plot below. Nice to see ACA going to -19C, but not too realistic.

image

jeanconn commented 5 years ago

I'm not having much luck with this yet

(sc) bash-4.1$ ./sandbox_starcheck -dir /data/mpcrit1/mplogs/2019/JUN1719/oflsa/ -out mytest
Using backstop file /data/mpcrit1/mplogs/2019/JUN1719/oflsa//CR167_1901.backstop
Using guide summary file /data/mpcrit1/mplogs/2019/JUN1719/oflsa//mps/mgJUN1719A.sum
Using OR file /data/mpcrit1/mplogs/2019/JUN1719/oflsa//mps/or/JUN1719_A.or
Using maneuver file /data/mpcrit1/mplogs/2019/JUN1719/oflsa//mps/mmJUN1719A.sum
Using DOT file /data/mpcrit1/mplogs/2019/JUN1719/oflsa//mps/mdJUN1719A.dot
Using mech check file /data/mpcrit1/mplogs/2019/JUN1719/oflsa//output/TEST_mechcheck.txt
Using fidsel file /data/mpcrit1/mplogs/2019/JUN1719/oflsa//History/FIDSEL.txt
Using dither file /data/mpcrit1/mplogs/2019/JUN1719/oflsa//History/DITHER.txt
Using radmon file /data/mpcrit1/mplogs/2019/JUN1719/oflsa//History/RADMON.txt
Using simtrans file /data/mpcrit1/mplogs/2019/JUN1719/oflsa//History/SIMTRANS.txt
Using simfocus file /data/mpcrit1/mplogs/2019/JUN1719/oflsa//History/SIMFOCUS.txt
Using attitude file /data/mpcrit1/mplogs/2019/JUN1719/oflsa//History/ATTITUDE.txt
Using characteristics file /data/mpcrit1/mplogs/2019/JUN1719/oflsa//mps/ode/characteristics/CHARACTERIS_19APR18
Using aimpoint file /data/mpcrit1/mplogs/2019/JUN1719/oflsa//output/JUN1719A_dynamical_offsets.txt
Using config file /proj/sot/ska/jeanproj/git/starcheck/starcheck/data/characteristics.yaml
Using odb file /proj/sot/ska/jeanproj/git/starcheck/starcheck/data/fid_CHARACTERISTICS
Using agasc_file file /fido.real/ska3/data/agasc/agasc1p7.h5
Using manerr file /data/mpcrit1/mplogs/2019/JUN1719/oflsa//output/JUN1719A_ManErr.txt
Using processing summary file /data/mpcrit1/mplogs/2019/JUN1719/oflsa//mps/msJUN1719A.sum
Using TLR file /data/mpcrit1/mplogs/2019/JUN1719/oflsa//CR167_1901.tlr
Using banned_agasc file /proj/sot/ska/jeanproj/git/starcheck/starcheck/data/agasc.bad
Using bad_pixel file /proj/sot/ska/jeanproj/git/starcheck/starcheck/data/ACABadPixels
Using acq_star_rdb file /proj/sot/ska/jeanproj/git/starcheck/starcheck/data/bad_acq_stars.rdb
Using gui_star_rdb file /proj/sot/ska/jeanproj/git/starcheck/starcheck/data/bad_gui_stars.rdb
Read 246 ACA bad pixels from /proj/sot/ska/jeanproj/git/starcheck/starcheck/data/ACABadPixels
Read 46 bad AGASC IDs from /proj/sot/ska/jeanproj/git/starcheck/starcheck/data/agasc.bad
#####################################################################
# calc_ccd_temps run at Tue Jun 25 13:28:27 2019 by jeanconn
# calc_ccd_temps version = 13.2
#####################################################################

Using backstop file /data/mpcrit1/mplogs/2019/JUN1719/oflsa/CR167_1901.backstop
Found 1154 backstop commands between 2019:167:19:05:48.434 and 2019:174:09:54:29.791
Fetching telemetry between 2019:137:19:05:48.434 and 2019:167:19:05:48.434
Traceback (most recent call last):
  File "<string>", line 29, in ccd_temp_wrapper
  File "/proj/sot/ska/jeanproj/git/starcheck/starcheck/calc_ccd_temps.py", line 156, in get_ccd_temps
    states = get_week_states(tstart, tstop, bs_cmds, tlm)
  File "/proj/sot/ska/jeanproj/git/starcheck/starcheck/calc_ccd_temps.py", line 306, in get_week_states
    merge_identical=True)
  File "/home/jeanconn/git/kadi/kadi/commands/states.py", line 1152, in get_states
    transitions = get_transitions_list(cmds, state_keys, start, stop, continuity)
  File "/home/jeanconn/git/kadi/kadi/commands/states.py", line 1025, in get_transitions_list
    transition_class.set_transitions(transitions_dict, cmds, start, stop)
  File "/home/jeanconn/git/kadi/kadi/commands/states.py", line 285, in set_transitions
    transitions_dict[date][name] = params[param_key]
KeyError: 'id'
KeyError: 'id' at line 29
 at ./starcheck/src/starcheck.pl line 45.
    main::__ANON__("KeyError: 'id' at line 29\x{a}") called at (eval 149) line 3
    main::ccd_temp_wrapper("__main__", "ccd_temp_wrapper", HASH(0x42043b0)) called at ./starcheck/src/starcheck.pl line 599

(sc) bash-4.1$ ipython
Python 3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 13:51:32) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.1.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: run starcheck/calc_ccd_temps.py /data/mpcrit1/mplogs/2019/JUN1719/oflsa --json-obsids jun1719a/obsids.json --model-spec starcheck/data/aca_spec.jso
   ...: n --char-file starcheck/data/characteristics.yaml
#####################################################################
# calc_ccd_temps run at Tue Jun 25 13:32:30 2019 by jeanconn
# calc_ccd_temps version = 13.2
#####################################################################

Using backstop file /data/mpcrit1/mplogs/2019/JUN1719/oflsa/CR167_1901.backstop
Found 1154 backstop commands between 2019:167:19:05:48.434 and 2019:174:09:54:29.791
Fetching telemetry between 2019:137:19:05:48.434 and 2019:167:19:05:48.434
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/proj/sot/ska/jeanproj/git/starcheck/starcheck/calc_ccd_temps.py in <module>()
    593     opt = get_options()
    594     try:
--> 595         json_obstemps = get_ccd_temps(**vars(opt))
    596         write_obstemps(opt.output_temps, json_obstemps)
    597     except Exception as msg:

/proj/sot/ska/jeanproj/git/starcheck/starcheck/calc_ccd_temps.py in get_ccd_temps(oflsdir, outdir, json_obsids, model_spec, char_file, orlist, verbose, **kwargs)
    154     tlm = get_telem_values(tstart, msids=['aacccdpt'], days=30)
    155 
--> 156     states = get_week_states(tstart, tstop, bs_cmds, tlm)
    157 
    158     # If the last obsid interval extends over the end of states

/proj/sot/ska/jeanproj/git/starcheck/starcheck/calc_ccd_temps.py in get_week_states(tstart, tstop, bs_cmds, tlm)
    304     state_keys = ['obsid', 'pitch', 'q1', 'q2', 'q3', 'q4', 'eclipse']
    305     states = kadi_states.get_states(cmds=cmds, state_keys=state_keys,
--> 306                                     merge_identical=True)
    307 
    308     states['tstart'] = DateTime(states['datestart']).secs

~/git/kadi/kadi/commands/states.py in get_states(start, stop, state_keys, cmds, continuity, reduce, merge_identical)
   1150     # and new state value at that date).  This goes through each active
   1151     # transition class and accumulates transitions.
-> 1152     transitions = get_transitions_list(cmds, state_keys, start, stop, continuity)
   1153 
   1154     # List of dict to hold state values.  Datestarts is the corresponding list of

~/git/kadi/kadi/commands/states.py in get_transitions_list(cmds, state_keys, start, stop, continuity)
   1023     # transitions from that class.
   1024     for transition_class in get_transition_classes(state_keys):
-> 1025         transition_class.set_transitions(transitions_dict, cmds, start, stop)
   1026 
   1027     # Convert the dict of transitions (keyed by date) into an ordered list of transitions

~/git/kadi/kadi/commands/states.py in set_transitions(cls, transitions_dict, cmds, start, stop)
    283             params = dict(REV_PARS_DICT[cmd['idx']])
    284             for name, param_key in zip(names, param_keys):
--> 285                 transitions_dict[date][name] = params[param_key]
    286 
    287 

KeyError: 'id'
jeanconn commented 5 years ago

I don't have much insight yet into what REV_PARS_DICT on the kadi side is supposed to be, what it is supposed to contain, and how one indexes back into it

ipdb> REV_PARS_DICT[cmd['idx']]
(('hex', '8032000'), ('msid', 'AOACRSTD'))
ipdb> cmd['idx']
0
ipdb> cmd
<Cmd 2019:167:19:11:48.434 MP_OBSID tlmsid=COAOSQID scs=131 step=2 timeline_id=0 vcdu=16263432 cmds=3 id=22261>
taldcroft commented 5 years ago

Ugh, I'm really sorry for wasting your time. I had forgotten to push up the kadi commit (from 13 days ago) that makes it actually work.

taldcroft commented 5 years ago

I tested c52156a by setting the state duration threshold to 150 sec instead of 150000 sec, and saw the expected warning.

#####################################################################
# calc_ccd_temps run at Thu Jun 27 06:37:55 2019 by aldcroft
# calc_ccd_temps version = 13.2
#####################################################################

Using backstop file /Users/aldcroft/ska/data/mpcrit1/mplogs/2019/JUN1719/oflsa/CR167_1901.backstop
Found 1154 backstop commands between 2019:167:19:05:48.434 and 2019:174:09:54:29.791
Fetching telemetry between 2019:137:19:05:48.434 and 2019:167:19:05:48.434

WARNING: state(s) exceeding 150 ksec duration, kadi.commands could be stale.

Calculating ACA thermal model
Propagation initial time and ACA: 2019:167:19:05:48.434 -12.11
jeanconn commented 5 years ago

Superseded by #330