diff --git a/ale/base/label_pds3.py b/ale/base/label_pds3.py index 8743697bc12a1316a2bf0e172ec491dae5adb36c..fd5c99574e976556146ba5e6d735f05f909e8ca2 100644 --- a/ale/base/label_pds3.py +++ b/ale/base/label_pds3.py @@ -10,12 +10,13 @@ class Pds3Label(): if not hasattr(self, "_label"): if isinstance(self._file, pvl.PVLModule): self._label = self._file - try: - self._label = pvl.loads(self._file) - except Exception: - self._label = pvl.load(self._file) - except: - raise ValueError("{} is not a valid label".format(self._file)) + else: + try: + self._label = pvl.loads(self._file, strict=False) + except Exception: + self._label = pvl.load(self._file) + except: + raise ValueError("{} is not a valid label".format(self._file)) return self._label diff --git a/ale/drivers/co_drivers.py b/ale/drivers/co_drivers.py index b8e4a8f4174363faeb9c457943b4dd834d796d88..eec96dc26bd49d68bf6b49049e32e617e861f9b7 100644 --- a/ale/drivers/co_drivers.py +++ b/ale/drivers/co_drivers.py @@ -77,7 +77,6 @@ class CassiniIssPds3LabelNaifSpiceDriver(Framer, Pds3Label, NaifSpice, RadialDis ("P120","UV3"):2002.71 } - wac_filter_to_focal_length = { ("B2","CL2"):200.85, ("B2","IRP90"):200.83, @@ -291,11 +290,38 @@ class CassiniIssPds3LabelNaifSpiceDriver(Framer, Pds3Label, NaifSpice, RadialDis ------- : int NAIF's Wac sensor frame ID, or ALE's Nac sensor frame ID - """ if self.instrument_id == "CASSINI_ISS_NAC": return 14082360 elif self.instrument_id == "CASSINI_ISS_WAC": return 14082361 + @property + def frame_chain(self): + """ + Construct the initial frame chain using the original sensor_frame_id + obtained from the ikid. Then tack on the ISIS iak rotation. + + Returns + ------- + : Object + Custom Cassini ALE Frame Chain object for rotation computation and application + """ + if not hasattr(self, '_frame_chain'): + + try: + # Call frinfo to check if the ISIS iak has been loaded with the + # additional reference frame. Otherwise, Fail and add it manually + spice.frinfo(self.sensor_frame_id) + self._frame_chain = super().frame_chain + except spice.utils.exceptions.NotFoundError as e: + self._frame_chain = FrameChain.from_spice(sensor_frame=self._original_naif_sensor_frame_id, + target_frame=self.target_frame_id, + center_ephemeris_time=self.center_ephemeris_time, + ephemeris_times=self.ephemeris_time,) + + rotation = ConstantRotation([[0, 0, 1, 0]], self.sensor_frame_id, self._original_naif_sensor_frame_id) + + self._frame_chain.add_edge(rotation=rotation) + return self._frame_chain diff --git a/tests/pytests/test_cassini_drivers.py b/tests/pytests/test_cassini_drivers.py index 27a132ad48876827b2f00e3d4a62b67686224670..6600c4b027efe8852f3086dcf0eb04844678d047 100644 --- a/tests/pytests/test_cassini_drivers.py +++ b/tests/pytests/test_cassini_drivers.py @@ -5,7 +5,7 @@ import os import numpy as np from ale.drivers import co_drivers import unittest -from unittest.mock import patch +from unittest.mock import PropertyMock, patch import json from conftest import get_image_label, get_image_kernels, get_isd, convert_kernels, compare_dicts @@ -88,3 +88,32 @@ class test_cassini_pds3_naif(unittest.TestCase): def test_sensor_frame_id(self): assert self.driver.sensor_frame_id == 14082360 + + @patch('ale.transformation.FrameChain.from_spice', return_value=ale.transformation.FrameChain()) + def test_custom_frame_chain(self, from_spice): + with patch('ale.drivers.co_drivers.spice.bods2c', return_value=-12345) as bods2c, \ + patch('ale.drivers.co_drivers.CassiniIssPds3LabelNaifSpiceDriver.target_frame_id', \ + new_callable=PropertyMock) as target_frame_id, \ + patch('ale.drivers.co_drivers.CassiniIssPds3LabelNaifSpiceDriver.ephemeris_start_time', \ + new_callable=PropertyMock) as ephemeris_start_time: + ephemeris_start_time.return_value = .1 + target_frame_id.return_value = -800 + frame_chain = self.driver.frame_chain + assert len(frame_chain.nodes()) == 2 + assert 14082360 in frame_chain.nodes() + assert -12345 in frame_chain.nodes() + from_spice.assert_called_with(center_ephemeris_time=2.4, ephemeris_times=[2.4], sensor_frame=-12345, target_frame=-800) + + @patch('ale.transformation.FrameChain.from_spice', return_value=ale.transformation.FrameChain()) + def test_custom_frame_chain_iak(self, from_spice): + with patch('ale.drivers.co_drivers.spice.bods2c', return_value=-12345) as bods2c, \ + patch('ale.drivers.co_drivers.CassiniIssPds3LabelNaifSpiceDriver.target_frame_id', \ + new_callable=PropertyMock) as target_frame_id, \ + patch('ale.drivers.co_drivers.CassiniIssPds3LabelNaifSpiceDriver.ephemeris_start_time', \ + new_callable=PropertyMock) as ephemeris_start_time, \ + patch('ale.drivers.co_drivers.spice.frinfo', return_value=True) as frinfo: + ephemeris_start_time.return_value = .1 + target_frame_id.return_value = -800 + frame_chain = self.driver.frame_chain + assert len(frame_chain.nodes()) == 0 + from_spice.assert_called_with(center_ephemeris_time=2.4, ephemeris_times=[2.4], nadir=False, sensor_frame=14082360, target_frame=-800)