Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions ale/base/data_isis.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ def rotate_state(table, rotation):
rotated_vel = None
return rotated_pos, rotated_vel, ephemeris_times

def get_naif_keyword(self, ale_name, naif_key):
val = self.naif_keywords.get(naif_key, None)
if val is None:
raise LookupError('Could not find a value for {} using the NAIF Keyword {}'.format(ale_name, naif_key))
return val
class IsisSpice():
"""
Mixin class for reading from an ISIS cube that has been spiceinit'd
Expand Down Expand Up @@ -350,7 +355,8 @@ def detector_center_sample(self):
list :
The center of the CCD formatted as line, sample
"""
return self.naif_keywords.get('INS{}_BORESIGHT_SAMPLE'.format(self.ikid), None)

return get_naif_keyword(self, 'detector_center_sample', 'INS{}_BORESIGHT_SAMPLE'.format(self.ikid))

@property
def detector_center_line(self):
Expand All @@ -364,7 +370,7 @@ def detector_center_line(self):
list :
The center of the CCD formatted as line, sample
"""
return self.naif_keywords.get('INS{}_BORESIGHT_LINE'.format(self.ikid), None)
return get_naif_keyword(self, 'detector_center_line', 'INS{}_BORESIGHT_LINE'.format(self.ikid))


@property
Expand Down Expand Up @@ -430,7 +436,7 @@ def focal2pixel_lines(self):
The coefficients of the affine transformation
formatted as constant, x, y
"""
return self.naif_keywords.get('INS{}_ITRANSL'.format(self.ikid), None)
return get_naif_keyword(self, 'focal2pixel_lines', 'INS{}_ITRANSL'.format(self.ikid))

@property
def focal2pixel_samples(self):
Expand All @@ -448,7 +454,7 @@ def focal2pixel_samples(self):
The coefficients of the affine transformation
formatted as constant, x, y
"""
return self.naif_keywords.get('INS{}_ITRANSS'.format(self.ikid), None)
return get_naif_keyword(self, 'focal2pixel_samples', 'INS{}_ITRANSS'.format(self.ikid))

@property
def pixel2focal_x(self):
Expand All @@ -461,7 +467,7 @@ def pixel2focal_x(self):
detector to focal plane x
"""

return self.naif_keywords.get('INS{}_TRANSX'.format(self.ikid), None)
return get_naif_keyword(self, 'pixel2focal_x', 'INS{}_TRANSX'.format(self.ikid))

@property
def pixel2focal_y(self):
Expand All @@ -474,7 +480,7 @@ def pixel2focal_y(self):
detector to focal plane y
"""

return self.naif_keywords.get('INS{}_TRANSY'.format(self.ikid), None)
return get_naif_keyword(self, 'pixel2focal_y', 'INS{}_TRANSY'.format(self.ikid))

@property
def focal_length(self):
Expand All @@ -490,7 +496,8 @@ def focal_length(self):
float :
The focal length in millimeters
"""
return self.naif_keywords.get('INS{}_FOCAL_LENGTH'.format(self.ikid), None)

return get_naif_keyword(self, 'focal_length', 'INS{}_FOCAL_LENGTH'.format(self.ikid))

@property
def target_body_radii(self):
Expand Down
3 changes: 2 additions & 1 deletion ale/drivers/co_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ale.base import Driver, WrongInstrumentException
from ale.base.data_naif import NaifSpice
from ale.base.data_isis import IsisSpice
from ale.base.data_isis import get_naif_keyword
from ale.base.label_pds3 import Pds3Label
from ale.base.label_isis import IsisLabel
from ale.base.type_distortion import RadialDistortion, NoDistortion
Expand Down Expand Up @@ -829,4 +830,4 @@ def focal_length(self):
The focal length in millimeters
"""
filters = self.label["IsisCube"]["BandBin"]['FilterName'].split("/")
return self.naif_keywords.get('INS{}_{}_{}_FOCAL_LENGTH'.format(self.ikid, filters[0], filters[1]), None)
return get_naif_keyword(self, 'focal_length', 'INS{}_{}_{}_FOCAL_LENGTH'.format(self.ikid, filters[0], filters[1]))
12 changes: 6 additions & 6 deletions ale/drivers/isis_ideal_drivers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from ale.base.data_isis import IsisSpice
from ale.base.data_isis import get_naif_keyword
from ale.base.label_isis import IsisLabel
from ale.base import Driver, WrongInstrumentException
from ale.base.type_sensor import LineScanner
Expand Down Expand Up @@ -129,7 +130,7 @@ def pixel2focal_x(self):
: list<double>
detector to focal plane x
"""
return self.naif_keywords.get('IDEAL_TRANSX')
return get_naif_keyword(self, 'pixel2focal_x', 'IDEAL_TRANSX')


@property
Expand All @@ -142,7 +143,7 @@ def pixel2focal_y(self):
: list<double>
detector to focal plane y
"""
return self.naif_keywords.get('IDEAL_TRANSY')
return get_naif_keyword(self, 'pixel2focal_y', 'IDEAL_TRANSY')


@property
Expand All @@ -155,8 +156,7 @@ def focal2pixel_lines(self):
: list<double>
focal plane to detector lines
"""

return self.naif_keywords.get('IDEAL_TRANSL')
return get_naif_keyword(self, 'focal2pixel_lines', 'IDEAL_TRANSL')


