libera_utils.spice_utils.KernelFileCache#

class libera_utils.spice_utils.KernelFileCache(kernel_url: str, max_cache_age: timedelta = datetime.timedelta(days=1), fallback_kernel: Path = None)#

Bases: object

Class for downloading, caching, and furnishing SPICE kernel files locally.

It attempts to find a cached kernel file in the user’s cache directory (OS-specific location). If that file is not there or is old, it attempts to download it from the specified location. If it is unable to do that, it can optionally read a fallback file included in the libera_utils package but this is not recommended.

Attributes:
cache_dir

Property that calls out to get the proper local cache directory

kernel_basename

Base filename of the kernel.

kernel_path

Return the local path location of the kernel if it exists.

Methods

clear()

Remove cached kernel file

download_kernel(kernel_url[, allowed_attempts])

Downloads a kernel from a URL or an S3 location to the system cache location.

furnsh()

Furnish the cached kernel

is_cached([include_stale])

Check the cache directory for kernel file that is within cache age limit.

__init__(kernel_url: str, max_cache_age: timedelta = datetime.timedelta(days=1), fallback_kernel: Path = None)#

Create a new file cache. Downloading is done on first access of kernel_path if the file is not already cached. Fallback occurs only after failing to download. :param kernel_url: Location of kernel file as a URL or an S3Path :type kernel_url: str or cloudpathlib.S3Path :param max_cache_age: Length of time to tolerate stale kernels in the cache without forcing a redownload. :type max_cache_age: datetime.timedelta :param fallback_kernel: Path pointing to a fallback kernel location. May be None, which disallows a fallback. :type fallback_kernel: pathlib.Path

Methods

clear()

Remove cached kernel file

download_kernel(kernel_url[, allowed_attempts])

Downloads a kernel from a URL or an S3 location to the system cache location.

furnsh()

Furnish the cached kernel

is_cached([include_stale])

Check the cache directory for kernel file that is within cache age limit.

Attributes

cache_dir

Property that calls out to get the proper local cache directory

kernel_basename

Base filename of the kernel.

kernel_path

Return the local path location of the kernel if it exists.

property cache_dir#

Property that calls out to get the proper local cache directory

Returns:

Path to the proper local cache for the system.

Return type:

pathlib.Path

clear()#

Remove cached kernel file

download_kernel(kernel_url: str, allowed_attempts: int = 3) Path#

Downloads a kernel from a URL or an S3 location to the system cache location.

Parameters:
  • kernel_url (str) – Filename of kernel on NAIF site, as discovered by find_most_recent_naif_kernel

  • allowed_attempts (int, Optional) – Number of allowed download times for naif kernel default = 3

Returns:

Location of downloaded file

Return type:

pathlib.Path

furnsh()#

Furnish the cached kernel

is_cached(include_stale: bool = False) bool#

Check the cache directory for kernel file that is within cache age limit. If present, return True.

Parameters:

include_stale (bool) – Default False. If True, results include kernel that are past the max age.

Returns:

Returns True if kernel is present locally and within the age limit.

Return type:

bool

property kernel_basename#

Base filename of the kernel.

Return type:

str

property kernel_path: Path#

Return the local path location of the kernel if it exists. If not, try downloading it. If that fails, return the fallback kernel, if allowed.