SpiceManager#

class SpiceManager#

Bases: object

Unified interface to NASA SPICE via SpiceyPy.

Provides static utility methods for loading/unloading SPICE kernels, querying body states and positions, converting between time systems, resolving body and frame identifiers, and computing geometric quantities (light time, ground-station visibility, etc.).

All methods that return physical quantities wrap their output in ArrayWUnits or ArrayWFrame to carry units and frames explicitly.

Notes

SpiceManager is a pure-static class; it holds no instance state. Configuration is done through class-level attributes:

  • kernel_list — list of currently loaded kernel paths.

  • kernel_folder — default folder scanned for scenario kernels.

  • poly_interp_deg — polynomial degree for state interpolation.

References

[1]

Annex et al., (2020). SpiceyPy: a Pythonic Wrapper for the SPICE Toolkit. Journal of Open Source Software, 5(46), 2050. https://doi.org/10.21105/joss.02050

[2]

Acton, C.H.; “Ancillary Data Services of NASA’s Navigation and Ancillary Information Facility;” Planetary and Space Science, Vol. 44, No. 1, pp. 65–70, 1996. DOI 10.1016/0032-0633(95)00107-7

[3]

Acton, C.; Bachman, N.; Semenov, B.; Wright, E.; “A look toward the future in the handling of space science mission geometry;” Planetary and Space Science (2017). DOI 10.1016/j.pss.2017.02.013

Attributes:
kernel_folder

Methods

YDS2et(year, doy, sec)

Method to convert a year, DOY, seconds into ephemeris times.

cal2et(cal)

Convert a calendar UTC string to ephemeris time.

check_kernel_status_in_pool(kernel_filename)

Check if a Spice kernel is loaded in the kernel pool.

ckbrief(ck_file[, tol, disp])

Extracts ID and interval information from a given C-kernel.

clear_kernels()

Unload all SPICE kernels from the kernel pool.

def_new_body(name, spiceId)

Define a new celestial body in the SPICE kernel.

et2YDS(et_list)

Method to convert a list of ephemeris times into (year, DOY, seconds) format.

et2cal(et)

Convert ephemeris time to a calendar UTC string.

et2jd(et[, form, prec, utclen])

Convert ephemeris time to a Julian Date string (JDUTC).

et2sclk(scId, et[, lenout])

Convert ephemeris time to a spacecraft clock string.

et2utc(et[, form, prec, utclen])

Convert ephemeris time to a UTC string.

frame_id_to_frame_name(frame_id)

Return the SPICE frame name for a given integer frame ID.

frame_name_to_frame_id(frame_name)

Return the SPICE integer frame ID for a given frame name.

generate_metakernel(directory[, output_file])

List all files in a directory and write them into a SPICE metakernel.

get_STMs(trgt_bdy, epoch_time, ...[, ...])

Retrieve or interpolate the State Transition Matrix (STM) at a given epoch.

get_attitude(trgt_bdy, epoch_time, ...)

Get the attitude of a target body at a specified epoch time.

get_elevation_angle(target, et[, station, ...])

Compute the elevation angle of a target body as seen from a DSN ground station using SPICE.

get_frame_w_spice_id(id_number)

Return the frame code and name associated with a NAIF body ID.

get_id_from_string(name_string)

Return the NAIF integer ID for a body given its SPICE name.

get_intervals(spkFile, objID)

Return the coverage interval of a body in an SPK file as JD strings.

get_lighttime(trgt_bdy, epoch_time, ...[, ...])

Calculate the light time between a target and an origin at a given epoch time.

get_name_from_id(spice_id)

Return the SPICE body name for a given NAIF integer ID.

get_observer_target_visibility_windows(...)

Determine the visibility windows between an observer and a target within a specified time range.

get_parameters(trgt_bdy, epoch_time, ...[, ...])

Retrieve and interpolate estimated parameters from a companion JSON file.

get_pos(trgt_bdy, epoch_time, ...[, ab_correct])

Get the position of a target body relative to an observer body at a given epoch.

get_propagator_settings(trgt_bdy, ...[, ...])

Retrieves the propagator settings for a given target, reference frame, and origin from JSON files.

get_sep_angle(target, et[, station, abcorr])

Compute the Sun–Earth–Probe (SEP) angle of a target body as seen from a DSN ground station.

get_state(trgt_bdy, epoch_time, ...[, ...])

Retrieve the state (position and velocity) of a target body relative to an origin body at a specified epoch time.

get_state_antenna(trgt_bdy, epoch_time, ...)

Retrieve the state (position and velocity) of the antenna on a target spacecraft relative to an origin body at a specified epoch time.

get_state_precise(trgt_bdy, epoch_time_high, ...)

Retrieve the state (position and velocity) of a target body relative to an origin body at a specified epoch time.

get_vel(trgt_bdy, epoch_time, ...[, ab_correct])

Calculates the velocity of a target body relative to an observer body at a specified epoch time and reference frame.

get_xfrm(frame_from, frame_to, epoch)

