Unverified Commit 92c1cf15 authored by acpaquette's avatar acpaquette Committed by GitHub
Browse files

HiRISE IsisLabel NaifSpice Driver (#471)

* Added initial working mro hirise driver

* Fixed error messaging in frame trace

* Added mro hirise tests
parent 3c1bb737
Loading
Loading
Loading
Loading
+144 −0
Original line number Diff line number Diff line
@@ -8,6 +8,8 @@ from ale.base.label_isis import IsisLabel
from ale.base.type_distortion import RadialDistortion
from ale.base.type_sensor import LineScanner

from ale import util


class MroCtxIsisLabelIsisSpiceDriver(LineScanner, IsisLabel, IsisSpice, RadialDistortion, Driver):

@@ -255,3 +257,145 @@ class MroCtxPds3LabelNaifSpiceDriver(LineScanner, Pds3Label, NaifSpice, RadialDi
          platform name
        """
        return self.label['SPACECRAFT_NAME']

hirise_ccd_lookup = {
  0: 0,
  1: 1,
  2: 2,
  3: 3,
  4: 12,
  5: 4,
  6: 10,
  7: 11,
  8: 5,
  9: 13,
  10: 6,
  11: 7,
  12: 8,
  13: 9
}

class MroHiRiseIsisLabelNaifSpiceDriver(LineScanner, IsisLabel, NaifSpice, RadialDistortion, Driver):
    """
    Driver for reading HiRise ISIS labels.
    """

    @property
    def instrument_id(self):
        """
        Returns an instrument id for uniquely identifying the instrument, but often
        also used to be piped into Spice Kernels to acquire IKIDs. Therefore they
        the same ID the Spice expects in bods2c calls.
        Expects instrument_id to be defined in the IsisLabel mixin. This should be
        a string of the form 'CTX'

        Returns
        -------
        : str
          instrument id
        """
        id_lookup = {
            "HIRISE" : "MRO_HIRISE"
        }
        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 "HIRISE CAMERA"


    @property
    def un_binned_rate(self):
        if not hasattr(self, "_un_binned_rate"):
            delta_line_timer_count = self.label["IsisCube"]["Instrument"]["DeltaLineTimerCount"]
            self._un_binned_rate = (74.0 + (delta_line_timer_count / 16.0)) / 1000000.0
        return self._un_binned_rate

    @property
    def ephemeris_start_time(self):
        if not hasattr(self, "_ephemeris_start_time"):
            tdi_mode = self.label["IsisCube"]["Instrument"]["Tdi"]
            bin_mode = self.label["IsisCube"]["Instrument"]["Summing"]
            # Code replicated from the ISIS HiRise Camera Model

            # The -74999 is the code to select the transformation from
            # high-precision MRO SCLK to ET
            start_time = spice.scs2e(-74999, self.spacecraft_clock_start_count)
            # Adjust the start time so that it is the effective time for
            # the first line in the image file.  Note that on 2006-03-29, this
            # time is now subtracted as opposed to adding it.  The computed start
            # time in the EDR is at the first serial line.
            start_time -= self.un_binned_rate * ((tdi_mode / 2.0) - 0.5);
            # Effective observation
            # time for all the TDI lines used for the
            # first line before doing binning
            start_time += self.un_binned_rate * ((bin_mode / 2.0) - 0.5);
            self._ephemeris_start_time = start_time
        return self._ephemeris_start_time

    @property
    def exposure_duration(self):
        if not hasattr(self, "_exposure_duration"):
            self._exposure_duration = self.un_binned_rate * self.label["IsisCube"]["Instrument"]["Summing"]
        return self._exposure_duration

    @property
    def ccd_ikid(self):
        ccd_number = hirise_ccd_lookup[self.label["IsisCube"]["Instrument"]["CpmmNumber"]]
        return spice.bods2c("MRO_HIRISE_CCD{}".format(ccd_number))

    @property
    def sensor_frame_id(self):
        return -74690

    @property
    def detector_center_sample(self):
        """
        Returns the center detector sample. Expects ikid to be defined. This should
        be an integer cont?aining the Naif Id code of the instrument.

        Returns
        -------
        : float
          Detector sample of the principal point
        """
        return 0

    @property
    def detector_center_line(self):
        """
        Returns the center detector line. Expects ikid to be defined. This should
        be an integer containing the Naif Id code of the instrument.

        Returns
        -------
        : float
          Detector line of the principal point
        """
        return 0

    @property
    def naif_keywords(self):
        """
        Updated set of naif keywords containing the NaifIkCode for the specific
        Juno filter used when taking the image.

        Returns
        -------
        : dict
          Dictionary of keywords and values that ISIS creates and attaches to the label
        """
        return {**super().naif_keywords, **util.query_kernel_pool(f"*{self.ccd_ikid}*")}

    @property
    def sensor_model_version(self):
        """
        Returns
        -------
        : int
          ISIS sensor model version
        """
        return 1
+8 −8
Original line number Diff line number Diff line
@@ -161,22 +161,22 @@ class FrameChain(nx.DiGraph):
                try:
                    matrix, frame_code = spice.ckfrot(frame_type_id, ephemeris_time)
                except:
                    raise Exception(f"The ck rotation from frame {frame_codes[-1]} can not \
                                      be found due to no pointing available at requested time \
                                      or a problem with the frame")
                    raise Exception(f"The ck rotation from frame {frame_codes[-1]} can not " +
                                    f"be found due to no pointing available at requested time {ephemeris_time} " +
                                     "or a problem with the frame")
            elif frame_type == 4:
                try:
                    matrix, frame_code = spice.tkfram(frame_type_id)
                except:
                    raise Exception(f"The tk rotation from frame {frame_codes[-1]} can not \
                                      be found")
                    raise Exception(f"The tk rotation from frame {frame_codes[-1]} can not " +
                                     "be found")
            elif frame_type == 5:
                matrix, frame_code = spice.zzdynrot(frame_type_id, center, ephemeris_time)

            else:
                raise Exception(f"The frame {frame_codes[-1]} has a type {frame_type_id} \
                                  not supported by your version of Naif Spicelib. \
                                  You need to update.")
                raise Exception(f"The frame {frame_codes[-1]} has a type {frame_type_id} " +
                                  "not supported by your version of Naif Spicelib. " +
                                  "You need to update.")

            frame_codes.append(frame_code)
            frame_types.append(frame_type)
+565 −0

File added.

Preview size limit exceeded, changes collapsed.

+1956 −0

File added.

Preview size limit exceeded, changes collapsed.

+223 −0
Original line number Diff line number Diff line
Object = IsisCube
  Object = Core
    StartByte   = 65537
    Format      = Tile
    TileSamples = 256
    TileLines   = 1000

    Group = Dimensions
      Samples = 256
      Lines   = 5000
      Bands   = 1
    End_Group

    Group = Pixels
      Type       = SignedWord
      ByteOrder  = Lsb
      Base       = 0.0
      Multiplier = 1.0
    End_Group
  End_Object

  Group = Instrument
    SpacecraftName              = "MARS RECONNAISSANCE ORBITER"
    InstrumentId                = HIRISE
    TargetName                  = Mars
    StartTime                   = 2006-11-17T03:27:53.118
    StopTime                    = 2006-11-17T03:27:54.792
    ObservationStartCount       = 848201291:54379
    SpacecraftClockStartCount   = 848201291:62546
    SpacecraftClockStopCount    = 848201293:41165
    ReadoutStartCount           = 848201300:53057
    CalibrationStartTime        = 2006-11-17T03:27:53.104
    CalibrationStartCount       = 848201291:61647
    AnalogPowerStartTime        = -9999
    AnalogPowerStartCount       = -9999
    MissionPhaseName            = "PRIMARY SCIENCE PHASE"
    LineExposureDuration        = 334.7500 <MICROSECONDS>
    ScanExposureDuration        = 83.6875 <MICROSECONDS>
    DeltaLineTimerCount         = 155
    Summing                     = 4
    Tdi                         = 64
    FocusPositionCount          = 2020
    PoweredCpmmFlag             = (On, On, On, On, On, On, On, On, On, On, On,
                                   On, On, On)
    CpmmNumber                  = 4
    CcdId                       = BG12
    ChannelNumber               = 0
    LookupTableType             = Stored
    LookupTableNumber           = 10
    LookupTableMinimum          = -9998
    LookupTableMaximum          = -9998
    LookupTableMedian           = -9998
    LookupTableKValue           = -9998
    StimulationLampFlag         = (Off, Off, Off)
    HeaterControlFlag           = (On, On, On, On, On, On, On, On, On, On, On,
                                   On, On, On)
    OptBnchFlexureTemperature   = 20.455 <C>
    OptBnchMirrorTemperature    = 20.1949 <C>
    OptBnchFoldFlatTemperature  = 20.5417 <C>
    OptBnchFpaTemperature       = 19.8482 <C>
    OptBnchFpeTemperature       = 19.5881 <C>
    OptBnchLivingRmTemperature  = 20.1949 <C>
    OptBnchBoxBeamTemperature   = 20.455 <C>
    OptBnchCoverTemperature     = 20.1082 <C>
    FieldStopTemperature        = 18.375 <C>
    FpaPositiveYTemperature     = 19.1548 <C>
    FpaNegativeYTemperature     = 19.0681 <C>
    FpeTemperature              = 17.9418 <C>
    PrimaryMirrorMntTemperature = 20.0215 <C>
    PrimaryMirrorTemperature    = 20.3683 <C>
    PrimaryMirrorBafTemperature = 0.414005 <C>
    MsTrussLeg0ATemperature     = 20.3683 <C>
    MsTrussLeg0BTemperature     = 20.5417 <C>
    MsTrussLeg120ATemperature   = 19.5881 <C>
    MsTrussLeg120BTemperature   = 20.2816 <C>
    MsTrussLeg240ATemperature   = 19.6748 <C>
    MsTrussLeg240BTemperature   = 19.9348 <C>
    BarrelBaffleTemperature     = -21.006 <C>
    SunShadeTemperature         = -28.7562 <C>
    SpiderLeg30Temperature      = 17.7686 <C>
    SpiderLeg150Temperature     = 18.2883 <C>
    SpiderLeg270Temperature     = 17.1623 <C>
    SecMirrorMtrRngTemperature  = 19.5881 <C>
    SecMirrorTemperature        = 20.7151 <C>
    SecMirrorBaffleTemperature  = -18.7871 <C>
    IeaTemperature              = 25.8353 <C>
    FocusMotorTemperature       = 21.4088 <C>
    IePwsBoardTemperature       = 17.7363 <C>
    CpmmPwsBoardTemperature     = 18.078 <C>
    MechTlmBoardTemperature     = 35.0546 <C>
    InstContBoardTemperature    = 34.6875 <C>
    DllLockedFlag               = (YES, YES)
    DllResetCount               = 0
    DllLockedOnceFlag           = (YES, YES)
    DllFrequenceCorrectCount    = 4
    ADCTimingSetting            = (5, 4)
    Unlutted                    = TRUE
  End_Group

  Group = Archive
    DataSetId              = MRO-M-HIRISE-2-EDR-V1.0
    ProducerId             = UA
    ObservationId          = PSP_001446_1790
    ProductId              = PSP_001446_1790_BG12_0
    ProductVersionId       = 1.0
    EdrProductCreationTime = 2006-11-17T05:03:31
    RationaleDescription   = Null
    OrbitNumber            = 1446
    SoftwareName           = "HiRISE_Observation v2.9 (2.43 2006/10/01
                              05:41:12)"
    ObservationStartTime   = 2006-11-17T03:27:52.993
    ReadoutStartTime       = 2006-11-17T03:28:01.973
    TrimLines              = 607
    FelicsCompressionFlag  = YES
    IdFlightSoftwareName   = IE_FSW_V4
  End_Group

  Group = BandBin
    Name   = BlueGreen
    Center = 500 <NANOMETERS>
    Width  = 200 <NANOMETERS>
  End_Group

  Group = Kernels
    NaifIkCode = -74699
  End_Group
End_Object

Object = Label
  Bytes = 65536
End_Object

Object = Table
  Name      = "HiRISE Calibration Ancillary"
  StartByte = 2626071
  Bytes     = 4920
  Records   = 41
  ByteOrder = Lsb

  Group = Field
    Name = GapFlag
    Type = Integer
    Size = 1
  End_Group

  Group = Field
    Name = LineNumber
    Type = Integer
    Size = 1
  End_Group

  Group = Field
    Name = BufferPixels
    Type = Integer
    Size = 12
  End_Group

  Group = Field
    Name = DarkPixels
    Type = Integer
    Size = 16
  End_Group
End_Object

Object = Table
  Name      = "HiRISE Calibration Image"
  StartByte = 2630991
  Bytes     = 41984
  Records   = 41
  ByteOrder = Lsb

  Group = Field
    Name = Calibration
    Type = Integer
    Size = 256
  End_Group
End_Object

Object = Table
  Name        = "HiRISE Ancillary"
  StartByte   = 2672975
  Bytes       = 600000
  Records     = 5000
  ByteOrder   = Lsb
  Association = Lines

  Group = Field
    Name = GapFlag
    Type = Integer
    Size = 1
  End_Group

  Group = Field
    Name = LineNumber
    Type = Integer
    Size = 1
  End_Group

  Group = Field
    Name = BufferPixels
    Type = Integer
    Size = 12
  End_Group

  Group = Field
    Name = DarkPixels
    Type = Integer
    Size = 16
  End_Group
End_Object

Object = History
  Name      = IsisCube
  StartByte = 2625537
  Bytes     = 534
End_Object

Object = OriginalLabel
  Name      = IsisCube
  StartByte = 3272975
  Bytes     = 25216
End_Object
End
Loading