4. SpiceManager#

class SpiceManager#

Bases: object

Wraps many SpiceyPy [1] functions NEED MORE

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]

Charles Acton, Nathaniel Bachman, Boris Semenov, Edward Wright; A look toward the future in the handling of space science mission geometry; Planetary and Space Science (2017); 10.1016/j.pss.2017.02.013

Methods

YDS2et(year, doy, sec)

Convert year, day, sec format into ephemeris times.

check_kernel_status_in_pool(kernel_filename)

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

clear_kernels()

Clears all loaded SPICE kernels.

def_new_body(name, spiceId)

Define a new celestial body in the SPICE kernel.

et2YDS(et)

Convert ephemeris times to year, day, and seconds format.

frame_id_to_frame_name(frame_id)

This method generetes the frame id given its name

frame_name_to_frame_id(frame_name)

This method generetes the frame name given its frame id

get_STMs(trgt_bdy, epoch_time, ...)

Retrieve the State Transition Matrices (STMs) for a given target body, epoch time, reference frame, and origin.

get_attitude(trgt_bdy, epoch_time, ...)

Get the attitude of a target body at a specified epoch time. Parameters: ----------- cls : class The class itself, used to access class methods and attributes. trgt_bdy : str or Body 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. epoch_time : float or EpochArray The epoch time at which the attitude is to be determined. Can be an instance of EpochArray or a float representing the time. reference_frame : str or Frame The reference frame in which the attitude is to be determined. Can be a string or an instance of Frame. tol : int The tolerance value for the attitude determination. Returns: -------- tuple 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.

get_frame_w_spice_id(id_number)

get frame_code and name associated with the frame_id number

get_id_from_string(name_string)

This method generetes the body spice id given its name

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)

This method generetes the body name given its spice 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 parameters from JSON files based on the given target, epoch_time, reference_frame, and origin.

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

Get the position of a target body relative to an origin body at a specified epoch time.

get_propagator_settings(trgt_bdy, ...)

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

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_vel(trgt_bdy, epoch_time, ...[, ab_correct])

Get the velocity of a target body relative to an origin at a specified epoch time.

get_xfrm(frame_from, frame_to, epoch)

This method returns the DCM rotation matrix between frame_from and frame_to at a given epoch

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.

list_all_frames([max_id])

This method generate a list of all frames with +- the value between max_id

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 3x3 double precision matrix with a 3-dimensional double precision vector.

name_to_ID(name)

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

print_kernels()

Prints the list of kernels loaded.

str2et(s)

unload_kernel_from_pool(kernel_filename)

Unload a kernel from the pool.

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

Write a segment of type 9 to an SPK file.

cal2et

et2cal

et2jd

et2sclk

et2utc

get_intervals

jd2et

sclk2et

utc2et

utc2tdb

classmethod clear_kernels()#

Clears all loaded SPICE kernels.

This method calls the spice.kclear() function to clear all loaded SPICE kernels from memory.

Returns:

None

classmethod get_STMs(trgt_bdy: str | scbt.Body, epoch_time: float | scbt.EpochArray, reference_frame: str | scbt.Frame, obsvr_bdy: scbt.Body | str)#

Retrieve the State Transition Matrices (STMs) for a given target body, epoch time, reference frame, and origin. :param trgt_bdy: The target body or its name. :type trgt_bdy: str or Body :param epoch_time: The epoch time for which the STM is required. :type epoch_time: float or EpochArray :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 State Transition Matrix (STM) corresponding to the closest epoch time.

Return type:

np.ndarray

Raises:

ValueError – If the STM JSON file could not be located or if the epoch time does not fall within any sequence leg or is out of range in STM data.

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

Get the attitude of a target body at a specified epoch time. Parameters: ———– cls : class

The class itself, used to access class methods and attributes.

trgt_bdystr or Body

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.

epoch_timefloat or EpochArray

The epoch time at which the attitude is to be determined. Can be an instance of EpochArray or a float representing the time.

reference_framestr or Frame

The reference frame in which the attitude is to be determined. Can be a string or an instance of Frame.

tolint

The tolerance value for the attitude determination.

4. Returns:#

tuple

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.

classmethod get_lighttime(trgt_bdy: str | scbt.Body, epoch_time: float | scbt.EpochArray, reference_frame: str | scbt.Frame, obsvr_bdy: str | scbt.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 | scbt.Body, epoch_time: float | scbt.EpochArray, reference_frame: str | scbt.Frame, obsvr_bdy: str | scbt.Body)#

Retrieve parameters from JSON files based on the given target, epoch_time, reference_frame, and origin. :param trgt_bdy: The target body name or Body object. :type trgt_bdy: str or Body :param epoch_time: The epoch time for which parameters are needed. :type epoch_time: float or EpochArray :param reference_frame: The reference frame name or Frame object. :type reference_frame: str or Frame :param obsvr_bdy: The origin body name or Body object. :type obsvr_bdy: str or Body

Returns:

An array of parameters with associated units.

Return type:

ArrayWUnits

Raises:
  • ValueError – If multiple matching JSON files are found.

  • ValueError – If no matching JSON file is found.

  • ValueError – If the given epoch_time does not fall within any leg’s epochsTDB.

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

Get the position 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 position is to be determined. Can be a string or a Body object.

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

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

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

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

Returns:

pos – The position of the target body relative to the origin body, expressed in units of kilometers.

Return type:

ArrayWUnits