Computes the direction cosine matrix (DCM) to transform coordinates from one reference frame to another at a given epoch.

id2name(id)

Convert given SPICE ID to the name of the associated body.

increase_kernel_priority(kernel_filename)

This function increases the priority of kernel to the top of the pool for kernels of the same type by unloading then loading it.

jd2et(jd)

Convert a Julian Date (JDTDB) to ephemeris time.

list_all_ck_ids(ck_file)

Return all NAIF IDs present in a C-kernel file.

list_all_frames([max_id])

List all SPICE reference frames currently detectable in the pool.

load_kernel(kernel_filenames)

Load SPICE kernels into the SPICE system.

load_kernel_from_mkfile(furnshKernelFilename)

Load a SPICE kernel from a given MK file.

matrix_times_vector(matrix, vector)

Multiply a \(3 \times 3\) matrix by a 3-vector via SPICE.

name_to_ID(name)

Converts a given name to its corresponding ID in the kernel pool.

print_kernels()

Print the source and type of every currently loaded SPICE kernel.

sce2c(sc, et)

Convert ephemeris time to encoded spacecraft clock ticks.

sclk2et(scId, sclk)

Convert a spacecraft clock string to ephemeris time.

str2et(s)

Convert a time string to ephemeris time (TDB seconds past J2000).

unload_kernel_from_pool(kernel_filename)

Unload a kernel from the pool.

utc2et(utc)

Convert a UTC time string to ephemeris time (TDB seconds past J2000).

utc2tdb(utc)

Convert a UTC time string to TDB seconds past J2000.

write_ck_type3(ck_path, inst_id, ref_frame, ...)

Write a CK type 3 segment (discrete pointing) to a new CK file.

write_spk_metadata_json(SPK_name, body, ...)

Write ONLY the JSON sidecars associated with an SPK (parameters/STMs/settings/mass profile).

write_spk_segment_type9(SPK_name, ...[, ...])

Write a segment of type 9 to an SPK file.

test

classmethod ckbrief(ck_file: str, tol: int = 0, disp: bool = False) list[dict]#

Extracts ID and interval information from a given C-kernel.

Parameters:
  • ck_file (str) – The path to the C-kernel file to be examined.

  • disp (bool, optional) – Flag to include a formatted print-out of the brief. Defaults to False.

Returns:

brief – A list containing information about each frame in the C-kernel. Each element of the list is a dict containing the following keys:

  • 'ID' : the NAIF integer code of the frame.

  • 'SCLK_INTERVAL' : the interval or intervals for which the frame is defined in the C-kernel, represented as encoded SCLK ticks by floats.

  • 'TDB_INTERVAL' : the interval or intervals for which the frame is defined in the C-kernel, represented as ephemeris time (TDB) EpochArray objects.

Return type:

list of dict

classmethod clear_kernels()#

Unload all SPICE kernels from the kernel pool.

Calls spice.kclear() to flush every kernel currently held in memory.

Return type:

None

classmethod get_STMs(trgt_bdy: str | Body, epoch_time: float, reference_frame: str | Frame, obsvr_bdy: str | Body, folder_path_override: str = None) ndarray#

Retrieve or interpolate the State Transition Matrix (STM) at a given epoch.

Searches the scenario kernel folder for a *_stms.json file whose body_ID, origin_ID, and reference_frame fields match the supplied arguments. If epoch_time coincides (within floating-point tolerance) with a stored epoch the corresponding STM is returned directly. Otherwise element-wise linear interpolation is performed between the two bracketing epochs.

Parameters:
  • trgt_bdy (str or Body) – Target body whose STMs are requested.

  • epoch_time (float) – TDB epoch (seconds past J2000) at which to retrieve/interpolate the STM.

  • reference_frame (str or Frame) – Reference frame recorded in the STM JSON file.

  • obsvr_bdy (str or Body) – Observer (origin) body recorded in the STM JSON file.

Returns:

STM – Shape (6, 6) State Transition Matrix evaluated at epoch_time.

Return type:

numpy.ndarray

Raises:

ValueError – If no matching STM JSON file is found, or if epoch_time lies outside the stored time span.

classmethod get_attitude(trgt_bdy: str | Body, epoch_time: float | EpochArray, reference_frame: str | Frame, tol: int)#

Get the attitude of a target body at a specified epoch time. :param trgt_bdy: The target body for which the attitude is to be determined. Can be an instance of Body or a string representing the body’s name. :type trgt_bdy: str or Body :param epoch_time: The epoch time at which the attitude is to be determined. Can be an instance of EpochArray or a float representing the time. :type epoch_time: float or EpochArray :param reference_frame: The reference frame in which the attitude is to be determined. Can be a string or an instance of Frame. :type reference_frame: str or Frame :param tol: The tolerance value for the attitude determination. :type tol: int

Returns:

A tuple containing: - ArrayWUnits: The state vector of the target body. - ArrayWUnits: The angular velocity of the target body. - ArrayWUnits: The angular acceleration of the target body.

Return type:

tuple

