Unverified Commit 4f3b906d authored by Austin Sanders's avatar Austin Sanders Committed by GitHub
Browse files

Mvic mpf driver (#485)

* Added legendre distortion model

* tests and data for mvic driver

* Initial NewHorizonsMvicIsisLabelNaifSpiceDriver

* Added missing import

* Renamed labels

* Fixed failing tests

* converted to mvic framer

* Added legendre distortion model

* tests and data for mvic driver

* Initial NewHorizonsMvicIsisLabelNaifSpiceDriver

* Added missing import

* Renamed labels

* Fixed failing tests

* Added ephemeris start/stop times

* Replaced mvic tdi isd with mvic framer isd

* Added data for mvic framer

* Updated mvic framer tests

* Address PR feedback

* deleted unused files

* Renamed mvic_isd to mvic_mpf_isd

* Address PR feedback
parent 3781ed64
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
class LegendreDistortion():
    """
    Mix-in for sensors that use a legendre distortion model.
    """

    @property
    def usgscsm_distortion_model(self):
        """
        Expects odtx and odty to be defined. These should be lists containing
        the legendre distortion coefficients

        Returns
        -------
        : dict
          Dictionary containing the usgscsm distortion model
        """
        return {
            "legendre":{
                "x_coefficients" : self.odtx,
                "y_coefficients" : self.odty
            }
        }


class RadialDistortion():
    """
    Mix-in for sensors that use a radial distortion model.
+234 −2
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ import spiceypy as spice
import numpy as np

from ale.base import Driver
from ale.base.type_distortion import NoDistortion
from ale.base.type_distortion import NoDistortion, LegendreDistortion
from ale.base.data_naif import NaifSpice
from ale.base.label_isis import IsisLabel
from ale.base.type_sensor import Framer
@@ -50,7 +50,6 @@ class NewHorizonsLorriIsisLabelNaifSpiceDriver(Framer, IsisLabel, NaifSpice, NoD
        1x1 binning: -98301
        4x4 binning: -98302


        Returns
        -------
        : integer
@@ -60,14 +59,42 @@ class NewHorizonsLorriIsisLabelNaifSpiceDriver(Framer, IsisLabel, NaifSpice, NoD

    @property
    def detector_center_line(self):
        """
        The center of the CCD in detector pixels
        Expects ikid to be defined. this should be the integer Naif ID code for
        the instrument.

        Returns
        -------
        list :
            The center of the CCD formatted as line, sample
        """
        return float(spice.gdpool('INS{}_BORESIGHT'.format(self.ikid), 0, 3)[0])

    @property
    def detector_center_sample(self):
        """
        The center of the CCD in detector pixels
        Expects ikid to be defined. this should be the integer Naif ID code for
        the instrument.

        Returns
        -------
        list :
            The center of the CCD formatted as line, sample
        """
        return float(spice.gdpool('INS{}_BORESIGHT'.format(self.ikid), 0, 3)[1])

    @property
    def sensor_name(self):
        """
        Returns the name of the instrument

        Returns
        -------
        : str
          Name of the sensor
        """
        return self.label['IsisCube']['Instrument']['SpacecraftName']

    @property
@@ -194,3 +221,208 @@ class NewHorizonsLeisaIsisLabelNaifSpiceDriver(LineScanner, IsisLabel, NaifSpice
          Exposure duration in seconds
        """
        return self.label['IsisCube']['Instrument']['ExposureDuration']


class NewHorizonsMvicIsisLabelNaifSpiceDriver(Framer, IsisLabel, NaifSpice, LegendreDistortion, Driver):
    """
    Driver for reading New Horizons MVIC ISIS3 Labels. These are Labels that have been
    ingested into ISIS from PDS EDR images but have not been spiceinit'd yet.
    """

    @property
    def parent_id(self):
        """
        The base naif id of the spacecraft.  For New Horizons, this is -98000.
        Required for distortion coefficients, which are not unique to instruments,
        but are instead shared by all instruments on the spacecraft + residuals.
        Returns
        -------
        : int
          Naif id of the spacecraft
        """
        return round(self.ikid, -2)


    @property
    def sensor_model_version(self):
        """
        Returns instrument model version
        Returns
        -------
        : int
          ISIS sensor model version
        """
        return 1


    @property
    def instrument_name(self):
        """
        The name of the instrument.  This is not included in the .fit label, but is
        present in the .lbl file, so it is not present in ISIS conversion, and it
        must be hard-coded.
        Returns
        -------
        : str
          Name of the instrument
        """
        return "MULTISPECTRAL VISIBLE IMAGING CAMERA"


    @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.
        Returns
        -------
        : str
          instrument id
        """
        id_lookup = {
          "MVIC_FRAMING" : "NH_MVIC"
        }
        return id_lookup[super().instrument_id]


    @property
    def ikid(self):
        """
        Overridden to grab the ikid from the Isis Cube since there is no way to
        obtain this value with a spice bods2c call. Isis sets this value during
        ingestion, based on the original fits file.
        Returns
        -------
        : integer
          Naif Integer ID code for the instrument
        """
        return self.label['IsisCube']['Kernels']['NaifFrameCode'][0]


    @property
    def detector_center_line(self):
        """ Returns detector center line.  This information is found in ik/nh_ralph_v100.ti, which
        is not loaded as an ik."""
        return -1


    @property
    def detector_center_sample(self):
        """ Returns detector center line.  This information is found in ik/nh_ralph_v100.ti, which
        is not loaded as an ik."""
        return 0


    @property
    def sensor_name(self):
        """
        Returns the name of the instrument
        Returns
        -------
        : str
          Name of the sensor
        """
        return self.label['IsisCube']['Instrument']['SpacecraftName']


    @property
    def odtx(self):
        """
        Returns the x coefficient for the optical distortion model
        Expects ikid to be defined. This must be the integer Naif id code of the instrument
        Returns
        -------
        : list
          Optical distortion x coefficients
        """
        return spice.gdpool('INS{}_DISTORTION_COEF_X'.format(self.parent_id),0, 20).tolist()


    @property
    def odty(self):
        """
        Returns the y coefficient for the optical distortion model.
        Expects ikid to be defined. This must be the integer Naif id code of the instrument
        Returns
        -------
        : list
          Optical distortion y coefficients
        """
        return spice.gdpool('INS{}_DISTORTION_COEF_Y'.format(self.parent_id), 0, 20).tolist()

    @property
    def band_times(self):
        if not hasattr(self, "_ephem_band_times"):
            band_times = self.label['IsisCube']['BandBin']['UtcTime']
            self._ephem_band_times = []
            for time in band_times:
                if type(time) is pvl.Quantity:
                   time = time.value
                self._ephem_band_times.append(spice.utc2et(time.strftime("%Y-%m-%d %H:%M:%S.%f")))
        return self._ephem_band_times


    @property
    def ephemeris_time(self):
        """
        Returns an array of times between the start/stop ephemeris times
        based on the number of lines in the image.
        Expects ephemeris start/stop times to be defined. These should be
        floating point numbers containing the start and stop times of the
        images.
        Expects image_lines to be defined. This should be an integer containing
        the number of lines in the image.

        Returns
        -------
        : ndarray
          ephemeris times split based on image lines
        """
        if not hasattr(self, "_ephemeris_time"):
          self._ephemeris_time = np.linspace(self.ephemeris_start_time, self.ephemeris_stop_time, self.image_lines + 1)
        return self._ephemeris_time 


    @property
    def ephemeris_start_time(self):
        """
        Returns the ephemeris start time of the image.
        Expects spacecraft_id to be defined. This should be the integer
        Naif ID code for the spacecraft.

        Returns
        -------
        : float
          ephemeris start time of the image
        """
        return self.band_times[0]


    @property
    def ephemeris_stop_time(self):
        """
        Returns the ephemeris stop time of the image.
        Expects spacecraft_id to be defined. This should be the integer
        Naif ID code for the spacecraft.

        Returns
        -------
        : float
          ephemeris stop time of the image
        """
        return self.band_times[-1]


    @property
    def naif_keywords(self):
        """
        Adds base NH instrument distortion, which is shared among all instruments on NH.
        Returns
        -------
        : dict
          Dictionary of keywords and values that ISIS creates and attaches to the label
        """
        return {**super().naif_keywords,
                f"INS{self.parent_id}_DISTORTION_COEF_X": self.odtx,
                f"INS{self.parent_id}_DISTORTION_COEF_Y": self.odty}
 No newline at end of file
+3270 −0

File added.

Preview size limit exceeded, changes collapsed.

+136 −0
Original line number Diff line number Diff line
DAFETF NAIF DAF ENCODED TRANSFER FILE
'DAF/CK  '
'2'
'6'
' < DAFCAT: CK CONCATENATION >                               '
BEGIN_ARRAY 1 115
'nhpc                                    '
'D7129C6B335^B'
'D712BD291C4^B'
'-17ED0'
'1'
'3'
'1'
115
'3541222C7874E8^0'
'-2A62D649E275CA^0'
'F3EC2A94272238^0'
'257C5FC00EFA76^0'
'-1A600588F08F2A^-3'
'130A28F352395B^-3'
'18F76CFA6C842^-4'
'355E1566128968^0'
'-2A69CFBA427C96^0'
'F3E57340DF9D9^0'
'2577030F5A5862^0'
'-33DC38D688F99E^-3'
'CAF88235126F08^-4'
'-AD8931F1833048^-5'
'354159B4EFBBDC^0'
'-2A6C536067585A^0'
'F3E6F0B376F5D^0'
'25934F4C4FFC46^0'
'64488A1DD6A81C^-4'
'-1A248844F809C3^-3'
'43D8F0822AE73^-4'
'3510044E0863DA^0'
'-2A67ED8B6346BC^0'
'F3ED5B3D264FA^0'
'25B45C75F45C82^0'
'-24711E0AC564A8^-3'
'-28B109DF586D22^-3'
'-1A25FEB8873B4^-3'
'34DFD8F30F550E^0'
'-2A628A6CEFE608^0'
'F3F3DFF897C368^0'
'25D3DD23E1AB38^0'
'-6DD152C288660C^-3'
'-261B97E3DB9C5E^-3'
'-3925C4AEBCCBC6^-3'
'34AEB3111C22BC^0'
'-2A5FFC72696D6E^0'
'F3F98E76967BA^0'
'25F69807733BE2^0'
'-4DD35FA1FF3F94^-3'
'-1AE724F4C9585^-3'
'-16FDB40D0E4007^-3'
'348AFFF922397A^0'
'-2A5F71F5DEDDA^0'
'F3FC896FC3662^0'
'261578556B6ED8^0'
'2AC1D2DB1D38FC^-3'
'-11E3398F20153^-3'
'-5FE39A8C62FB1C^-4'
'3483CF1F604F88^0'
'-2A5F89A813FD4^0'
'F3FCE7F0FAA2E8^0'
'261CEADDD748E4^0'
'-9401AC175C60F^-4'
'1496427C9129D2^-4'
'6D70E5E2FF5CC^-5'
'34A65FFF207F9E^0'
'-2A65BE1374FC5C^0'
'F3F4FA17AD1EA^0'
'2619158D461F7A^0'
'99C6712747A6B8^-4'
'1B6B63D0FCF03D^-3'
'23EF3886980DD6^-3'
'34CED6641CAC8^0'
'-2A68AE76ABD89A^0'
'F3ED5827641CE8^0'
'260EAD72265B64^0'
'-84486D81EA5948^-3'
'5AA8F009BCACB8^-4'
'-2495BA8768A4BC^-3'
'34F9603B0CADB6^0'
'-2A76D654C27832^0'
'F3E111CAD11CB^0'
'261270DEF692CE^0'
'102F71B3C3473F^-3'
'213EE43668C54E^-3'
'280235008374A4^-3'
'3522680001FFD2^0'
'-2A7FF616395D9^0'
'F3D6C49F32C598^0'
'261110E526ED42^0'
'50465B7881B344^-3'
'176D23B6E00A03^-3'
'27E005F7DE4EA^-3'
'354CDC5B5D4022^0'
'-2A84E6B87538F4^0'
'F3CE06E24B59B8^0'
'26082EA0A18F3^0'
'-17EE0CF16119EE^-3'
'110F69B7B92292^-3'
'-533C7942B7BD^-4'
'356523A1C54C4E^0'
'-2A8D629DB77E6A^0'
'F3C63629B6C8D^0'
'260EBBA2992546^0'
'31040575DBEB0E^-3'
'69F3FBDB2E462^-4'
'85F55F0A45107^-4'
'D7129C6B335^B'
'D7129E086F^B'
'D712A0E4DB^B'
'D712A3C147^B'
'D712A69DB3^B'
'D712A97A1F^B'
'D712AB8706^B'
'D712AC568B^B'
'D712AF32F7^B'
'D712B20F63^B'
'D712B4EBCF^B'
'D712B7C83B^B'
'D712BAA4A7^B'
'D712BD291C4^B'
'D7129C6B335^B'
'1^1'
'E^1'
END_ARRAY 1 115
TOTAL_ARRAYS 1
 ~NAIF/SPC BEGIN COMMENTS~
This CK is for testing with the image: /Users/arsanders/pds/nh/mvic/small/mpf/mpf_0295610274_0x539_sci_isis.cub

This CK was generated using the following command: {}
 ~NAIF/SPC END COMMENTS~
+945 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading