Skip to content

Commit

Permalink
added tmp path
Browse files Browse the repository at this point in the history
  • Loading branch information
laspsandoval committed Aug 22, 2024
1 parent 5a41884 commit 42ce81b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
12 changes: 10 additions & 2 deletions imap_processing/spice/kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 4 additions & 7 deletions imap_processing/tests/spice/test_kernels.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Tests coverage for imap_processing/spice/kernels.py"""

import os

import numpy as np
import pytest
import spiceypy as spice
Expand Down Expand Up @@ -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)
Expand All @@ -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()

0 comments on commit 42ce81b

Please sign in to comment.