Skip to main content

Routines for parsing SPICE text kernels

Project description

GitHub release; latest by date GitHub Release Date Test Status Documentation Status Code coverage
PyPI - Version PyPI - Format PyPI - Downloads PyPI - Python Version
GitHub commits since latest release GitHub commit activity GitHub last commit
Number of GitHub open issues Number of GitHub closed issues Number of GitHub open pull requests Number of GitHub closed pull requests
GitHub License Number of GitHub stars GitHub forks

Introduction

textkernel is a set of routines for parsing SPICE text kernels. This module implements the complete syntax specification as discussed in the SPICE Kernel Required Reading document, "kernel.req": https://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/req/kernel.html

textkernel is a product of the PDS Ring-Moon Systems Node.

Installation

The textkernel module is available via the rms-textkernel package on PyPI and can be installed with:

pip install rms-textkernel

Getting Started

The textkernel module provides two functions for reading text kernels:

  • from_text: Given a string representing the contents of a text kernel, return a dictionary of the values found.
  • from_file: Given the path to a text kernel, read the contents and return a dictionary of the values found.

and two functions for manipulating text kernels:

  • continued_value: Interpret a list of strings as one or more continued strings.
  • update_dict: Merge the contents of two text kernel dictionaries, preserving nested values.

Details of each function are available in the module documentation.

The simplest use case is as follows:

import textkernel
tkdict = textkernel.from_file('path/to/kernel/file')

(The file path can be any URL accepted by FCPath.)

The returned dictionary tkdict is keyed by all the parameter names (on the left side of an equal sign) in the text kernel, and each associated dictionary value is that found on the right side. Values are Python ints, floats, strings, datetime objects, or lists of one or more of these.

Hierarchical Keys

For convenience, the returned dictionary adds additional "hierarchical" keys that provide alternative access to the same values. Hierarchical keys are substrings from the original parameter name, which return a sub-dictionary keyed by part or all of the remainder of that parameter name.

Parameter names with a slash are split apart as if they represented components of a file directory tree, so these are equivalent:

tkdict["DELTET/EB"] == tkdict["DELTET"]["EB"]

When a body or frame ID is embedded inside a parameter name, it is extracted, converted to integer, and used as a piece of the hierarchy, making these equivalent:

tkdict["BODY399_POLE_RA"] == tkdict["BODY"][399]["POLE_RA"]
tkdict["SCLK01_MODULI_32"] == tkdict["SCLK"][-32]["01_MODULI"]

Leading and trailing underscores before and after the embedded numeric ID are stripped from the hierarchical keys, as you can see in the examples above. Note also that the components of the parameter name are re-ordered in the second example, so that the second key is always the numeric ID.

When the name associated with a body or frame ID is known, that name can be used in the place of the integer ID:

tkdict["BODY"][399] == tkdict["BODY"]["EARTH"]
tkdict["FRAME"][10013] == tkdict["FRAME"]["IAU_EARTH"]
tkdict["SCLK"][-32] == tkdict["SCLK"]["VOYAGER 2"]

If a frame is uniquely or primarily associated with a particular central body, that body's ID can also be used in place of the frame's ID:

tkdict["FRAME"][399] == tkdict["FRAME"]["IAU_EARTH"]

Note that the "BODY" and "FRAME" dictionaries also have an additional entry keyed by "ID", which returns the associated integer ID:

tkdict["FRAME"][623]["ID"] = 623
tkdict["FRAME"]["IAU_SUTTUNGR"]["ID"] = 623

This ensures that you can look up a body or frame by name and readily obtain its ID.

Contributing

Information on contributing to this package can be found in the Contributing Guide.

Links

Licensing

This code is licensed under the Apache License v2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rms_textkernel-1.1.0.tar.gz (268.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rms_textkernel-1.1.0-py3-none-any.whl (43.3 kB view details)

Uploaded Python 3

File details

Details for the file rms_textkernel-1.1.0.tar.gz.

File metadata

  • Download URL: rms_textkernel-1.1.0.tar.gz
  • Upload date:
  • Size: 268.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rms_textkernel-1.1.0.tar.gz
Algorithm Hash digest
SHA256 c48cde40287bb7c0d362f42a683509861ed644af16bf6bee39f775b075389db2
MD5 6cc04c4c57da77ae607e468563a3c428
BLAKE2b-256 265de37e73d1202e3ac208bdf180f44db64942202c9f6892283b892500a43c6b

See more details on using hashes here.

File details

Details for the file rms_textkernel-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: rms_textkernel-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 43.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rms_textkernel-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0db3dfe6c48e6414b0ed984f70df7c19a7c46e6a7b3d0712fe98001cea1f7f5
MD5 f99f8c0ad0f4a9d67dfb4192266edf61
BLAKE2b-256 c3da92d748285dbab23c51cbb0140644e8755c7aa07572a33d18de365a3d292d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page