classmethod get_elevation_angle(target: str, et, station: str = 'DSS-14', abcorr: str = 'LT+S') float#

Compute the elevation angle of a target body as seen from a DSN ground station using SPICE.

This method uses the SPICE toolkit to calculate the elevation angle of a target relative to a Deep Space Network (DSN) ground station. The calculation is performed in the station’s local topocentric frame (e.g., DSS-14_TOPO), where the convention is X = East, Y = North, and Z = Up.

Parameters:
  • target (str) – The name or NAIF ID of the target body. Examples: "MRO" or "-74".

  • et (float) – Ephemeris time at which to compute the elevation angle.

  • station (str) – The DSN ground station name or NAIF ID used as the observer. Must match the identifiers defined in the loaded SPICE kernels. Defaults to "DSS-14".

  • abcorr (str, optional) – Aberration correction to apply when computing the geometry. Examples: - "NONE": No corrections. - "LT": Light-time correction only. - "LT+S": Light-time + stellar aberration correction (default).

Returns:

elevation_angle – The elevation angle of the target relative to the local horizon at the specified DSN station, expressed in radians (or the units defined by cls._spc_angle_units). Positive values indicate the target is above the horizon, while negative values indicate it is below.

Return type:

ArrayWUnits

Notes

  • The station’s topocentric frame (e.g., DSS-14_TOPO) must be defined in the

loaded SPICE kernels. - The axis convention for topocentric frames is assumed to be: X = East, Y = North, Z = Up. - To obtain azimuth as well, use atan2(East, North) in the same frame. - Requires SPICE kernels for:

  • DSN station locations and frames.

  • Target body ephemerides.

  • Leapseconds (LSK).

classmethod get_lighttime(trgt_bdy: str | Body, epoch_time: float | EpochArray, reference_frame: str | Frame, obsvr_bdy: str | Body, aberration_correction: str = 'None')#

Calculate the light time between a target and an origin at a given epoch time.

Parameters:
  • trgt_bdy (str or Body) – The target body or its name as a string.

  • epoch_time (EpochArray or float) – The epoch time at which to calculate the light time.

  • reference_frame (str or Frame) – The reference frame or its name as a string.

  • origin (str or Body) – The origin body or its name as a string.

  • aberration_correction (str, optional) – The aberration correction to apply. Defaults to None.

Returns:

light_time – The light time as an array with units.

Return type:

ArrayWUnits

classmethod get_parameters(trgt_bdy: str | Body, epoch_time: float | EpochArray, reference_frame: str | Frame, obsvr_bdy: str | Body, folder_path_override: str = None)#

Retrieve and interpolate estimated parameters from a companion JSON file.

Searches the scenario kernel folder for a *_parameters.json file whose body_ID, origin_ID, and reference_frame fields match the supplied arguments. If the file contains a multi-leg sequence, the leg whose epochsTDB interval contains epoch_time is selected. Within each leg (or in the flat, non-sequence case) the stored parameter time series is fitted with a polynomial of degree cls.poly_interp_par_deg and evaluated at epoch_time.

Parameters:
  • trgt_bdy (str or Body) – Target body whose parameters are requested.

  • epoch_time (float or EpochArray) – TDB epoch (seconds past J2000) at which to evaluate the parameters.

  • reference_frame (str or Frame) – Reference frame recorded in the JSON file.

  • obsvr_bdy (str or Body) – Observer (origin) body recorded in the JSON file.

  • folder_path_override (str, optional) – Absolute path to the folder that contains the JSON files. When None (default), cls.kernel_folder is used if set; otherwise falls back to <cwd>/data/kernels/scenario.

Returns:

parameters – Interpolated parameter vector with units reconstructed from the unitsPower / unitsScale fields stored in the JSON.

Return type:

ArrayWUnits

Raises:
  • ValueError – If no matching JSON file is found, or if epoch_time does not fall within any leg’s time span.

  • RuntimeWarning – If more than one matching JSON file is found; the most recently modified file is used.

classmethod get_pos(trgt_bdy: str | Body, epoch_time: float | EpochArray, reference_frame: str | Frame, obsvr_bdy: str | Body, ab_correct: str = 'None')#

Get the position of a target body relative to an observer body at a given epoch. This method computes the position vector of a target body as observed from an observer body at a specified epoch time, in a given reference frame.

Parameters:
  • trgt_bdy (str | Body) – The target body whose position is to be computed. Can be specified as a string (body name) or a Body object.

  • epoch_time (float | EpochArray) – The epoch time(s) at which to compute the position. Can be a single float value or an EpochArray for multiple time points.

  • reference_frame (str | Frame) – The reference frame in which to express the position vector. Can be specified as a string (frame name) or a Frame object.

  • obsvr_bdy (str | Body) – The observer body from which the target position is measured. Can be specified as a string (body name) or a Body object.

  • ab_correct (str, optional) – Aberration correction specification. Defaults to “None”. Common values include “NONE”, “LT”, “LT+S”, “CN”, “CN+S”, “XLT”, “XLT+S”, “XCN”, “XCN+S”.

