Skip to content

Commit

Permalink
use a temporary directory for generated kernel files
Browse files Browse the repository at this point in the history
  • Loading branch information
aelanman committed Jan 10, 2022
1 parent deb854b commit 0e21011
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
15 changes: 9 additions & 6 deletions lunarsky/spice_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import os
import tempfile
from astropy.utils.data import download_files_in_parallel
from astropy.coordinates.matrix_utilities import rotation_matrix
from astropy.time import Time
Expand All @@ -13,6 +14,8 @@
_J2000 = Time("J2000")
LSP_ID = 98 # Lunar surface point ID

TEMPORARY_KERNEL_DIR = tempfile.TemporaryDirectory()


def check_is_loaded(search):
"""
Expand Down Expand Up @@ -102,14 +105,15 @@ def lunar_surface_ephem(latitude, longitude, lsp_id=LSP_ID):
states = np.zeros((len(ets), 6))
states[:, :3] = np.repeat(pos_mcmf[None, :], len(ets), axis=0)

fname = os.path.join(DATA_PATH, "current_lunar_point.bsp")
if os.path.exists(fname):
os.remove(fname)
handle = spice.spkopn(fname, "SPK_file", 0)
point_id = fm_center_id
center = 301
frame = "MOON_ME"
degree = 1

fname = os.path.join(TEMPORARY_KERNEL_DIR.name, "current_lunar_point.bsp")
if os.path.exists(fname):
os.remove(fname)
handle = spice.spkopn(fname, "SPK_FILE", 0)
spice.spkw09(
handle,
point_id,
Expand All @@ -124,8 +128,7 @@ def lunar_surface_ephem(latitude, longitude, lsp_id=LSP_ID):
ets.tolist(),
)
spice.spkcls(handle)

return fname
spice.furnsh(fname)


def topo_frame_def(latitude, longitude, moon=True):
Expand Down
2 changes: 1 addition & 1 deletion lunarsky/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
import warnings

# Ignore a deprecation from spiceypy
# Ignore deprecation warnings from spiceypy
@pytest.fixture(autouse=True)
def ignore_representation_deprecation():
warnings.filterwarnings(
Expand Down
3 changes: 1 addition & 2 deletions lunarsky/topo.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ def _spice_setup(latitude, longitude):
latlon = spice.gcpool("TOPO_LAT_LON", 0, 8)
loadnew = not latlon == ["{:.4f}".format(ll) for ll in [latitude, longitude]]
if loadnew:
spk = lunar_surface_ephem(latitude, longitude)
spice.furnsh(spk)
lunar_surface_ephem(latitude, longitude) # Furnishes SPK for lunar surface point
station_name, idnum, frame_specs, latlon = topo_frame_def(
latitude, longitude, moon=True
)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"use_scm_version": {
"root": ".",
"relative_to": __file__,
"local_scheme": "guess-next-dev",
"local_scheme": "no-local-version",
"write_to": "lunarsky/version.py",
},
"include_package_data": True,
Expand Down

0 comments on commit 0e21011

Please sign in to comment.