curryer.spicierpy.ext

Extensions to SPICE and the wrapper SpiceyPy.

@author: Brandon Stone

Attributes

Classes

load_kernel

SPICE Kernel Context Manager.

Functions

object_frame(obj_name[, as_id])

Retrieve frame name/id associated with an object name or id.

kernel_coverage(filename, body[, as_segments, to_fmt])

Determine the coverage window for an entire kernel file.

kernel_objects(filename[, as_id])

Determine what objects (names or codes) are within a kernel file.

infer_ids(spacecraft_name, spacecraft_id[, ...])

Infer NAIF IDs based on the spacecraft ID.

instrument_boresight(instrument[, n_vectors, norm])

Retrieve an instrument's boresight vector from the kernel pool.

brief(kernel_file[, bin_])

Brief summary of a kernel file.

spice_error_to_val([err_value, err_flag, pass_flag, ...])

Wrapper to catch spice errors and convert them to non-error values.

query_ephemeris(ugps_times, target, observer[, ...])

Query SPICE ephemeris data from pre-loaded kernels.

Module Contents

curryer.spicierpy.ext.logger
class curryer.spicierpy.ext.load_kernel(kernels)

SPICE Kernel Context Manager.

_loaded = []
__enter__()
__exit__(exc_type, exc_val, exc_tb)
__del__()
property loaded

List of kernels that have been loaded.

_iter_load(kernels)

Load multiple kernels.

load(kernel)

Load a kernel file.

unload(kernel=None, clear=False)

Unload a kernel file.

curryer.spicierpy.ext.object_frame(obj_name, as_id=False)

Retrieve frame name/id associated with an object name or id.

Parameters:
  • obj_name (str or int) – Object name or id to get the frame for.

  • as_id (bool, default=False) – If True, change return to be the frame id instead of the name.

Returns:

frame_name – Associated frame name, or id if as_id=True.

Return type:

str or int

curryer.spicierpy.ext.kernel_coverage(filename, body, as_segments=False, to_fmt='ugps')

Determine the coverage window for an entire kernel file.

Parameters:
  • filename (str or Path) – SPICE kernel file.

  • body (int or str) – NAIF body code or name to check coverage of. A string is assumed to be a body name, while an int is assumed to be a body code. Note: Using a body name requires that the body definition is loaded into memory; integer codes will work regardless.

  • as_segments (bool) – Option to return the coverage of each segment.

  • to_fmt (str, optional) – Datetime format for the returned times. Default=’ugps’.

Returns:

Start and stop coverage times in to_fmt or GPS microseconds.

Return type:

tuple of two int or float or str

Notes

Kernel dependencies of filename should be loaded prior to the function call (i.e., the spacecraft clock kernel (SCLK) for an attitude kernel (CK)).

curryer.spicierpy.ext.kernel_objects(filename, as_id=False)

Determine what objects (names or codes) are within a kernel file.

Parameters:
  • filename (str) – SPICE kernel file.

  • as_id (bool, optional) – If False (default) return the NAIF body names, otherwise return the body codes. Note: Using a body name requires that the body definition is loaded into memory; integer codes will work regardless.

Returns:

Collection of NAIF body names (default) or codes found within the kernel file (filename).

Return type:

tuple of str or tuple of ints

curryer.spicierpy.ext.infer_ids(spacecraft_name, spacecraft_id, instruments=None, from_dsn=False, from_norad=False)

Infer NAIF IDs based on the spacecraft ID.

Useful when planning out the necessary IDs; not meant to reverse existing IDs since the following rules are not strictly enforced.

Parameters:
  • spacecraft_name (str) – Spacecraft or mission name.

  • spacecraft_id (int) – Spacecraft ID; all other IDs are based on this. NOTE: It should be a negative number, unless from_dsn or from_norad is used.

  • instruments (str or list of str, optional) – One or more instrument names to create IDs for.

  • from_dsn (bool, optional) – Option to interpret spacecraft_id as a JPL Deep Space Network (DSN) ID. It will be converted to a SPICE-like spacecraft ID using the standard convention.

  • from_norad (bool, optional) – Option to interpret spacecraft_id as a NORAD tracking ID. It will be converted to a SPICE-like spacecraft ID using the standard convention.

Returns:

Collection of the mission name and IDs (spacecraft, clock, ephemeris, attitude), and instrument names and IDs.

Return type:

collections.dict

curryer.spicierpy.ext.instrument_boresight(instrument, n_vectors=1, norm=False)

Retrieve an instrument’s boresight vector from the kernel pool.

Parameters:
  • instrument (str or int or sds_spice.spicierypy.obj.Instrument) – The instrument ID, name or object to retrieve the boresight of.

  • n_vectors (int, optional) – Number of vectors to retrieve. Default=1

  • norm (bool, optional) – Option to return normalized vectors. Default=False

Return type:

numpy.ndarray

curryer.spicierpy.ext.brief(kernel_file, bin_=None)

Brief summary of a kernel file.

curryer.spicierpy.ext.spice_error_to_val(err_value=None, err_flag=None, pass_flag=None, disable=False)

Wrapper to catch spice errors and convert them to non-error values.

Parameters:
  • err_value (any) – Value to return when a SPICE error is encountered (e.g. nans).

  • err_flag (any) – Value to return with the err_value to indicate that an error had occurred. Can be a callable, excepting the error object.

  • pass_flag (any) – Value to return with the function’s return to indicate that no error had occurred. Can be a callable, excepting the output value.

  • disable (bool) – Option to disable to the error handling.

Returns:

  • any – Return from the wrapped function if no error was encountered, otherwise the err_value.

  • any – Flag indicating if an error occurred (err_flag) or not (pass_flag).

curryer.spicierpy.ext.POSITION_COLUMNS = ('x', 'y', 'z')
curryer.spicierpy.ext.VELOCITY_COLUMNS = ('vx', 'vy', 'vz')
curryer.spicierpy.ext.query_ephemeris(ugps_times, target, observer, ref_frame='J2000', correction=None, velocity=False, allow_nans=False)

Query SPICE ephemeris data from pre-loaded kernels.

Parameters:
  • ugps_times (list of int) – One or more UGPS times to query data for.

  • target (str or int or Body) – Name or ID of the target object.

  • observer (str or int or Body) – Name or ID of the observing object.

  • ref_frame (str or Frame, optional) – Reference frame of the ephemeris data. Default=”J2000”

  • correction (str, optional) – SPICE correction to apply to the data (e.g., “LT”). Default=None

  • velocity (bool, optional) – Query position and velocity. Default is position only. Note that velocity requires angular velocity in all connected CK kernels.

  • allow_nans (bool, optional) – Allow setting NaNs for times when insufficient SPICE kernel data would otherwise raise an exception. Note: Setting this flag significantly impacts read performance. Default=False.

Return type:

pd.DataFrame