Returns:

  • The position vector(s) of the target body relative to the observer body.

  • The exact return type depends on the implementation of _get_pos_core.

Notes

This method is a wrapper around _get_pos_core and delegates the actual computation to that core method.

classmethod get_propagator_settings(trgt_bdy: str | Body, reference_frame: str | Frame, obsvr_bdy: str | Body, folder_path_override: str = None)#

Retrieves the propagator settings for a given target, reference frame, and origin from JSON files. :param trgt_bdy: The target body or its name. :type trgt_bdy: str or Body :param reference_frame: The reference frame or its name. :type reference_frame: str or Frame :param obsvr_bdy: The origin body or its name. :type obsvr_bdy: str or Body

Returns:

The propagator settings data from the corresponding JSON file.

Return type:

dict

Raises:

ValueError – If the settings JSON file could not be located.

classmethod get_sep_angle(target: str, et, station: str = 'DSS-14', abcorr: str = 'LT+S') float#

Compute the Sun–Earth–Probe (SEP) angle of a target body as seen from a DSN ground station.

The SEP angle is defined as the angle at the observer (DSN station) between the vector pointing to the Sun and the vector pointing to the spacecraft (target). This is the standard “solar elongation angle” used in mission operations to assess geometry for radiometric tracking and solar corona effects.

Parameters:
  • target (str) – The name or NAIF ID of the target body. Examples: "OSIRIS-REX" or "-64".

  • et (float) – Ephemeris Time (seconds past J2000 TDB) at which to compute the SEP angle.

  • station (str, optional) – DSN ground station name or NAIF ID used as the observer. Must match the identifiers defined in the loaded SPICE kernels. Default is "DSS-14".

  • abcorr (str, optional) – Aberration correction to apply when computing the geometry. Examples: - "NONE": No corrections. - "LT": Light-time correction only. - "LT+S": Light-time + stellar aberration correction (default).

Returns:

sep_angle – The SEP angle in radians (or converted via cls._spc_angle_units). Larger angles correspond to better tracking geometry (target farther from the Sun as seen from Earth).

Return type:

ArrayWUnits

Notes

  • Requires SPICE kernels for:
    • DSN station locations (SPK + topocentric frame definitions).

    • Target body ephemerides (SPK).

    • Solar system ephemerides (SPK).

    • Leapseconds (LSK).

  • This angle is distinct from elevation angle (target above station horizon). SEP measures angular separation from the Sun, not from the horizon.

  • Often used to set operational limits during solar conjunctions.

Examples

et = scb.SpiceManager.utc2et("2017-09-22T16:52:00")  # OSIRIS-REx EGA
sep = MyClass.get_sep_angle("OSIRIS-REX", et, station="DSS-14")
print(sep.to("deg"))
classmethod get_state(trgt_bdy: str | Body, epoch_time: float | EpochArray, reference_frame: str | Frame, obsvr_bdy: str | Body, aberration_correction: str = 'None')#

Retrieve the state (position and velocity) of a target body relative to an origin body at a specified epoch time.

Parameters:
  • trgt_bdy (str or Body) – The target body for which the state is to be retrieved. Can be a string name or a Body object.

  • epoch_time (float or EpochArray) – The epoch time at which the state is to be retrieved. Can be an EpochArray object or a float representing the time.

  • reference_frame (str or Frame) – The reference frame in which the state is to be retrieved. Can be a Frame object or a string name.

  • obsvr_bdy (str or Body) – The observing body relative to which the state is to be retrieved. Can be a string name or a Body object.

  • aberration_correction (str, optional) – The aberration correction to be applied. Defaults to None.

Returns:

state – An array containing the state (position and velocity) of the target body with associated units.

Return type:

ArrayWUnits

classmethod get_state_antenna(trgt_bdy: Body, epoch_time: float, reference_frame: Frame, obsvr_bdy: Body, antenna_offset: ndarray, offset_reference_frame: Frame, ab_correct: str = 'None')#

Retrieve the state (position and velocity) of the antenna on a target spacecraft relative to an origin body at a specified epoch time.

Parameters:
  • trgt_bdy (str) – The target body for which the position is to be determined. Can be a string or a Body object.

  • epoch_time (float) – The epoch time at which the position is to be determined. Can be a float or an EpochArray object.

  • reference_frame (Frame) – The reference frame in which the position is to be determined. Can be a string or a Frame object.

  • obsvr_bdy (str) – The observing body from which the position is to be measured. Can be a string or a Body object.

  • antenna_offset (np.ndarray) – The antenna-CoM offset vector, expressed in the “spacecraft_body_frame” reference frame.

  • offset_reference_frame (Frame) – The spaceraft body-fixed reference frame. The origin of this frame is used to account for the antenna offset vector.

  • ab_correct (str, optional) – Aberration correction to be applied. Defaults to None.

Returns:

state – The State of the antenna relative to the origin body, expressed in units of km and km/sec

Return type:

np.ndarra()

