Skip to content

jacobwilliams/jsonspice

Repository files navigation

Python library to monkeypatch SpiceyPy to allow JSON kernels (and Python dictionaries).

GitHub Badge CI Status last-commit PyPI Downloads Conda Downloads

Description

The standard text kernel format for the SPICE Toolkit is the "PCK" file (with extension .tpc). Examples of these files can be seen here. The PCK file is a data file format that exists in no other domain. So, it may be more convenient to use a standard file format such as JSON, as well as native Python dictionaries. The jsonspice library allows you to do this by monkey patching SpiceyPy so that JSON kernels will "just work".

Installation

PyPi

pip install jsonspice

conda

conda install conda-forge::jsonspice

JSON kernel format

The following PCK file:

KPL/PCK

\begintext
An example kernel

\begindata
TIME3      = @1972-JAN-1
AAA        = 1
AAA       += 2
VARIABLE   = (1.0 2.0 3.0)
VARIABLE2  = 42.0

Has the equivalent JSON kernel representation:

// An example kernel
{
    "TIME3": "@1972-JAN-1",
    "AAA" : 1,
    "+AAA" : 2,
    "VARIABLE": [1.0, 2.0, 3.0],
    "VARIABLE2": 42.0
}

Some things to note about the JSON version:

  • Optional comments are supported (using the JSON5 library). Other than this, the file is a standard JSON file.
  • The SPICE "@" format for time variables is supported using a normal string that begins with the "@" character.
  • The SPICE "+=" assignment to append to an existing variable is supported by prepending the variable name with the "+" character.

The JSON version of SPICE "meta-kernels" is also supported. See the SPICE documentation for details of that format.

Example usage

To use this library, if must be imported BEFORE SpiceyPy. Once that is done, the normal furnsh() method can be used.

import jsonspice  # import first to monkeypatch spiceypy
import spiceypy

# load a normal kernel
spiceypy.furnsh('de-403-masses.tpc')

# load a JSON kernel
spiceypy.furnsh('de-403-masses.json')

# also works with dicts:
spiceypy.furnsh({"BODY8_GM": 6836534.064})
spiceypy.furnsh({"time": '@1972-JAN-1'})
spiceypy.furnsh({"+abc": [4,5,6]})

Documentation

The API documentation for the latest master branch can be found here.

See also

About

Python library to monkeypatch SpiceyPy to allow JSON kernels

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors