Utils#

Spice Utils#

pykep.utils.spice_version()#

Retrieves the installed version of the NAIF spice toolkit.

Returns:

string: SPICE toolbox version installed in the system.

pykep.utils.load_spice_kernels(paths)#

Loads one or more kernels for use with the NAIF spice toolkit.

Args:

paths (string or list): The path (or paths) of the kernels to load

pykep.utils.unload_spice_kernels(paths)#

Unloads from memory one or more kernels for use with the NAIF spice toolkit.

Args:

paths (string or list): The path (or paths) of the kernels to load

pykep.utils.inspect_spice_kernel(path)#

Detects the objects contained in a specific kernel. This is useful to understand the possibile queries to make for a certain kernel.

Args:

path (string): The path (or paths) of the kernels to load

Returns:

list: the NAIF ids of the objects found in the kernels.

pykep.utils.name2naifid(name)#

Retreives the NAIF id of some planet/comet/spacecraft

Args:

name (string): The name of the planet/comet/spacecraft to be found

Returns:

int the NAIF id of the the planet/comet/spacecraft

pykep.utils.extract_coverage_window(path, naifid, window_n=0)#

Extracts the n-th SPK coverage window for a given NAIF ID and returns it as PyKEP epochs.

The SPK coverage start/end times returned by SPICE are ET (TDB) seconds past J2000. Here we map them to a uniform seconds-from-2000-01-01T00:00:00 (UTC-labeled origin) representation, so that the resulting PyKEP epoch is strictly 1:1 with ET everywhere (this is not “UTC elapsed seconds” with leap seconds).

The offset constant 43135.816087188054 [s] is ET0 = str2et(“2000-01-01 00:00:00 UTC”), i.e. the ET value of the UTC-labeled origin of pykep mjd2000; thus mjd2000_days = (et - ET0) / 86400, implemented as (et + 43135.816087188054) * SEC2DAY.

Args:

path (string): The path (or paths) of the kernel where the ephemerides are defined in windows. naifid (int): The NAIF id. window_n (int): The window to consider (in case ephs are defined in multiple windows of validity)

Returns:

pk.epoch, pk.epoch: Starting and final epoch of the n-th window

pykep.utils.epoch2utc(pykep_epoch)#

Converts a PyKEP epoch (mjd2000) into a SPICE-formatted UTC calendar string.

The input epoch is assumed to be a uniform time variable expressed as days since the UTC-labeled origin 2000-01-01 00:00:00 (i.e. strictly 1:1 with SPICE ET everywhere; it is not “UTC elapsed seconds” with leap seconds).

The constant 43135.816087188054 [s] is ET0 = str2et(“2000-01-01 00:00:00 UTC”). We first reconstruct the ET value via et = mjd2000*86400 - ET0, then use SPICE et2utc to obtain the UTC calendar representation. A leapseconds kernel is loaded to enable correct ET↔UTC conversion.

Args:

pykep_epoch (pk.epoch): PyKEP epoch whose .mjd2000 is days since 2000-01-01 00:00:00 (UTC-labeled origin).

Returns:

string: UTC calendar string corresponding to the input epoch.

pykep.utils.framename2naifid(name)#

Retreives the NAIF id of some reference frame

Args:

name (string): The name of the reference frame to be found

Returns:

int the NAIF id of the reference frame

pykep.utils.rotation_matrix(origin, destination, ep=2000-01-01T00:00:00.000000)#

Rotation matrix between frames at epoch.

Args:

origin (string): The name of the origin reference frame.

destination (string): The name of the destination reference frame.

ep (epoch): Epoch. Defaults to pk.epoch(0).

Returns:

npumpy.ndarray: The rotation matrix.

pykep.utils.naifid2name(naifid)#

Retreives the planet/comet/spacecraft name from its NAIF id.

Args:

name (int): The NAIF id.

Returns:

string the name of the the planet/comet/spacecraft

Encoding Utils#

pykep.alpha2direct(alphas)#

Converts from alpha encoded to transfer times.

Args:

alphas (list): a sequence of transfer times encoded using the alpha encoding.

T (float): the total transfer time.

Returns:

list:: The encoded transfer times

pykep.direct2alpha(tofs)#

Converts from transfer times to alpha encoded.

Args:

tofs (list): a sequence of transfer times.

Returns:

list:, float: The alpha-encoded transfer times, the total transfer time (for cenvenience)

pykep.eta2direct(etas, max_tof)#

Converts from eta encoded to transfer times.

Args:

etas (list): a sequence of transfer times encoded using the eta encoding.

max_tof (float): maximum time of flight (might actually be less according to the value of the last eta.)

Returns:

list: The encoded transfer times

pykep.direct2eta(tofs, max_tof)#

Converts from transfer times to eta encoded.

Args:

tofs (list): a sequence of transfer times

max_tof (float): maximum time of flight (might actually be less according to the value of the last eta.)

Returns:

list: The eta-encoded transfer times

pykep.utils.uvV2cartesian(uvV)#

This function converts the uvV encoding of a vector to cartesian coordinates

Args:

uvV (array-like): a sequence of 3 floats representing the vector in uvV encoding.

Returns:

list:: The vector in cartesian coordinates

pykep.utils.cartesian2uvV(V)#

This function converts the cartesian coordinates of a vector to uvV encoding

Args:

V (array-like): a sequence of 3 floats representing the vector in cartesian coordinates.

Returns:

list:: The vector in uvV encoding

Miscellanea#

pykep.utils.planet_to_keplerian(pla, when: epoch, mu=None)#

Transforms a planet to its Keplerian version

The planet returned will be Keplerian, with elements identical to the osculating elements at t0 of the input planet. Hence its ephemerides can be computed at any epoch, but will only be matching the original ones at t0.

This utility is useful to extend the validity range of some planet’s ephemerides.

Args:

pla (planet): the input planet.

when (epoch): the epoch to match the osculating elements.

mu (float, optional): the central body parameter. Defaults to the one computed from the input planet.

Returns:

planet: a Keplerian planet.