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
Property that calls out to get the proper local cache directory
Base filename of the kernel.
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:
- 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:
- Returns:
Location of downloaded file
- Return type:
- furnsh()#
Furnish the cached kernel