diff --git a/ale/base/data_isis.py b/ale/base/data_isis.py index 27c58b9c5..849beee5a 100644 --- a/ale/base/data_isis.py +++ b/ale/base/data_isis.py @@ -147,6 +147,11 @@ def rotate_state(table, rotation): rotated_vel = None return rotated_pos, rotated_vel, ephemeris_times +def get_naif_keyword(self, ale_name, naif_key): + val = self.naif_keywords.get(naif_key, None) + if val is None: + raise LookupError('Could not find a value for {} using the NAIF Keyword {}'.format(ale_name, naif_key)) + return val class IsisSpice(): """ Mixin class for reading from an ISIS cube that has been spiceinit'd @@ -350,7 +355,8 @@ def detector_center_sample(self): list : The center of the CCD formatted as line, sample """ - return self.naif_keywords.get('INS{}_BORESIGHT_SAMPLE'.format(self.ikid), None) + + return get_naif_keyword(self, 'detector_center_sample', 'INS{}_BORESIGHT_SAMPLE'.format(self.ikid)) @property def detector_center_line(self): @@ -364,7 +370,7 @@ def detector_center_line(self): list : The center of the CCD formatted as line, sample """ - return self.naif_keywords.get('INS{}_BORESIGHT_LINE'.format(self.ikid), None) + return get_naif_keyword(self, 'detector_center_line', 'INS{}_BORESIGHT_LINE'.format(self.ikid)) @property @@ -430,7 +436,7 @@ def focal2pixel_lines(self): The coefficients of the affine transformation formatted as constant, x, y """ - return self.naif_keywords.get('INS{}_ITRANSL'.format(self.ikid), None) + return get_naif_keyword(self, 'focal2pixel_lines', 'INS{}_ITRANSL'.format(self.ikid)) @property def focal2pixel_samples(self): @@ -448,7 +454,7 @@ def focal2pixel_samples(self): The coefficients of the affine transformation formatted as constant, x, y """ - return self.naif_keywords.get('INS{}_ITRANSS'.format(self.ikid), None) + return get_naif_keyword(self, 'focal2pixel_samples', 'INS{}_ITRANSS'.format(self.ikid)) @property def pixel2focal_x(self): @@ -461,7 +467,7 @@ def pixel2focal_x(self): detector to focal plane x """ - return self.naif_keywords.get('INS{}_TRANSX'.format(self.ikid), None) + return get_naif_keyword(self, 'pixel2focal_x', 'INS{}_TRANSX'.format(self.ikid)) @property def pixel2focal_y(self): @@ -474,7 +480,7 @@ def pixel2focal_y(self): detector to focal plane y """ - return self.naif_keywords.get('INS{}_TRANSY'.format(self.ikid), None) + return get_naif_keyword(self, 'pixel2focal_y', 'INS{}_TRANSY'.format(self.ikid)) @property def focal_length(self): @@ -490,7 +496,8 @@ def focal_length(self): float : The focal length in millimeters """ - return self.naif_keywords.get('INS{}_FOCAL_LENGTH'.format(self.ikid), None) + + return get_naif_keyword(self, 'focal_length', 'INS{}_FOCAL_LENGTH'.format(self.ikid)) @property def target_body_radii(self): diff --git a/ale/drivers/co_drivers.py b/ale/drivers/co_drivers.py index 94fe3e61e..b0130d2b6 100644 --- a/ale/drivers/co_drivers.py +++ b/ale/drivers/co_drivers.py @@ -8,6 +8,7 @@ from ale.base import Driver, WrongInstrumentException from ale.base.data_naif import NaifSpice from ale.base.data_isis import IsisSpice +from ale.base.data_isis import get_naif_keyword from ale.base.label_pds3 import Pds3Label from ale.base.label_isis import IsisLabel from ale.base.type_distortion import RadialDistortion, NoDistortion @@ -829,4 +830,4 @@ def focal_length(self): The focal length in millimeters """ filters = self.label["IsisCube"]["BandBin"]['FilterName'].split("/") - return self.naif_keywords.get('INS{}_{}_{}_FOCAL_LENGTH'.format(self.ikid, filters[0], filters[1]), None) + return get_naif_keyword(self, 'focal_length', 'INS{}_{}_{}_FOCAL_LENGTH'.format(self.ikid, filters[0], filters[1])) diff --git a/ale/drivers/isis_ideal_drivers.py b/ale/drivers/isis_ideal_drivers.py index 2e62d0654..ea35a1313 100644 --- a/ale/drivers/isis_ideal_drivers.py +++ b/ale/drivers/isis_ideal_drivers.py @@ -1,4 +1,5 @@ from ale.base.data_isis import IsisSpice +from ale.base.data_isis import get_naif_keyword from ale.base.label_isis import IsisLabel from ale.base import Driver, WrongInstrumentException from ale.base.type_sensor import LineScanner @@ -129,7 +130,7 @@ def pixel2focal_x(self): : list detector to focal plane x """ - return self.naif_keywords.get('IDEAL_TRANSX') + return get_naif_keyword(self, 'pixel2focal_x', 'IDEAL_TRANSX') @property @@ -142,7 +143,7 @@ def pixel2focal_y(self): : list detector to focal plane y """ - return self.naif_keywords.get('IDEAL_TRANSY') + return get_naif_keyword(self, 'pixel2focal_y', 'IDEAL_TRANSY') @property @@ -155,8 +156,7 @@ def focal2pixel_lines(self): : list focal plane to detector lines """ - - return self.naif_keywords.get('IDEAL_TRANSL') + return get_naif_keyword(self, 'focal2pixel_lines', 'IDEAL_TRANSL') @property @@ -169,7 +169,7 @@ def focal2pixel_samples(self): : list focal plane to detector samples """ - return self.naif_keywords.get('IDEAL_TRANSS') + return get_naif_keyword(self, 'focal2pixel_samples', 'IDEAL_TRANSS') @property def focal_length(self): @@ -183,7 +183,7 @@ def focal_length(self): float : The focal length in millimeters """ - return self.naif_keywords.get('IDEAL_FOCAL_LENGTH', None) + return get_naif_keyword(self, 'focal_length', 'IDEAL_FOCAL_LENGTH') @property def detector_center_sample(self): diff --git a/ale/drivers/lro_drivers.py b/ale/drivers/lro_drivers.py index be8e5fa57..ee95fb91d 100644 --- a/ale/drivers/lro_drivers.py +++ b/ale/drivers/lro_drivers.py @@ -6,6 +6,7 @@ from ale.base import Driver, WrongInstrumentException from ale.base.data_naif import NaifSpice from ale.base.data_isis import IsisSpice +from ale.base.data_isis import get_naif_keyword from ale.base.label_pds3 import Pds3Label from ale.base.label_isis import IsisLabel from ale.base.type_sensor import LineScanner, Radar, PushFrame @@ -595,11 +596,7 @@ def odtk(self): : list Radial distortion coefficients. There is only one coefficient for LROC NAC l/r """ - key = 'INS{}_OD_K'.format(self.ikid) - ans = self.naif_keywords.get(key, None) - if ans is None: - raise Exception('Could not parse the distortion model coefficients using key: ' + key) - return [ans] + return get_naif_keyword(self, 'odtk', 'INS{}_OD_K'.format(self.ikid)) @property def detector_center_sample(self): @@ -1005,13 +1002,9 @@ def odtk(self): : list Radial distortion coefficients. """ - key = 'INS{}_OD_K'.format(self.fikid) - ans = self.naif_keywords.get(key, None) - if ans is None: - raise Exception('Could not parse the distortion model coefficients using key: ' + key) - - ans = [x * -1 for x in ans] - return ans + val = get_naif_keyword(self, 'odtk', 'INS{}_OD_K'.format(self.fikid)) + val = [x * -1 for x in val] + return val @property def framelet_height(self): @@ -1031,11 +1024,7 @@ def pixel2focal_x(self): : list detector to focal plane x """ - key = 'INS{}_TRANSX'.format(self.fikid) - ans = self.naif_keywords.get(key, None) - if ans is None: - raise Exception('Could not parse detector to focal plane x using key: ' + key) - return ans + return get_naif_keyword(self, 'pixel2focal_x', 'INS{}_TRANSX'.format(self.fikid)); @property def pixel2focal_y(self): @@ -1047,11 +1036,7 @@ def pixel2focal_y(self): : list detector to focal plane y """ - key = 'INS{}_TRANSY'.format(self.fikid) - ans = self.naif_keywords.get(key, None) - if ans is None: - raise Exception('Could not parse detector to focal plane y using key: ' + key) - return ans + return get_naif_keyword(self, 'pixel2focal_y', 'INS{}_TRANSY'.format(self.fikid)) @property def focal_length(self): @@ -1067,11 +1052,7 @@ def focal_length(self): float : The focal length in millimeters """ - key = 'INS{}_FOCAL_LENGTH'.format(self.fikid) - ans = self.naif_keywords.get(key, None) - if ans is None: - raise Exception('Could not parse the focal length using key: ' + key) - return ans + return get_naif_keyword(self, 'focal_length', 'INS{}_FOCAL_LENGTH'.format(self.fikid)) @property def detector_center_sample(self): @@ -1085,11 +1066,7 @@ def detector_center_sample(self): list : The center of the CCD formatted as line, sample """ - key = 'INS{}_BORESIGHT_SAMPLE'.format(self.fikid) - ans = self.naif_keywords.get(key, None) - if ans is None: - raise Exception('Could not parse the detector center sample using key: ' + key) - return ans + return get_naif_keyword(self, 'detector_center_sample', 'INS{}_BORESIGHT_SAMPLE'.format(self.fikid)) @property def detector_center_line(self): @@ -1103,11 +1080,7 @@ def detector_center_line(self): list : The center of the CCD formatted as line, sample """ - key = 'INS{}_BORESIGHT_LINE'.format(self.fikid) - ans = self.naif_keywords.get(key, None) - if ans is None: - raise Exception('Could not parse the detector center line using key: ' + key) - return ans + return get_naif_keyword(self, 'detector_center_sample', 'INS{}_BORESIGHT_LINE'.format(self.fikid)) class LroLrocWacIsisLabelNaifSpiceDriver(PushFrame, IsisLabel, NaifSpice, RadialDistortion, Driver): """ diff --git a/tests/pytests/test_data_isis.py b/tests/pytests/test_data_isis.py index 482266273..66d6eddb3 100644 --- a/tests/pytests/test_data_isis.py +++ b/tests/pytests/test_data_isis.py @@ -519,11 +519,13 @@ def test_sun_position(testdata): def test_detector_center_sample(testdata): - assert testdata.detector_center_sample == None + with pytest.raises(LookupError): + testdata.detector_center_sample def test_detector_center_line(testdata): - assert testdata.detector_center_line == None + with pytest.raises(LookupError): + testdata.detector_center_line def test_focal_length(testdata): @@ -713,4 +715,4 @@ def test_no_tables(): with pytest.raises(ValueError): test_mix_in.inst_position_table with pytest.raises(ValueError): - test_mix_in.sun_position_table + test_mix_in.sun_position_table \ No newline at end of file