diff --git a/imap_processing/spice/kernels.py b/imap_processing/spice/kernels.py index 5e906df9e..35382ef20 100644 --- a/imap_processing/spice/kernels.py +++ b/imap_processing/spice/kernels.py @@ -162,10 +162,15 @@ def wrapper_ensure_spice(*args: Any, **kwargs: Any) -> Any: @ensure_spice -def create_pointing_frame() -> Path: +def create_pointing_frame(pointing_frame_dir: Optional[Path] = None) -> Path: """ Create the pointing frame. + Parameters + ---------- + pointing_frame_dir : Path + Directory of where pointing frame will be saved. + Returns ------- path_to_pointing_frame : Path @@ -184,7 +189,10 @@ def create_pointing_frame() -> Path: q_avg = spice.m2q(rotation_matrix) # TODO: come up with naming convention. - path_to_pointing_frame = directory / "imap_dps.bc" + if pointing_frame_dir is None: + path_to_pointing_frame = directory / "imap_dps.bc" + else: + path_to_pointing_frame = pointing_frame_dir / "imap_dps.bc" # Open a new CK file, returning the handle of the opened file. # https://spiceypy.readthedocs.io/en/main/documentation.html#spiceypy.spiceypy.ckopn diff --git a/imap_processing/tests/spice/test_kernels.py b/imap_processing/tests/spice/test_kernels.py index 3694b5b5f..ba8c069db 100644 --- a/imap_processing/tests/spice/test_kernels.py +++ b/imap_processing/tests/spice/test_kernels.py @@ -1,7 +1,5 @@ """Tests coverage for imap_processing/spice/kernels.py""" -import os - import numpy as np import pytest import spiceypy as spice @@ -131,16 +129,16 @@ def test_create_rotation_matrix(et_times, kernels): np.testing.assert_allclose(rotation_matrix, rotation_matrix_expected, atol=1e-4) -def test_create_pointing_frame(spice_test_data_path, kernels): +def test_create_pointing_frame(spice_test_data_path, kernels, tmp_path): """Tests create_pointing_frame function.""" # TODO: remove spice.furnsh(kernels) after ensure_spice update. spice.furnsh(kernels) ck_kernel, _, _, _ = spice.kdata(0, "ck") et_start, et_end, et_times = _get_et_times(ck_kernel) - create_pointing_frame() + create_pointing_frame(pointing_frame_dir=tmp_path) # After imap_dps.bc has been created. - dps_kernel = str(spice_test_data_path / "imap_dps.bc") + dps_kernel = str(tmp_path / "imap_dps.bc") spice.furnsh(dps_kernel) rotation_matrix_1 = spice.pxform("ECLIPJ2000", "IMAP_DPS", et_start + 100) @@ -156,5 +154,4 @@ def test_create_pointing_frame(spice_test_data_path, kernels): np.testing.assert_allclose(rotation_matrix_1, rotation_matrix_expected, atol=1e-4) # Verify imap_dps.bc has been created. - assert (spice_test_data_path / "imap_dps.bc").exists() - os.remove(spice_test_data_path / "imap_dps.bc") + assert (tmp_path / "imap_dps.bc").exists()