Commit 516ba90b authored by Jesse Mapel's avatar Jesse Mapel Committed by GitHub
Browse files

Updated MDIS test to use portions of actual kernels and an actual image label (#249)

* Sample MDIS test

* All tests at least running

* Tests now passing with relative paths

* Removed leftover code

* Removed leftover code

* added DS_Store to gitignore

* added binary kernels to git ignore

* Moved getting kernels and converting to binary to conftest

* Updated after merge from upstream

* Fixed multiple assignment

* Removed extra slice assignment

* Cleaned up convert_kernels
parent b2e61155
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -205,3 +205,10 @@ dmypy.json

# Jupyter ignores
.ipynb_checkpoints

# Mac ignores
.DS_Store

# Binary Kernels
*.bsp
*.bc
+6 −3
Original line number Diff line number Diff line
@@ -284,8 +284,11 @@ class NaifSpice():
                                     self.reference_frame,
                                     self.light_time_correction,
                                     self.target_name)
        positions = 1000 * np.asarray([sun_state[:3]])
        velocities = 1000 * np.asarray([sun_state[3:6]])
        times = np.asarray([self.center_ephemeris_time])

        return [sun_state[:4].tolist()], [sun_state[3:6].tolist()], [self.center_ephemeris_time]
        return positions, velocities, times

    @property
    def sensor_position(self):
@@ -432,7 +435,7 @@ class NaifSpice():
        naif_keywords['INS{}_ITRANSL'.format(self.ikid)] = self.focal2pixel_lines
        naif_keywords['INS{}_ITRANSS'.format(self.ikid)] = self.focal2pixel_samples
        naif_keywords['INS{}_FOCAL_LENGTH'.format(self.ikid)] = self.focal_length
        naif_keywords['INS{}_BORESIGHT_SAMPLE'.format(self.ikid)] = self.detector_center_sample
        naif_keywords['INS{}_BORESIGHT_LINE'.format(self.ikid)] = self.detector_center_line
        naif_keywords['INS{}_BORESIGHT_SAMPLE'.format(self.ikid)] = self.detector_center_sample + 0.5
        naif_keywords['INS{}_BORESIGHT_LINE'.format(self.ikid)] = self.detector_center_line + 0.5

        return naif_keywords
+13 −1
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ class MessengerMdisPds3NaifSpiceDriver(Framer, Pds3Label, NaifSpice, Driver):
        : double
          focal length in meters
        """
        coeffs = spice.gdpool('INS{}_FL_TEMP_COEFFS '.format(self.fikid), 0, 5)
        coeffs = spice.gdpool('INS{}_FL_TEMP_COEFFS '.format(self.fikid), 0, 6)

        # reverse coeffs, MDIS coeffs are listed a_0, a_1, a_2 ... a_n where
        # numpy wants them a_n, a_n-1, a_n-2 ... a_0
@@ -207,6 +207,18 @@ class MessengerMdisPds3NaifSpiceDriver(Framer, Pds3Label, NaifSpice, Driver):
                }
            }

    @property
    def pixel_size(self):
        """
        Overriden because the MESSENGER IK uses PIXEL_PITCH and the units
        are already millimeters

        Returns
        -------
        : float pixel size
        """
        return spice.gdpool('INS{}_PIXEL_PITCH'.format(self.ikid), 0, 1)


class MessengerMdisIsisLabelNaifSpiceDriver(IsisLabel, NaifSpice, Framer, Driver):
    """
+74 −4
Original line number Diff line number Diff line
import subprocess
import os
import numpy as np
import ale

class SimpleSpice():
    def scs2e(self, *args):
@@ -31,10 +34,77 @@ class SimpleSpice():
        return 0.1
    def cidfrm(self, *args):
        return (2000, "Test_Body_Frame", True)
    def furnsh(self, *args):
        if not hasattr(self, '_loaded_kernels'):
            self._loaded_kernels = []
        self._loaded_kernels.append(args)

def get_mockkernels(self, *args):
    return "some_metakernel"

ale_root = os.path.split(ale.__file__)[0]
data_root = os.path.join(ale_root, '../tests/pytests/data')
dirs = next(os.walk(data_root, topdown=True))[1]
dirs = [d for d in dirs if not d.startswith('.')]
image_2_data = {}

for d in dirs:
    tmp = os.path.join(data_root, d)
    image_2_data[d] = [os.path.join(tmp, f) for f in os.listdir(tmp) if not f.startswith('.')]

def get_image_kernels(image):
    """
    Get the kernels to use with a test image.

    Parameters
    ----------
    image : str
            The image name to get kernels for. I.E. 'EN1072174528M'

    Returns
    -------
    : list
      A list containing the absolute paths to the kernels for the images.
      This list contains all of the kernel files available in the test image's
      data directory which may contain transfer files that need to be converted
      to binary files.
    """
    if not isinstance(image, str):
        try:
            image = str(image)
        except:
            raise KeyError('Cannot coerce requested image name to string')
    if image in image_2_data:
        return image_2_data[image]
    else:
        raise KeyError('Could not find test data for' + image)

def convert_kernels(kernels):
    """
    Convert any transfer kernels in a list to binary kernels

    Parameters
    ----------
    kernels : list
              A list of kernels. Only transfer kernels present in the list will
              be converted. Non-transfer kernels will be ignored.

    Returns
    -------
    updated_kernels : list
                      The updated kernel list where all transfer kernels have
                      been replaced with their converted binary kernel. This
                      is designed to be passed directly to furnsh.
    binary_kernels : list
                     The list of binary kernels created.
    """
    ext_map = {
        '.xc' : '.bc',
        '.xsp' : '.bsp'
    }
    binary_kernels = []
    updated_kernels = []
    for kernel in kernels:
        split_kernel = os.path.splitext(kernel)
        if split_kernel[1] in ext_map:
            subprocess.call(['tobin', os.path.join(data_root, kernel)])
            kernel = split_kernel[0] + ext_map[split_kernel[1]]
            binary_kernels.append(kernel)
        updated_kernels.append(kernel)
    return updated_kernels, binary_kernels