classmethod get_state_precise(trgt_bdy: str | Body, epoch_time_high: float | EpochArray, reference_frame: str | Frame, obsvr_bdy: str | Body, aberration_correction: str = 'None', epoch_time_low: float | EpochArray = None)#

Retrieve the state (position and velocity) of a target body relative to an origin body at a specified epoch time.

Parameters:
  • trgt_bdy (str or Body) – The target body for which the state is to be retrieved. Can be a string name or a Body object.

  • epoch_time_high (float or EpochArray) – The epoch time at which the state is to be retrieved. Can be an EpochArray object or a float representing the time. This is the high component

  • reference_frame (str or Frame) – The reference frame in which the state is to be retrieved. Can be a Frame object or a string name.

  • obsvr_bdy (str or Body) – The observing body relative to which the state is to be retrieved. Can be a string name or a Body object.

  • aberration_correction (str, optional) – The aberration correction to be applied. Defaults to None.

  • epoch_time_low (float or EpochArray) – The epoch time at which the state is to be retrieved. Can be an EpochArray object or a float representing the time. This is the low component

Returns:

state – An array containing the state (position and velocity) of the target body with associated units.

Return type:

ArrayWUnits

classmethod get_vel(trgt_bdy: str | Body, epoch_time: float | EpochArray, reference_frame: str | Frame, obsvr_bdy: str | Body, ab_correct: str = 'None')#

Calculates the velocity of a target body relative to an observer body at a specified epoch time and reference frame.

Parameters:
  • trgt_bdy (str | Body) – The target body for which the velocity is to be computed. Can be a string identifier or a Body object.

  • epoch_time (float | EpochArray) – The epoch time(s) at which to compute the velocity. Can be a single float or an array of epochs.

  • reference_frame (str | Frame) – The reference frame in which the velocity is expressed. Can be a string or a Frame object.

  • obsvr_bdy (str | Body) – The observer body relative to which the velocity is computed. Can be a string identifier or a Body object.

  • ab_correct (str, optional) – Aberration correction flag. Defaults to “None”.

Returns:

The computed velocity of the target body relative to the observer in the specified reference frame.

Return type:

Velocity or array-like

classmethod get_xfrm(frame_from: str, frame_to: str, epoch)#

Computes the direction cosine matrix (DCM) to transform coordinates from one reference frame to another at a given epoch.

Parameters:
  • frame_from (str) – The name of the source reference frame.

  • frame_to (str) – The name of the target reference frame.

  • epoch – The epoch at which the transformation is computed. The type depends on the implementation (e.g., float, datetime).

Returns:

The direction cosine matrix (DCM) representing the transformation from frame_from to frame_to at the specified epoch.

Return type:

numpy.ndarray

classmethod print_kernels()#

Print the source and type of every currently loaded SPICE kernel.

Iterates over all kernels tracked by spice.ktotal and prints each entry’s file path and kernel type to stdout.

Return type:

None

classmethod write_ck_type3(ck_path: str, inst_id: int, ref_frame: str, sclk_id: int, et_list: list[float] | ndarray, quats: ndarray | None = None, avvs: ndarray | None = None, dcm_cb=None, segid: str = 'SCB GENERATED CK TYPE 3', make_intervals: str = 'per_sample', load_after: bool = True)#

Write a CK type 3 segment (discrete pointing) to a new CK file.

Parameters:
  • ck_path (str) – Output CK file path (.bc or .ck).

  • inst_id (int) – NAIF instrument/frame ID for the CK segment (the CK “INST” id).

  • ref_frame (str) – Base/reference frame name (usually ‘J2000’).

  • sclk_id (int) – NAIF spacecraft clock ID code used by sce2c().

  • et_list (array-like) – ET (TDB seconds past J2000) sample times.

  • quats (ndarray, optional) – Quaternions rotating vectors from ref_frame to inst frame. Shape (N,4) or (4,N). If None, must provide dcm_cb.

  • avvs (ndarray, optional) – Angular velocities expressed in ref_frame. Shape (N,3) or (3,N). If None, AVFLAG=0 and zeros are written (or FD-estimated if dcm_cb provided and you want).

  • dcm_cb (callable, optional) – Function et -> (3,3) DCM C_ref_to_inst. If provided and quats is None, quats are built via spice.m2q(C). spice.m2q uses SPICE quaternion convention. :contentReference[oaicite:2]{index=2}

  • segid (str) – Segment ID (<= 40 chars recommended).

  • make_intervals ({'per_sample','single'}) –

    • ‘per_sample’: NINTS=N-1, STARTS=sclkdp[:-1]

    • ’single’ : NINTS=1, STARTS=[sclkdp[0]]

  • load_after (bool) – If True, furnsh() the CK after writing.

Returns:

ck_path – Path to the written CK file.

Return type:

str

Notes

CKW03 requirements include monotonically increasing SCLKDP and descriptor times containing the data range. :contentReference[oaicite:3]{index=3}

