From 0e210118e0e0921585bf11b0dc413036b07b1bf0 Mon Sep 17 00:00:00 2001 From: Adam Lanman Date: Mon, 10 Jan 2022 11:34:32 -0500 Subject: [PATCH] use a temporary directory for generated kernel files --- lunarsky/spice_utils.py | 15 +++++++++------ lunarsky/tests/conftest.py | 2 +- lunarsky/topo.py | 3 +-- setup.py | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lunarsky/spice_utils.py b/lunarsky/spice_utils.py index 5b8bb45..2c07af9 100644 --- a/lunarsky/spice_utils.py +++ b/lunarsky/spice_utils.py @@ -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 @@ -13,6 +14,8 @@ _J2000 = Time("J2000") LSP_ID = 98 # Lunar surface point ID +TEMPORARY_KERNEL_DIR = tempfile.TemporaryDirectory() + def check_is_loaded(search): """ @@ -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, @@ -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): diff --git a/lunarsky/tests/conftest.py b/lunarsky/tests/conftest.py index 0b1fbc4..08d9531 100644 --- a/lunarsky/tests/conftest.py +++ b/lunarsky/tests/conftest.py @@ -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( diff --git a/lunarsky/topo.py b/lunarsky/topo.py index cb8c22c..32b7bd8 100644 --- a/lunarsky/topo.py +++ b/lunarsky/topo.py @@ -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 ) diff --git a/setup.py b/setup.py index 79c8e68..b36b0bb 100644 --- a/setup.py +++ b/setup.py @@ -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,