util — General Utilities

The ale.util module

New in version 0.1.0:

ale.util.JBFPvlParser(lines)

Janky But Faster PVL Parser(TM)

Only really supports ISIS’s Kernel DB files. This is because KernelDB files are sometimes very large for smithed kernels. This should bring the parsing time for those DB files from minutes to seconds. Still needs nested object/group support and it should be able to read most PVL files.

Parameters

linesstr

string body of PVL file.

ReturnsPVLModule

object representing the parsed PVL

ale.util.create_spk_dependency_tree(kernels)

construct the dependency tree for the body states in a set of kernels.

Parameters

kernelslist

The list of kernels to evaluate the dependencies in. If two kernels in this list contain the same information for the same pair of bodies, then the later kernel in the list will be identified in the kernel property for that edge in dep_tree.

Returns

dep_treenx.DiGraph

The dependency tree for the kernels. Nodes are bodies. There is an edge from one node to another if the state of the body of the source node is defined relative to the state of the body of the destination node. The kernel edge property identifies what kernel the information for the edge is defined in.

ale.util.duckpool(naifvar, start=0, length=10, default=None)

Duck typing friendly version of spiceypy kernel pool functions.

Parameters

naifvarstr

naif var string to query pool for

startint

Index of first value

lengthint

max number of values returned

defaultobj

Default value to return if key is not found in kernel pool

Returns

: obj

Spice value returned from spiceypy if found, default value otherwise

ale.util.find_kernels(cube, isis_data, format_as=<class 'dict'>)

Find all kernels for a cube and return a json object with categorized kernels.

Parameters

cubestr

Path to an ISIS cube

isis_datastr

path to $ISISDATA

format_asobj

What type to return the kernels as, ISIS3-like dict/PVL or flat list

Returns

: obj

Container with kernels

ale.util.generate_kernels_from_cube(cube, expand=False, format_as='list')

Parses a cube label to obtain the kernels from the Kernels group.

Parameters

cubecube

Path to the cube to pull the kernels from.

expandbool, optional

Whether or not to expand variables within kernel paths based on your IsisPreferences file. See get_isis_preferences() for how the IsisPreferences file is found.

format_asstr, optional {‘list’, ‘dict’}

How to return the kernels: either as a one-dimensional ordered list, or as a dictionary of kernel lists.

Returns

: list

One-dimensional ordered list of all kernels from the Kernels group in the cube.

: Dictionary

Dictionary of lists of kernels with the keys being the Keywords from the Kernels group of cube itself, and the values being the values associated with that Keyword in the cube.

ale.util.get_ck_frames(kernel)

Get all of the reference frames defined in a kernel.

Parameters

kernelstr

The path to the kernel

Returns

idslist

The set of reference frames IDs defined in the kernel

ale.util.get_isis_mission_translations(isis_data)

Use ISIS translation files and return a lookup table.

Parameters

isis_datastr

path to $ISIS3DATA

Returns

: dict

Dictionary mapping label mission strings to ISIS3 mission strings

ale.util.get_isis_preferences(isis_preferences=None)

Returns ISIS Preference file as a pvl object.

This will search the following locations, in order, for an IsisPreferences file:

  1. The .Isis directory in your home directory

  2. The directory pointed to by the ISISROOT environment variable

ale.util.get_metakernels(spice_dir=None, missions={}, years={}, versions={})

Given a root directory, get any subdirectory containing metakernels, assume spice directory structure.

Mostly doing filtering here, might be worth using Pandas?

Parameters

spice_dirstr

Path containing Spice directories downloaded from NAIF’s website

missionsset, str

Mission or set of missions to search for

yearsset, str, int

year or set of years to search for

versionsset, str

version or set of versions to search for

ale.util.query_kernel_pool(matchstr='*', max_length=10)

Collect multiple keywords from the naif kernel pool based on a template string

Parameters

matchstrstr

matchi_c formatted str

max_lengthint

maximum length array to get from naif keywords

Returns

: dict

python dictionary of naif keywords in {keyword:value} format.

ale.util.read_pvl(path, use_jank=False)

Syntax sugar, used to load a pvl object file from path

Parameters

pathstr

Path to Pvl file

use_jankbool

If true, uses faster but less reliable JBFPvlParser, else uses standard PVL parser.

ale.util.search_isis_db(dbobj, labelobj, isis_data)

Given an PVL obj of a KernelDB file and an Isis Label for a cube, find the best kernel to attach to the cube.

The Logic here is a bit gross, but it matches ISIS’s implementation very closely.

Parameters

dbobjPVLModule

ISIS3 KernelDB file as a loaded PVLModule

labelobjPVLModule

Cube label as loaded PVLModule

isis_datastr

path to $ISISDATA

Returns

: dict

dictionary containing kernel list and optionally the kernel type if relevant.

ale.util.spkmerge_config_string(dep_tree, output_spk, bodies, lsk, start, stop)

Create the contents of an spkmerge config file that will produce a spk that completely defines the state of a list of bodies for a time range.

Parameters

dep_treenx.DiGraph

Dependency tree from create_kernel_dependency_tree that contains information about what the state of different bodies are relative to and where that information is stored.

output_spkstr

The path to the SPK that will be output by spkmerge

bodieslist

The list of body ID codes that need to be defined in the kernel created by spkmerge

lskstr

The absolute path to the leap second kernel to use

startstr

The UTC start time for the kernel created by spkmerge

stopstr

The UTC stop time for the kernel created by spkmerge

Returns

: str

The contents of an spkmerge config file that will produce a kernel that defines the state of the input bodies for the input time range.

ale.util.write_metakernel_from_kernel_list(kernels)

Parameters

kernelsstr

list of kernel paths

Returns

: str

Returns string representation of a Naif Metakernel file