libera_utils.kernel_maker#

Module containing CLI tool for creating SPICE kernels from packets

Functions

azel_kernel_cli_handler(parsed_args)

Generate SPICE Az/El kernels from command line arguments.

create_jpss_kernel_dataframe_from_csv(csv_path)

Create a Curryer-compatible JPSS kernel DataFrame from a CSV ephemeris file.

create_kernel_dataframe_from_l1a(...)

Create a Curryer-compatible kernel DataFrame from an L1A Dataset.

create_kernel_dataframe_from_l1a_netcdf(...)

Create a Curryer-compatible kernel DataFrame from an L1A NetCDF file.

create_kernel_from_l1a(l1a_data, ...[, ...])

Create a SPICE kernel from a single L1A Dataset for a kernel data product type.

create_kernel_from_packets(input_data_files, ...)

Create a SPICE kernel from one or more input packet files and kernel data product type.

create_kernels_from_manifest(input_manifest, ...)

Generate SPICE kernels from a manifest file of L1A NetCDF products.

jpss_kernel_cli_handler(parsed_args)

Generate SPICE JPSS kernels from command line arguments.

make_kernel(config_file, output_kernel[, ...])

Create a SPICE kernel from a configuration file and input data.

libera_utils.kernel_maker.azel_kernel_cli_handler(parsed_args: Namespace)#

Generate SPICE Az/El kernels from command line arguments.

Parameters:

parsed_args (argparse.Namespace) – Namespace of parsed CLI arguments.

Returns:

Output manifest file containing one or more kernel files.

Return type:

libera_utils.io.manifest.Manifest

libera_utils.kernel_maker.create_jpss_kernel_dataframe_from_csv(csv_path: CloudPath | Path) tuple[DataFrame, tuple[datetime, datetime]]#

Create a Curryer-compatible JPSS kernel DataFrame from a CSV ephemeris file.

This function reads a CSV file containing simulated JPSS ephemeris data with GPS time, position, and velocity information. It converts the GPS time to UTC and then to SPICE Ephemeris Time (ET) for use in kernel generation.

Parameters:

csv_path (filenaming.PathType) – Path to the CSV ephemeris file (local or S3).

Returns:

A tuple containing: - DataFrame with ET time columns (ADGPS_JPSS_ET and ADCFA_JPSS_ET)

and position/velocity data fields

  • UTC time range tuple (start, end) for the data

Return type:

tuple[pd.DataFrame, tuple[datetime, datetime]]

Raises:
  • FileNotFoundError – If the CSV file does not exist at the specified path

  • ValueError – If required columns are missing from the CSV file

Notes

  • Requires SPICE leap second kernel (LSK) to be loaded for ET conversion

  • Creates both ADGPS_JPSS_ET and ADCFA_JPSS_ET columns with identical values

libera_utils.kernel_maker.create_kernel_dataframe_from_l1a(l1a_dataset: Dataset, apid: int, sample_group_name: str) tuple[DataFrame, tuple[datetime, datetime]]#

Create a Curryer-compatible kernel DataFrame from an L1A Dataset.

This function extracts sample group data from an L1A Dataset and converts it into a pandas DataFrame suitable for SPICE kernel generation with Curryer. The time coordinates are converted from datetime64 to SPICE Ephemeris Time (ET).

Parameters:
  • l1a_dataset (xr.Dataset) – L1A Dataset containing sample group data with time coordinates. Should be created by parse_packets_to_l1a_dataset() or read from an L1A NetCDF file.

  • apid (int) – The APID (Application Process Identifier) that identifies which packet configuration to use for extracting sample group metadata. Use LiberaApid enum values.

  • sample_group_name (str) – The name of the sample group to extract from the L1A dataset. This is used to infer the time dimension and data fields.

Returns:

A tuple containing: - DataFrame with ET time column and sample data fields - UTC time range tuple (start, end) for the data

Return type:

tuple[pd.DataFrame, tuple[datetime, datetime]]

Raises:
  • ValueError – If the APID has multiple sample groups and sample_group_name is not provided, or if the specified sample_group_name is not found in the packet configuration

  • KeyError – If required fields are missing from the L1A dataset

  • TypeError – If l1a_dataset is not an xarray.Dataset

libera_utils.kernel_maker.create_kernel_dataframe_from_l1a_netcdf(netcdf_path: CloudPath | Path, apid: int, sample_group_name: str) tuple[DataFrame, tuple[datetime, datetime]]#

Create a Curryer-compatible kernel DataFrame from an L1A NetCDF file.

This convenience function opens an L1A NetCDF file and extracts sample group data for SPICE kernel generation. It wraps create_kernel_dataframe_from_l1a() to provide a simpler interface when working with NetCDF files.

Parameters:
  • netcdf_path (filenaming.PathType) – Path to the L1A NetCDF file (local or S3). The file should be created by parse_packets_to_l1a_dataset() or equivalent processing.

  • apid (int) – The APID (Application Process Identifier) that identifies which packet configuration to use for extracting sample group metadata. Use LiberaApid enum values.

  • sample_group_name (str) – The name of the sample group to extract from the L1A dataset.

Returns:

A tuple containing: - DataFrame with ET time column and sample data fields - UTC time range tuple (start, end) for the data

