Skip to content

Commit

Permalink
Mex fixes (#541)
Browse files Browse the repository at this point in the history
* Doc string typo fix

* Initial mex hrsc fixes for times

* Initial test updates to mex

* Add truth ISDs

* Made all mex drivers use the NoDistortion mixin

* Added changelog entry

* Fixed failing tests
  • Loading branch information
acpaquette authored Jun 2, 2023
1 parent 8aa3b10 commit 759b307
Show file tree
Hide file tree
Showing 7 changed files with 690 additions and 859 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ release.

## [Unreleased]

### Fixed
- MexHrscIsisLabelNaifSpice and MexHrscPds3NaifSpice have had there ephemeris times changed and sampling factor updated. MexHrscIsisLabelNaifSpice has also had it's focal length, and focal plane translation updated to reflect those found in the MexHrscPds3NaifSpice driver [#541](https://github.com/DOI-USGS/ale/pull/541)

## [0.9.0] - 2023-04-19

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion ale/base/label_isis.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def image_samples(self):
@property
def sampling_factor(self):
"""
Returns the summing factor from the PDS3 label. For example a return value of 2
Returns the summing factor from the ISIS label. For example a return value of 2
indicates that 2 lines and 2 samples (4 pixels) were summed and divided by 4
to produce the output pixel value.
Expand Down
112 changes: 75 additions & 37 deletions ale/drivers/mex_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from ale.base.label_isis import IsisLabel
from ale.base.type_sensor import LineScanner
from ale.base.type_sensor import Framer
from ale.base.type_distortion import RadialDistortion
from ale.base.type_distortion import NoDistortion

FILTER_SPECIFIC_LOOKUP = {
# This table contains the filter specific information from the ISIS iak kernel. The format is as follows:
Expand Down Expand Up @@ -69,7 +69,7 @@
[-8569.5561557859, 0.068566503695773, 142.857126402363]],
}

class MexHrscPds3NaifSpiceDriver(LineScanner, Pds3Label, NaifSpice, RadialDistortion, Driver):
class MexHrscPds3NaifSpiceDriver(LineScanner, Pds3Label, NaifSpice, NoDistortion, Driver):
"""
Driver for a PDS3 Mars Express (Mex) High Resolution Stereo Camera (HRSC) images.
Expand All @@ -90,19 +90,6 @@ class MexHrscPds3NaifSpiceDriver(LineScanner, Pds3Label, NaifSpice, RadialDistor
"""

@property
def odtk(self):
"""
The coefficients for the distortion model
Returns
-------
: list
Radial distortion coefficients. There is only one coefficient for LROC NAC l/r
"""
return [0.0, 0.0, 0.0]


@property
def ikid(self):
"""
Expand Down Expand Up @@ -417,8 +404,8 @@ def read_image_data(self):
with open(self._file, 'rb') as image_file:
bytes_per_record = self.label['RECORD_BYTES']
num_records = self.label['FILE_RECORDS']
img_start_record = self.label['^IMAGE']
img_start_byte = bytes_per_record * (img_start_record - 1) # Offset by one for zero-based records
img_start_record = self.label['^IMAGE'] - 1 # Offset by one for zero-based records
img_start_byte = bytes_per_record * img_start_record
num_img_records = num_records - img_start_record
image_file.seek(img_start_byte)

Expand All @@ -436,6 +423,16 @@ def read_image_data(self):
self._binary_ephemeris_times = times


@property
def ephemeris_start_time(self):
"""
Returns
-------
: float
starting ephemeris time
"""
return self.binary_ephemeris_times[0]

@property
def ephemeris_stop_time(self):
"""
Expand All @@ -450,6 +447,20 @@ def ephemeris_stop_time(self):
"""
return self.binary_ephemeris_times[-1] + self.binary_exposure_durations[-1]

@property
def sampling_factor(self):
"""
Returns the summing factor from the PDS3 label. For example a return value of 2
indicates that 2 lines and 2 samples (4 pixels) were summed and divided by 4
to produce the output pixel value.
Returns
-------
: int
Number of samples and lines combined from the original data to produce a single pixel in this image
"""
return self.label.get('MACROPIXEL_SIZE', 1)


# TODO We need to confirm that returning nothing here does not affect
# calculations elsewhere in code. Or is there possibly just a better way of
Expand Down Expand Up @@ -482,7 +493,7 @@ def sensor_model_version(self):
return 1


class MexHrscIsisLabelNaifSpiceDriver(LineScanner, IsisLabel, NaifSpice, RadialDistortion, Driver):
class MexHrscIsisLabelNaifSpiceDriver(LineScanner, IsisLabel, NaifSpice, NoDistortion, Driver):

@property
def instrument_id(self):
Expand Down Expand Up @@ -526,7 +537,6 @@ def detector_center_line(self):
"""
return 0.0


@property
def detector_center_sample(self):
"""
Expand Down Expand Up @@ -576,7 +586,11 @@ def line_scan_rate(self):
list of lines, list of ephemeris times, and list of exposure
times
"""
return self.times_table['LineStart'], self.times_table['EphemerisTime'], self.times_table['ExposureTime']
times = self.times_table['EphemerisTime']
times = [time - self.center_ephemeris_time for time in times]
start_lines = self.times_table['LineStart']
start_lines = [line - .5 for line in start_lines]
return start_lines, times, self.times_table['ExposureTime']

@property
def ephemeris_start_time(self):
Expand Down Expand Up @@ -613,7 +627,6 @@ def ikid(self):
"""
return spice.bods2c("MEX_HRSC_HEAD")


@property
def fikid(self):
"""
Expand All @@ -631,50 +644,75 @@ def fikid(self):
"""
return spice.bods2c(self.instrument_id)

@property
def focal_length(self):
"""
Returns the focal length of the filter-specific sensor
Expects fikid to be defined. This must be the integer Naif id code of
the filter-specific instrument.
NOTE: These values are pulled from ISIS iak kernels.
Returns
-------
: float
focal length
"""
return FILTER_SPECIFIC_LOOKUP[self.fikid][0]

@property
def focal2pixel_lines(self):
"""
Expects fikid to be defined. This must be the integer Naif id code of
the filter-specific instrument.
NOTE: These values are pulled from ISIS iak kernels.
Returns
-------
: list<double>
focal plane to detector lines
"""
return [0.0, 0.0, 111.111111111111]
return FILTER_SPECIFIC_LOOKUP[self.fikid][4]


@property
def focal2pixel_samples(self):
"""
Expects fikid to be defined. This must be the integer Naif id code of
the filter-specific instrument.
NOTE: These values are pulled from ISIS iak kernels.
Returns
-------
: list<double>
focal plane to detector samples
"""
return [0.0, 111.111111111111, 0.0]
return FILTER_SPECIFIC_LOOKUP[self.fikid][3]

@property
def sampling_factor(self):
"""
Returns the summing factor from the PDS3 label. For example a return value of 2
indicates that 2 lines and 2 samples (4 pixels) were summed and divided by 4
to produce the output pixel value.
class MexSrcPds3NaifSpiceDriver(Framer, Pds3Label, NaifSpice, RadialDistortion, Driver):
Returns
-------
: int
Number of samples and lines combined from the original data to produce a single pixel in this image
"""
summing = self.label['IsisCube']['Instrument'].get("Summing", 1)
return summing

class MexSrcPds3NaifSpiceDriver(Framer, Pds3Label, NaifSpice, NoDistortion, Driver):
"""
Driver for a PDS3 Mars Express (Mex) High Resolution Stereo Camera (HRSC) - Super Resolution
Channel (SRC) image.
"""

@property
def odtk(self):
"""
The coefficients for the distortion model. No distortion model, so pass in all zeroes.
Returns
-------
: list
Radial distortion coefficients.
"""
return [0.0, 0.0, 0.0]


@property
def ikid(self):
"""
Expand Down
141 changes: 0 additions & 141 deletions tests/pytests/data/h5270_0000_ir2/h5270_0000_ir2_pds3.lbl
Original file line number Diff line number Diff line change
Expand Up @@ -115,147 +115,6 @@ RADIANCE_OFFSET = 0.0 <W*m**-2*sr**-1>
RADIANCE_SCALING_FACTOR = 0.0169353 <W*m**-2*sr**-1>
REFLECTANCE_SCALING_FACTOR = 0.00215382

/* DATA OBJECT DEFINITIONS */
Object = IMAGE
INTERCHANGE_FORMAT = BINARY
LINES = 400
LINE_PREFIX_BYTES = 68
LINE_SAMPLES = 1288
SAMPLE_TYPE = MSB_INTEGER
SAMPLE_BITS = 16
BANDS = 1
BAND_STORAGE_TYPE = BAND_SEQUENTIAL
MAXIMUM = 136
MEAN = 72.9682
MINIMUM = 29
STANDARD_DEVIATION = 17.629
End_Object

/* IMAGE HEADER DATA ELEMENTS */
Object = IMAGE_HEADER
HEADER_TYPE = VICAR2
INTERCHANGE_FORMAT = ASCII
BYTES = 7932
^DESCRIPTION = VICAR2.TXT
End_Object
End
PDS_VERSION_ID = PDS3

/* FILE DATA ELEMENTS */
RECORD_TYPE = FIXED_LENGTH
RECORD_BYTES = 2644
FILE_RECORDS = 15095
LABEL_RECORDS = 4

/* POINTERS TO DATA OBJECTS */
^IMAGE_HEADER = 5
^IMAGE = 8

/* IDENTIFICATION DATA ELEMENTS */
FILE_NAME = H5270_0000_IR2.IMG
DATA_SET_ID = MEX-M-HRSC-3-RDR-V2.0
DETECTOR_ID = MEX_HRSC_IR
EVENT_TYPE = MARS-REGIONAL-MAPPING-Vo-Te-Im
INSTRUMENT_HOST_ID = MEX
INSTRUMENT_HOST_NAME = "MARS EXPRESS"
INSTRUMENT_ID = HRSC
INSTRUMENT_NAME = "HIGH RESOLUTION STEREO CAMERA"
MISSION_NAME = "MARS EXPRESS"
MISSION_PHASE_NAME = ME_Phase_11
PROCESSING_LEVEL_ID = 2
PRODUCT_CREATION_TIME = 2009-04-30T15:19:42.000Z
PRODUCT_ID = H5270_0000_IR2.IMG
RELEASE_ID = 0062
REVISION_ID = 0000

/* TIME DATA ELEMENTS */
SPACECRAFT_CLOCK_START_COUNT = 1/0150552525.07284
SPACECRAFT_CLOCK_STOP_COUNT = 1/0150552792.64947
START_TIME = 2008-02-08T12:08:53.843Z
STOP_TIME = 2008-02-08T12:12:10.561Z

/* ORBITAL DATA ELEMENTS */
ASCENDING_NODE_LONGITUDE = 118.52
MAXIMUM_RESOLUTION = 55.3 <m/pixel>
FOOTPRINT_POINT_LATITUDE = (25.9975, 25.9916, 25.9739, 25.85, 25.599,
25.351, 25.2208, 24.5915, 24.4629, 24.0857,
23.9617, 22.7055, 22.577, 20.2998, 17.6826,
17.4193, 17.1598, 13.0429, 13.0429, 13.0427,
13.0427, 13.0425, 13.0425, 13.0423, 13.0423,
13.0421, 13.0421, 13.042, 13.042, 13.0418,
13.0416, 13.0415, 13.0411, 13.0409, 13.0406,
13.0404, 13.04, 13.0396, 13.0392, 13.0388,
13.0381, 13.0377, 13.0372, 13.0367, 13.0364,
13.0362, 13.0357, 13.0354, 13.0353, 13.0348,
13.0346, 13.0345, 13.0343, 13.0338, 13.0336,
13.0335, 13.0332, 13.0327, 13.0324, 13.0323,
13.032, 13.0315, 13.0312, 13.0311, 13.0308,
13.0306, 13.0314, 17.2063, 17.3388, 17.7327,
17.8665, 18.0031, 18.1342, 18.2588, 18.6486,
18.7797, 18.9094, 19.4369, 19.8287, 19.9612,
20.0923, 20.2223, 21.1159, 21.2444, 21.62,
21.7442, 21.9976, 22.1232, 22.251, 22.6309,
22.7559, 22.8791, 23.0084, 23.1362, 24.9031,
25.151, 25.4021, 25.7834, 25.9087, 25.9975)
FOOTPRINT_POINT_LONGITUDE = (78.2107, 76.9405, 76.9316, 76.9337, 76.9367,
76.9407, 76.9404, 76.9464, 76.9466, 76.95,
76.9517, 76.9613, 76.9611, 76.9667, 76.9603,
76.9585, 76.9579, 76.9246, 76.9359, 76.9483,
76.9978, 77.0101, 77.0225, 77.0349, 77.0844,
77.0968, 77.1092, 77.1216, 77.1711, 77.1835,
77.1958, 77.2578, 77.2825, 77.3444, 77.3691,
77.431, 77.4434, 77.5178, 77.5302, 77.6046,
77.617, 77.6791, 77.7039, 77.7661, 77.7785,
77.791, 77.8531, 77.8655, 77.878, 77.9277,
77.9401, 77.9526, 77.965, 78.0147, 78.0272,
78.0396, 78.0521, 78.1018, 78.1143, 78.1268,
78.1393, 78.189, 78.2015, 78.214, 78.2265,
78.2514, 78.2556, 78.2459, 78.2449, 78.2432,
78.2416, 78.2388, 78.2383, 78.2406, 78.2406,
78.2402, 78.2403, 78.2371, 78.2363, 78.2352,
78.2347, 78.2347, 78.231, 78.2298, 78.2303,
78.231, 78.2301, 78.23, 78.2291, 78.2277,
78.228, 78.229, 78.2273, 78.2263, 78.2208,
78.2219, 78.2215, 78.2186, 78.2185, 78.2107)
ORBIT_NUMBER = 5270
ORBITAL_ECCENTRICITY = 0.573
ORBITAL_INCLINATION = 86.74
ORBITAL_SEMIMAJOR_AXIS = 8712.4
PERIAPSIS_ALTITUDE = 331.9
PERIAPSIS_ARGUMENT_ANGLE = 151.2
PERIAPSIS_TIME = 2008-02-08T12:08:35.000Z
SPACECRAFT_ORIENTATION = (0.0, -1.0, 0.0)
^MEX_ORIENTATION_DESC = MEX_ORIENTATION_DESC.TXT
SPACECRAFT_POINTING_MODE = ACROSSTRACK
^MEX_POINTING_DESC = MEX_POINTING_DESC.TXT
RIGHT_ASCENSION = -1e+32
DECLINATION = -1e+32
OFFSET_ANGLE = 0.05
SPACECRAFT_SOLAR_DISTANCE = 2.42797e+08
TARGET_NAME = MARS

/* CAMERA DATA ELEMENTS */
DETECTOR_TEMPERATURE = 17.351 <degC>
FOCAL_PLANE_TEMPERATURE = 7.9716 <degC>
INST_CMPRS_NAME = "DISCRETE COSINE TRANSFORMATION (DCT)"
INST_CMPRS_RATIO = 11.2342
INST_CMPRS_QUALITY = 0
INST_CMPRS_QUANTZ_TBL_ID = 0
INSTRUMENT_TEMPERATURE = 11.0301 <degC>
LENS_TEMPERATURE = 8.1755 <degC>
MACROPIXEL_SIZE = 4
MISSING_FRAMES = 0
PIXEL_SUBSAMPLING_FLAG = N
SAMPLE_FIRST_PIXEL = 80
SIGNAL_CHAIN_ID = 2

/* RADIOMETRIC DATA ELEMENTS */
BANDWIDTH = 81.0 <nm>
CENTER_FILTER_WAVELENGTH = 955.5 <nm>
RADIANCE_OFFSET = 0.0 <W*m**-2*sr**-1>
RADIANCE_SCALING_FACTOR = 0.0169353 <W*m**-2*sr**-1>
REFLECTANCE_SCALING_FACTOR = 0.00215382

/* DATA OBJECT DEFINITIONS */
Object = IMAGE
INTERCHANGE_FORMAT = BINARY
Expand Down
Loading

0 comments on commit 759b307

Please sign in to comment.