@property
Expand All @@ -169,7 +169,7 @@ def focal2pixel_samples(self):
: list<double>
focal plane to detector samples
"""
return self.naif_keywords.get('IDEAL_TRANSS')
return get_naif_keyword(self, 'focal2pixel_samples', 'IDEAL_TRANSS')

@property
def focal_length(self):
Expand All @@ -183,7 +183,7 @@ def focal_length(self):
float :
The focal length in millimeters
"""
return self.naif_keywords.get('IDEAL_FOCAL_LENGTH', None)
return get_naif_keyword(self, 'focal_length', 'IDEAL_FOCAL_LENGTH')

@property
def detector_center_sample(self):
Expand Down
47 changes: 10 additions & 37 deletions ale/drivers/lro_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ale.base import Driver, WrongInstrumentException
from ale.base.data_naif import NaifSpice
from ale.base.data_isis import IsisSpice
from ale.base.data_isis import get_naif_keyword
from ale.base.label_pds3 import Pds3Label
from ale.base.label_isis import IsisLabel
from ale.base.type_sensor import LineScanner, Radar, PushFrame
Expand Down Expand Up @@ -595,11 +596,7 @@ def odtk(self):
: list
Radial distortion coefficients. There is only one coefficient for LROC NAC l/r
"""
key = 'INS{}_OD_K'.format(self.ikid)
ans = self.naif_keywords.get(key, None)
if ans is None:
raise Exception('Could not parse the distortion model coefficients using key: ' + key)
return [ans]
return get_naif_keyword(self, 'odtk', 'INS{}_OD_K'.format(self.ikid))

@property
def detector_center_sample(self):
Expand Down Expand Up @@ -1005,13 +1002,9 @@ def odtk(self):
: list
Radial distortion coefficients.
"""
key = 'INS{}_OD_K'.format(self.fikid)
ans = self.naif_keywords.get(key, None)
if ans is None:
raise Exception('Could not parse the distortion model coefficients using key: ' + key)

ans = [x * -1 for x in ans]
return ans
val = get_naif_keyword(self, 'odtk', 'INS{}_OD_K'.format(self.fikid))
val = [x * -1 for x in val]
return val

@property
def framelet_height(self):
Expand All @@ -1031,11 +1024,7 @@ def pixel2focal_x(self):
: list<double>
detector to focal plane x
"""
key = 'INS{}_TRANSX'.format(self.fikid)
ans = self.naif_keywords.get(key, None)
if ans is None:
raise Exception('Could not parse detector to focal plane x using key: ' + key)
return ans
return get_naif_keyword(self, 'pixel2focal_x', 'INS{}_TRANSX'.format(self.fikid));

@property
def pixel2focal_y(self):
Expand All @@ -1047,11 +1036,7 @@ def pixel2focal_y(self):
: list<double>
detector to focal plane y
"""
key = 'INS{}_TRANSY'.format(self.fikid)
ans = self.naif_keywords.get(key, None)
if ans is None:
raise Exception('Could not parse detector to focal plane y using key: ' + key)
return ans
return get_naif_keyword(self, 'pixel2focal_y', 'INS{}_TRANSY'.format(self.fikid))

@property
def focal_length(self):
Expand All @@ -1067,11 +1052,7 @@ def focal_length(self):
float :
The focal length in millimeters
"""
key = 'INS{}_FOCAL_LENGTH'.format(self.fikid)
ans = self.naif_keywords.get(key, None)
if ans is None:
raise Exception('Could not parse the focal length using key: ' + key)
return ans
return get_naif_keyword(self, 'focal_length', 'INS{}_FOCAL_LENGTH'.format(self.fikid))

@property
def detector_center_sample(self):
Expand All @@ -1085,11 +1066,7 @@ def detector_center_sample(self):
list :
The center of the CCD formatted as line, sample
"""
key = 'INS{}_BORESIGHT_SAMPLE'.format(self.fikid)
ans = self.naif_keywords.get(key, None)
if ans is None:
raise Exception('Could not parse the detector center sample using key: ' + key)
return ans
return get_naif_keyword(self, 'detector_center_sample', 'INS{}_BORESIGHT_SAMPLE'.format(self.fikid))

@property
def detector_center_line(self):
Expand All @@ -1103,11 +1080,7 @@ def detector_center_line(self):
list :
The center of the CCD formatted as line, sample
"""
key = 'INS{}_BORESIGHT_LINE'.format(self.fikid)
ans = self.naif_keywords.get(key, None)
if ans is None:
raise Exception('Could not parse the detector center line using key: ' + key)
return ans
return get_naif_keyword(self, 'detector_center_sample', 'INS{}_BORESIGHT_LINE'.format(self.fikid))

class LroLrocWacIsisLabelNaifSpiceDriver(PushFrame, IsisLabel, NaifSpice, RadialDistortion, Driver):
"""
Expand Down
8 changes: 5 additions & 3 deletions tests/pytests/test_data_isis.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,11 +519,13 @@ def test_sun_position(testdata):


def test_detector_center_sample(testdata):
assert testdata.detector_center_sample == None
with pytest.raises(LookupError):
testdata.detector_center_sample


def test_detector_center_line(testdata):
assert testdata.detector_center_line == None
with pytest.raises(LookupError):
testdata.detector_center_line


def test_focal_length(testdata):
Expand Down Expand Up @@ -713,4 +715,4 @@ def test_no_tables():
with pytest.raises(ValueError):
test_mix_in.inst_position_table
with pytest.raises(ValueError):
test_mix_in.sun_position_table
test_mix_in.sun_position_table
Loading