From 2ce71e336493b7e0ecf270f771371cf919212e39 Mon Sep 17 00:00:00 2001 From: Kelvin Date: Tue, 10 Aug 2021 11:17:11 -0700 Subject: [PATCH 1/2] added missing HRSC properties --- ale/drivers/mex_drivers.py | 288 ++++++++++++++++++++++--------------- ale/util.py | 5 +- 2 files changed, 176 insertions(+), 117 deletions(-) diff --git a/ale/drivers/mex_drivers.py b/ale/drivers/mex_drivers.py index 179d7efa1..fdeaa522a 100644 --- a/ale/drivers/mex_drivers.py +++ b/ale/drivers/mex_drivers.py @@ -483,123 +483,179 @@ def sensor_model_version(self): class MexHrscIsisLabelNaifSpiceDriver(LineScanner, IsisLabel, NaifSpice, RadialDistortion, Driver): - @property - def instrument_id(self): - """ - Returns the name of the instrument - - Returns - ------- - : str - Name of the instrument - """ - if(super().instrument_id != "HRSC"): - raise Exception ("Instrument ID is wrong.") - return self.label['IsisCube']['Archive']['DetectorId'] - - - @property - def sensor_name(self): - """ - Returns the name of the instrument. Need to over-ride isis_label because - InstrumentName is not defined in the ISIS label for MEX HSRC cubes. - - Returns - ------- - : str - Name of the sensor - """ - return self.instrument_id - - - @property - def sensor_model_version(self): - """ - Returns - ------- - : int - ISIS sensor model version - """ - return 1 - - @property - def times_table(self): - """ - Returns EphermisTime, ExposureTime, and LinesStart informtation which was stored as - binary information in the ISIS cube. - - Returns - ------- - : dict - Dictionary with EphemerisTime, ExposureTime, and LineStart. - """ - isis_bytes = read_table_data(self.label['Table'], self._file) - return parse_table(self.label['Table'], isis_bytes) - - @property - def line_scan_rate(self): - """ - Returns - ------- - : tuple - list of lines, list of ephemeris times, and list of exposure - times - """ - return self.times_table['LineStart'], self.times_table['EphemerisTime'], self.times_table['ExposureTime'] - - @property - def ephemeris_start_time(self): - """ - Returns - ------- - : float - starting ephemeris time - """ - return self.times_table['EphemerisTime'][0] - - @property - def ephemeris_stop_time(self): - """ - Returns - ------- - : float - ephemeris stop time - """ - last_line = self.times_table['LineStart'][-1] - return self.times_table['EphemerisTime'][-1] + ((self.image_lines - last_line + 1) * self.times_table['ExposureTime'][-1]) - - @property - def ikid(self): - """ - Returns the Naif ID code for the HRSC head instrument - - This would be the Naif ID code for the base (or "head") instrument. - - Returns - ------- - : int - Naif ID used to for indentifying the instrument in Spice kernels - """ - return spice.bods2c("MEX_HRSC_HEAD") - - - @property - def fikid(self): - """ - Naif ID code of the filter dependent instrument codes. - - Expects filter_number to be defined. This should be an integer containing - the filter number from the pds3 label. - Expects ikid to be defined. This should be the integer Naif ID code for - the instrument. - - Returns - ------- - : int - Naif ID code used in calculating focal length - """ - return spice.bods2c(self.instrument_id) + @property + def detector_center_line(self): + """ + Returns the center detector line. + + For HRSC, we are dealing with a single line, so center line will be 0. + + Returns + ------- + : float + Detector line of the principal point + """ + return 0.0 + + @property + def detector_center_sample(self): + """ + Returns the center detector sample. + + For HRSC, center sample is consistent regardless of filter. This is + different from ISIS's center sample because ISIS line scan sensors use + 0.5 based detector samples. + + Returns + ------- + : float + Detector sample of the principal point + """ + return 2592.0 + + + @property + def instrument_id(self): + """ + Returns the name of the instrument + + Returns + ------- + : str + Name of the instrument + """ + if(super().instrument_id != "HRSC"): + raise Exception ("Instrument ID is wrong.") + return self.label['IsisCube']['Archive']['DetectorId'] + + + @property + def sensor_name(self): + """ + Returns the name of the instrument. Need to over-ride isis_label because + InstrumentName is not defined in the ISIS label for MEX HSRC cubes. + + Returns + ------- + : str + Name of the sensor + """ + return self.instrument_id + + + @property + def sensor_model_version(self): + """ + Returns + ------- + : int + ISIS sensor model version + """ + return 1 + + @property + def times_table(self): + """ + Returns EphermisTime, ExposureTime, and LinesStart informtation which was stored as + binary information in the ISIS cube. + + Returns + ------- + : dict + Dictionary with EphemerisTime, ExposureTime, and LineStart. + """ + isis_bytes = read_table_data(self.label['Table'], self._file) + return parse_table(self.label['Table'], isis_bytes) + + @property + def line_scan_rate(self): + """ + Returns + ------- + : tuple + list of lines, list of ephemeris times, and list of exposure + times + """ + return self.times_table['LineStart'], self.times_table['EphemerisTime'], self.times_table['ExposureTime'] + + @property + def ephemeris_start_time(self): + """ + Returns + ------- + : float + starting ephemeris time + """ + return self.times_table['EphemerisTime'][0] + + @property + def ephemeris_stop_time(self): + """ + Returns + ------- + : float + ephemeris stop time + """ + last_line = self.times_table['LineStart'][-1] + return self.times_table['EphemerisTime'][-1] + ((self.image_lines - last_line + 1) * self.times_table['ExposureTime'][-1]) + + @property + def ikid(self): + """ + Returns the Naif ID code for the HRSC head instrument + + This would be the Naif ID code for the base (or "head") instrument. + + Returns + ------- + : int + Naif ID used to for indentifying the instrument in Spice kernels + """ + return spice.bods2c("MEX_HRSC_HEAD") + + + @property + def fikid(self): + """ + Naif ID code of the filter dependent instrument codes. + + Expects filter_number to be defined. This should be an integer containing + the filter number from the pds3 label. + Expects ikid to be defined. This should be the integer Naif ID code for + the instrument. + + Returns + ------- + : int + Naif ID code used in calculating focal length + """ + return spice.bods2c(self.instrument_id) + + @property + def focal2pixel_lines(self): + """ + NOTE: These values are pulled from ISIS iak kernels. + + Returns + ------- + : list + focal plane to detector lines + """ + return [0.0, 0.0, 111.111111111111] + + + @property + def focal2pixel_samples(self): + """ + NOTE: These values are pulled from ISIS iak kernels. + + Returns + ------- + : list + focal plane to detector samples + """ + return [0.0, 111.111111111111, 0.0] class MexSrcPds3NaifSpiceDriver(Framer, Pds3Label, NaifSpice, RadialDistortion, Driver): """ diff --git a/ale/util.py b/ale/util.py index f9890f133..98bc4bbe9 100644 --- a/ale/util.py +++ b/ale/util.py @@ -154,7 +154,6 @@ def get_isis_preferences(isis_preferences=None): try: isisrootprefs_path = os.path.join(os.environ["ISISROOT"], 'IsisPreferences') - isisroot = os.environ['ISISROOT'] isisrootprefs = read_pvl(isisrootprefs_path) except (FileNotFoundError, KeyError) as e: isisrootprefs = {} @@ -259,6 +258,10 @@ def load_table_data(key): kernels = [kernel for kernel in chain.from_iterable(mk_paths.values()) if isinstance(kernel, str)] if expand: isisprefs = get_isis_preferences() + + if not "DataDirectory" in isisprefs: + warnings.warn("No IsisPreferences file found, is your ISISROOT env var set?") + kernels = [expandvars(expandvars(k, dict_to_lower(isisprefs['DataDirectory']))) for k in kernels] return kernels elif (format_as == 'dict'): From 06e335c0a2f6be3131bbb3b5e0431c1f434126d1 Mon Sep 17 00:00:00 2001 From: Kelvin Date: Tue, 10 Aug 2021 11:23:52 -0700 Subject: [PATCH 2/2] moved properties for instrument id to the top --- ale/drivers/mex_drivers.py | 59 +++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/ale/drivers/mex_drivers.py b/ale/drivers/mex_drivers.py index fdeaa522a..7ea1d80b8 100644 --- a/ale/drivers/mex_drivers.py +++ b/ale/drivers/mex_drivers.py @@ -481,7 +481,36 @@ def sensor_model_version(self): """ return 1 + class MexHrscIsisLabelNaifSpiceDriver(LineScanner, IsisLabel, NaifSpice, RadialDistortion, Driver): + + @property + def instrument_id(self): + """ + Returns the name of the instrument + + Returns + ------- + : str + Name of the instrument + """ + if(super().instrument_id != "HRSC"): + raise Exception ("Instrument ID is wrong.") + return self.label['IsisCube']['Archive']['DetectorId'] + + + @property + def sensor_name(self): + """ + Returns the name of the instrument. Need to over-ride isis_label because + InstrumentName is not defined in the ISIS label for MEX HSRC cubes. + + Returns + ------- + : str + Name of the sensor + """ + return self.instrument_id @property def detector_center_line(self): @@ -514,36 +543,6 @@ def detector_center_sample(self): """ return 2592.0 - - @property - def instrument_id(self): - """ - Returns the name of the instrument - - Returns - ------- - : str - Name of the instrument - """ - if(super().instrument_id != "HRSC"): - raise Exception ("Instrument ID is wrong.") - return self.label['IsisCube']['Archive']['DetectorId'] - - - @property - def sensor_name(self): - """ - Returns the name of the instrument. Need to over-ride isis_label because - InstrumentName is not defined in the ISIS label for MEX HSRC cubes. - - Returns - ------- - : str - Name of the sensor - """ - return self.instrument_id - - @property def sensor_model_version(self): """