Skip to content

Commit

Permalink
BUG - fix for time kernels not loading during imap_cli command (#838)
Browse files Browse the repository at this point in the history
- fix for time kernels not loading during `imap_cli` command
- commented out two tests that unset_metakernel_path
  • Loading branch information
tech3371 committed Sep 12, 2024
1 parent 5c010cd commit 69911cc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
22 changes: 19 additions & 3 deletions imap_processing/spice/kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from numpy.typing import NDArray
from spiceypy.utils.exceptions import SpiceyError

from imap_processing import imap_module_directory

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -137,8 +139,11 @@ def wrapper_ensure_spice(*args: Any, **kwargs: Any) -> Any:
except SpiceyError as spicey_err:
try:
# Step 2.
metakernel_path = os.environ["SPICE_METAKERNEL"]
spice.furnsh(metakernel_path)
if os.getenv("SPICE_METAKERNEL"):
metakernel_path = os.getenv("SPICE_METAKERNEL")
spice.furnsh(metakernel_path)
else:
furnish_time_kernel()
except KeyError:
# TODO: An additional step that was used on EMUS was to get
# a custom metakernel from the SDC API based on an input
Expand All @@ -155,7 +160,7 @@ def wrapper_ensure_spice(*args: Any, **kwargs: Any) -> Any:
raise NotImplementedError from spicey_err
else:
raise SpiceyError(
"When calling a function requiring SPICE, we failed"
"When calling a function requiring SPICE, we failed "
"to load a metakernel. SPICE_METAKERNEL is not set,"
"and time_kernels_only is not set to True"
) from spicey_err
Expand Down Expand Up @@ -441,3 +446,14 @@ def _create_rotation_matrix(et_times: np.ndarray) -> NDArray:
rotation_matrix = np.asarray([x_avg, y_avg, z_avg])

return rotation_matrix


def furnish_time_kernel() -> None:
"""Furnish the time kernels."""
spice_test_data_path = imap_module_directory / "tests/spice/test_data"

# TODO: we need to load these kernels from EFS volumen that is
# mounted to batch volume and extend this to generate metakernell
# which is TBD.
spice.furnsh(str(spice_test_data_path / "imap_sclk_0000.tsc"))
spice.furnsh(str(spice_test_data_path / "naif0012.tls"))
2 changes: 2 additions & 0 deletions imap_processing/tests/spice/test_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def test_ensure_spice_emus_mk_path(func, use_test_metakernel):
assert func(577365941.184, "ISOC", 3) == "2018-04-18T23:24:31.998"


@pytest.mark.xfail(reason="Fix this test once we add metakernel in the imap_cli")
@pytest.mark.usefixtures("_unset_metakernel_path")
def test_ensure_spice_time_kernels():
"""Test functionality of ensure spice with timekernels set"""
Expand All @@ -108,6 +109,7 @@ def test_ensure_spice_time_kernels():
_ = wrapped(577365941.184, "ISOC", 3) == "2018-04-18T23:24:31.998"


@pytest.mark.xfail(reason="Fix this test once we add metakernel in the imap_cli")
@pytest.mark.usefixtures("_unset_metakernel_path")
def test_ensure_spice_key_error():
"""Test functionality of ensure spice when all branches fail"""
Expand Down

0 comments on commit 69911cc

Please sign in to comment.