Commands API¶
Commands¶
- kadi.commands.commands_v2.clear_caches()[source]¶
Clear all commands caches.
This is useful for testing and in case upstream products like the Command Events sheet have changed during a session.
- kadi.commands.commands_v2.get_cmds(start=None, stop=None, *, inclusive_stop=False, scenario=None, **kwargs) CommandTable [source]¶
Get commands using loads table, relying entirely on RLTT.
- Parameters:
- startCxoTime-like
Start time for cmds
- stopCxoTime-like
Stop time for cmds
- scenariostr, None
Scenario name
- inclusive_stopbool
Include commands at exactly
stop
if True.- loads_stopCxoTime-like, None
Stop time for loads table (default is all available loads, but useful for development/testing work)
- **kwargsdict
key=val keyword argument pairs for filtering
- Returns:
- CommandTable
Observations¶
- kadi.commands.observations.get_observations(start=None, stop=None, *, obsid=None, scenario=None, cmds=None, starcat_date=None)[source]¶
Get observations corresponding to input parameters.
The
start
,stop
,starcat_date
andobsid
parameters serve as matching filters on the list of observations that is returned.Over the mission there are thousands of instances of multiple observations with the same obsid, so this function always returns a list of observation parameters even when
obsid
is specified. This most frequently occurs after any unexpected stoppage of the observng loads (SCS-107) which therefore cancels subsequent obsid commanding. In many cases you can just use the first element.Examples:
>>> from kadi.commands import get_observations >>> obs = get_observations(obsid=8008)[0] >>> obs {'obsid': 8008, 'simpos': 92904, 'obs_stop': '2007:002:18:04:28.965', 'manvr_start': '2007:002:04:31:48.216', 'targ_att': (0.149614271, 0.490896707, 0.831470649, 0.21282047), 'npnt_enab': True, 'obs_start': '2007:002:04:46:58.056', 'prev_att': (0.319214732, 0.535685207, 0.766039803, 0.155969017), 'starcat_date': '2007:002:04:31:43.965', 'starcat_idx': 147908, 'source': 'DEC2506C'} >>> obs_all = get_observations() # All observations in commands archive # Might be convenient to handle this as a Table >>> from astropy.table import Table >>> obs_all = Table(obs_all) >>> from kadi.commands import get_observations >>> get_observations(starcat_date='2022:001:17:00:58.521') [{'obsid': 23800, 'simpos': 75624, 'obs_stop': '2022:002:01:24:53.004', 'manvr_start': '2022:001:17:01:02.772', 'targ_att': (0.177875061, 0.452625075, 0.827436517, 0.280784286), 'npnt_enab': True, 'obs_start': '2022:001:17:33:53.255', 'prev_att': (0.116555575, -0.407948573, -0.759717367, 0.492770009), 'starcat_date': '2022:001:17:00:58.521', 'starcat_idx': 171677, 'source': 'DEC3021A'}]
- Parameters:
- startCxoTime-like, None
Start time (default=beginning of commands)
- stopCxoTime-like, None
Stop time (default=end of commands)
- obsidint, None
ObsID
- scenariostr, None
Scenario
- cmdsCommandTable, None
Use this command table instead of querying the archive
- starcat_dateCxoTime-like, None
Date of the observation’s star catalog
- Returns:
- list of dict
Observation parameters for matching observations.
- kadi.commands.observations.get_starcats(start=None, stop=None, *, obsid=None, scenario=None, cmds=None, as_dict=False, starcat_date=None, show_progress=False)[source]¶
Get a list of star catalogs corresponding to input parameters.
The
start
,stop
andobsid
parameters serve as matching filters on the list of star catalogs that is returned.By default the result is a list of
ACATable
objects similar to the output ofproseco.get_aca_catalog
.If
as_dict
isTrue
then the the result is a list of dictionaries with the same keys as the table columns plus a special “meta” key. The “meta” value is a dict with relevant metadata including the obsid, att, date, duration, sim_offset, and detctor. This method is substantially faster than the default.There are numerous instances of multiple observations with the same obsid, so this function always returns a list of star catalogs even when
obsid
is specified. In most cases you can just use the first element.The
mag
column corresponds to the AGASC magnitude without the AGASC supplement.Star ID’s are determined by finding the brightest AGASC star within a search box centered at the catalog location. The search box is 1.5 arcsec halfwidth in size, but it can be changed by setting the
star_id_match_halfwidth
configuration parameter. Fid ID’s are determined similarly by computing fid locations given the commanded SIM-Z position. The default box size is 40 arcsec halfwidth, but it can be changed by setting thefid_id_match_halfwidth
configuration parameter.The first time each particular star catalog is fetched, the star and fid ID’s are computed which is relatively slow. The resulting star catalog is (by default) cached in the
~/.kadi/starcats.db
file. Subsequent calls are significantly faster.Example:
>>> from kadi.commands import get_starcats >>> cat = get_starcats(obsid=8008)[0] >>> cat [<ACATable length=11> slot idx id type sz mag maxmag yang zang dim res int64 int64 int64 str3 str3 float64 float64 float64 float64 int64 int64 ----- ----- -------- ---- ---- ------- ------- -------- -------- ----- ----- 0 1 1 FID 8x8 7.00 8.00 937.71 -829.17 1 1 1 2 5 FID 8x8 7.00 8.00 -1810.42 1068.87 1 1 2 3 6 FID 8x8 7.00 8.00 403.68 1712.93 1 1 3 4 31075128 BOT 6x6 9.35 10.86 -318.22 1202.41 20 1 4 5 31076560 BOT 6x6 9.70 11.20 -932.79 -354.55 20 1 5 6 31463496 BOT 6x6 9.46 10.97 2026.85 1399.61 20 1 6 7 31983336 BOT 6x6 8.64 10.14 890.71 -1600.39 20 1 7 8 32374896 BOT 6x6 9.17 10.66 2023.08 -2021.72 13 1 0 9 31075368 ACQ 6x6 9.13 10.64 54.04 754.79 20 1 1 10 31982136 ACQ 6x6 10.19 11.70 562.06 -186.39 20 1 2 11 32375384 ACQ 6x6 9.79 11.30 1612.28 -428.24 20 1]
- Parameters:
- startCxoTime-like, None
Start time (default=beginning of commands)
- stopCxoTime-like, None
Stop time (default=end of commands)
- obsidint, None
ObsID
- scenariostr, None
Scenario
- cmdsCommandTable, None
Use this command table instead of querying the archive.
- as_dictbool, False
Return a list of dict instead of a list of ACATable objects.
- starcat_dateCxoTime-like, None
Date of the observation’s star catalog
- show_progressbool
Show progress bar for long queries (default=False)
- Returns:
- list
List of star catalogs (ACATable or dict) for matching observations.
- kadi.commands.observations.get_starcats_as_table(start=None, stop=None, *, obsid=None, unique=False, scenario=None, cmds=None, starcat_date=None)[source]¶
Get a single table of star catalog entries corresponding to input parameters.
This function calls
get_starcats
with the same parameters and then concatenates the results into a single table for convenience. In addition to the usual star catalog columns, theobsid
andstarcat_date
are included.The
unique
parameter can be set toTrue
to only return unique star catalog entries. There are numerous instances of a single commanded star catalogs that is associated with two ObsIDs, for instance ACIS undercover observations. To get only the first one, setunique=True
.In the following example we get every unique commanded guide star in 2020 and then join that with the corresponding observation information:
>>> from kadi.commands import get_starcats_as_table, get_observations >>> from astropy import table >>> start='2020:001' >>> stop='2021:001' >>> aces = get_starcats_as_table(start, stop, unique=True) >>> ok = np.isin(aces['type'], ['GUI', 'BOT']) >>> guides = aces[ok] >>> obss = table.Table(get_observations(start, stop)) >>> obss = obss[~obss['starcat_date'].mask] # keep only obs with starcat >>> guides = table.join(guides, obss, keys=['starcat_date', 'obsid'])
- Parameters:
- startCxoTime-like, None
Start time (default=beginning of commands)
- stopCxoTime-like, None
Stop time (default=end of commands)
- obsidint, None
ObsID
- uniquebool
If True return remove duplicate entries
- scenariostr, None
Scenario
- cmdsCommandTable, None
Use this command table instead of querying the archive.
- starcat_dateCxoTime-like, None
Date of the observation’s star catalog
- Returns:
- Table
Star catalog entries for matching observations.
Utils¶
- class kadi.commands.utils.TimeSeriesChunk(first: kadi.commands.utils.TimeSeriesPoint = None, min: kadi.commands.utils.TimeSeriesPoint = None, max: kadi.commands.utils.TimeSeriesPoint = None, last: kadi.commands.utils.TimeSeriesPoint = None)[source]¶
- kadi.commands.utils.add_figure_regions(fig: Figure, figure_start: CxoTime | str | float | int | ndarray | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | complex | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | None, figure_stop: CxoTime | str | float | int | ndarray | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | complex | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | None, region_starts: List[CxoTime | str | float | int | ndarray | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | complex | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | None], region_stops: List[CxoTime | str | float | int | ndarray | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | complex | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | None], color: str = 'black', opacity: float = 0.2, line_width: float = 3)[source]¶
Add regions to a figure with a date-based x-axis
figure_start
andfigure_stop
are the start and stop times for the figure.region_starts
andregion_stops
are lists of start/stop times for regions.
- kadi.commands.utils.fill_gaps_with_nan(times: list, vals: list, max_gap: float, dt: float = 0.001)[source]¶
Fill gaps in
vals
with NaNs where gaps intimes
is more thanmax_gap
.Do something like:
times = [1, 2, 20, 21, 22] => [1, 2, 2.001, 19.999, 20, 21, 22] vals = [1, 2, 3, 4, 5] => [1.0, 2.0, NaN, NaN, 3.0, 4.0, 5.0]
- Parameters:
- times
times
- vals
values
- max_gap
maximum gap in seconds
- dt
time delta to use for filling gaps
- Returns:
- times, vals with gaps filled with NaNs