+125 −0
Original line number Diff line number Diff line
Messenger/MDIS Instrument Kernel
=============================================================

This instrument kernel (I-kernel) contains parameters that
describe the Messenger MDIS narrow angle (NAC) and wide angle (WAC)
camera

Version and Date
-------------------------------------------------------------

Version 2.0 -- July 31, 2005 -- Kris Becker, U.S. Geological Survey,
    Flagstaff, AZ
    Initial version.

Version 3.0 -- April 24, 2007 -- Kris Becker, U.S. Geological Survey,
    Updated for modifications/refinements to the framing kernel.  These
    changes were introduced in msgr_v070.tf.

Version 4.0 -- December 06, 2007 -- Kris Becker, U.S. Geological Survey,
    Added initial camera distortion parameter for both NAC and WAC as
    well as update the focal lengths.  This model is provided courtesy
    of Scott Turner, JHU, on 2007/12/03.

Version 5.0 -- January 17, 2008 - Kris Becker, U.S. Geological Survey
    Turns out the MDIS WAC has different focal lengths for each
    of the 12 filters.  The distortion model development was done
    using filter 2, the clear filter.  The other filter focal lengths
    are derived from the ratio of the published (SIS) length and
    the new focal lenght of filter 2.

Version 6.0 -- September 30, 2009 -- Kris Becker, U.S. Geological Survey
    Greatly slimmed down version since much of the keywords in previous
    versions has now been incorporated in the newest instrument kernel (IK),
    msgr_mdis_v110.ti.

Version 7.0 -- January 12, 2010 -- Debbie A. Cook, U.S. Geological Survey
    Update to include CK_FRAME_ID and CK_REFERENCE_ID

$Id: mdisAddendumXXX.ti,v 1.3 2008/01/18 13:30:30 kbecker Exp $
-------------------------------------------------------------

The following is the definitions for the MDIS Narrow Angle Camera (MDIS-NAC).
Some missions use have time offsets that are needed in order to correct for
timing into the SPICE kernels.  Set the CK time tolerances used when searching
for camera pointing attitude in the CK kernels.

SPK and CK time biases are used in cases where an offset exists in these
kernels in relation to spacecraft clock time.  These times are expressed in
seconds.  The CK_TIME_TOLERANCE is used as a direct argument in the NAIF
routine (ckpg_c) that finds camera pointing.  This is expressed in spacecraft
clock ticks.

\begindata
INS-236820_SPK_TIME_BIAS      = 0.0
INS-236820_CK_TIME_BIAS       = 0.0
INS-236820_CK_TIME_TOLERANCE  = 1

\begintext

The REFERENCE_FRAME and FRAME are used to specify the frames that translate
from spacecraft instrument platform to the instrument orientation.  These
are specific to each mission and are defined in the frame kernel (FK).
For MESSENGER, these are defined in msgr_v???.tf.

\begindata
INS-236820_REFERENCE_FRAME    = 'MSGR_SPACECRAFT'

INS-236820_BORESIGHT_SAMPLE   = 512.5
INS-236820_BORESIGHT_LINE     = 512.5

\begintext
These are the parameters required for writing c-kernels.  Isis will
create ck with the same frame endpoints as the mission ck.  For 
Messenger the ck instrument frame is MSGR_SPACECRAFT (-236000), and the
ck reference frame is J2000 (1).

\begindata
INS-236820_CK_FRAME_ID=-236000
INS-236820_CK_REFERENCE_ID=1

\begintext
This is the description of the Messenger MDIS wide angle camera (MDIS-WAC).
It has twelve filters on a wheel, however, the transforms for pixel/detector
coordinates are independantly defined to simplify maintainance of these
values should the need arise during flight.

\begindata
INS-236800_SPK_TIME_BIAS     = 0.0
INS-236800_CK_TIME_BIAS      = 0
INS-236800_CK_TIME_TOLERANCE = 1

INS-236800_REFERENCE_FRAME    = 'MSGR_SPACECRAFT'

INS-236800_BORESIGHT_SAMPLE   = 512.5
INS-236800_BORESIGHT_LINE     = 512.5

\begintext
These are the parameters required for writing c-kernels.  Isis will
create ck with the same frame endpoints as the mission ck.  For 
Messenger the ck instrument frame is MSGR_SPACECRAFT (-236000), and the
ck reference frame is J2000 (1).

\begindata
INS-236800_CK_FRAME_ID=-236000
INS-236800_CK_REFERENCE_ID=1

\begintext
OBSERVER/TARGET SWAPPING and STELLAR ABERRATION and LIGHT TIME CORRECTION

These parameters set MESSENGER MDIS WAC/NAC to swap observer/target,
sets light time correction to "LT+S" and disables correction for light time to
surface.

\begindata

INS-236800_SWAP_OBSERVER_TARGET = 'TRUE'
INS-236800_LIGHTTIME_CORRECTION = 'LT+S'
INS-236800_LT_SURFACE_CORRECT = 'FALSE'

INS-236820_SWAP_OBSERVER_TARGET = 'TRUE'
INS-236820_LIGHTTIME_CORRECTION = 'LT+S'
INS-236820_LT_SURFACE_CORRECT = 'FALSE'

\begintext
Loading