Commit 62c7ca78 authored by Jesse Mapel's avatar Jesse Mapel Committed by acpaquette
Browse files

Updated Kaguya test to use actual kernels (#254)

* Kaguya kernels

* Added Kaguya test

* Added debug

* Updated convert kernels to use regex

* Minor updates

* A comment

* Removed debug prints

* Updated to new parameterized fixture

* Updated with new loads logic

* Started porting test to using loads

* More test updates

* More tests

* Removed redundant tests
parent a9a55c01
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -212,3 +212,6 @@ dmypy.json
# Binary Kernels
*.bsp
*.bc

# Binary Images
*.cub
+1 −1
Original line number Diff line number Diff line
@@ -289,7 +289,7 @@ class NaifSpice():
        sun_state, _ = spice.spkezr("SUN",
                                     self.center_ephemeris_time,
                                     self.reference_frame,
                                     self.light_time_correction,
                                     'NONE',
                                     self.target_name)
        positions = 1000 * np.asarray([sun_state[:3]])
        velocities = 1000 * np.asarray([sun_state[3:6]])
+2 −47
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ class KaguyaTcPds3NaifSpiceDriver(LineScanner, Pds3Label, NaifSpice, Driver):
        : int
          Sensor frame id
        """
        return spice.bods2c("LISM_{}_HEAD".format(super().instrument_id))
        return spice.namfrm("LISM_{}_HEAD".format(super().instrument_id))


    @property
@@ -158,19 +158,6 @@ class KaguyaTcPds3NaifSpiceDriver(LineScanner, Pds3Label, NaifSpice, Driver):
        """
        return self.label.get('CORRECTED_SC_CLOCK_STOP_COUNT').value

    @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 of the spacecraft.

        Returns
        -------
        : float
          ephemeris stop time of the image
        """
        return spice.sct2e(self.spacecraft_id, self.spacecraft_clock_stop_count)

    @property
    def spacecraft_clock_start_count(self):
        """
@@ -211,7 +198,7 @@ class KaguyaTcPds3NaifSpiceDriver(LineScanner, Pds3Label, NaifSpice, Driver):
        : int
          The detector line of the principle point
        """
        return spice.gdpool('INS{}_CENTER'.format(self.ikid), 0, 2)[0] - 0.5
        return spice.gdpool('INS{}_CENTER'.format(self.ikid), 0, 2)[1] - 0.5

    @property
    def detector_center_sample(self):
@@ -229,38 +216,6 @@ class KaguyaTcPds3NaifSpiceDriver(LineScanner, Pds3Label, NaifSpice, Driver):
        """
        return spice.gdpool('INS{}_CENTER'.format(self.ikid), 0, 2)[0] - 0.5

    @property
    def _sensor_orientation(self):
        """
        Returns quaternions describing the orientation of the sensor.
        Expects ephemeris_time to be defined. This should be a list containing
        ephemeris times during which the image was taken.
        Expects instrument_id to be defined in the Pds3Label mixin. This should be
        a string of the form TC1 or TC2self.
        Expects reference_frame to be defined. This should be a string containing
        the name of the reference_frame.

        Returns
        -------
        : list
          Quaternions describing the orentiation of the sensor
        """
        if not hasattr(self, '_orientation'):
            ephem = self.ephemeris_time

            qua = np.empty((len(ephem), 4))
            for i, time in enumerate(ephem):
                instrument = super().instrument_id
                # Find the rotation matrix
                camera2bodyfixed = spice.pxform("LISM_{}_HEAD".format(instrument),
                                                self.reference_frame,
                                                time)
                q = spice.m2q(camera2bodyfixed)
                qua[i,:3] = q[1:]
                qua[i,3] = q[0]
            self._orientation = qua
        return self._orientation.tolist()


    @property
    def reference_frame(self):
+29 −8
Original line number Diff line number Diff line
import subprocess
import os
import re
import warnings
import numpy as np
import ale

@@ -40,6 +42,24 @@ class SimpleSpice():
def get_mockkernels(self, *args):
    return "some_metakernel"

def compare_dicts(ldict, rdict):
    differences = []
    for key in rdict:
        if key not in ldict:
            differences.append(f'Key {key} is present in the right dict, but not the left dict.')
    for key, item in ldict.items():
        if key not in rdict:
            differences.append(f'Key {key} is present in the left dict, but not the right dict.')
        elif isinstance(item, dict):
            differences.extend(compare_dicts(item, rdict[key]))
        elif isinstance(item, np.ndarray):
            if not np.allclose(item, rdict[key]):
                differences.append(f'Array values of key {key} are not almost equal {item} : {rdict[key]}.')
        else:
            if item != rdict[key]:
                differences.append(f'Values of key {key} are not equal {item} : {rdict[key]}.')
    return differences

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]
@@ -109,17 +129,18 @@ def convert_kernels(kernels):
    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]]
        if 'x' in split_kernel[1].lower():
            bin_output = subprocess.run(['tobin', os.path.join(data_root, kernel)],
                                        capture_output=True, check=True)
            matches = re.search(r'To: (.*\.b\w*)', str(bin_output.stdout))
            if not matches:
                warnings.warn('Failed to convert transfer kernel, ' + kernel + ', skipping...')
            else:
                kernel = matches.group(1)
                binary_kernels.append(kernel)
        updated_kernels.append(kernel)
    return updated_kernels, binary_kernels
+2151 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading