Utilities API documentation

Utilities for the engineering archive.

Ska.engarchive.utils.get_fetch_size(msids, start, stop, stat=None, interpolate_dt=None, fast=True)[source]

Estimate the memory size required to fetch the msids between start and stop. 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 in msids).

  • 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

Ska.engarchive.utils.logical_intervals(times, bools, complete_intervals=True, max_gap=None)[source]

Determine contiguous intervals during which bools is True.

If complete_intervals is True (default) 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 than max_gap are filled with a fictitious False value to create an artificial interval boundary at max_gap / 2 seconds from the nearest data value.

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 Ska.engarchive 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)
Returns:

Table of intervals

Ska.engarchive.utils.ss_vector(start, stop=None, obj='Earth')[source]

Calculate vector to Earth, Sun, or Moon in Chandra body coordinates between start and stop 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 Ska.engarchive.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

Ska.engarchive.utils.state_intervals(times, vals)[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

Example:

>>> from Ska.engarchive import fetch, utils
>>> dat = fetch.Msid('cobsrqid', '2010:003', '2010:004')
>>> 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.
Returns:

structured array table of intervals

Previous topic

Plotting API documentation

Next topic

<no title>