classmethod write_spk_metadata_json(SPK_name: str, body: Body, origin_ID: float, ref_frame: Frame, epochs_TDB: list, degree_poly: float, parameters_JSON: list = None, STMs_JSON: list = None, state_definition: list = None, sequence_definition: list = None, leg_data: dict = None, propagator_settings: dict = None, mass_profile: SCBPolynomial = None)#

Write ONLY the JSON sidecars associated with an SPK (parameters/STMs/settings/mass profile).

This avoids writing any additional SPK segments (no dummy segments), and avoids SPICE descriptor-time errors.

Notes

  • epochs_TDB is included so JSON has a time reference; for sequences it can be the concatenated full epochs list or the global seq.total_epochsTDB list.

  • For sequence_definition != None, epochs_TDB is not directly used for legs epochs; _prepare_sequence_data uses sequence_definition.epochs_vec.

classmethod write_spk_segment_type9(SPK_name: str, SPK_SEG_ID: str, body: Body, origin_ID: float, ref_frame: Frame, epochs_TDB: list, degree_poly: float, state_SPICE: list, parameters_JSON: list = None, STMs_JSON: list = None, state_definition: list = None, sequence_definition: list = None, leg_data: dict = None, propagator_settings: dict = None, mass_profile: SCBPolynomial = None)#

Write a segment of type 9 to an SPK file.

Parameters:
  • SPK_name (str) – The name of the SPK file.

  • SPK_SEG_ID (str) – The segment ID.

  • body (object) – The body object.

  • origin_ID (int) – The ID of the origin.

  • ref_frame (frame) – The reference frame.

  • epochs_TDB (list) – The array of epochs in TDB format.

  • degree_poly (int) – The degree of the polynomial.

  • state_SPICE (list) – The array of states in SPICE format.

  • parameters_JSON (list, optional) – The array of parameters in JSON format.

  • STMs_JSON (list, optional) – The array of state transition matrices in JSON format.

  • state_definition (list, optional) – The state definition.

  • sequence_definition (object, optional) – The sequence definition.

  • leg_data (dict, optional) – The body, origin, and reference frame data for each leg.

  • propagator_settings (dict, optional) – The propagator settings.

  • mass_profile (SCBPolynomial, optional) – The mass profile.

Return type:

None

static YDS2et(year, doy, sec)#

Method to convert a year, DOY, seconds into ephemeris times.

Parameters:
Returns:

et – List of ephemeris times

Return type:

list

static cal2et(cal: str) float#

Convert a calendar UTC string to ephemeris time.

Alias for str2et(); accepts any time string format recognised by SPICE.

Parameters:

cal (str) – Calendar or ISO time string (e.g. "2017 SEP 22 16:52:00").

Returns:

et – TDB seconds past J2000.

Return type:

float

static check_kernel_status_in_pool(kernel_filename: str) bool#

Check if a Spice kernel is loaded in the kernel pool.

Parameters:

kernel_filename (str) – Filename of the kernel to be checked.

Returns:

Returns True if the kernel is in the pool and False if not.

Return type:

bool

static def_new_body(name, spiceId)#

Define a new celestial body in the SPICE kernel.

Parameters:
  • name (str) – The name of the celestial body.

  • spiceId (int) – The SPICE ID of the celestial body.

Return type:

None

static et2YDS(et_list)#

Method to convert a list of ephemeris times into (year, DOY, seconds) format.

Parameters:

et_list (float or list of float) – List of ephemeris times

Returns:

(years,doys,secs) – List of years, day of years, and seconds associated to the input et_list

Return type:

Tuple of lists

static et2cal(et: float | ndarray[tuple[Any, ...], dtype[_ScalarT]])#

Convert ephemeris time to a calendar UTC string.

Accepts scalar floats, 0-D arrays, or N-D arrays and preserves the input shape in the output.

Parameters:

et (float or numpy.ndarray) – TDB seconds past J2000. May be scalar or array-valued.

Returns:

cal – Calendar UTC string(s) in "C" (civil) format. A scalar et returns a single str; a 1-D array returns a 1-D array of strings; a higher-dimensional array is reshaped back to the original shape.

Return type:

str or numpy.ndarray of str

static et2jd(et: float, form: str = 'J', prec: int = 27, utclen: int = 27) str#

Convert ephemeris time to a Julian Date string (JDUTC).

Parameters:
  • et (float) – TDB seconds past J2000.

  • form (str, optional) – Format code; default "J" produces a Julian Date string.

  • prec (int, optional) – Digits of precision for fractional days. Default 27.

  • utclen (int, optional) – Length of the output string buffer. Default 27.

Returns:

jd – Julian Date string. The returned value is always JDUTC.

Return type:

str

static et2sclk(scId: int, et: float, lenout: int = 30) str#

Convert ephemeris time to a spacecraft clock string.

Thin wrapper around spice.sce2s.

Parameters:
  • scId (int) – NAIF spacecraft integer ID.

  • et (float) – TDB seconds past J2000 to convert.

  • lenout (int, optional) – Maximum length of the output SCLK string. Default 30.

Returns:

sclk – Spacecraft clock string corresponding to et.

Return type:

str

