diff --git a/ale/base/data_isis.py b/ale/base/data_isis.py index 905261efda1785a1144e76cd9beb3125fd6260fa..3401c5e3248809a2a3b0299d211a3906b77e48d2 100644 --- a/ale/base/data_isis.py +++ b/ale/base/data_isis.py @@ -79,7 +79,7 @@ def parse_table(table_label, data): offset += data_sizes[field['Type']] * field['Size'] # Parse the keywords from the label - results.update({key : value for key, value in table_label.items() if not isinstance(value, pvl._collections.PVLGroup)}) + results.update({key : value for key, value in table_label.items() if not isinstance(value, pvl.collections.PVLGroup)}) return results diff --git a/ale/base/label_isis.py b/ale/base/label_isis.py index e25e36df2ccc01c4b54dba8d161f763a994636a4..66847e73e9a3238a1b1fe1c72ac3b395a5255760 100644 --- a/ale/base/label_isis.py +++ b/ale/base/label_isis.py @@ -10,10 +10,11 @@ class IsisLabel(): if not hasattr(self, "_label"): if isinstance(self._file, pvl.PVLModule): self._label = self._file + grammar = pvl.grammar.ISISGrammar() try: - self._label = pvl.loads(self._file) + self._label = pvl.loads(self._file, grammar=grammar) except Exception: - self._label = pvl.load(self._file) + self._label = pvl.load(self._file, grammar=grammar) except: raise ValueError("{} is not a valid label".format(self._file)) return self._label @@ -236,7 +237,7 @@ class IsisLabel(): if 'ExposureDuration' in self.label['IsisCube']['Instrument']: exposure_duration = self.label['IsisCube']['Instrument']['ExposureDuration'] # Check for units on the PVL keyword - if isinstance(exposure_duration, pvl._collections.Units): + if isinstance(exposure_duration, pvl.collections.Quantity): units = exposure_duration.units if "ms" in units.lower() or 'milliseconds' in units.lower(): exposure_duration = exposure_duration.value * 0.001 @@ -261,7 +262,7 @@ class IsisLabel(): Line exposure duration in seconds """ line_exposure_duration = self.label['IsisCube']['Instrument']['LineExposureDuration'] - if isinstance(line_exposure_duration, pvl._collections.Units): + if isinstance(line_exposure_duration, pvl.collections.Quantity): units = line_exposure_duration.units if "ms" in units.lower(): line_exposure_duration = line_exposure_duration.value * 0.001 diff --git a/ale/base/label_pds3.py b/ale/base/label_pds3.py index fd5c99574e976556146ba5e6d735f05f909e8ca2..ae15af04d30351afb259dbe573ee453ed78eddde 100644 --- a/ale/base/label_pds3.py +++ b/ale/base/label_pds3.py @@ -12,7 +12,7 @@ class Pds3Label(): self._label = self._file else: try: - self._label = pvl.loads(self._file, strict=False) + self._label = pvl.loads(self._file) except Exception: self._label = pvl.load(self._file) except: diff --git a/ale/drivers/dawn_drivers.py b/ale/drivers/dawn_drivers.py index 163dd2f7548a0813d981f1a1afc35f2268c1112b..2cfec8857f087df3d4b2f36f5427aebecdeab9e7 100644 --- a/ale/drivers/dawn_drivers.py +++ b/ale/drivers/dawn_drivers.py @@ -39,37 +39,6 @@ class DawnFcPds3NaifSpiceDriver(Framer, Pds3Label, NaifSpice, Driver): return "{}_FILTER_{}".format(ID_LOOKUP[instrument_id], filter_number) - @property - def label(self): - """ - Loads a PVL from from the _file attribute and - parses the binary table data. - - Returns - ------- - PVLModule : - Dict-like object with PVL keys - """ - class PvlDecoder(pvl.decoder.PVLDecoder): - def unescape_next_char(self, stream): - esc = stream.read(1) - string = '\{}'.format(esc.decode('utf-8')).encode('utf-8') - return string - - if not hasattr(self, "_label"): - if isinstance(self._file, pvl.PVLModule): - self._label = self._file - try: - self._label = pvl.loads(self._file, PvlDecoder) - except Exception: - - # PvlDecoder class to ignore all escape sequences when getting - # the label - self._label = pvl.load(self._file, PvlDecoder) - except: - raise ValueError("{} is not a valid label".format(self._file)) - return self._label - @property def spacecraft_name(self): """ diff --git a/ale/drivers/lro_drivers.py b/ale/drivers/lro_drivers.py index 1c066951a6299ccd795fc7a06c3d9ecb43d8fb0e..00b69620dbf365627e2711f098279bf6505c4bb3 100644 --- a/ale/drivers/lro_drivers.py +++ b/ale/drivers/lro_drivers.py @@ -616,7 +616,7 @@ class LroMiniRfIsisLabelNaifSpiceDriver(Radar, NaifSpice, IsisLabel, Driver): : float start time """ - return spice.str2et(str(self.utc_start_time)) + return spice.str2et(self.utc_start_time.strftime("%Y-%m-%d %H:%M:%S.%f")) @property def ephemeris_stop_time(self): @@ -628,7 +628,7 @@ class LroMiniRfIsisLabelNaifSpiceDriver(Radar, NaifSpice, IsisLabel, Driver): : float stop time """ - return spice.str2et(str(self.utc_stop_time)) + return spice.str2et(self.utc_stop_time.strftime("%Y-%m-%d %H:%M:%S.%f")) @property def look_direction(self): diff --git a/ale/drivers/ody_drivers.py b/ale/drivers/ody_drivers.py index c55387c8eda51f86ad5dcf00aa6dc9405b3be087..05828afc65b7c0c7fef06f7488d8e61e660723ef 100644 --- a/ale/drivers/ody_drivers.py +++ b/ale/drivers/ody_drivers.py @@ -50,7 +50,7 @@ class OdyThemisIrIsisLabelNaifSpiceDriver(LineScanner, IsisLabel, NaifSpice, NoD def ephemeris_start_time(self): og_start_time = super().ephemeris_start_time offset = self.label["IsisCube"]["Instrument"]["SpacecraftClockOffset"] - if isinstance(offset, pvl._collections.Units): + if isinstance(offset, pvl.collections.Quantity): units = offset.units if "ms" in units.lower(): offset = offset.value * 0.001 @@ -121,7 +121,7 @@ class OdyThemisVisIsisLabelNaifSpiceDriver(LineScanner, IsisLabel, NaifSpice, No og_start_time = super().ephemeris_start_time offset = self.label["IsisCube"]["Instrument"]["SpacecraftClockOffset"] - if isinstance(offset, pvl._collections.Units): + if isinstance(offset, pvl.collections.Quantity): units = offset.units if "ms" in units.lower(): offset = offset.value * 0.001 @@ -142,7 +142,7 @@ class OdyThemisVisIsisLabelNaifSpiceDriver(LineScanner, IsisLabel, NaifSpice, No Line exposure duration in seconds """ line_exposure_duration = self.label['IsisCube']['Instrument']['ExposureDuration'] - if isinstance(line_exposure_duration, pvl._collections.Units): + if isinstance(line_exposure_duration, pvl.collections.Quantity): units = line_exposure_duration.units if "ms" in units.lower(): line_exposure_duration = line_exposure_duration.value * 0.001 diff --git a/ale/drivers/tgo_drivers.py b/ale/drivers/tgo_drivers.py index 69b21f67df4df515dd83fbac801ed2ea1340f5e7..1f980230cdb59880aa80e3878eebedc66a91d238 100644 --- a/ale/drivers/tgo_drivers.py +++ b/ale/drivers/tgo_drivers.py @@ -50,7 +50,7 @@ class TGOCassisIsisLabelNaifSpiceDriver(Framer, IsisLabel, NaifSpice, NoDistorti : float ephemeris start time of the image. """ - return spice.utc2et(str(self.label['IsisCube']['Instrument']['StartTime'])) + return spice.utc2et(self.utc_start_time.strftime("%Y-%m-%d %H:%M:%S.%f")) @property def sensor_frame_id(self): diff --git a/ale/drivers/voyager_drivers.py b/ale/drivers/voyager_drivers.py index c1f9c267260feb7886adbe1ed9c5bcaccc45b65f..e1d174381828f443a56f2642f49d3c58097c7a80 100644 --- a/ale/drivers/voyager_drivers.py +++ b/ale/drivers/voyager_drivers.py @@ -49,7 +49,7 @@ class VoyagerCameraIsisLabelNaifSpiceDriver(Framer, IsisLabel, NaifSpice, Driver @property def ephemeris_start_time(self): - inital_time = spice.utc2et(self.utc_start_time.isoformat()) + inital_time = spice.utc2et(self.utc_start_time.strftime("%Y-%m-%d %H:%M:%S.%f")) # To get shutter end (close) time, subtract 2 seconds from the start time updated_time = inital_time - 2 # To get shutter start (open) time, take off the exposure duration from the end time. diff --git a/environment.yml b/environment.yml index 712eaef3da825cc03ec45566c1e7f15f710e4a0b..db30c99785a739e2fa3633a2fa85298483d0b188 100644 --- a/environment.yml +++ b/environment.yml @@ -11,6 +11,7 @@ dependencies: - nlohmann_json - numpy - pvl + - pytz - python - python-dateutil - scipy diff --git a/tests/pytests/data/JNCR_2016240_01M06152_V01/JNCR_2016240_01M06152_V01_isis3.lbl b/tests/pytests/data/JNCR_2016240_01M06152_V01/JNCR_2016240_01M06152_V01_isis3.lbl index 8874f31e2305631009582da8d2bf49f6666a45c2..339a2a368558195debbb21582a4a84b608d47b76 100644 --- a/tests/pytests/data/JNCR_2016240_01M06152_V01/JNCR_2016240_01M06152_V01_isis3.lbl +++ b/tests/pytests/data/JNCR_2016240_01M06152_V01/JNCR_2016240_01M06152_V01_isis3.lbl @@ -26,10 +26,10 @@ Object = IsisCube InstrumentId = JNC TargetName = JUPITER - # Start time for the entire observation, i.e. start time for FrameNumber 1. + /* Start time for the entire observation, i.e. start time for FrameNumber 1. */ StartTime = 2016-08-27T09:00:04.129 - # Start count for the entire observation, i.e. start count for FrameNumber 1. + /* Start count for the entire observation, i.e. start count for FrameNumber 1. */ SpacecraftClockStartCount = 525560580:87 ExposureDuration = 204.800000 <ms> InterFrameDelay = 0.378 <s> diff --git a/tests/pytests/test_isis_label.py b/tests/pytests/test_isis_label.py index 8633e6da630d571ece29d6c919fdefc53439ec5e..ed05dbc851e1654e1f9a552de4ea97fca2e8019e 100644 --- a/tests/pytests/test_isis_label.py +++ b/tests/pytests/test_isis_label.py @@ -1,6 +1,6 @@ import pytest import pvl -from datetime import datetime +from datetime import datetime, timezone import ale from ale import base @@ -57,7 +57,7 @@ DpuId = DPU-A PivotAngle = -18.805847167969 <Degrees> Unlutted = 1 LutInversionTable = $messenger/calibration/LUT_INVERT/MDISLUTINV_0.TAB -# added to allow for testing +/* added to allow for testing */ LineExposureDuration = 1000 End_Group @@ -113,10 +113,10 @@ def test_spacecraft_clock_stop_count(test_cube_label): assert test_cube_label.spacecraft_clock_stop_count == "1/0089576657:990000" def test_utc_start_time(test_cube_label): - assert test_cube_label.utc_start_time == datetime(2007, 6, 6, 00, 22, 10, 751814) + assert test_cube_label.utc_start_time == datetime(2007, 6, 6, 00, 22, 10, 751814, timezone.utc) def test_utc_stop_time(test_cube_label): - assert test_cube_label.utc_stop_time == datetime(2007, 6, 6, 00, 22, 10, 768814) + assert test_cube_label.utc_stop_time == datetime(2007, 6, 6, 00, 22, 10, 768814, timezone.utc) def test_target_name(test_cube_label): assert test_cube_label.target_name.lower() == "venus" diff --git a/tests/pytests/test_kaguya_drivers.py b/tests/pytests/test_kaguya_drivers.py index 6b6b4239584e058a0aafc66765439a838d10ad54..3b8b70bd9b600512370d2a24047739ab27fde7a5 100644 --- a/tests/pytests/test_kaguya_drivers.py +++ b/tests/pytests/test_kaguya_drivers.py @@ -1,7 +1,7 @@ import pytest import os import numpy as np -import datetime +from datetime import datetime, timezone import spiceypy as spice from importlib import reload import json @@ -56,10 +56,10 @@ class test_pds_naif(unittest.TestCase): assert self.driver.short_mission_name == 'selene' def test_utc_start_time(self): - assert self.driver.utc_start_time == datetime.datetime(2009, 4, 5, 20, 9, 53, 607478, tzinfo=datetime.timezone.utc) + assert self.driver.utc_start_time == datetime(2009, 4, 5, 20, 9, 53, 607478, timezone.utc) def test_utc_stop_time(self): - assert self.driver.utc_stop_time == datetime.datetime(2009, 4, 5, 20, 10, 23, 864978, tzinfo=datetime.timezone.utc) + assert self.driver.utc_stop_time == datetime(2009, 4, 5, 20, 10, 23, 864978, timezone.utc) def test_instrument_id(self): assert self.driver.instrument_id == 'LISM_TC1_STF' diff --git a/tests/pytests/test_pds3_label.py b/tests/pytests/test_pds3_label.py index 944650316864f6eabfa1806a72f169699f5483d7..5ea655cc288dec1e6f13692f6599670258a2de87 100644 --- a/tests/pytests/test_pds3_label.py +++ b/tests/pytests/test_pds3_label.py @@ -1,7 +1,7 @@ import pytest import pvl -from datetime import datetime +from datetime import datetime, timezone import ale from ale import base from ale.base.label_pds3 import Pds3Label @@ -84,10 +84,10 @@ def test_instrument_host_name(test_image_label): assert test_image_label.instrument_host_name.lower() == 'mars reconnaissance orbiter' def test_utc_start_time(test_image_label): - assert test_image_label.utc_start_time == datetime(2006, 11, 1, 22, 45, 53, 570000) + assert test_image_label.utc_start_time == datetime(2006, 11, 1, 22, 45, 53, 570000, timezone.utc) def test_utc_stop_time(test_image_label): - assert test_image_label.utc_stop_time == datetime(2006, 11, 1, 23, 49, 50, 370000) + assert test_image_label.utc_stop_time == datetime(2006, 11, 1, 23, 49, 50, 370000, timezone.utc) def test_image_lines(test_image_label): assert test_image_label.image_lines == 2432