chandra_cmd_states API¶
add_nonload_cmds¶
Add non-load commands to the database and generate code to recreate those commands for archive purposes. See also cmd_states.cmd_set().
Usage: add_nonload_cmds.py [options] [cmd_set_arg1 …]:
Options:
-h, --help show this help message and exit
--dbi=DBI Database interface (sqlite|sybase)
--server=SERVER DBI server (<filename>|sybase)
--check Check for recent non-load commands and do not generate
commands
--date=DATE Date for command set
--cmd-set=CMD_SET Command set name (obsid|manvr|scs107|nsm|acis)
--loglevel=LOGLEVEL Log level (10=debug, 20=info, 30=warnings)
--archive-file=FILE Archive file for storing nonload cmd sets
--interrupt Interrupt timelines and load_segments after ``date``
--observing-only Interrupt only 'observing' timelines
Examples:
# Print recent non-load commands
add_nonload_cmds.py --check
# Add a maneuver to RA, Dec, Roll = 10, 20, 30
add_nonload_cmds.py --date '2009:065:12:13:14' --cmd-set manvr 10 20 30
# Add an autonomous NSM transition (which also runs SCS107)
add_nonload_cmds.py --date '2009:001:12:13:14' --interrupt --cmd-set nsm --dry-run
add_nonload_cmds.py --date '2009:001:12:13:14' --interrupt --cmd-set scs107
# Add ACIS CTI commanding
add_nonload_cmds.py --date '2012:072:20:52:00.000' --cmd-set aciscti
cmd_states¶
This module provides the core functions for creating, manipulating and updating the Chandra commanded states database.
- chandra_cmd_states.cmd_states.cmd_set(name, *args)¶
Return a predefined cmd_set
namegenerated with *args.- Parameters:
name – cmd set name (manvr|scs107|nsm)
*args – optional args
- Returns:
cmd set
- chandra_cmd_states.cmd_states.decode_power(mnem)¶
Decode number of chips and feps from a ACIS power command Return a dictionary with the number of chips and their identifiers
Example:
>>> decode_power("WSPOW08F3E") {'ccd_count': 5, 'ccds': 'I0 I1 I2 I3 S3 ', 'clocking': 0, 'fep_count': 5, 'feps': '1 2 3 4 5 ', 'vid_board': 1}
- Parameters:
mnem – power command string
- chandra_cmd_states.cmd_states.generate_cmds(time, cmd_set)¶
Generate a set of commands based on the supplied
cmd_setstarting from the specifiedtime.The
cmd_setis a list of command definitions like the output of read_backstop() but with an optional ‘dur’ key in each command and no absolute time values. This key specifies the duration of that command in seconds. Normally this routine is used with the predefinedCMD_SETvalues.- Parameters:
cmd_set – list of command definitions
time – starting time for command set
- Returns:
list of command dicts ala read_backstop()
- chandra_cmd_states.cmd_states.get_cmds(datestart='1998:001:00:00:00.000', datestop='2099:001:00:00:00.000', db=None, update_db=None, timeline_loads=None, mp_dir='/Users/aldcroft/ska/data/mpcrit1/mplogs')¶
Get all commands with
datestart< date <=datestopusing DBI objectdb. This includes both commands already in the database and new commands. Ifupdate_dbis True then update the database cmds table to reflect new and/or deleted commands.Use
datestart< date instead of <= because in typical ussagedatestartis the start date of a state and one wants commands after those that generated the original state transition.The timeline_loads table is relied upon as the final authority of which commands were (will be) run on-board. The timeline_load values can change in the database in the event of an autonomous or ground-commanded load segment interrupt. The strategy is to regenerate the list of commands that were (will be) run on-board using commands already in the database supplemented by backstop commands found in the SOTMP repository of load products.
- Parameters:
datestart – start date (Chandra.Time ‘date’ str) (default=1998:001)
datestop – stop date (default=2099:001)
db – Ska.DBI.DBI object (required)
update_db – update the ‘cmds’ table
- Returns:
cmds- Return type:
list of dicts
- chandra_cmd_states.cmd_states.get_state0(date=None, db=None, date_margin=10, datepar='datestop')¶
From the cmd_states table get the last state with
dateparbeforedate.It is assumed that the cmd_states database table is populated and accurate (definitive) at times more than
date_margindays before the present time. The conservative default value ofdate_margin=10allows for processing downtime. The table is accessed via thedbobject.If
date_marginis None then no date margin is applied and the most recent available state that meets the date selection criteria (including that pcad_mode == ‘NPNT’) will be used. In this case adatemust be supplied.- Parameters:
db – Ska.DBI.DBI object. Created automatically if not supplied.
date – date cutoff for state0 (Chandra.Time compatible value) or None
date_margin – days before current time for definitive values or None
datepar – table parameter for select (datestop|datestart)
- Returns:
state0- Return type:
dict
- chandra_cmd_states.cmd_states.get_states(state0, cmds, exclude=None)¶
Get states resulting from the spacecraft commands
cmdsstarting from an initialstate0.State keys in the
excludelist or set will be excluded from causing a transition. This is useful if a state parameter (e.g. simfa_pos) is not of interest. An excluding parameter will have incorrect values in the returned states.A state is a dict with key values corresponding to the following database schema:
Name
Type
Size
datestart
varchar
21
datestop
varchar
21
obsid
int
4
power_cmd
varchar
11
si_mode
varchar
8
pcad_mode
varchar
6
vid_board
bit
1
clocking
bit
1
fep_count
int
4
ccd_count
int
4
simpos
int
4
simfa_pos
int
4
pitch
float
8
ra
float
8
dec
float
8
roll
float
8
q1
float
8
q2
float
8
q3
float
8
q4
float
8
trans_keys
varchar
60
letg
varchar
4
hetg
varchar
4
dither
varchar
4
The input commands must be a list of dicts including keys
date, vcdu, cmd, params, time. See also Ska.ParseCM.read_backstop().- Parameters:
state0 – initial state.
cmds – list of commands
ignore – list or set of state keys to ignore
- Returns:
recarray of states starting with state0 (which might be modified)
- chandra_cmd_states.cmd_states.insert_cmds_db(cmds, timeline_id, db)¶
Insert the
cmdsinto thedbtable ‘cmds’ withtimeline_id. Command parameters are also inserted into ‘cmd_intpars’ and ‘cmd_fltpars’ tables.timeline_idcan be None to indicate non-load commands (from ground or autonomous).Each command must be dict with at least the following keys:
date
char
time
float
cmd
char
Optional keys are:
params
dict
paramstr
char
tlmsid
char
msid
char
vcdu
int
step
int
scs
int
The input
cmdsare used to populate three tables:cmds
name
type
length
id (PK)
int
4
timeline_id
int
4
date
char
21
time
float
8,
cmd
varchar
12
tlmsid
varchar
10
msid
varchar
8
vcdu
int
4
step
int
4
scs
int
4
cmd_intpars and cmd_fltpars
name
type
length
cmd_id (FK)
int
4
timeline_id (FK)
int
4
name
varchar
15
value
int/float
8
- Parameters:
cmds – list of command dicts, e.g. from Ska.ParseCM.read_backstop()
db – Ska.DBI.DBI object
timeline_id – id of timeline load segment that contains commands
- Returns:
None
- chandra_cmd_states.cmd_states.interpolate_states(states, times)¶
Interpolate
statesnp.recarray at given times.- Parameters:
states – states (np.recarray)
times – times (np.array or list)
- Returns:
statesview attimes
- chandra_cmd_states.cmd_states.interrupt_loads(datestop, db, observing_only=False, current_only=False)¶
Interrupt the timelines with db.datestop >
datestopby updating the table datestop accordingly. Use DBI handledbto access tables. Ifcurrent_onlyis set then only update the load that actually containsdatestop.- Parameters:
datestop – load stop date
db – Ska.DBI.DBI object
observing_only – only interrupt ‘observing’ slots (131,132,133)
current_only – only stop the load containing datestop
- Returns:
None
- chandra_cmd_states.cmd_states.reduce_states(states, cols, allow_identical=True)¶
Reduce the input
statesso that only transitions in thecolscolumns are noticed.- Parameters:
states – numpy recarray of states
cols – notice transitions in this list of columns
allow_identical – allow null transitions between apparently identical states
- Returns:
numpy recarray of reduced states
get_cmd_states¶
Get the Chandra commanded states over a range of time.
- chandra_cmd_states.get_cmd_states.fetch_states(start=None, stop=None, vals=None, allow_identical=False, dbi='hdf5', server=None, user='aca_read', database='aca')¶
Get Chandra commanded states over a range of time as a structured array.
Examples:
# Get commanded states using the default HDF5 table >>> from chandra_cmd_states import fetch_states >>> states = fetch_states('2011:100:12:00:00', '2011:101:12:00:00', vals=['obsid', 'simpos']) >>> states[['datestart', 'datestop', 'obsid', 'simpos']] array([('2011:100:11:53:12.378', '2011:101:00:23:01.434', 13255, 75624), ('2011:101:00:23:01.434', '2011:101:00:26:01.434', 13255, 91272), ('2011:101:00:26:01.434', '2011:102:13:39:07.421', 12878, 91272)], dtype=[('datestart', '|S21'), ('datestop', '|S21'), ('obsid', '<i8'), ('simpos', '<i8')]) # Get same states from Sybase (25 times slower) >>> states2 = fetch_states('2011:100:12:00:00', '2011:101:12:00:00', vals=['obsid', 'simpos'], dbi='sybase') >>> states2 == states array([ True, True, True], dtype=bool)
- Parameters:
start – start date (default=Now-10 days)
stop – stop date (default=None)
vals – list of state columns for output
allow_identical – Allow identical states from cmd_states table
dbi – database interface (default=hdf5)
server – DBI server or HDF5 file (default=None)
user – sybase database user (default=’aca_read’)
database – sybase database (default=Ska.DBI default)
- chandra_cmd_states.get_cmd_states.get_h5_states(start, stop, server)¶
Get states from HDF5
serverfile betweenstartandstop.
- chandra_cmd_states.get_cmd_states.get_sql_states(start, stop, dbi, server, user, database)¶
Get states from SQL server between
startandstop.
- chandra_cmd_states.get_cmd_states.main(main_args=None)¶
Command line interface to fetch_states.
interrupt_loads¶
Update timelines table to reflect an mission load interrupt.
update_cmd_states¶
- chandra_cmd_states.update_cmd_states.check_consistency(db, h5, n_check=3000)¶
Check that the cmd_states table in
dbhas the same length and final datestart.
- chandra_cmd_states.update_cmd_states.delete_cmd_states(datestart, db, h5)¶
Delete cmd_states table entries that have datestart greater than or equal to the supplied
datestartarg. Do this for the SQL database handledband the HDF5 object handleh5.
- chandra_cmd_states.update_cmd_states.get_options()¶
Get options for command line interface to update_cmd_states.
- chandra_cmd_states.update_cmd_states.get_states_i_diff(db_states, states)¶
Get the index position where db_states and states differ.
If the states are identical then None is returned.
- Parameters:
db_states – states in database
states – new reference states
- Returns:
i_diff
- chandra_cmd_states.update_cmd_states.insert_cmd_states(states, i_diff, db, h5)¶
Insert new
states[idiff:]intodbandh5d.
- chandra_cmd_states.update_cmd_states.log_mismatch(mismatches, db_states, states, i_diff)¶
Log the states and state differences leading to a diff between the database cmd_states and the proposed states from commanding / products
- chandra_cmd_states.update_cmd_states.main()¶
Command line interface to update the cmd_states table to reflect current load segments / timelines in database.
Usage: update_cmd_states.py [options]:
Options: -h, --help show this help message and exit --dbi=DBI Database interface (sqlite|sybase) --server=SERVER DBI server (<filename>|sybase) --user=USER database user (default=Ska.DBI default) --database=DATABASE database name (default=Ska.DBI default) --h5file=H5FILE filename for HDF5 version of cmd_states --datestart=DATESTART Starting date for update (default=Now-10 days) --mp_dir=DIR MP directory. (default=/data/mpcrit1/mplogs) --loglevel=LOGLEVEL Log level (10=debug, 20=info, 30=warnings)
- chandra_cmd_states.update_cmd_states.make_hdf5_cmd_states(db, h5)¶
Make a new HDF5 command states table in
h5from the existing database version.
- chandra_cmd_states.update_cmd_states.update_states_db(states, db, h5)¶
Make the
dbdatabase cmd_states table consistent with the suppliedstates. Matchstatesto corresponding values in cmd_states tables, then delete from table at the point of a mismatch (if any).- Parameters:
states – input states (numpy recarray)
db – Ska.DBI.DBI object
h5 – HDF5 object holding commanded states table (as h5.root.data)
- Return type:
None