SPICE Kernel selection (cassini_upyp.kernellib)#
This module contains utilities to select SPICE kernels depending on the ephemeris time, and produce automatic kernel list.
- cassini_upyp.kernellib.ckernel_covers_yd(ckernel, year, doy)#
Return whether a CK kernel file spans a given year/day-of-year date.
The CK filename is expected to follow the pattern
YYDDD_YYDDD*.bc, where the start and stop coverage dates are encoded as two-digit year (YY) and three-digit day-of-year (DDD).- Parameters:
ckernel (str) – CK filename (or basename).
year (str) – Target year (e.g.,
"2007"or"07"). Only the last two digits are used.doy (str) – Target day of year as a zero-padded string (e.g.,
"032").
- Returns:
Trueif the target date falls within the encoded coverage interval (inclusive), otherwiseFalse.- Return type:
bool
- cassini_upyp.kernellib.ckernel_covers_et(ckernel, et)#
Return whether a CK kernel provides coverage at a given ephemeris time.
The function checks all objects contained in the CK file and tests whether the input ephemeris time
etfalls within any of their coverage intervals.- Parameters:
ckernel (str) – Path to the CK kernel file.
et (float) – Target ephemeris time (seconds past J2000, TDB).
- Returns:
Trueif any object in the CK kernel coverset(inclusive), otherwiseFalse.- Return type:
bool
- cassini_upyp.kernellib.spkernel_covers_et(spkernel, et, obj_id=-82)#
Return whether an SPK (Spacecraft and Planet) kernel provides coverage at a given ephemeris time.
The function queries the time coverage for a specified object ID in the SPK file and checks whether the input ephemeris time
etfalls within any coverage interval.- Parameters:
spkernel (str) – Path to the SPK kernel file.
et (float) – Target ephemeris time (seconds past J2000, TDB).
obj_id (int, optional) – NAIF ID of the object whose coverage is queried. Default is
-82(Cassini spacecraft).
- Returns:
Trueif the SPK kernel coversetfor the given object ID (inclusive), otherwiseFalse.- Return type:
bool
- cassini_upyp.kernellib.metakernel(et, save=False, savefile=None, filter_yd=None)#
Select the SPICE kernels needed for a given epoch and optionally write a meta-kernel file.
The function inspects the local kernel tree (
kernels_dir) and builds a list of kernel file paths to load with SPICE for the requested ephemeris timeet. It always includes the standard kernels (LSK, SCLK, FK, IK, PCK), then selects:CK kernels whose coverage includes
et(optionally pre-filtered by an
encoded year/DOY interval in the CK filename), - SPK kernels whose coverage includes
etfor the default target object.If multiple CK candidates are found, the selection is further restricted to files whose name contains
'ra'(reconstructed data).Optionally, the resulting list can be written as a SPICE meta-kernel file (
.tm).- Parameters:
et (float) – Ephemeris time (seconds past J2000, TDB) used to select time-dependent kernels.
save (bool, optional) – If
True, write a meta-kernel file containing the selected kernels. Default isFalse.savefile (str or None, optional) – Output meta-kernel path to the file. If provided without extension,
.tmis appended. IfNone, a name is generated fromfilter_yd(YY_DDD.tm) or fromet(<int(et)>.tm). Default isNone.filter_yd (tuple(str, str) or None, optional) – Optional pre-filter for CK filenames using a target (year, day-of-year). The CK filename is expected to encode a coverage interval (see
ckernel_covers_yd). IfNone, all CK files are considered. Default isNone.
- Returns:
List of kernel file paths (as strings) to be loaded with
spice.furnsh.- Return type:
list of str
Notes
The function temporarily loads the LSK and SCLK to allow CK coverage queries,
then unloads them before returning. - Paths are returned as strings because SPICE expects string paths.
See also
ckernel_covers_yd()CK filename interval filter (YYDDD_YYDDD*.bc).
ckernel_covers_et()CK coverage test for a given ET.
spkernel_covers_et()SPK coverage test for a given ET.
- cassini_upyp.kernellib.yd_to_et(year, doy, hour=0, minute=0, second=0)#
Convert a UTC calendar date given as (year, day-of-year) to ephemeris time (ET).
The function builds an ISO-8601 day-of-year UTC string (
YYYY-DDDThh:mm:ss.sssZ) and converts it to ephemeris time using SPICEstr2et.- Parameters:
year (int or str) – UTC year (e.g.,
2009or"2009").doy (int or str) – UTC day of year in
[1, 365]or[1, 366]for leap years.hour (int or str, optional) – UTC hour in
[0, 23]. Default is0.minute (int or str, optional) – UTC minute in
[0, 59]. Default is0.second (float or int or str, optional) – UTC seconds in
[0.0, 60.0). Default is0.
- Returns:
Ephemeris time in seconds past J2000 (TDB).
- Return type:
float
- Raises:
ValueError – If the day-of-year is out of range for the given year, or if the time of day fields are invalid.
Notes
This function requires access to the Leap Seconds Kernel (LSK).