Skip to content

Commit

Permalink
Patch for leapsecond delayed finding/loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
BStoneLASP committed Oct 23, 2024
1 parent de4743d commit 80b01ec
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
4 changes: 1 addition & 3 deletions curryer/kernels/attitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

logger = logging.getLogger(__name__)

DEFAULT_LSK_FILE = str(spicetime.leapsecond.find_default_file())


class AttitudeTypes(Enum):
"""Attitude kernel types.
Expand Down Expand Up @@ -84,7 +82,7 @@ class AbstractAttitudeProperties(AbstractKernelProperties):
ck_type: TypedDataDescriptor = TypedDataDescriptor(default=AttitudeTypes.LINEAR_QUAT, dtype=AttitudeTypes)

# Existing kernels that are required to build this one.
leapsecond_kernel: str = DEFAULT_LSK_FILE
leapsecond_kernel: str = None
frame_kernel: str = None
clock_kernel: str = None
create_clock: bool = False # If true, writes to `clock_kernel`.
Expand Down
7 changes: 4 additions & 3 deletions curryer/kernels/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

logger = logging.getLogger(__name__)

DEFAULT_LSK_FILE = str(spicetime.leapsecond.find_default_file())


class TypedDataDescriptor:
"""Data descriptor that enforces typing through casting.
Expand Down Expand Up @@ -68,7 +66,7 @@ class AbstractKernelProperties:
input_gap_threshold: str = None

# Existing kernels that are required to build this one.
leapsecond_kernel: str = DEFAULT_LSK_FILE
leapsecond_kernel: str = None

# Misc.
version: int = 1
Expand All @@ -80,6 +78,9 @@ def __post_init__(self):
if self.SUPPORTED_INPUT_DATA_TYPES is not None and self.input_data_type not in self.SUPPORTED_INPUT_DATA_TYPES:
raise ValueError(f'Invalid properties class for input type {self.input_data_type}')

if self.leapsecond_kernel is None:
self.leapsecond_kernel = str(spicetime.leapsecond.find_default_file())

if self.relative_dir:
self.relative_dir = Path(self.relative_dir)
self._update_paths(['leapsecond_kernel'])
Expand Down
4 changes: 1 addition & 3 deletions curryer/kernels/ephemeris.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

logger = logging.getLogger(__name__)

DEFAULT_LSK_FILE = str(spicetime.leapsecond.find_default_file())


class EphemerisTypes(Enum):
"""Ephemeris kernel types.
Expand Down Expand Up @@ -88,7 +86,7 @@ class AbstractEphemerisProperties(AbstractKernelProperties):
spk_type: str = None

# Existing kernels that are required to build this one.
leapsecond_kernel: str = DEFAULT_LSK_FILE
leapsecond_kernel: str = None
planet_kernels: typing.List[str] = None # Optional

def __post_init__(self):
Expand Down
12 changes: 10 additions & 2 deletions curryer/spicetime/leapsecond.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"""
import datetime
import logging
import os
import re
import time
import warnings
Expand All @@ -30,6 +31,8 @@
_LEAPSECOND_FILE_GLOB = 'naif*.tls'
LEAPSECOND_BASE_URL = 'https://naif.jpl.nasa.gov/pub/naif/generic_kernels/lsk/'

LEAPSECOND_USER_FILE_PATH = None


def find_default_file():
"""Find the library's default leapsecond kernel file.
Expand All @@ -43,8 +46,13 @@ def find_default_file():
# Locate the latest kernel file, relative to this module file.
# Pylint thinks the `Path` class is really a `PurePath`.
# pylint: disable=no-member
path = Path(__file__).parent
path = path.joinpath(_LEAPSECOND_FILE_PATH).resolve()
if LEAPSECOND_USER_FILE_PATH is not None:
path = Path(LEAPSECOND_USER_FILE_PATH)
elif os.getenv('LEAPSECOND_FILE_ENV', None):
path = Path(os.getenv('LEAPSECOND_FILE_ENV'))
else:
path = Path(__file__).parent
path = path.joinpath(_LEAPSECOND_FILE_PATH).resolve()
leapsecond_files = list(path.glob(_LEAPSECOND_FILE_GLOB))
leapsecond_files.sort()

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "lasp-curryer"
version = "0.0.5"
version = "0.0.6"
packages = [
{ include = "curryer" }
]
Expand Down

0 comments on commit 80b01ec

Please sign in to comment.