Return type:

tuple[pd.DataFrame, tuple[datetime, datetime]]

Raises:
  • FileNotFoundError – If the NetCDF file does not exist at the specified path

  • ValueError – If the file cannot be opened as a valid NetCDF file, or if validation errors occur in create_kernel_dataframe_from_l1a()

Examples

>>> from libera_utils.constants import LiberaApid
>>> df, utc_range = create_kernel_dataframe_from_l1a_netcdf(
...     netcdf_path="path/to/l1a_file.nc",
...     apid=LiberaApid.jpss_sc_pos,
...     sample_group_name="ADGPS"
... )
libera_utils.kernel_maker.create_kernel_from_l1a(l1a_data: str | CloudPath | Path | Dataset, kernel_identifier: str | DataProductIdentifier, output_dir: str | CloudPath | Path, overwrite=False) CloudPath | Path#

Create a SPICE kernel from a single L1A Dataset for a kernel data product type.

This operates on a single L1A Dataset (or path to an L1A NetCDF file). The assumption is that this L1A file should contain all the necessary data to create the requested SPICE kernel type. Multiple inputs are expected to be handled at the level of creating the L1A data product from source data (packets).

Parameters:
  • l1a_data (str | filenaming.PathType | xr.Dataset) – L1A Dataset or path to L1A NetCDF file containing decoded packet data suitable for generating the requested SPICE kernel.

  • kernel_identifier (str | DataProductIdentifier) – Data product identifier that is associated with a kernel.

  • output_dir (str | filenaming.PathType) – Output location for the SPICE kernels and output manifest.

  • overwrite (bool) – Option to overwrite any existing similar-named SPICE kernels.

Returns:

Output kernel file path.

Return type:

filenaming.PathType

libera_utils.kernel_maker.create_kernel_from_packets(input_data_files: list[str | CloudPath | Path], kernel_identifier: str | DataProductIdentifier, output_dir: str | CloudPath | Path, overwrite=False) CloudPath | Path#

Create a SPICE kernel from one or more input packet files and kernel data product type.

The packet files passed as input must be convertible to L1A Dataset products. This function is a light wrapper around the core kernel creation logic that handles creating kernels from L1A Datasets.

This function is not intended for use in the production pipeline since L1A processing is a a separate step from kernel generation. However, for development and analysis purposes, this allows us to run both steps in one function call: packets -> L1A Dataset -> SPICE kernel.

Parameters:
  • input_data_files (list[str, filenaming.PathType]) – List of packet files to process. Multiple files are combined into a single L1A dataset before extracting data for kernel generation.

  • kernel_identifier (str | DataProductIdentifier) – Data product identifier that is associated with a kernel.

  • output_dir (str | filenaming.PathType) – Output location for the SPICE kernels and output manifest.

  • overwrite (bool) – Option to overwrite any existing similar-named SPICE kernels.

Returns:

Output kernel file path.

Return type:

filenaming.PathType

libera_utils.kernel_maker.create_kernels_from_manifest(input_manifest: str | CloudPath | Path, kernel_product_ids: str | DataProductIdentifier | list[str | DataProductIdentifier], output_dir: str | CloudPath | Path, overwrite=False)#

Generate SPICE kernels from a manifest file of L1A NetCDF products.

Parameters:
  • input_manifest (str | filenaming.PathType) – Input manifest file containing one or more L1A NetCDF product files containing decoded packet data suitable for generating the requested SPICE kernels.

  • kernel_product_ids (str | DataProductIdentifier | list[str | DataProductIdentifier]) – One or more SPICE kernel data product identifiers for SPICE kernel products to generate.

  • output_dir (str | filenaming.PathType) – Output location for the SPICE kernels and output manifest.

  • overwrite (bool, optional) – Option to overwrite any existing similar-named SPICE kernels.

Returns:

Output manifest file containing one or more kernel files.

Return type:

libera_utils.io.manifest.Manifest

libera_utils.kernel_maker.jpss_kernel_cli_handler(parsed_args: Namespace)#

Generate SPICE JPSS kernels from command line arguments.

Parameters:

parsed_args (argparse.Namespace) – Namespace of parsed CLI arguments.

Returns:

Output manifest file containing one or more kernel files.

Return type:

libera_utils.io.manifest.Manifest

libera_utils.kernel_maker.make_kernel(config_file: str | Path, output_kernel: str | CloudPath | Path, input_data: DataFrame | None = None, overwrite: bool = False, append: bool | int = False) CloudPath | Path#

Create a SPICE kernel from a configuration file and input data.

Parameters:
  • config_file (str | pathlib.Path) – JSON configuration file defining how to create the kernel.

  • output_kernel (str | filenaming.PathType) – Output directory or file to create the kernel. If a directory, the file name will be based on the config_file, but with the SPICE file extension.

  • input_data (pd.DataFrame | None) – pd.DataFrame containing kernel input data. If not supplied, the config is assumed to reference an input data file.

  • overwrite (bool) – Option to overwrite an existing file.

  • append (bool | int) – Option to append to an existing file. Anything truthy will be treated as True.

Returns:

Output kernel file path

Return type:

filenaming.PathType