classmethod get_propagator_settings(trgt_bdy: str | scbt.Body, reference_frame: str | scbt.Frame, obsvr_bdy: str | scbt.Body)#

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_state(trgt_bdy: str | scbt.Body, epoch_time: float | scbt.EpochArray, reference_frame: str | scbt.Frame, obsvr_bdy: str | scbt.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_vel(trgt_bdy: str | scbt.Body, epoch_time: float | scbt.EpochArray, reference_frame: str | scbt.Frame, obsvr_bdy: str | scbt.Body, ab_correct: str = 'None')#

Get the velocity of a target body relative to an origin at a specified epoch time.

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

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

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

  • obsvr_bdy (str or Body) – The origin relative to which the velocity is to be determined. Can be a string or a Body object.

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

Returns:

vel – The velocity of the target body as an ArrayWUnits object with the appropriate units.

Return type:

ArrayWUnits

classmethod print_kernels()#

Prints the list of kernels loaded.

This method retrieves the list of kernels loaded using the SPICE library and prints each kernel’s source and description.

Returns:

None

classmethod write_spk_segment_type9(SPK_name, SPK_SEG_ID, body_ID, origin_ID, ref_frame, epochs_TDB, degree_poly, state_SPICE, parameters_JSON=None, STMs_JSON=None, state_definition=None, sequence_definition=None, propagator_settings=None)#

Write a segment of type 9 to an SPK file.

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

  • body_ID (int) – The ID of the body.

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

  • ref_frame (str) – The reference frame.

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

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

  • num_states (int) – The number of states.

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

  • parameters_JSON (optional, dict) – The array of parameters for JSON format.

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

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

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

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

Returns:

None

static YDS2et(year, doy, sec)#

Convert year, day, sec format into ephemeris times.

static cal2et(cal: str)#
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.

Returns:

None

static et2YDS(et)#

Convert ephemeris times to year, day, and seconds format.

static et2cal(et: float)#
static et2jd(et: float, form='J', prec=27, utclen=27)#
static et2sclk(scId: int, et: float, lenout=30)#
static et2utc(et: float, form='ISOC', prec=27, utclen=27)#
static frame_id_to_frame_name(frame_id: int) str#

This method generetes the frame id given its name

Parameters:

frame_id (int) – frame id of the reference frame

Returns:

frame’s spice name

Return type:

str

Note

frame_id is different than the usual body_id used in spice

static frame_name_to_frame_id(frame_name: str) int#

This method generetes the frame name given its frame id

Parameters:

frame_name (str) – frame name of the reference frame

Returns:

frame’s spice id

Return type:

int

Note

frame_id is different than the usual body_id used in spice

static get_frame_w_spice_id(id_number: int)#

get frame_code and name associated with the frame_id number

Parameters:

id_number (int) – The frame id number

Returns:

Return type:

int

Returns:

(3,3) rotation matrix to transform between frame_from to frame_to

Return type:

float

static get_id_from_string(name_string: str) int#

This method generetes the body spice id given its name

Parameters:

name_string (str) – Spice name of the body

Returns:

body’s spice id

Return type:

id

static get_intervals(spkFile, objID)#
static get_name_from_id(spice_id: int) str#

This method generetes the body name given its spice id

Parameters:

spice_id (int) – Spice id of the body

Returns:

body’s spice name

Return type:

str

static get_observer_target_visibility_windows(obsvr_bdy: str | scbt.Body, trgt_bdy: str | scbt.Body, epoch_start: float | scbt.EpochArray, epoch_end: float | scbt.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, scbt.Body]):

The observer, either as a string name or a scbt.Body object.

trgt_bdy (Union[str, scbt.Body]):

The target, either as a string name or a scbt.Body object.

epoch_start (Union[float, scbt.EpochArray]):

The start time of the observation window.

epoch_end (Union[float, scbt.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: tuple: A tuple containing the number of visibility windows and a list of visibility windows.

static get_xfrm(frame_from: str, frame_to: str, epoch) array#

This method returns the DCM rotation matrix between frame_from and frame_to at a given epoch

Parameters:
  • frame_from (str) – name of the source frame (needs to be spice defined)

  • frame_to (str) – name of the target frame (needs to be spice defined)

  • epoch (float) – ephemeris epoch to convert between the two epochs

Returns:

(3,3) rotation matrix to transform between frame_from to frame_to

Return type:

np.array

Warning

both frame_from and frame_to needs to be spice-defined reference frames

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)#
static list_all_frames(max_id: int = 100000) list#

This method generate a list of all frames with +- the value between max_id

Parameters:

max_id (int) – maximum frame id to check

Returns:

list of the reference frames detected in the pool

Return type:

list

Note

frame_id is different than the usual body_id used in spice

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.

Returns:

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.

Returns:

None

static matrix_times_vector(matrix, vector)#

Multiply a 3x3 double precision matrix with a 3-dimensional double precision vector.

https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/mxv_c.html

Parameters:
  • matrix (np.array) – rotation matrix

  • vector (np.array) – vector

Returns:

vector

Return type:

np.array

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 sclk2et(scId: int, sclk: str)#
static str2et(s: str)#
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. :param kernel_filename: Filename of the Spice kernel being unloaded. :type kernel_filename: str

static utc2et(utc: str)#
static utc2tdb(utc: str)#
kernel_folder = 'C:\\Users\\Zack\\pythonVSCode\\scarabaeus/data/kernels/scenario'#
kernel_list = []#
poly_interp_deg = 3#
poly_interp_par_deg = 1#