Utilities API documentation¶
Utilities for the engineering archive.
- cheta.utils.get_date_id(date)[source]¶
Get date_id format used in sync repo index.
- Parameters:
date –
- Returns:
date_id
- cheta.utils.get_fetch_size(msids, start, stop, stat=None, interpolate_dt=None, fast=True)[source]¶
Estimate the memory size required to fetch the
msids
betweenstart
andstop
. This is generally intended for limiting queries to be less than ~100 Mb and allows for making some assumptions for improved performance (see below).Returns a tuple of the estimated megabytes of memory for the raw fetch and megabytes for the final output (which is different only in the case of interpolating). This is done by fetching 3 days of telemetry (2010:001 to 2010:004) and scaling appropriately.
If
fast
is True (default) then if either of the conditions below apply a result of (-1, -1) is returned, indicating that the fetch will probably be less than ~100 Mb and should be OK. (This does not account for the number of MSIDs passed inmsids
).Fetch duration (stop - start) is less than 30 days
Fetch
stat
is ‘5min’ or ‘daily’
- Parameters:
msids – list of MSIDs or a single MSID
start – start time
stop – stop time
stat – fetch stat (None|’5min’|’daily’, default=None)
interpolate_dt – interpolate the output to uniform time steps (default=None)
fast – return (-1, -1) if conditions on duration / stat (default=True)
- Returns:
fetch_Mb, interpolated_Mb
- cheta.utils.get_ofp_states(start, stop)[source]¶
Get the Onboard Flight Program (OFP) states between
start
and ``stop`.This is normally “NRML” but in safe mode it is “SAFE” or other values. State codes: [‘NNRM’ ‘STDB’ ‘STBS’ ‘NRML’ ‘NSTB’ ‘SUOF’ ‘SYON’ ‘DPLY’ ‘SYSF’ ‘STUP’ ‘SAFE’]
- Parameters:
start – start time (CxoTimeLike)
stop – stop time (CxoTimeLike)
- Returns:
astropy Table of OFP state intervals
- cheta.utils.get_telem_table(msids: list, start: ~cxotime.cxotime.CxoTime | str | float | int | ~numpy.ndarray | ~numpy._typing._array_like._SupportsArray[~numpy.dtype] | ~numpy._typing._nested_sequence._NestedSequence[~numpy._typing._array_like._SupportsArray[~numpy.dtype]] | bool | complex | bytes | ~numpy._typing._nested_sequence._NestedSequence[bool | int | float | complex | str | bytes] | None, stop: ~cxotime.cxotime.CxoTime | str | float | int | ~numpy.ndarray | ~numpy._typing._array_like._SupportsArray[~numpy.dtype] | ~numpy._typing._nested_sequence._NestedSequence[~numpy._typing._array_like._SupportsArray[~numpy.dtype]] | bool | complex | bytes | ~numpy._typing._nested_sequence._NestedSequence[bool | int | float | complex | str | bytes] | None, time_pad: ~astropy.units.quantity.Quantity = <Quantity 15. min>, unit_system: str = 'eng') Table [source]¶
Fetch telemetry for a list of MSIDs and return as an Astropy Table.
This interpolates all the MSIDs to the time base of the first MSID in the list. It also fetches
time_pad
more than requested to ensure that the samples are complete (e.g. if the interval is between MSID samples).If no telemetry is available for the requested interval then an empty table is returned with all float columns.
- Parameters:
msids – fetch msids list
start – start time for telemetry (CxoTime-like)
stop – stop time for telemetry (CxoTime-like)
time_pad – Quantity time pad on each end for fetch (default=15 min)
unit_system – unit system for fetch (“eng” | “cxc” | “sci”, default=”eng”)
- Returns:
Table of requested telemetry values from fetch
- cheta.utils.logical_intervals(times, bools, complete_intervals=False, max_gap=None, start=None, stop=None)[source]¶
Determine contiguous intervals during which bools is True.
If
complete_intervals
is True (default is False) then the intervals are guaranteed to be complete so that the all reported intervals had a transition before and after within the telemetry interval.If
max_gap
is specified then any time gaps longer thanmax_gap
are filled with a fictitious False value to create an artificial interval boundary atmax_gap / 2
seconds from the nearest data value.If
start
is specified then the first interval will be fromstart
. Ifstop
is specified then the last interval will be tostop
.Returns an astropy Table with a row for each interval. Columns are:
datestart: date of interval start
datestop: date of interval stop
duration: duration of interval (sec)
tstart: time of interval start (CXC sec)
tstop: time of interval stop (CXC sec)
Example (find SCS107 runs via telemetry):
>>> from cheta import utils, fetch >>> dat = fetch.Msidset(['3tscmove', 'aorwbias', 'coradmen'], '2012:190', '2012:205') >>> dat.interpolate(32.8) # Sample MSIDs onto 32.8 second intervals (like 3TSCMOVE) >>> scs107 = ((dat['3tscmove'].vals == 'T') & (dat['aorwbias'].vals == 'DISA') & (dat['coradmen'].vals == 'DISA')) >>> scs107s = utils.logical_intervals(dat.times, scs107) >>> print(scs107s['datestart', 'datestop', 'duration']) datestart datestop duration --------------------- --------------------- ------------- 2012:194:20:00:31.652 2012:194:20:04:21.252 229.600000083 2012:196:21:07:36.452 2012:196:21:11:26.052 229.600000083 2012:201:11:45:46.852 2012:201:11:49:36.452 229.600000083
- Parameters:
times – array of time stamps in CXC seconds
bools – array of logical True/False values
complete_intervals – return only complete intervals (default=True)
max_gap – max allowed gap between time stamps (sec, default=None)
start – start time (CxoTimeLike, default=None)
stop – stop time (CxoTimeLike, default=None)
- Returns:
Table of intervals
- cheta.utils.set_fetch_basedir(basedir)[source]¶
Temporarily override the base directory that fetch uses for telemetry data.
Example to use local data:
>>> with set_fetch_basedir('.'): ... dat = fetch.Msid('aacccdpt', '2018:001', '2018:100')
- Parameters:
basedir – str or os.PathLike, base directory for cheta data
- cheta.utils.ss_vector(start, stop=None, obj='Earth')[source]¶
Calculate vector to Earth, Sun, or Moon in Chandra body coordinates between
start
andstop
dates at 5 minute (328 sec) intervals.The return value in a NumPy structured array table (see below) which contains the distance in km from Chandra to the the solar system object along with the corresponding direction vectors in Chandra body coordinates and in the ECI frame. For convenience the attitude quaternion components are also provided.
Output table columns:
times: time in CXC seconds
distance: Distance to object (km)
body_x: X component of object in Chandra body coordinates
body_y: Y component of object in Chandra body coordinates
body_z: Z component of object in Chandra body coordinates
eci_x: X component of object relative to Chandra in ECI coordinates
eci_y: Y component of object relative to Chandra in ECI coordinates
eci_z: Z component of object relative to Chandra in ECI coordinates
q1: component 1 of the attitude quaternion
q2: component 2 of the attitude quaternion
q3: component 3 of the attitude quaternion
q4: component 4 of the attitude quaternion
Example:
from cheta.utils import ss_vector from Ska.Matplotlib import plot_cxctime vec = ss_vector('2010:001', '2010:030', obj='Sun') figure(1) clf() subplot(2, 1, 1) plot_cxctime(vec['times'], vec['body_x'], '-b') plot_cxctime(vec['times'], vec['body_y'], '-r') plot_cxctime(vec['times'], vec['body_z'], '-g') subplot(2, 1, 2) plot_cxctime(vec['times'], vec['distance'])
- Parameters:
start – start time (DateTime format)
stop – stop time (DateTime format)
obj – solar system object (‘Earth’, ‘Moon’, ‘Sun’)
- Returns:
table of vector values
- cheta.utils.state_intervals(times, vals, start=None, stop=None)[source]¶
Determine contiguous intervals during which the
vals
is unchanged.Returns an Astropy Table with a row for each interval. Columns are:
datestart: date of interval start
datestop: date of interval stop
duration: duration of interval (sec)
tstart: time of interval start (CXC sec)
tstop: time of interval stop (CXC sec)
val: MSID value during the interval
If
start
is specified then the first interval will be fromstart
. Ifstop
is specified then the last interval will be tostop
.Example:
>>> from cheta import fetch, utils >>> dat = fetch.Msid('cobsrqid', '2010:003:12:00:00', '2010:004:12:00:00') >>> obsids = utils.state_intervals(dat.times, dat.vals) >>> print(obsids['datestart', 'datestop', 'val']) datestart datestop val --------------------- --------------------- ------- 2010:003:12:00:00.976 2010:004:09:07:44.180 11011.0 2010:004:09:07:44.180 2010:004:09:40:52.680 56548.0 2010:004:09:40:52.680 2010:004:12:00:00.280 12068.0
- Parameters:
times – times (CXC seconds)
vals – state values for which intervals are returned.
start – start time (CxoTimeLike, default=None)
stop – stop time (CxoTimeLike, default=None)
- Returns:
structured array table of intervals