From b3f353f9996386373f28943f5802290a4db2832d Mon Sep 17 00:00:00 2001 From: Oleg Alexandrov <oleg.alexandrov@gmail.com> Date: Tue, 17 May 2022 08:23:10 -0700 Subject: [PATCH] Print clear error messages when cannot look up things (#455) * Print clear error messages when cannot look up things * Spell out the failing key --- ale/drivers/lro_drivers.py | 51 ++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/ale/drivers/lro_drivers.py b/ale/drivers/lro_drivers.py index 0fadd79..5331de6 100644 --- a/ale/drivers/lro_drivers.py +++ b/ale/drivers/lro_drivers.py @@ -573,7 +573,11 @@ class LroLrocNacIsisLabelIsisSpiceDriver(LineScanner, IsisSpice, IsisLabel, Driv : list Radial distortion coefficients. There is only one coefficient for LROC NAC l/r """ - return [self.naif_keywords.get('INS{}_OD_K'.format(self.ikid), None)] + 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] @property def detector_center_sample(self): @@ -873,7 +877,6 @@ class LroLrocWacIsisLabelIsisSpiceDriver(PushFrame, IsisLabel, IsisSpice, Radial } return id_lookup[super().instrument_id] - @property def sensor_name(self): return self.label['IsisCube']['Instrument']['SpacecraftName'] @@ -940,10 +943,13 @@ class LroLrocWacIsisLabelIsisSpiceDriver(PushFrame, IsisLabel, IsisSpice, Radial : list Radial distortion coefficients. """ - coeffs = self.naif_keywords.get('INS{}_OD_K'.format(self.fikid), None) - coeffs = [x * -1 for x in coeffs] - return coeffs - + 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 @property def framelet_height(self): @@ -963,8 +969,11 @@ class LroLrocWacIsisLabelIsisSpiceDriver(PushFrame, IsisLabel, IsisSpice, Radial : list<double> detector to focal plane x """ - return self.naif_keywords.get('INS{}_TRANSX'.format(self.fikid), None) - + 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 @property def pixel2focal_y(self): @@ -976,7 +985,11 @@ class LroLrocWacIsisLabelIsisSpiceDriver(PushFrame, IsisLabel, IsisSpice, Radial : list<double> detector to focal plane y """ - return self.naif_keywords.get('INS{}_TRANSY'.format(self.fikid), None) + 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 @property def focal_length(self): @@ -992,8 +1005,12 @@ class LroLrocWacIsisLabelIsisSpiceDriver(PushFrame, IsisLabel, IsisSpice, Radial float : The focal length in millimeters """ - return self.naif_keywords.get('INS{}_FOCAL_LENGTH'.format(self.fikid), None) - + 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 + @property def detector_center_sample(self): """ @@ -1006,7 +1023,11 @@ class LroLrocWacIsisLabelIsisSpiceDriver(PushFrame, IsisLabel, IsisSpice, Radial list : The center of the CCD formatted as line, sample """ - return self.naif_keywords.get('INS{}_BORESIGHT_SAMPLE'.format(self.fikid), None) + 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 @property def detector_center_line(self): @@ -1020,7 +1041,11 @@ class LroLrocWacIsisLabelIsisSpiceDriver(PushFrame, IsisLabel, IsisSpice, Radial list : The center of the CCD formatted as line, sample """ - return self.naif_keywords.get('INS{}_BORESIGHT_LINE'.format(self.fikid), None) + 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 class LroLrocWacIsisLabelNaifSpiceDriver(PushFrame, IsisLabel, NaifSpice, RadialDistortion, Driver): """ -- GitLab