static et2utc(et: float, form: str = 'ISOC', prec: int = 27, utclen: int = 27) str#

Convert ephemeris time to a UTC string.

Parameters:
  • et (float) – TDB seconds past J2000.

  • form (str, optional) – Output format code passed to spice.et2utc. Common values: "ISOC" (ISO calendar, default), "ISOD" (ISO day-of-year), "C" (calendar), "D" (day-of-year), "J" (Julian date).

  • prec (int, optional) – Number of digits of precision for fractional seconds. Default 27.

  • utclen (int, optional) – Length of the output string buffer. Default 27.

Returns:

utc – UTC time string in the requested format.

Return type:

str

static frame_id_to_frame_name(frame_id: int) str#

Return the SPICE frame name for a given integer frame ID.

Results are cached with functools.lru_cache() for performance.

Parameters:

frame_id (int) – SPICE integer frame ID to resolve.

Returns:

frame_name – SPICE name of the reference frame.

Return type:

str

Notes

The frame ID is distinct from the body NAIF ID used in SPK/PCK kernels.

static frame_name_to_frame_id(frame_name: str) int#

Return the SPICE integer frame ID for a given frame name.

Parameters:

frame_name (str) – SPICE name of the reference frame (e.g. "J2000").

Returns:

frame_id – SPICE integer frame ID corresponding to frame_name.

Return type:

int

Notes

The frame ID is distinct from the body NAIF ID used in SPK/PCK kernels.

static generate_metakernel(directory: str, output_file: str = 'output_metakernel.tm')#

List all files in a directory and write them into a SPICE metakernel.

Parameters:
  • directory (str) – Path to the directory containing kernels.

  • output_file (str) – Name of the output metakernel file (default ‘output_metakernel.tm’).

static get_frame_w_spice_id(id_number: int)#

Return the frame code and name associated with a NAIF body ID.

Parameters:

id_number (int) – NAIF integer body ID to look up (e.g. 499 for Mars).

Returns:

result(frame_code, frame_name) where frame_code is the integer SPICE frame ID and frame_name is its string identifier.

Return type:

tuple of (int, str)

Raises:

ValueError – If id_number has no associated frame in the kernel pool.

static get_id_from_string(name_string: str) int#

Return the NAIF integer ID for a body given its SPICE name.

Parameters:

name_string (str) – SPICE body name (e.g. "EARTH", "MARS", "-60000").

Returns:

id_num – NAIF integer ID of the body.

Return type:

int

static get_intervals(spkFile: str, objID: int) list[str]#

Return the coverage interval of a body in an SPK file as JD strings.

Retrieves the first (and typically only) time window for objID from the SPK coverage window and converts the endpoints to Julian Date strings.

Parameters:
  • spkFile (str) – Full path to the SPK file. The file must already be accessible on disk (it does not need to be loaded into the kernel pool).

  • objID (int) – NAIF integer body ID whose coverage is requested.

Returns:

interval[start_jd, end_jd] where each element is a Julian Date string produced by spice.timout.

Return type:

list of str

static get_name_from_id(spice_id: int) str#

Return the SPICE body name for a given NAIF integer ID.

Parameters:

spice_id (int) – NAIF integer body ID (e.g. 399 for Earth).

Returns:

name – SPICE body name corresponding to spice_id.

Return type:

str

static get_observer_target_visibility_windows(obsvr_bdy: str | Body, trgt_bdy: str | Body, epoch_start: float | EpochArray, epoch_end: float | EpochArray, step_size: float = 300.0, angle_limit: float = 10.0, inframe: str = 'obs', abcorr: str = 'None', crdsys: str = 'LATITUDINAL', coord: str = 'LATITUDE', relate: str = '>', adjust: float = 0.0, num_intervals: int = 1000)#

Determine the visibility windows between an observer and a target within a specified time range.

Parameters:
  • obsvr_bdy (Union[str, scb.Body]) – The observer, either as a string name or a scb.Body object.

  • trgt_bdy (Union[str, scb.Body]) – The target, either as a string name or a scb.Body object.

  • epoch_start (Union[float, scb.EpochArray]) – The start time of the observation window.

  • epoch_end (Union[float, scb.EpochArray]) – he end time of the observation window.

  • step_size (float, optional) – The step size in seconds for the search. Default is 300.0.

  • angle_limit (float, optional) – The angular limit for visibility in degrees. Default is 10.0.

  • inframe (str, optional) – The reference frame for the observation. Default is “obs”.

  • abcorr (str, optional) – Aberration correction. Default is “None”.

  • crdsys (str, optional) – Coordinate system. Default is “LATITUDINAL”.

  • coord (str, optional) – Coordinate type. Default is “LATITUDE”.

  • relate (str, optional) – Relational operator for the coordinate comparison. Default is “>”.

  • adjust (float, optional) – Adjustment value for the search. Default is 0.0.

  • num_intervals (int, optional) – Maximum number of intervals for the search. Default is 1000.

Returns:

A tuple containing the number of visibility windows and a list of visibility windows.

Return type:

tuple

