Commit 50ec6aee authored by Jesse Mapel's avatar Jesse Mapel Committed by GitHub
Browse files

Fixes to the ISIS label mix-in and CTX driver (#192)

* Updated ISIS Label mix-in

* More updates for CTX from ISIS labels

* typo fix

* Fixed an issue with exposure duration

* Cleaned up unit conversion
parent f4a07391
Loading
Loading
Loading
Loading
+80 −17
Original line number Diff line number Diff line
@@ -132,13 +132,60 @@ class IsisLabel():
        : str
          Spacecraft clock start count
        """
        try:
            start_count = self.label['IsisCube']['Instrument']['SpacecraftClockStartCount']
        if 'SpacecraftClockStartCount' in self.label['IsisCube']['Instrument']:
            return self.label['IsisCube']['Instrument']['SpacecraftClockStartCount']
        elif 'SpacecraftClockCount' in self.label['IsisCube']['Instrument']:
            return self.label['IsisCube']['Instrument']['SpacecraftClockCount']
        elif 'SpacecraftClockStartCount' in self.label['IsisCube']['Archive']:
            return self.label['IsisCube']['Archive']['SpacecraftClockStartCount']
        else:
            return None

        except:
            start_count = self.label['IsisCube']['Archive']['SpacecraftClockStartCount']
    @property
    def spacecraft_clock_stop_count(self):
        """
        The spacecraft clock stop count, frequently used to determine the stop time
        of the image.

        Returns
        -------
        : str
          Spacecraft clock stop count
        """
        if 'SpacecraftClockStopCount' in self.label['IsisCube']['Instrument']:
            return self.label['IsisCube']['Instrument']['SpacecraftClockStopCount']
        elif 'SpacecraftClockStopCount' in self.label['IsisCube']['Archive']:
            return self.label['IsisCube']['Archive']['SpacecraftClockStopCount']
        else:
            return None

    @property
    def utc_start_time(self):
        """
        The UTC start time of the image.
        This is generally less accurate than converting the spacecraft start
        clock count using the spacecraft clock kernel (SCLK).

        Returns
        -------
        : datetime
          Start time of the image in UTC
        """
        return self.label['IsisCube']['Instrument']['StartTime']

        return start_count
    @property
    def utc_stop_time(self):
        """
        The UTC stop time of the image.
        This is generally less accurate than converting the spacecraft stop
        clock count using the spacecraft clock kernel (SCLK).

          Returns
        -------
        : datetime
          Stop time of the image in UTC
        """
        return self.label['IsisCube']['Instrument']['StopTime']

    @property
    def exposure_duration(self):
@@ -150,17 +197,22 @@ class IsisLabel():
        : float
          Exposure duration in seconds
        """
        try:
            units = self.label['IsisCube']['Instrument']['ExposureDuration'].units
        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):
                units = exposure_duration.units
                if "ms" in units.lower():
                exposure_duration = self.label['IsisCube']['Instrument']['ExposureDuration'].value * 0.001
                    exposure_duration = exposure_duration.value * 0.001
                else:
                    # if not milliseconds, the units are probably seconds
                exposure_duration = self.label['IsisCube']['Instrument']['ExposureDuration'].value
        except:
                    exposure_duration = exposure_duration.value
            else:
                # if no units are available, assume the exposure duration is given in milliseconds
            exposure_duration = self.label['IsisCube']['Instrument']['ExposureDuration'].value * 0.001
                exposure_duration = exposure_duration * 0.001
            return exposure_duration
        else:
            return self.line_exposure_duration

    @property
    def line_exposure_duration(self):
@@ -172,4 +224,15 @@ class IsisLabel():
        : float
          Line exposure duration in seconds
        """
        return self.label['IsisCube']['Instrument']['LineExposureDuration'] * 0.001 # scale to seconds
        line_exposure_duration = self.label['IsisCube']['Instrument']['LineExposureDuration']
        if isinstance(line_exposure_duration, pvl._collections.Units):
            units = line_exposure_duration.units
            if "ms" in units.lower():
                line_exposure_duration = line_exposure_duration.value * 0.001
            else:
                # if not milliseconds, the units are probably seconds
                line_exposure_duration = line_exposure_duration.value
        else:
            # if no units are available, assume the exposure duration is given in milliseconds
            line_exposure_duration = line_exposure_duration * 0.001
        return line_exposure_duration
+17 −1
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@ class MroCtxIsisLabelNaifSpiceDriver(IsisLabel, NaifSpice, LineScanner, RadialDi
        if not hasattr(self, '_metakernel'):
            self._metakernel = None
            for mk in mks:
                if str(self.start_time.year) in os.path.basename(mk):
                if str(self.utc_start_time.year) in os.path.basename(mk):
                    self._metakernel = mk
        return self._metakernel

@@ -105,6 +105,13 @@ class MroCtxIsisLabelNaifSpiceDriver(IsisLabel, NaifSpice, LineScanner, RadialDi
        }
        return id_lookup[super().instrument_id]

    @property
    def sensor_name(self):
        """
        ISIS doesn't propergate this to the ingested cube label, so hard-code it.
        """
        return "CONTEXT CAMERA"

    @property
    def ephemeris_start_time(self):
        """
@@ -122,6 +129,15 @@ class MroCtxIsisLabelNaifSpiceDriver(IsisLabel, NaifSpice, LineScanner, RadialDi
            self._ephemeris_start_time = spice.scs2e(self.spacecraft_id, sclock)
        return self._ephemeris_start_time

    @property
    def ephemeris_stop_time(self):
        """
        ISIS doesn't preserve the spacecraft stop count that we can use to get
        the ephemeris stop time of the image, so compute the epehemris stop time
        from the start time and the exposure duration.
        """
        return self.ephemeris_start_time + self.exposure_duration * self.image_lines

    @property
    def spacecraft_name(self):
        """
+10 −0
Original line number Diff line number Diff line
import pytest
import pvl
from datetime import datetime

import ale
from ale import base
@@ -108,6 +109,15 @@ def test_isis_label(test_cube_label):
def test_spacecraft_clock_start_count(test_cube_label):
    assert test_cube_label.spacecraft_clock_start_count == "1/0089576657:973000"

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)

def test_utc_stop_time(test_cube_label):
    assert test_cube_label.utc_stop_time == datetime(2007, 6, 6, 00, 22, 10, 768814)

def test_target_name(test_cube_label):
    assert test_cube_label.target_name.lower() == "venus"