From 096eeaad59dcd02533385e94b0c520cb0c890cf9 Mon Sep 17 00:00:00 2001 From: antonhibl Date: Thu, 11 Jan 2024 14:38:20 -0700 Subject: [PATCH 01/11] fixed PVLModule loading with ale.load(s) --- ale/base/label_isis.py | 13 +++++++------ ale/drivers/__init__.py | 12 ++++++++++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/ale/base/label_isis.py b/ale/base/label_isis.py index 28d1642d2..2a42ec02d 100644 --- a/ale/base/label_isis.py +++ b/ale/base/label_isis.py @@ -12,12 +12,13 @@ def label(self): self._label = self._file grammar = pvl.grammar.ISISGrammar() grammar.comments+=(("#", "\n"), ) - try: - self._label = pvl.loads(self._file, grammar=grammar) - except Exception: - self._label = pvl.load(self._file, grammar=grammar) - except: - raise ValueError("{} is not a valid label".format(self._file)) + if not isinstance(self._file, pvl.PVLModule): + try: + self._label = pvl.loads(self._file, grammar=grammar) + except Exception: + self._label = pvl.load(self._file, grammar=grammar) + except: + raise ValueError("{} is not a valid label".format(self._file)) return self._label @property diff --git a/ale/drivers/__init__.py b/ale/drivers/__init__.py index dbb2609c2..1de801697 100644 --- a/ale/drivers/__init__.py +++ b/ale/drivers/__init__.py @@ -73,8 +73,6 @@ def load(label, props={}, formatter='ale', verbose=False, only_isis_spice=False, when one has updated the ephemeris information on an ISIS cube. * ``only_naif_spice=True`` Used for example, when one has a data product or an ISIS cube, but not yet obtained ephemeris information. - - Parameters ---------- label : str String path to the given label file @@ -158,6 +156,16 @@ def load(label, props={}, formatter='ale', verbose=False, only_isis_spice=False, print("Success with: ", driver) print("ISD:\n", json.dumps(isd, indent=2, cls=AleJsonEncoder)) return isd + except AttributeError: + res = driver(label, props=props) + # get instrument_id to force early failure + res.instrument_id + with res as driver: + isd = formatter(driver) + if verbose: + print("Success with: ", driver) + print("ISD:\n", json.dumps(isd, indent=2, cls=AleJsonEncoder)) + return isd except Exception as e: if verbose: print(f'Failed: {e}\n') From c1d399c352f5ca7076ae535ddbf4fa71250554ab Mon Sep 17 00:00:00 2001 From: antonhibl Date: Thu, 11 Jan 2024 14:41:51 -0700 Subject: [PATCH 02/11] removing unnecessary attributeerror exception handler --- ale/drivers/__init__.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/ale/drivers/__init__.py b/ale/drivers/__init__.py index 1de801697..66a3eee12 100644 --- a/ale/drivers/__init__.py +++ b/ale/drivers/__init__.py @@ -156,16 +156,6 @@ def load(label, props={}, formatter='ale', verbose=False, only_isis_spice=False, print("Success with: ", driver) print("ISD:\n", json.dumps(isd, indent=2, cls=AleJsonEncoder)) return isd - except AttributeError: - res = driver(label, props=props) - # get instrument_id to force early failure - res.instrument_id - with res as driver: - isd = formatter(driver) - if verbose: - print("Success with: ", driver) - print("ISD:\n", json.dumps(isd, indent=2, cls=AleJsonEncoder)) - return isd except Exception as e: if verbose: print(f'Failed: {e}\n') From 9ed338936e6df7e7b6886533e07e8e75c4add30a Mon Sep 17 00:00:00 2001 From: antonhibl Date: Wed, 17 Jan 2024 12:46:46 -0700 Subject: [PATCH 03/11] fixing removed word --- ale/drivers/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ale/drivers/__init__.py b/ale/drivers/__init__.py index 66a3eee12..dbb2609c2 100644 --- a/ale/drivers/__init__.py +++ b/ale/drivers/__init__.py @@ -73,6 +73,8 @@ def load(label, props={}, formatter='ale', verbose=False, only_isis_spice=False, when one has updated the ephemeris information on an ISIS cube. * ``only_naif_spice=True`` Used for example, when one has a data product or an ISIS cube, but not yet obtained ephemeris information. + + Parameters ---------- label : str String path to the given label file From 43080ab071986c5a1f5fb429723103b25eb634ae Mon Sep 17 00:00:00 2001 From: antonhibl Date: Tue, 23 Jan 2024 12:14:00 -0700 Subject: [PATCH 04/11] adding changelog entry for bugfix --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b811094e1..4fd1271e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,7 @@ release. - Fixed LRO MiniRF drivers naif keywords focal to pixel and pixel to focal translations to be correct. [#569](https://github.com/DOI-USGS/ale/pull/569) - Bugfix for position and orientation for MSL cameras (driver MslMastcamPds3NaifSpiceDriver). Validated that Nav and Mast LBL files (for both left and right sensor) produce correctly positioned and oriented CSM cameras, that are self-consistent and consistent with a prior DEM for the site. [#580](https://github.com/DOI-USGS/ale/pull/580) - Bug fix for ray direction for MSL. [#589](https://github.com/DOI-USGS/ale/pull/589) +- Bug fix for pvl.loads() to allow the ingestion of PVLObjects into ale.loads() [#591](https://github.com/DOI-USGS/ale/pull/591) ### Changed - Removed the affine6p library and replaced affine6p's affine transformation with a numpy solution [#579](https://github.com/DOI-USGS/ale/pull/579) From e3d8363207536e8c4bca8fbe6e8fe06d2cbb2890 Mon Sep 17 00:00:00 2001 From: antonhibl Date: Tue, 23 Jan 2024 18:46:24 -0700 Subject: [PATCH 05/11] added a test for pvl.load/ale.loads on PVLObjects Not completely done as I need to figure out how to load some kind of test cube akin to the one I am using inside of the test itself without loading it from local storage. There should be some way to put it in the test data area my main problem is I would like to avoid putting a whole cube in the test's data folder as they are larger files and I believe that convention of putting cubes there is to be avoided. --- tests/pytests/test_driver_verification.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/pytests/test_driver_verification.py diff --git a/tests/pytests/test_driver_verification.py b/tests/pytests/test_driver_verification.py new file mode 100644 index 000000000..cf0146d1a --- /dev/null +++ b/tests/pytests/test_driver_verification.py @@ -0,0 +1,17 @@ +import pytest +import pvl +import ale + +# I need to figure out how to get some kind of test cube in the test without +# referencing it locally +testCube = "/Users/ahibl/astro_efs/test_imgs/uvvis/LUA3107H.161.clem.cub_ISIS.cub" + +@pytest.fixture +def test_loads(): + isis_kerns = ale.util.generate_kernels_from_cube(testCube, expand=True) + pvl_obj = pvl.load(testCube) + res = ale.loads(pvl_obj, props={"kernels": isis_kerns}, only_naif_spice=True) + return res + +def test_pass(test_loads): + pass \ No newline at end of file From 4492cc6f419d5fe3866a83eea256440c84d5b0ea Mon Sep 17 00:00:00 2001 From: antonhibl Date: Tue, 23 Jan 2024 18:50:41 -0700 Subject: [PATCH 06/11] changed test file name to better reflect contents --- tests/pytests/test_pvl_load.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/pytests/test_pvl_load.py diff --git a/tests/pytests/test_pvl_load.py b/tests/pytests/test_pvl_load.py new file mode 100644 index 000000000..cf0146d1a --- /dev/null +++ b/tests/pytests/test_pvl_load.py @@ -0,0 +1,17 @@ +import pytest +import pvl +import ale + +# I need to figure out how to get some kind of test cube in the test without +# referencing it locally +testCube = "/Users/ahibl/astro_efs/test_imgs/uvvis/LUA3107H.161.clem.cub_ISIS.cub" + +@pytest.fixture +def test_loads(): + isis_kerns = ale.util.generate_kernels_from_cube(testCube, expand=True) + pvl_obj = pvl.load(testCube) + res = ale.loads(pvl_obj, props={"kernels": isis_kerns}, only_naif_spice=True) + return res + +def test_pass(test_loads): + pass \ No newline at end of file From a028edfd39c5695ba05b828d4da7bf9d0df99604 Mon Sep 17 00:00:00 2001 From: antonhibl Date: Wed, 31 Jan 2024 10:45:47 -0700 Subject: [PATCH 07/11] updating test changes --- tests/pytests/test_driver_verification.py | 17 ----------- tests/pytests/test_pvl_load.py | 37 +++++++++++++++-------- 2 files changed, 25 insertions(+), 29 deletions(-) delete mode 100644 tests/pytests/test_driver_verification.py diff --git a/tests/pytests/test_driver_verification.py b/tests/pytests/test_driver_verification.py deleted file mode 100644 index cf0146d1a..000000000 --- a/tests/pytests/test_driver_verification.py +++ /dev/null @@ -1,17 +0,0 @@ -import pytest -import pvl -import ale - -# I need to figure out how to get some kind of test cube in the test without -# referencing it locally -testCube = "/Users/ahibl/astro_efs/test_imgs/uvvis/LUA3107H.161.clem.cub_ISIS.cub" - -@pytest.fixture -def test_loads(): - isis_kerns = ale.util.generate_kernels_from_cube(testCube, expand=True) - pvl_obj = pvl.load(testCube) - res = ale.loads(pvl_obj, props={"kernels": isis_kerns}, only_naif_spice=True) - return res - -def test_pass(test_loads): - pass \ No newline at end of file diff --git a/tests/pytests/test_pvl_load.py b/tests/pytests/test_pvl_load.py index cf0146d1a..e391dbd8c 100644 --- a/tests/pytests/test_pvl_load.py +++ b/tests/pytests/test_pvl_load.py @@ -1,17 +1,30 @@ -import pytest import pvl import ale +import os +import json +import unittest +from unittest.mock import patch -# I need to figure out how to get some kind of test cube in the test without -# referencing it locally -testCube = "/Users/ahibl/astro_efs/test_imgs/uvvis/LUA3107H.161.clem.cub_ISIS.cub" +from ale.drivers.clementine_drivers import ClementineIsisLabelNaifSpiceDriver -@pytest.fixture -def test_loads(): - isis_kerns = ale.util.generate_kernels_from_cube(testCube, expand=True) - pvl_obj = pvl.load(testCube) - res = ale.loads(pvl_obj, props={"kernels": isis_kerns}, only_naif_spice=True) - return res +from conftest import get_image_kernels, convert_kernels, get_image_label -def test_pass(test_loads): - pass \ No newline at end of file +class test_pvl_loads(unittest.TestCase): + + def setUp(self): + lbl = get_image_label("LUA3107H.161", "isis3") + self.driver = ClementineIsisLabelNaifSpiceDriver(lbl) + + def test_load_kernels(self): + kerns = get_image_kernels('LUA3107H.161') + updated_kerns, binary_kerns = convert_kernels(kerns) + yield updated_kerns + for kern in binary_kerns: + os.remove(kern) + + def test_pvl_load(self): + cube_label = get_image_label('LUA3107H.161', "isis3") + cube_pvl_obj = pvl.load(cube_label) + isd = ale.loads(cube_pvl_obj, props={'kernels': self.test_load_kernels(), 'exact_ck_times': False}, only_naif_spice=True) + isd_obj = json.loads(isd) + return isd_obj From 1807d51c0a62adad15e638b99c62cab8abbd9342 Mon Sep 17 00:00:00 2001 From: antonhibl Date: Wed, 31 Jan 2024 13:59:13 -0700 Subject: [PATCH 08/11] added check to parse_label for PVLModule existence, and redefeined test away from unittest --- ale/drivers/__init__.py | 2 ++ tests/pytests/test_pvl_load.py | 33 ++++++++++++++------------------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/ale/drivers/__init__.py b/ale/drivers/__init__.py index dbb2609c2..a62666b47 100644 --- a/ale/drivers/__init__.py +++ b/ale/drivers/__init__.py @@ -213,6 +213,8 @@ def parse_label(label, grammar=pvl.grammar.PVLGrammar()): load loads """ + if isinstance(label, pvl.PVLModule): + return label try: parsed_label = pvl.loads(label, grammar=grammar) except Exception: diff --git a/tests/pytests/test_pvl_load.py b/tests/pytests/test_pvl_load.py index e391dbd8c..3f87220c8 100644 --- a/tests/pytests/test_pvl_load.py +++ b/tests/pytests/test_pvl_load.py @@ -1,30 +1,25 @@ +import pytest import pvl import ale import os import json -import unittest -from unittest.mock import patch from ale.drivers.clementine_drivers import ClementineIsisLabelNaifSpiceDriver from conftest import get_image_kernels, convert_kernels, get_image_label -class test_pvl_loads(unittest.TestCase): +@pytest.fixture +def test_load_kernels(): + kerns = get_image_kernels('LUA3107H.161') + updated_kerns, binary_kerns = convert_kernels(kerns) + yield updated_kerns + for kern in binary_kerns: + os.remove(kern) - def setUp(self): - lbl = get_image_label("LUA3107H.161", "isis3") - self.driver = ClementineIsisLabelNaifSpiceDriver(lbl) - - def test_load_kernels(self): - kerns = get_image_kernels('LUA3107H.161') - updated_kerns, binary_kerns = convert_kernels(kerns) - yield updated_kerns - for kern in binary_kerns: - os.remove(kern) - def test_pvl_load(self): - cube_label = get_image_label('LUA3107H.161', "isis3") - cube_pvl_obj = pvl.load(cube_label) - isd = ale.loads(cube_pvl_obj, props={'kernels': self.test_load_kernels(), 'exact_ck_times': False}, only_naif_spice=True) - isd_obj = json.loads(isd) - return isd_obj +def test_pvl_load(test_load_kernels): + cube_label = get_image_label('LUA3107H.161', "isis3") + cube_pvl_obj = pvl.load(cube_label) + isd = ale.loads(cube_pvl_obj, props={'kernels': test_load_kernels, 'exact_ck_times': False}, only_naif_spice=True, verbose=True) + isd_obj = json.loads(isd) + return isd_obj From e30928dc60b8e0266800ed7ffed84eddbff89be4 Mon Sep 17 00:00:00 2001 From: antonhibl Date: Wed, 31 Jan 2024 14:16:07 -0700 Subject: [PATCH 09/11] replacing if not isinstance with simpler else statement --- ale/base/label_isis.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ale/base/label_isis.py b/ale/base/label_isis.py index 2a42ec02d..a37ea945b 100644 --- a/ale/base/label_isis.py +++ b/ale/base/label_isis.py @@ -10,9 +10,9 @@ def label(self): if not hasattr(self, "_label"): if isinstance(self._file, pvl.PVLModule): self._label = self._file - grammar = pvl.grammar.ISISGrammar() - grammar.comments+=(("#", "\n"), ) - if not isinstance(self._file, pvl.PVLModule): + else: + grammar = pvl.grammar.ISISGrammar() + grammar.comments+=(("#", "\n"), ) try: self._label = pvl.loads(self._file, grammar=grammar) except Exception: From 1fc0f64db9f32c37b70191fb9de00cbbb7074861 Mon Sep 17 00:00:00 2001 From: antonhibl Date: Wed, 31 Jan 2024 14:24:35 -0700 Subject: [PATCH 10/11] removed unneeded driver import --- tests/pytests/test_pvl_load.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/pytests/test_pvl_load.py b/tests/pytests/test_pvl_load.py index 3f87220c8..dd879ed97 100644 --- a/tests/pytests/test_pvl_load.py +++ b/tests/pytests/test_pvl_load.py @@ -4,8 +4,6 @@ import os import json -from ale.drivers.clementine_drivers import ClementineIsisLabelNaifSpiceDriver - from conftest import get_image_kernels, convert_kernels, get_image_label @pytest.fixture @@ -16,10 +14,9 @@ def test_load_kernels(): for kern in binary_kerns: os.remove(kern) - def test_pvl_load(test_load_kernels): cube_label = get_image_label('LUA3107H.161', "isis3") cube_pvl_obj = pvl.load(cube_label) isd = ale.loads(cube_pvl_obj, props={'kernels': test_load_kernels, 'exact_ck_times': False}, only_naif_spice=True, verbose=True) isd_obj = json.loads(isd) - return isd_obj + return isd_obj \ No newline at end of file From 2ffbff3bf2e3016c02e52bdb2b2326ba8e92a1ab Mon Sep 17 00:00:00 2001 From: antonhibl Date: Tue, 9 Apr 2024 14:54:20 -0700 Subject: [PATCH 11/11] fixed tests --- tests/pytests/test_pvl_load.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/pytests/test_pvl_load.py b/tests/pytests/test_pvl_load.py index dd879ed97..a28bba0e9 100644 --- a/tests/pytests/test_pvl_load.py +++ b/tests/pytests/test_pvl_load.py @@ -16,7 +16,6 @@ def test_load_kernels(): def test_pvl_load(test_load_kernels): cube_label = get_image_label('LUA3107H.161', "isis3") - cube_pvl_obj = pvl.load(cube_label) - isd = ale.loads(cube_pvl_obj, props={'kernels': test_load_kernels, 'exact_ck_times': False}, only_naif_spice=True, verbose=True) + isd = ale.loads(cube_label, props={'kernels': test_load_kernels, 'exact_ck_times': False}, only_naif_spice=True, verbose=True) isd_obj = json.loads(isd) return isd_obj \ No newline at end of file