static id2name(id: int)#

Convert given SPICE ID to the name of the associated body.

static increase_kernel_priority(kernel_filename: str)#

This function increases the priority of kernel to the top of the pool for kernels of the same type by unloading then loading it.

Note: this is the method recommended by the Spice documentation.

Parameters:

kernel_filename (str) – Filename of the

static jd2et(jd: float) float#

Convert a Julian Date (JDTDB) to ephemeris time.

Parameters:

jd (float) – Julian Date in the TDB time scale.

Returns:

et – TDB seconds past J2000.

Return type:

float

Notes

A leap-second correction (spice.deltet) is added to account for the drift between JD and ET.

static list_all_ck_ids(ck_file: str) list[int]#

Return all NAIF IDs present in a C-kernel file.

Parameters:

ck_file (str) – Absolute or relative path to the CK file.

Returns:

ids – NAIF integer IDs of every object stored in ck_file.

Return type:

list of int

static list_all_frames(max_id: int = 100000) list#

List all SPICE reference frames currently detectable in the pool.

Scans integer frame IDs in \([-\texttt{max\_id},\,+\texttt{max\_id})\) and collects every ID for which SPICE returns a non-empty name.

Parameters:

max_id (int, optional) – Half-range of the frame-ID scan window. Defaults to 100000.

Returns:

frames_list – Names of all reference frames found.

Return type:

list of str

Notes

Frame IDs are distinct from body NAIF IDs used in SPK/PCK kernels.

static load_kernel(kernel_filenames)#

Load SPICE kernels into the SPICE system.

Parameters:

kernel_filenames (str or list) – A single kernel filename or a list of kernel filenames to be loaded.

Return type:

None

static load_kernel_from_mkfile(furnshKernelFilename)#

Load a SPICE kernel from a given MK file.

Parameters:

furnshKernelFilename (str) – The filename of the MK file to load.

Return type:

None

static matrix_times_vector(matrix, vector)#

Multiply a \(3 \times 3\) matrix by a 3-vector via SPICE.

Computes \(\mathbf{w} = \mathbf{M}\,\mathbf{v}\) using spice.mxv (CSPICE mxv_c).

Parameters:
  • matrix (numpy.ndarray) – Shape (3, 3) double-precision matrix (e.g. a rotation matrix).

  • vector (numpy.ndarray) – Shape (3,) double-precision vector.

Returns:

result – Shape (3,) product \(\mathbf{M}\mathbf{v}\).

Return type:

numpy.ndarray

static name_to_ID(name)#

Converts a given name to its corresponding ID in the kernel pool.

Parameters:

name (str) – The name to be converted.

Returns:

The ID corresponding to the given name, or None if the name is not found in the kernel pool.

Return type:

int or None

static sce2c(sc: int, et: float) float#

Convert ephemeris time to encoded spacecraft clock ticks.

Thin wrapper around spice.sce2c.

Parameters:
  • sc (int) – NAIF spacecraft integer ID (e.g. -64 for OSIRIS-REx).

  • et (float) – TDB seconds past J2000 to convert.

Returns:

sclk_ticks – Encoded SCLK ticks corresponding to et.

Return type:

float

static sclk2et(scId: int, sclk: str) float#

Convert a spacecraft clock string to ephemeris time.

Thin wrapper around spice.scs2e.

Parameters:
  • scId (int) – NAIF spacecraft integer ID (e.g. -64 for OSIRIS-REx).

  • sclk (str) – Spacecraft clock time string as it appears in the SCLK kernel.

Returns:

et – TDB seconds past J2000 corresponding to sclk.

Return type:

float

static str2et(s: str) float#

Convert a time string to ephemeris time (TDB seconds past J2000).

Thin wrapper around spice.str2et. Accepts a wide range of formats (ISO calendar, DOY, JD, etc.).

Parameters:

s (str) – Time string recognised by SPICE (e.g. "2017-09-22T16:52:00"). Julian-Date strings are treated as JDUTC.

Returns:

et – TDB seconds past J2000 corresponding to s.

Return type:

float

static test(file)#
static unload_kernel_from_pool(kernel_filename: str)#

Unload a kernel from the pool. If the kernel is not in the pool then no action is taken.

Parameters:

kernel_filename (str) – Filename of the Spice kernel being unloaded.

static utc2et(utc: str) float#

Convert a UTC time string to ephemeris time (TDB seconds past J2000).

Thin wrapper around spice.utc2et.

Parameters:

utc (str) – UTC time string in a format recognised by SPICE (e.g. "2017-09-22T16:52:00").

Returns:

et – Equivalent ephemeris time in TDB seconds past J2000.

Return type:

float

static utc2tdb(utc: str) float#

Convert a UTC time string to TDB seconds past J2000.

Alias for utc2et().

Parameters:

utc (str) – UTC time string in a format recognised by SPICE.

Returns:

tdb – TDB seconds past J2000.

Return type:

float

kernel_folder = None#
kernel_list = []#
poly_interp_deg = 3#
poly_interp_par_deg = 1#