Unverified Commit e3b40c4a authored by Amy Stamile's avatar Amy Stamile Committed by GitHub
Browse files

Osirisrex Driver (#476)

* OsirisRex driver

* Added kernels

* Added tests

* Removed absolute paths.

* Cleared notebook cells.

* removed print.prt

* Fixes kernel load issues with iks.

* Added doc strings.
parent 18813191
Loading
Loading
Loading
Loading
+123 −0
Original line number Diff line number Diff line
import spiceypy as spice

import ale
from ale.base.data_naif import NaifSpice
from ale.base.label_isis import IsisLabel
from ale.base.type_sensor import Framer
from ale.base.base import Driver
from ale.base.type_distortion import RadialDistortion

class OsirisRexCameraIsisLabelNaifSpiceDriver(Framer, IsisLabel, NaifSpice, RadialDistortion, Driver):
    @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
        """
        sensor_lookup = {
        "MapCam" : "MAPCAM",
        "PolyCam" : "POLYCAM",
        "SamCam" : "SAMCAM"
        }
        return 'ORX_OCAMS_' + sensor_lookup[super().instrument_id]

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

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

    @property
    def exposure_duration(self):
        """
        The exposure duration of the image, in seconds. Unit is "Millisec" in label
        therefore failing in the label_isis exposure duration checks.

        Returns
        -------
        : float
          Exposure duration in seconds
        """
        return self.label['IsisCube']['Instrument']['ExposureDuration'].value * 0.001


    @property
    def sensor_frame_id(self):
        """
        Returns the Naif ID code for the sensor reference frame.
        This is the frame of the OsirisRex instrument itself, and is not dependent on filter.

        Returns
        -------
        : int
          Naif ID code for the sensor frame
        """
        return -64000


    @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
        -------
        : int
          The detector line of the principle point
        """
        return float(spice.gdpool('INS{}_CCD_CENTER'.format(self.ikid), 0, 2)[1])

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

        Returns
        -------
        : int
          The detector sample of the principle point
        """

        return float(spice.gdpool('INS{}_CCD_CENTER'.format(self.ikid), 0, 2)[0])

    @property
    def filter_name(self):
        """
        The name of the filter used to capture the image

        Returns
        -------
        : string
          The name of the filter
        """
        return self.label['IsisCube']['BandBin']['FilterName'].strip().upper()

    @property
    def odtk(self):
        """
        The coefficients for the radial distortion model
        Expects ikid to be defined. This must be the integer Naif id code of the instrument

        Returns
        -------
        : list
          Radial distortion coefficients
        """
        if self.filter_name == "UNKNOWN":
            return spice.gdpool('INS{}_OD_K'.format(self.ikid),0, 3).tolist()
        else:
            return spice.gdpool('INS{ikid}_OD_K_{filter}'.format(ikid = self.ikid, filter = self.filter_name),0, 3).tolist()
+5 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ except ImportError:
from itertools import chain
from datetime import datetime
import pytz
import numpy as np

import subprocess
import re
@@ -257,6 +258,10 @@ def get_kernels_from_isis_pvl(kernel_group, expand=True, format_as="list"):
    mk_paths['Clock'] = [kernel_group.get('Clock', None)]
    mk_paths['Extra'] = [kernel_group.get('Extra', None)]

    # handles issue with OsirisRex instrument kernels being in a 2d list
    if isinstance(mk_paths['Instrument'][0], list):
        mk_paths['Instrument'] = np.concatenate(mk_paths['Instrument']).flat

    if (format_as == 'list'):
        # get kernels as 1-d string list
        kernels = [kernel for kernel in chain.from_iterable(mk_paths.values()) if isinstance(kernel, str)]
+59 −0
Original line number Diff line number Diff line
%% Cell type:code id: tags:

``` python
fileName = '/osirisrex/tsts/mapcam/truth/20190303T100344S990_map_iofL2pan_V001-spiceinit.cub'

import os
os.environ["ISISDATA"] = "/isis3/isis_data"
os.environ["ISISTESTDATA"] = "/pkgs/isis_testData"
os.environ["ISISROOT"] = "/isis/ISIS3/build"

import ale
from ale.drivers.osirisrex_drivers import OsirisRexCameraIsisLabelNaifSpiceDriver
from ale.formatters.formatter import to_isd
import spiceypy as spice
from ale.drivers import AleJsonEncoder
```

%% Cell type:code id: tags:

``` python
from ale.util import generate_kernels_from_cube
kernels = generate_kernels_from_cube(fileName, expand=True, format_as='list')
```

%% Cell type:code id: tags:

``` python
with OsirisRexCameraIsisLabelNaifSpiceDriver(fileName, props = {"kernels": kernels}) as driver:
    isisString = to_isd(driver)
```

%% Cell type:code id: tags:

``` python
isisString
```

%% Cell type:code id: tags:

``` python
import json

isis_dict = isisString

json_file = os.path.splitext(fileName)[0] + '.json'

with open(json_file, 'w') as fp:
    json.dump(isis_dict, fp, cls = AleJsonEncoder)

with open(json_file, 'r') as fp:
    isis_dict = json.load(fp)

isis_dict.keys()
```

%% Cell type:code id: tags:

``` python
```
+651 −0
Original line number Diff line number Diff line
DAFETF NAIF DAF ENCODED TRANSFER FILE
'DAF/SPK '
'2'
'6'
'SPKMERGE                                                    '
BEGIN_ARRAY 1 48
'1999RQ36                                '
'240DC53B1660A8^8'
'240DC633C3B08A^8'
'2012C3'
'A'
'1'
'2'
48
'23F571C^8'
'2A3^6'
'-289EC3D879217^7'
'-522CDA5729194C^7'
'3AD74D081D7352^6'
'121B9367A79B43^6'
'-1A52A7A0F93D2E^5'
'-1B34DB8D17BB72^4'
'8358E119D8C1F^3'
'-4475046C744454^2'
'-1E23DDF7C36B63^2'
'3FDC61E17EA6A6^1'
'36D5EA30F174DC^0'
'-1A36C62CF3739A^0'
'964BB692A94E4^-2'
'7039AC6CA86F18^-2'
'63A1AED03C2A64^7'
'-F4A1ED328AE59^6'
'-9CAF4CC383A308^6'
'945B0CB5243D88^5'
'15813689D6757^5'
'-356DD775C7C0CC^4'
'-8F347F102029F8^2'
'E609FF5E9082A^2'
'-11C953D506A8A8^2'
'-2963FC26CB887C^1'
'95E3D65FEC2348^0'
'268ADF13A0DD72^-2'
'-3545E7E3A373D4^-1'
'-15859424B5A833^-2'
'3878E471D9CA48^7'
'-84A5CA91F7AB28^6'
'-58CA267FD89DC4^6'
'5299E5EBCD646^5'
'C438C1D67F01A^4'
'-1E1378F90741BA^4'
'-59D8A29E1F23F^2'
'824AAB5205017^2'
'-9EC5D7DB6538C8^1'
'-17B454CF4A16D1^1'
'5446E23D98F4F4^0'
'4DC803CF17819C^-2'
'-1CDFCE35EA4F8B^-1'
'-B7D86A8C03F48^-3'
'23CB41C^8'
'546^6'
'2C^2'
'1^1'
END_ARRAY 1 48
BEGIN_ARRAY 2 505
'                                        '
'240DC53B1660A8^8'
'240DC633C3B08A^8'
'-40'
'2012C3'
'1'
'1'
505
'240DC56CBE7FD^8'
'14DC1851470108^2'
'2D13EEE3E2BA48^2'
'3A8467245A3B18^2'
'46769924C474B8^2'
'4EDA776ECDBE9^2'
'54BEFBACA277E^2'
'5AA37FEA77313^2'
'75E0C72B8718A^2'
'C5535CE3D3E35^3'
'DE62031923A34^3'
'EE06A5638BFB9^3'
'0^0'
'0^0'
'0^0'
'0^0'
'64609568DDAC4^1'
'-110900FE783EC8^-3'
'-2E66412AA8FEAC^0'
'63211C10060464^-4'
'-20A0A6872666C^1'
'-1773C9119D875B^-3'
'-9D800527C0141^-8'
'-97D7E393425AC^-A'
'-47227D0DA86E5^-C'
'56371CBF825828^-C'
'14F56AFC89^-B'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'3417FA22E3C782^-8'
'A32CAAB8395D6^-A'
'-20B36CB37ED49^-B'
'-9BE056C769AE98^-C'
'-177AE256472^-B'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'42819B15E3BD34^-8'
'95C3062FF9527^-A'
'84298EC823EE58^-B'
'-1E73EEEE34D76^-C'
'-12D014B917C^-B'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'5^1'
'4^1'
'4^1'
'4^1'
'240DC59912337E^8'
'17779B5B6FF128^2'
'2C53B3ACB6F23^2'
'412FCBFDFDF338^2'
'5967A29099AC78^2'
'66D81AD1112D48^2'
'72CA4CD17B66E8^2'
'7B2E2B1B84B0C^2'
'75E0C72B8718A^2'
'C5535CE3D3E35^3'
'DE62031923A34^3'
'EE06A5638BFB9^3'
'0^0'
'0^0'
'0^0'
'0^0'
'645DA224F136B4^1'
'-110AB71398626E^-3'
'-2E551646E9E52E^0'
'632A3E79210F6C^-4'
'-20A4B608A70FF6^1'
'-17730EFF5FDC4^-3'
'-9EC0CCBE99B6E^-8'
'-A96A54B3F9659^-A'
'DE95B665A050C^-C'
'-46B438A75DD678^-C'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'356699CF08C4AC^-8'
'AEB522F860F58^-A'
'-532B759CF3FADC^-B'
'-14DAB40ED6033D^-B'
'4FCE00EDD4^-C'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'43D6F98113C444^-8'
'B87EB951718B3^-A'
'803113708DDF98^-B'
'-7D33FFADDE9588^-C'
'23F6D03448^-C'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'5^1'
'3^1'
'4^1'
'4^1'
'240DC5B089CED8^8'
'17779B5B6FF128^2'
'2EEF36B6DFE25^2'
'43CB4F0826E358^2'
'58A767596DE46^2'
'70DF3DEC099DA^2'
'7E4FB62C811E7^2'
'8A41E82CEB581^2'
'75E0C72B8718A^2'
'C5535CE3D3E35^3'
'DE62031923A34^3'
'EE06A5638BFB9^3'
'0^0'
'0^0'
'0^0'
'0^0'
'645C122D7BE5A^1'
'-110BA0676B2C13^-3'
'-2E4BFEECCEFE9^0'
'632F2B62553AF^-4'
'-20A6DC4F233FB4^1'
'-1772AAF3179C3^-3'
'-9F69BF3838B7A8^-8'
'-A8F2799F00CB1^-A'
'77DB14F89A82F8^-C'
'-73D27EFA88^-C'
'-25F6F54C7871F4^-C'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'360E36643C5BCC^-8'
'A79C9533971FB8^-A'
'-7188DC4C9D5C54^-B'
'-1978F65B2272B2^-B'
'-2821B99B4A^-C'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'449749D058BEAC^-8'
'C0504F44FA67F8^-A'
'7D195F388DCCBC^-B'
'-AA21EC626B4F48^-C'
'-2043043AC^-C'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'5^1'
'4^1'
'4^1'
'4^1'
'240DC5AB1E412A^8'
'2EEF36B6E0E28^1'
'2EEF36B6E0E28^1'
'2EEF36B6E0E28^1'
'58A767596DE46^2'
'70DF3DEC099DA^2'
'7E4FB62C811E7^2'
'8A41E82CEB581^2'
'75E0C72B8718A^2'
'C5535CE3D3E35^3'
'DE62031923A34^3'
'EE06A5638BFB9^3'
'0^0'
'0^0'
'0^0'
'0^0'
'645C6E9056B96C^1'
'-110B6A6DCAF509^-3'
'-2E4E18812AA0EA^0'
'632E06C826B9AC^-4'
'-20A65D37A5EE12^1'
'-1772C227EE88CC^-3'
'-9F4728D7AFBA1^-8'
'-198CAB935838^-A'
'-198CAB935838^-A'
'0^0'
'-9F4728D7AFBA1^-8'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'35E57CEC7DF00A^-8'
'12047FA50FC6^-A'
'12047FA50FC6^-A'
'0^0'
'35E57CEC7DF00A^-8'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'4468BA978F5648^-8'
'16BCCF8815AC^-A'
'16BCCF8815AC^-A'
'0^0'
'4468BA978F5648^-8'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'3^1'
'2^1'
'2^1'
'2^1'
'240DC5B3FF9914^8'
'5F2647EBB33D8^1'
'8E157EA2942^1'
'BD04B55975028^1'
'BD04B55975028^1'
'BD04B55975028^1'
'7E4FB62C811E7^2'
'8A41E82CEB581^2'
'75E0C72B8718A^2'
'C5535CE3D3E35^3'
'DE62031923A34^3'
'EE06A5638BFB9^3'
'0^0'
'0^0'
'0^0'
'0^0'
'645BD7329784EC^1'
'-110BC2EA1B0DFC^-3'
'-2E4AA7BB212C4C^0'
'632FE654C6EC0C^-4'
'-20A72D70F8772^1'
'-17729C1CDB7FA5^-3'
'-9F94871AD12798^-8'
'-33D0F6843AD9AA^-A'
'-3E003693558FC8^-D'
'-1F1DA3A28^-D'
'-9F4728D7AFBA1^-8'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'361B36F8D818B2^-8'
'23D7491E534E22^-A'
'-6B2D9D9D88A6C^-C'
'-3A805EFB6^-D'
'35E57CEC7DF00A^-8'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'44AE396C2D4FA4^-8'
'2EA5BF62DC2DFC^-A'
'53FB06145A3DC4^-C'
'-2C67F7808^-D'
'4468BA978F5648^-8'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'4^1'
'3^1'
'3^1'
'3^1'
'240DC6011A0804^8'
'1B7EF9B087E1C^2'
'3138A287DCECA^2'
'42630854C4837^2'
'4D1A6EF12C1FC^2'
'530CD36FE75398^2'
'55FBC6DB5561C^2'
'58EABA46C36FE8^2'
'75E0C72B8718A^2'
'C5535CE3D3E35^3'
'DE62031923A34^3'
'EE06A5638BFB9^3'
'0^0'
'0^0'
'0^0'
'0^0'
'6456B471F03228^1'
'-110ECA4D4A8D8B^-3'
'-2E2CC59A367CBE^0'
'634071D37C7F44^-4'
'-20AE3D234C902C^1'
'-17714B42E0B4C1^-3'
'-A23F0DC3EF6B2^-8'
'-F70A73071F3408^-A'
'-452DFF7FEAB774^-B'
'-1B4CE18B0663BA^-B'
'-22CC2ED12CD338^-C'
'2322A51128^-C'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'37AD1795DDCCCC^-8'
'805E8C422F54A^-A'
'-F92ED2BD905598^-B'
'-1BED0F2C544D07^-B'
'345FD40511A43A^-C'
'1758AC9AD6^-C'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'47242FAC7367B^-8'
'E37F9D308365A^-A'
'16BE4A616C81DF^-B'
'-3749270D252A6E^-B'
'-D5BFA1A63386E^-C'
'-1381EB758C^-C'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'6^1'
'5^1'
'5^1'
'5^1'
'240DC63EF7B9D2^8'
'1EEED8E6991E^2'
'3DDDB1CD323C^2'
'595CAB7DBA1DC^2'
'6F1654550F28A^2'
'8040BA21F6BF7^2'
'8AF820BE5E5BC^2'
'90EA853D198F98^2'
'93D978A8879DC^2'
'C5535CE3D3E35^3'
'DE62031923A34^3'
'EE06A5638BFB9^3'
'0^0'
'0^0'
'0^0'
'0^0'
'645294D9F77FCC^1'
'-111141FD7DE48C^-3'
'-2E14C7A8F6148C^0'
'634E028AA58824^-4'
'-20B3E74DC6DB5A^1'
'-177034734F42B6^-3'
'-A484962A41CCE8^-8'
'-127A6245DA10A7^-9'
'-9C3E268E048478^-B'
'-155786A742BEC8^-B'
'13FF7823A30A66^-B'
'-5BAD0157004BF^-C'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'3885A239355F34^-8'
'5F48542CBB3478^-A'
'-19F9FAFE1BFF32^-A'
'-17536CD917160A^-B'
'209911125DF14C^-B'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'4906EFF76CFCB4^-8'
'E8A189C679EAA8^-A'
'-117D376CA12EDD^-A'
'-B54D40AD3D9DF8^-B'
'-239B1C87440606^-B'
'2083EE34BA00D2^-B'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'0^0'
'6^1'
'5^1'
'4^1'
'5^1'
'240DC56CBE7FD^8'
'240DC59912337E^8'
'240DC5A82F4DBE^8'
'240DC5AB1E412A^8'
'240DC5B3FF9914^8'
'240DC6011A0804^8'
'240DC63E2F4DBE^8'
'7^1'
END_ARRAY 2 505
BEGIN_ARRAY 3 39
'DE-0424LE-0424                          '
'240DC53B1660A8^8'
'240DC633C3B08A^8'
'A'
'0'
'1'
'2'
39
'2416674^8'
'A8C^5'
'-2F8F0002B54CAA^5'
'-2650DF4268D3D8^4'
'-AE634854CB0A6^1'
'1F35EB9A06979D^0'
'3ABC5452BD3F56^-1'
'-550CCC25DD6D9C^-2'
'-1DFC1D4FBB3DE7^-3'
'1D8C94D4E6D3A^-3'
'-42068C1E04F1FC^-4'
'3CFA272C7E2F2^-6'
'16FD1DDCA9E195^-5'
'FD5A183FBD6578^5'
'543FBD1678B4^3'
'-1895A1E0CB0041^2'
'-31AE596860FE84^0'
'1ADF95731E4B7A^-1'
'3C31B710F9C89E^-2'
'-CEF0658246DFC^-3'
'E08EC78BFD7A1^-4'
'201E2D9C42CECA^-4'
'-A20B79FBC3B298^-5'
'F19094ECE0457^-6'
'6C1E50AD3D9504^5'
'35E4A8CF0CC282^3'
'-A36179FD4F3EC8^1'
'-19A68E419F3A21^0'
'7D6F688A26D07^-2'
'289CEDB4258D84^-2'
'-6B5B7A9D216208^-3'
'46F77BEFD913F8^-4'
'18006AD016CB85^-4'
'-56F5909C729294^-5'
'5AE98DB8A0B92C^-6'
'240BDB4^8'
'1518^6'
'23^2'
'1^1'
END_ARRAY 3 39
TOTAL_ARRAYS 3
 ~NAIF/SPC BEGIN COMMENTS~
; /ale/osirisrex/20190303T100344S990_map_iofL2pan_V001-spiceinit_0.bsp LOG FILE

; Created 2022-07-20/11:45:35.00.
;
; BEGIN SPKMERGE COMMANDS

LEAPSECONDS_KERNEL = /base/kernels/lsk/naif0012.tls

SPK_KERNEL = /ale/osirisrex/20190303T100344S990_map_iofL2pan_V001-spiceinit_0.bsp
SOURCE_SPK_KERNEL = /osirisrex/kernels/spk/orx_190301_190424_190412_od125_v1.bsp
    INCLUDE_COMMENTS = NO
    BODIES           = -64, 2101955
    BEGIN_TIME       = 2019 MAR 03 10:49:25.902
    END_TIME         = 2019 MAR 03 10:53:34.579
SOURCE_SPK_KERNEL = /osirisrex/kernels/tspk/de424.bsp
    INCLUDE_COMMENTS = NO
    BODIES           = 10
    BEGIN_TIME       = 2019 MAR 03 10:49:25.902
    END_TIME         = 2019 MAR 03 10:53:34.579

; END SPKMERGE COMMANDS
 ~NAIF/SPC END COMMENTS~
+1372 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading