Commit 3b44dd96 authored by acpaquette's avatar acpaquette Committed by GitHub
Browse files

Pvl 1.0.0 Update (#373)

* Error throw changed from ParseError to LexemError

* Fixed label comments to be pvl comments not python comments

* Updated isis label parse to use the ISISGrammar and removed + from reserved characters

* Fixed dawn and kaguya drivers

* A small PVL fix and a bunch of datetime related fixes

* Added pytz to the environment file

* Removed strict argument from pvl.loads

* Fixed another collections call
parent c3a602a5
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -79,7 +79,7 @@ def parse_table(table_label, data):
            offset += data_sizes[field['Type']] * field['Size']
            offset += data_sizes[field['Type']] * field['Size']


    # Parse the keywords from the label
    # 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
    return results


+5 −4
Original line number Original line Diff line number Diff line
@@ -10,10 +10,11 @@ class IsisLabel():
        if not hasattr(self, "_label"):
        if not hasattr(self, "_label"):
            if isinstance(self._file, pvl.PVLModule):
            if isinstance(self._file, pvl.PVLModule):
                self._label = self._file
                self._label = self._file
            grammar = pvl.grammar.ISISGrammar()
            try:
            try:
                self._label = pvl.loads(self._file)
                self._label = pvl.loads(self._file, grammar=grammar)
            except Exception:
            except Exception:
                self._label = pvl.load(self._file)
                self._label = pvl.load(self._file, grammar=grammar)
            except:
            except:
                raise ValueError("{} is not a valid label".format(self._file))
                raise ValueError("{} is not a valid label".format(self._file))
        return self._label
        return self._label
@@ -236,7 +237,7 @@ class IsisLabel():
        if 'ExposureDuration' in self.label['IsisCube']['Instrument']:
        if 'ExposureDuration' in self.label['IsisCube']['Instrument']:
            exposure_duration = self.label['IsisCube']['Instrument']['ExposureDuration']
            exposure_duration = self.label['IsisCube']['Instrument']['ExposureDuration']
            # Check for units on the PVL keyword
            # 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
                units = exposure_duration.units
                if "ms" in units.lower() or 'milliseconds' in units.lower():
                if "ms" in units.lower() or 'milliseconds' in units.lower():
                    exposure_duration = exposure_duration.value * 0.001
                    exposure_duration = exposure_duration.value * 0.001
@@ -261,7 +262,7 @@ class IsisLabel():
          Line exposure duration in seconds
          Line exposure duration in seconds
        """
        """
        line_exposure_duration = self.label['IsisCube']['Instrument']['LineExposureDuration']
        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
            units = line_exposure_duration.units
            if "ms" in units.lower():
            if "ms" in units.lower():
                line_exposure_duration = line_exposure_duration.value * 0.001
                line_exposure_duration = line_exposure_duration.value * 0.001
+1 −1
Original line number Original line Diff line number Diff line
@@ -12,7 +12,7 @@ class Pds3Label():
                self._label = self._file
                self._label = self._file
            else:
            else:
                try:
                try:
                    self._label = pvl.loads(self._file, strict=False)
                    self._label = pvl.loads(self._file)
                except Exception:
                except Exception:
                    self._label = pvl.load(self._file)
                    self._label = pvl.load(self._file)
                except:
                except:
+0 −31
Original line number Original line Diff line number Diff line
@@ -39,37 +39,6 @@ class DawnFcPds3NaifSpiceDriver(Framer, Pds3Label, NaifSpice, Driver):


        return "{}_FILTER_{}".format(ID_LOOKUP[instrument_id], filter_number)
        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
    @property
    def spacecraft_name(self):
    def spacecraft_name(self):
        """
        """
+2 −2
Original line number Original line Diff line number Diff line
@@ -616,7 +616,7 @@ class LroMiniRfIsisLabelNaifSpiceDriver(Radar, NaifSpice, IsisLabel, Driver):
        : float
        : float
          start time
          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
    @property
    def ephemeris_stop_time(self):
    def ephemeris_stop_time(self):
@@ -628,7 +628,7 @@ class LroMiniRfIsisLabelNaifSpiceDriver(Radar, NaifSpice, IsisLabel, Driver):
        : float
        : float
          stop time
          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
    @property
    def look_direction(self):
    def look_direction(self):
Loading