planetmapper.base
- 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
andplanetmapper.BasicBody
.You are unlikely to need to use this class directly - use
planetmapper.Body
orplanetmapper.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 byglob.glob
are sorted bysort_kernel_paths()
before being passed tospice.furnsh
.Hint
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
orplanetmapper.Observation
).- Parameters:
*paths – Paths to spice kernels, evaluated using
glob.glob
withrecursive=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 overspk/old/kernel.bsp
kernel_101.bsp
should take precedence overkernel_100.bsp
a/kernel.bsp
should take precedence overx/y/z/kernel.bsp
Warning
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
.- Parameters:
kernels – Iterable of kernel paths.
- Returns:
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 planetmapper.base.prevent_kernel_loading() kernels_to_load = [...] for kernel in kernels_to_load: spice.furnsh(kernel) # After setting up the kernels, you can use PlanetMapper as normal body = planetmapper.Body('mars', '2021-01-01T00:00:00') body.plot_wireframe_km()
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.
- Parameters:
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.
If a kernel path has been manually set using
set_kernel_path()
, then this path is used.Otherwise the value of the environment variable
PLANETMAPPER_KERNEL_PATH
is used.If
PLANETMAPPER_KERNEL_PATH
is not set, then the default value,'~/spice_kernels/'
is used.
- Parameters:
return_source – If
True
, return a tuple of the kernel path and a string which indicates the source of the kernel path. IfFalse
(the default), return only the kernel path. The possible source strings are:'set_kernel_path()'
,'PLANETMAPPER_KERNEL_PATH'
, and'default'
.- Returns:
The path of the directory of SPICE kernels used in PlanetMapper. If
return_source
isTrue
, then a tuple of the kernel path and a string indicating the source of the kernel path is returned.