class planetmapper.base.BodyBase(*, target: str | int, utc: str | datetime.datetime | float | None, observer: str | int, aberration_correction: str, observer_frame: str, **kwargs)[source]

Bases: SpiceBase

Base class for planetmapper.Body and planetmapper.BasicBody.

You are unlikely to need to use this class directly - use planetmapper.Body or planetmapper.BasicBody instead.

planetmapper.base.load_kernels(*paths, clear_before: bool = False) list[str][source]

Load spice kernels defined by patterns.

This function calls spice.furnsh on all kernels matching the provided patterns. The kernel paths returned by glob.glob are sorted by sort_kernel_paths() before being passed to spice.furnsh.


You generally don’t need to call this function directly - it is called automatically the first time you create any object that inherits from planetmapper.SpiceBase (e.g. planetmapper.Body or planetmapper.Observation).

  • *paths – Paths to spice kernels, evaluated using glob.glob with recursive=True.

  • clear_before – Clear kernel pool before loading new kernels.

planetmapper.base.sort_kernel_paths(kernels: Iterable[str]) list[str][source]

Sort kernel paths by path depth and alphabetically.

Kernels are sorted so that kernels in subdirectories are loaded before kernels in parent directories, and kernels in the same directory are sorted alphabetically. Kernels loaded later will take precedence over kernels loaded earlier, so this means that when kernels contain overlapping data:

  • spk/kernel.bsp should take precedence over spk/old/kernel.bsp

  • kernel_101.bsp should take precedence over kernel_100.bsp

  • a/kernel.bsp should take precedence over x/y/z/kernel.bsp


Although this function attempts to sort kernels in a sensible way, it is possible that it will not always do the right thing. If you have multiple kernels containing overlapping data (e.g. old predicted JWST ephemerides), it is generally safer to delete the old kernels, move them into a completely separate directory, or load them manually yourself using spice.furnsh.


kernels – Iterable of kernel paths.


Sorted list of kernel paths.

planetmapper.base.prevent_kernel_loading() None[source]

Prevent PlanetMapper from automatically loading kernels.

This function can be used if want to load kernels manually using spice.furnsh.

import spiceypy as spice
import planetmapper

# Call this function before creating any objects that inherit from SpiceBase,
# then load your desired kernels manually
kernels_to_load = [...]
for kernel in kernels_to_load:

# After setting up the kernels, you can use PlanetMapper as normal
body = planetmapper.Body('mars', '2021-01-01T00:00:00')

Calling clear_kernels() will re-enable automatic kernel loading.

planetmapper.base.clear_kernels() None[source]

Clear spice kernel pool.

This function calls spice.kclear(), and also indicates to PlanetMapper that kernels will need to be reloaded when a new object is created.

planetmapper.base.set_kernel_path(path: str | None) None[source]

Set the path of the directory containing SPICE kernels. See the kernel directory documentation for more detail.


path – Directory which PlanetMapper will search for SPICE kernels. If None, then the default value of '~/spice_kernels/' will be used.

planetmapper.base.get_kernel_path(return_source: Literal[False] = False) str[source]
planetmapper.base.get_kernel_path(return_source: Literal[True]) tuple[str, str]

Get the path of the directory of SPICE kernels used in PlanetMapper.

  1. If a kernel path has been manually set using set_kernel_path(), then this path is used.

  2. Otherwise the value of the environment variable PLANETMAPPER_KERNEL_PATH is used.

  3. If PLANETMAPPER_KERNEL_PATH is not set, then the default value, '~/spice_kernels/' is used.


return_source – If True, return a tuple of the kernel path and a string which indicates the source of the kernel path. If False (the default), return only the kernel path. The possible source strings are: 'set_kernel_path()', 'PLANETMAPPER_KERNEL_PATH', and 'default'.


The path of the directory of SPICE kernels used in PlanetMapper. If return_source is True, then a tuple of the kernel path and a string indicating the source of the kernel path is returned.