diff --git a/ale/drivers/__init__.py b/ale/drivers/__init__.py index c721bd335532732225715b394aebe1d694fb3114..dec72175e47023f5b67aa0e6cb0a929b8e45722d 100644 --- a/ale/drivers/__init__.py +++ b/ale/drivers/__init__.py @@ -16,6 +16,7 @@ from collections import OrderedDict from ale.formatters.usgscsm_formatter import to_usgscsm from ale.formatters.isis_formatter import to_isis +from ale.formatters.formatter import to_isd from ale.base.data_isis import IsisSpice from abc import ABC @@ -32,7 +33,8 @@ __all__ = [driver for driver in __all__ if driver not in __disabled_drivers__] __driver_modules__ = [importlib.import_module('.'+m, package='ale.drivers') for m in __all__] __formatters__ = {'usgscsm': to_usgscsm, - 'isis': to_isis} + 'isis': to_isis, + 'ale' : to_isd} def sort_drivers(drivers=[]): return list(sorted(drivers, key=lambda x:IsisSpice in x.__bases__, reverse=False)) @@ -51,7 +53,7 @@ class AleJsonEncoder(json.JSONEncoder): return obj.isoformat() return json.JSONEncoder.default(self, obj) -def load(label, props={}, formatter='usgscsm', verbose=False): +def load(label, props={}, formatter='ale', verbose=False): """ Attempt to load a given label from all possible drivers @@ -86,6 +88,6 @@ def load(label, props={}, formatter='usgscsm', verbose=False): traceback.print_exc() raise Exception('No Such Driver for Label') -def loads(label, props='', formatter='usgscsm', verbose=False): +def loads(label, props='', formatter='ale', verbose=False): res = load(label, props, formatter, verbose=verbose) return json.dumps(res, cls=AleJsonEncoder) diff --git a/ale/formatters/formatter.py b/ale/formatters/formatter.py new file mode 100644 index 0000000000000000000000000000000000000000..b7451498ffd899a20b57ad70ac057be18e8e341d --- /dev/null +++ b/ale/formatters/formatter.py @@ -0,0 +1,164 @@ +import json +import numpy as np +from scipy.interpolate import interp1d, BPoly + +from networkx.algorithms.shortest_paths.generic import shortest_path + +from ale.transformation import FrameChain +from ale.base.type_sensor import LineScanner, Framer +from ale.rotation import ConstantRotation, TimeDependentRotation + +def to_isd(driver): + """ + Formatter to create sensor model meta data from a driver. + + Parameters + ---------- + driver : Driver + Concrete driver for the image that meta data is being generated for. + + Returns + ------- + string + The ISIS compatible meta data as a JSON encoded string. + """ + + + meta_data = {} + + meta_data['IsisCameraVersion'] = driver.sensor_model_version + + # interiror orientation + meta_data['NaifKeywords'] = driver.naif_keywords + meta_data['detector_sample_summing'] = driver.sample_summing + meta_data['detector_line_summing'] = driver.line_summing + meta_data['focal_length_model'] = { + 'focal_length' : driver.focal_length + } + meta_data['detector_center'] = { + 'line' : driver.detector_center_line, + 'sample' : driver.detector_center_sample + } + + meta_data['starting_detector_line'] = driver.detector_start_line + meta_data['starting_detector_sample'] = driver.detector_start_sample + meta_data['focal2pixel_lines'] = driver.focal2pixel_lines + meta_data['focal2pixel_samples'] = driver.focal2pixel_samples + meta_data['optical_distortion'] = driver.usgscsm_distortion_model + + # general information + meta_data['image_lines'] = driver.image_lines + meta_data['image_samples'] = driver.image_samples + meta_data['name_platform'] = driver.platform_name + meta_data['name_sensor'] = driver.sensor_name + meta_data['reference_height'] = { + "maxheight": 1000, + "minheight": -1000, + "unit": "m" + } + + # line scan sensor model specifics + if isinstance(driver, LineScanner): + meta_data['name_model'] = 'USGS_ASTRO_LINE_SCANNER_SENSOR_MODEL' + meta_data['interpolation_method'] = 'lagrange' + + start_lines, start_times, scan_rates = driver.line_scan_rate + center_time = driver.center_ephemeris_time + meta_data['line_scan_rate'] = [[line, time, rate] for line, time, rate in zip(start_lines, start_times, scan_rates)] + meta_data['starting_ephemeris_time'] = driver.ephemeris_start_time + meta_data['center_ephemeris_time'] = center_time + + # frame sensor model specifics + if isinstance(driver, Framer): + meta_data['name_model'] = 'USGS_ASTRO_FRAME_SENSOR_MODEL' + meta_data['center_ephemeris_time'] = driver.center_ephemeris_time + + frame_chain = driver.frame_chain + sensor_frame = driver.sensor_frame_id + target_frame = driver.target_frame_id + + body_radii = driver.target_body_radii + meta_data['radii'] = { + 'semimajor' : body_radii[0], + 'semiminor' : body_radii[2], + 'unit' : 'km' + } + + instrument_pointing = {} + source_frame, destination_frame, time_dependent_sensor_frame = frame_chain.last_time_dependent_frame_between(1, sensor_frame) + + # Reverse the frame order because ISIS orders frames as + # (destination, intermediate, ..., intermediate, source) + instrument_pointing['TimeDependentFrames'] = shortest_path(frame_chain, destination_frame, 1) + time_dependent_rotation = frame_chain.compute_rotation(1, destination_frame) + instrument_pointing['CkTableStartTime'] = time_dependent_rotation.times[0] + instrument_pointing['CkTableEndTime'] = time_dependent_rotation.times[-1] + instrument_pointing['CkTableOriginalSize'] = len(time_dependent_rotation.times) + instrument_pointing['EphemerisTimes'] = time_dependent_rotation.times + instrument_pointing['Quaternions'] = time_dependent_rotation.quats[:, [3, 0, 1, 2]] + instrument_pointing['AngularVelocity'] = time_dependent_rotation.av + + # Reverse the frame order because ISIS orders frames as + # (destination, intermediate, ..., intermediate, source) + instrument_pointing['ConstantFrames'] = shortest_path(frame_chain, sensor_frame, destination_frame) + constant_rotation = frame_chain.compute_rotation(destination_frame, sensor_frame) + instrument_pointing['ConstantRotation'] = constant_rotation.rotation_matrix().flatten() + meta_data['InstrumentPointing'] = instrument_pointing + + body_rotation = {} + source_frame, destination_frame, time_dependent_target_frame = frame_chain.last_time_dependent_frame_between(target_frame, 1) + + if source_frame != 1: + # Reverse the frame order because ISIS orders frames as + # (destination, intermediate, ..., intermediate, source) + body_rotation['TimeDependentFrames'] = shortest_path(frame_chain, source_frame, 1) + time_dependent_rotation = frame_chain.compute_rotation(1, source_frame) + body_rotation['CkTableStartTime'] = time_dependent_rotation.times[0] + body_rotation['CkTableEndTime'] = time_dependent_rotation.times[-1] + body_rotation['CkTableOriginalSize'] = len(time_dependent_rotation.times) + body_rotation['EphemerisTimes'] = time_dependent_rotation.times + body_rotation['Quaternions'] = time_dependent_rotation.quats[:, [3, 0, 1, 2]] + body_rotation['AngularVelocity'] = time_dependent_rotation.av + + if source_frame != target_frame: + # Reverse the frame order because ISIS orders frames as + # (destination, intermediate, ..., intermediate, source) + body_rotation['ConstantFrames'] = shortest_path(frame_chain, target_frame, source_frame) + constant_rotation = frame_chain.compute_rotation(source_frame, target_frame) + body_rotation['ConstantRotation'] = constant_rotation.rotation_matrix().flatten() + + meta_data['BodyRotation'] = body_rotation + + j2000_rotation = frame_chain.compute_rotation(target_frame, 1) + + instrument_position = {} + positions, velocities, times = driver.sensor_position + instrument_position['SpkTableStartTime'] = times[0] + instrument_position['SpkTableEndTime'] = times[-1] + instrument_position['SpkTableOriginalSize'] = len(times) + instrument_position['EphemerisTimes'] = times + # Rotate positions and velocities into J2000 then scale into kilometers + velocities = j2000_rotation.rotate_velocity_at(positions, velocities, times)/1000 + positions = j2000_rotation.apply_at(positions, times)/1000 + instrument_position['Positions'] = positions + instrument_position['Velocities'] = velocities + meta_data['InstrumentPosition'] = instrument_position + + sun_position = {} + positions, velocities, times = driver.sun_position + sun_position['SpkTableStartTime'] = times[0] + sun_position['SpkTableEndTime'] = times[-1] + sun_position['SpkTableOriginalSize'] = len(times) + sun_position['EphemerisTimes'] = times + # Rotate positions and velocities into J2000 then scale into kilometers + velocities = j2000_rotation.rotate_velocity_at(positions, velocities, times)/1000 + positions = j2000_rotation.apply_at(positions, times)/1000 + sun_position['Positions'] = positions + sun_position['Velocities'] = velocities + meta_data['SunPosition'] = sun_position + + # check that there is a valid sensor model name + if 'name_model' not in meta_data: + raise Exception('No CSM sensor model name found!') + + return meta_data diff --git a/tests/pytests/conftest.py b/tests/pytests/conftest.py index 77f2a55c73f262c9b9d459ad0d2dffde3c6f4e05..c49b36bec02c3bb76ccce8afb5b4c5731de3d4a0 100644 --- a/tests/pytests/conftest.py +++ b/tests/pytests/conftest.py @@ -3,6 +3,8 @@ import os import re import warnings import numpy as np +import json + import ale from glob import glob @@ -93,6 +95,17 @@ def get_image_label(image, label_type='pds3'): return label_file[0] +def get_isd(instrument): + if not isinstance(instrument, str): + raise KeyError('instrument name is not a string') + + label_file = glob(os.path.join(data_root, 'isds',f'{instrument}_isd.json')) + if not label_file: + raise Exception(f'Could not find label file for {instrument}') + + return json.load(open(label_file[0])) + + def get_image_kernels(image): """ Get the kernels to use with a test image. diff --git a/tests/pytests/data/isds/ctx_isd.json b/tests/pytests/data/isds/ctx_isd.json new file mode 100644 index 0000000000000000000000000000000000000000..4b99577e95beb301bc2e61e55390c77e374f8ffb --- /dev/null +++ b/tests/pytests/data/isds/ctx_isd.json @@ -0,0 +1,506 @@ +{ + "IsisCameraVersion": 1, + "NaifKeywords": { + "BODY499_RADII": [ + 3396.19, + 3396.19, + 3376.2 + ], + "BODY_FRAME_CODE": 10014, + "BODY_CODE": 499, + "INS-74021_FOV_ANGLE_UNITS": "DEGREES", + "TKFRAME_-74021_UNITS": "DEGREES", + "INS-74021_FOV_ANGULAR_SIZE": [ + 5.73, + 0.001146 + ], + "INS-74021_PIXEL_LINES": 1.0, + "TKFRAME_-74021_ANGLES": [ + 0.0, + 0.0, + 0.0 + ], + "INS-74021_IFOV": [ + 2e-05, + 2e-05 + ], + "FRAME_-74021_CENTER": -74.0, + "INS-74021_F/RATIO": 3.25, + "INS-74021_PLATFORM_ID": -74000.0, + "INS-74021_CCD_CENTER": [ + 2500.5, + 0.5 + ], + "INS-74021_PIXEL_SAMPLES": 5000.0, + "INS-74021_FOCAL_LENGTH": 352.9271664, + "INS-74021_FOV_CROSS_ANGLE": 0.00057296, + "INS-74021_TRANSX": [ + 0.0, + 0.0, + 0.007 + ], + "INS-74021_FOV_CLASS_SPEC": "ANGLES", + "INS-74021_TRANSY": [ + 0.0, + 0.007, + 0.0 + ], + "INS-74021_FOV_REF_VECTOR": [ + 0.0, + 1.0, + 0.0 + ], + "INS-74021_BORESIGHT": [ + 0.0, + 0.0, + 1.0 + ], + "FRAME_-74021_NAME": "MRO_CTX", + "INS-74021_PIXEL_PITCH": 0.007, + "TKFRAME_-74021_AXES": [ + 1.0, + 2.0, + 3.0 + ], + "TKFRAME_-74021_SPEC": "ANGLES", + "INS-74021_BORESIGHT_LINE": 0.430442527, + "INS-74021_FOV_SHAPE": "RECTANGLE", + "INS-74021_BORESIGHT_SAMPLE": 2543.46099, + "FRAME_-74021_CLASS": 4.0, + "INS-74021_CK_FRAME_ID": -74000.0, + "INS-74021_ITRANSL": [ + 0.0, + 142.85714285714, + 0.0 + ], + "INS-74021_FOV_REF_ANGLE": 2.86478898, + "INS-74021_ITRANSS": [ + 0.0, + 0.0, + 142.85714285714 + ], + "FRAME_-74021_CLASS_ID": -74021.0, + "INS-74021_OD_K": [ + -0.0073433925920054505, + 2.8375878636241697e-05, + 1.2841989124027099e-08 + ], + "INS-74021_FOV_FRAME": "MRO_CTX", + "INS-74021_CK_REFERENCE_ID": -74900.0, + "TKFRAME_-74021_RELATIVE": "MRO_CTX_BASE", + "INS-74021_PIXEL_SIZE": [ + 0.007, + 0.007 + ], + "SCLK_PARTITION_END_74999": [ + 52973626698957.0, + 56987144678331.0, + 58187590527162.99, + 60316687182323.0, + 60877152115000.0, + 61228279788693.0, + 61339176915162.99, + 61899057915627.0, + 63521451859691.0, + 65622287643263.0 + ], + "SCLK01_N_FIELDS_74999": 2.0, + "SCLK01_OUTPUT_DELIM_74999": 1.0, + "BODY499_POLE_DEC": [ + 52.8865, + -0.0609, + 0.0 + ], + "SCLK01_OFFSETS_74999": [ + 0.0, + 0.0 + ], + "SCLK_DATA_TYPE_74999": 1.0, + "SCLK01_COEFFICIENTS_74999": [ + 0.0, + -631195148.816, + 1.0, + 3097283854336.0, + -583934347.816, + 1.0, + 5164027215872.0, + -552398346.816, + 1.0, + 7230770577408.0 + ], + "SCLK01_TIME_SYSTEM_74999": 2.0, + "SCLK_PARTITION_START_74999": [ + 0.0, + 52973626982399.99, + 56987144683520.0, + 58187590533120.0, + 60316687204352.01, + 60877152124927.99, + 61228279791616.0, + 61339176927232.0, + 61899057922048.0, + 63521451868160.0 + ], + "BODY499_POLE_RA": [ + 317.68143, + -0.1061, + 0.0 + ], + "BODY499_PM": [ + 176.63, + 350.89198226, + 0.0 + ], + "SCLK01_MODULI_74999": [ + 4294967296.0, + 65536.0 + ] + }, + "detector_sample_summing": 1, + "detector_line_summing": 1, + "focal_length_model": { + "focal_length": 352.9271664 + }, + "detector_center": { + "line": 0.430442527, + "sample": 2542.96099 + }, + "starting_detector_line": 0, + "starting_detector_sample": 0, + "focal2pixel_lines": [ + 0.0, + 142.85714285714, + 0.0 + ], + "focal2pixel_samples": [ + 0.0, + 0.0, + 142.85714285714 + ], + "optical_distortion": { + "radial": { + "coefficients": [ + -0.0073433925920054505, + 2.8375878636241697e-05, + 1.2841989124027099e-08 + ] + } + }, + "image_lines": 400, + "image_samples": 5056, + "name_platform": "Mars_Reconnaissance_Orbiter", + "name_sensor": "CONTEXT CAMERA", + "reference_height": { + "maxheight": 1000, + "minheight": -1000, + "unit": "m" + }, + "name_model": "USGS_ASTRO_LINE_SCANNER_SENSOR_MODEL", + "interpolation_method": "lagrange", + "line_scan_rate": [ + [ + 0.5, + -0.37540000677108765, + 0.001877 + ] + ], + "starting_ephemeris_time": 297088762.24158406, + "center_ephemeris_time": 297088762.61698407, + "radii": { + "semimajor": 3396.19, + "semiminor": 3376.2, + "unit": "km" + }, + "InstrumentPointing": { + "TimeDependentFrames": [ + -74000, + -74900, + 1 + ], + "CkTableStartTime": 297088762.24158406, + "CkTableEndTime": 297088762.9923841, + "CkTableOriginalSize": 6, + "EphemerisTimes": [ + 297088762.24158406, + 297088762.3917441, + 297088762.5419041, + 297088762.69206405, + 297088762.84222406, + 297088762.9923841 + ], + "Quaternions": [ + [ + 0.42061124835443375, + 0.1860622266332136, + -0.23980124331599867, + 0.8549633847610767 + ], + [ + 0.42062260840195603, + 0.186123564618581, + -0.23976950628253949, + 0.8549533460089124 + ], + [ + 0.4206354696231763, + 0.18618437842074986, + -0.23973759356053978, + 0.8549427262458993 + ], + [ + 0.42064763332258537, + 0.18624550650991442, + -0.23970570189408144, + 0.8549323694681581 + ], + [ + 0.42065922954773666, + 0.1863066728084066, + -0.23967381992970707, + 0.8549222750073063 + ], + [ + 0.4206714374933977, + 0.1863668684529047, + -0.23964184692167076, + 0.8549121108185723 + ] + ], + "AngularVelocity": [ + [ + -0.0006409728984903079, + 0.0005054077299115119, + 0.0004718267948468069 + ], + [ + -0.0006410700774431097, + 0.0005044862657976017, + 0.0004731836236807216 + ], + [ + -0.0006408186407087456, + 0.0004992170698116158, + 0.0004802237192760833 + ], + [ + -0.0006363961683672021, + 0.0004989647975959612, + 0.00047654664046286975 + ], + [ + -0.0006376443791903504, + 0.0004996117504290811, + 0.00047678850931380653 + ], + [ + -0.0006404093657132724, + 0.0005028749658176146, + 0.0004805228583087444 + ] + ], + "ConstantFrames": [ + -74021, + -74020, + -74699, + -74690, + -74000 + ], + "ConstantRotation": [ + 0.9999995608798441, + -1.51960241928035e-05, + 0.0009370214510594064, + 1.5276552075356694e-05, + 0.9999999961910578, + -8.593317911879532e-05, + -0.000937020141647677, + 8.594745584079714e-05, + 0.9999995573030465 + ] + }, + "BodyRotation": { + "TimeDependentFrames": [ + 10014, + 1 + ], + "CkTableStartTime": 297088762.24158406, + "CkTableEndTime": 297088762.9923841, + "CkTableOriginalSize": 6, + "EphemerisTimes": [ + 297088762.24158406, + 297088762.3917441, + 297088762.5419041, + 297088762.69206405, + 297088762.84222406, + 297088762.9923841 + ], + "Quaternions": [ + [ + -0.8371209459443085, + 0.2996928944391797, + 0.10720760458181891, + 0.4448811306448063 + ], + [ + -0.8371185783490869, + 0.2996934649760026, + 0.1072060096645597, + 0.4448855856569007 + ], + [ + -0.8371162107293473, + 0.2996940355045328, + 0.10720441474371896, + 0.44489004065791765 + ], + [ + -0.8371138430875174, + 0.2996946060241849, + 0.1072028198209324, + 0.44489449564328926 + ], + [ + -0.8371114754203602, + 0.2996951765357392, + 0.10720122489401934, + 0.44489895061910595 + ], + [ + -0.8371091077303039, + 0.29969574703861046, + 0.10719962996461516, + 0.4449034055807993 + ] + ], + "AngularVelocity": [ + [ + 3.16238646979841e-05, + -2.880432898124293e-05, + 5.6520131658726165e-05 + ], + [ + 3.1623864697983686e-05, + -2.880432898124763e-05, + 5.652013165872402e-05 + ], + [ + 3.162386469798325e-05, + -2.880432898125237e-05, + 5.652013165872185e-05 + ], + [ + 3.162386469798283e-05, + -2.880432898125708e-05, + 5.6520131658719694e-05 + ], + [ + 3.1623864697982405e-05, + -2.8804328981261782e-05, + 5.6520131658717505e-05 + ], + [ + 3.162386469798195e-05, + -2.88043289812665e-05, + 5.652013165871536e-05 + ] + ] + }, + "InstrumentPosition": { + "SpkTableStartTime": 297088762.24158406, + "SpkTableEndTime": 297088762.9923841, + "SpkTableOriginalSize": 6, + "EphemerisTimes": [ + 297088762.24158406, + 297088762.3917441, + 297088762.5419041, + 297088762.69206405, + 297088762.84222406, + 297088762.9923841 + ], + "Positions": [ + [ + -1885.298067561683, + 913.165223601331, + -2961.966828003069 + ], + [ + -1885.5928012826328, + 912.7436266030271, + -2961.910568238333 + ], + [ + -1885.8874970695995, + 912.3220111689507, + -2961.8542488448256 + ], + [ + -1886.1821547735613, + 911.9003774862961, + -2961.797869848145 + ], + [ + -1886.47677475216, + 911.4787252225885, + -2961.7414312040696 + ], + [ + -1886.7713566477582, + 911.0570545575632, + -2961.684932934942 + ] + ], + "Velocities": [ + [ + -1.9629237646703683, + -2.80759072221274, + 0.37446657801485306 + ], + [ + -1.9626712192798401, + -2.807713482051373, + 0.3748636774173111 + ], + [ + -1.9624186346660286, + -2.807836185534424, + 0.3752607691067297 + ], + [ + -1.9621660109346446, + -2.8079588326107823, + 0.37565785291714804 + ], + [ + -1.9619133478903363, + -2.8080814233753033, + 0.37605492915558875 + ], + [ + -1.961660645638678, + -2.8082039577768683, + 0.37645199765665144 + ] + ] + }, + "SunPosition": { + "SpkTableStartTime": 297088762.61698407, + "SpkTableEndTime": 297088762.61698407, + "SpkTableOriginalSize": 1, + "EphemerisTimes": [ + 297088762.61698407 + ], + "Positions": [ + [ + -208246643.08248276, + -7677087.066457123, + 2103548.956999197 + ] + ], + "Velocities": [ + [ + -0.21020163267146563, + -23.901883517440407, + -10.957471339412034 + ] + ] + } +} diff --git a/tests/pytests/test_mro_drivers.py b/tests/pytests/test_mro_drivers.py index e1d96d601cdf1656ac028e36899c2463adc7fd9b..11713563b75d8f6973f5895493988d20e0be96f5 100644 --- a/tests/pytests/test_mro_drivers.py +++ b/tests/pytests/test_mro_drivers.py @@ -10,276 +10,10 @@ import spiceypy as spice import ale from ale.drivers.mro_drivers import MroCtxPds3LabelNaifSpiceDriver, MroCtxIsisLabelNaifSpiceDriver, MroCtxIsisLabelIsisSpiceDriver -from conftest import get_image_kernels, convert_kernels, get_image_label, compare_dicts - -@pytest.fixture() -def usgscsm_compare_dict(): - return { - 'radii': {'semimajor': 3396.19, 'semiminor': 3376.2, 'unit': 'km'}, - 'sensor_position': {'positions': [[-615024.6029557, -97969.68743736, -3574019.26371975], - [-615533.14603391, -97907.93120584, -3573934.57376263], - [-616041.67554001, -97846.16219439, -3573849.81184277], - [-616550.19123687, -97784.38044738, -3573764.97799019], - [-617058.69359867, -97722.58582759, -3573680.07219406], - [-617567.18227279, -97660.77852259, -3573595.09438568]], - 'velocities': [[-3386.71997092, 411.22641239, 563.75851535], - [-3386.62961915, 411.31156579, 564.23771317], - [-3386.53919809, 411.39670907, 564.71689945], - [-3386.44870778, 411.48184218, 565.19607397], - [-3386.35814814, 411.56696521, 565.6752371], - [-3386.26751923, 411.65207807, 566.15438866]], - 'unit': 'm'}, - 'sun_position': {'positions': [[-127052102329.16032, 139728839049.65073, -88111530293.94502]], - 'velocities': [[9883868.06162645, 8989183.29614645, 881.9339912834714]], - 'unit': 'm'}, - 'sensor_orientation': {'quaternions': [[0.0839325155418464, 0.01773153459973093, 0.9946048838768001, 0.05832709905329942], - [0.08400255389846106, 0.017728573660888425, 0.9945982552324419, 0.05834020314559307], - [0.08407274386779334, 0.01772597983213095, 0.9945916990701015, 0.058351653947255444], - [0.08414295024563552, 0.01772323147647109, 0.9945850926215931, 0.05836389744430205], - [0.08421298603777544, 0.017720474751607096, 0.9945784602692478, 0.05837674302007029], - [0.08428244063999614, 0.017718270399902286, 0.9945719105583338, 0.05838876451978814]]}, - 'detector_sample_summing': 1, - 'detector_line_summing': 1, - 'focal_length_model': {'focal_length': 352.9271664}, - 'detector_center': {'line': 0.430442527, 'sample': 2542.96099}, - 'starting_detector_line': 0, - 'starting_detector_sample': 0, - 'focal2pixel_lines': [0.0, 142.85714285714, 0.0], - 'focal2pixel_samples': [0.0, 0.0, 142.85714285714], - 'optical_distortion': {'radial': {'coefficients': [-0.0073433925920054505, 2.8375878636241697e-05, 1.2841989124027099e-08]}}, - 'image_lines': 400, - 'image_samples': 5056, - 'name_platform': 'MARS_RECONNAISSANCE_ORBITER', - 'name_sensor': 'CONTEXT CAMERA', - 'reference_height': {'maxheight': 1000, 'minheight': -1000, 'unit': 'm'}, - 'name_model': 'USGS_ASTRO_LINE_SCANNER_SENSOR_MODEL', - 'interpolation_method': 'lagrange', - 'line_scan_rate': [[0.5, -0.37540000677108765, 0.001877]], - 'starting_ephemeris_time': 297088762.24158406, - 'center_ephemeris_time': 297088762.61698407, - 't0_ephemeris': -0.37540000677108765, - 'dt_ephemeris': 0.15016000270843505, - 't0_quaternion': -0.37540000677108765, - 'dt_quaternion': 0.15016000270843505} - -@pytest.fixture() -def isis_compare_dict(): - return { - 'CameraVersion': 1, -"NaifKeywords": { - "BODY499_RADII": [ - 3396.19, - 3396.19, - 3376.2 - ], - "BODY_FRAME_CODE": 10014, - "BODY_CODE": 499, - "INS-74021_FOV_ANGLE_UNITS": "DEGREES", - "TKFRAME_-74021_UNITS": "DEGREES", - "INS-74021_FOV_ANGULAR_SIZE": [ - 5.73, - 0.001146 - ], - "INS-74021_PIXEL_LINES": 1.0, - "TKFRAME_-74021_ANGLES": [ - 0.0, - 0.0, - 0.0 - ], - "INS-74021_IFOV": [ - 2e-05, - 2e-05 - ], - "FRAME_-74021_CENTER": -74.0, - "INS-74021_F/RATIO": 3.25, - "INS-74021_PLATFORM_ID": -74000.0, - "INS-74021_CCD_CENTER": [ - 2500.5, - 0.5 - ], - "INS-74021_PIXEL_SAMPLES": 5000.0, - "INS-74021_FOCAL_LENGTH": 352.9271664, - "INS-74021_FOV_CROSS_ANGLE": 0.00057296, - "INS-74021_TRANSX": [ - 0.0, - 0.0, - 0.007 - ], - "INS-74021_FOV_CLASS_SPEC": "ANGLES", - "INS-74021_TRANSY": [ - 0.0, - 0.007, - 0.0 - ], - "INS-74021_FOV_REF_VECTOR": [ - 0.0, - 1.0, - 0.0 - ], - "INS-74021_BORESIGHT": [ - 0.0, - 0.0, - 1.0 - ], - "FRAME_-74021_NAME": "MRO_CTX", - "INS-74021_PIXEL_PITCH": 0.007, - "TKFRAME_-74021_AXES": [ - 1.0, - 2.0, - 3.0 - ], - "TKFRAME_-74021_SPEC": "ANGLES", - "INS-74021_BORESIGHT_LINE": 0.430442527, - "INS-74021_FOV_SHAPE": "RECTANGLE", - "INS-74021_BORESIGHT_SAMPLE": 2543.46099, - "FRAME_-74021_CLASS": 4.0, - "INS-74021_CK_FRAME_ID": -74000.0, - "INS-74021_ITRANSL": [ - 0.0, - 142.85714285714, - 0.0 - ], - "INS-74021_FOV_REF_ANGLE": 2.86478898, - "INS-74021_ITRANSS": [ - 0.0, - 0.0, - 142.85714285714 - ], - "FRAME_-74021_CLASS_ID": -74021.0, - "INS-74021_OD_K": [ - -0.0073433925920054505, - 2.8375878636241697e-05, - 1.2841989124027099e-08 - ], - "INS-74021_FOV_FRAME": "MRO_CTX", - "INS-74021_CK_REFERENCE_ID": -74900.0, - "TKFRAME_-74021_RELATIVE": "MRO_CTX_BASE", - "INS-74021_PIXEL_SIZE": [ - 0.007, - 0.007 - ], - "SCLK_PARTITION_END_74999": [ - 52973626698957.0, - 56987144678331.0, - 58187590527162.99, - 60316687182323.0, - 60877152115000.0, - 61228279788693.0, - 61339176915162.99, - 61899057915627.0, - 63521451859691.0, - 65622287643263.0 - ], - "SCLK01_N_FIELDS_74999": 2.0, - "SCLK01_OUTPUT_DELIM_74999": 1.0, - "BODY499_POLE_DEC": [ - 52.8865, - -0.0609, - 0.0 - ], - "SCLK01_OFFSETS_74999": [ - 0.0, - 0.0 - ], - "SCLK_DATA_TYPE_74999": 1.0, - "SCLK01_COEFFICIENTS_74999": [ - 0.0, - -631195148.816, - 1.0, - 3097283854336.0, - -583934347.816, - 1.0, - 5164027215872.0, - -552398346.816, - 1.0, - 7230770577408.0 - ], - "SCLK01_TIME_SYSTEM_74999": 2.0, - "SCLK_PARTITION_START_74999": [ - 0.0, - 52973626982399.99, - 56987144683520.0, - 58187590533120.0, - 60316687204352.01, - 60877152124927.99, - 61228279791616.0, - 61339176927232.0, - 61899057922048.0, - 63521451868160.0 - ], - "BODY499_POLE_RA": [ - 317.68143, - -0.1061, - 0.0 - ], - "BODY499_PM": [ - 176.63, - 350.89198226, - 0.0 - ], - "SCLK01_MODULI_74999": [ - 4294967296.0, - 65536.0 - ] - }, - 'InstrumentPointing': {'TimeDependentFrames': [-74000, -74900, 1], - 'ConstantFrames': [-74021, -74020, -74699, -74690, -74000], - 'ConstantRotation': [0.9999995608798441, -1.51960241928035e-05, 0.0009370214510594064, 1.5276552075356694e-05, 0.9999999961910578, -8.593317911879532e-05, -0.000937020141647677, 8.594745584079714e-05, 0.9999995573030465], - 'CkTableStartTime': 297088762.24158406, - 'CkTableEndTime': 297088762.9923841, - 'CkTableOriginalSize': 6, - 'EphemerisTimes': [297088762.24158406, 297088762.3917441, 297088762.5419041, 297088762.69206405, 297088762.84222406, 297088762.9923841], - 'Quaternions': [[0.42061125, 0.18606223, -0.23980124, 0.85496338], - [0.42062261, 0.18612356, -0.23976951, 0.85495335], - [0.42063547, 0.18618438, -0.23973759, 0.85494273], - [0.42064763, 0.18624551, -0.2397057 , 0.85493237], - [0.42065923, 0.18630667, -0.23967382, 0.85492228], - [0.42067144, 0.18636687, -0.23964185, 0.85491211]], - 'AngularVelocity': [[-0.0006409728984903079, 0.0005054077299115119, 0.0004718267948468069], - [-0.0006410700774431097, 0.0005044862657976017, 0.0004731836236807216], - [-0.0006408186407087456, 0.0004992170698116158, 0.0004802237192760833], - [-0.0006363961683672021, 0.0004989647975959612, 0.00047654664046286975], - [-0.0006376443791903504, 0.0004996117504290811, 0.00047678850931380653], - [-0.0006404093657132724, 0.0005028749658176146, 0.0004805228583087444]]}, - 'BodyRotation': {'TimeDependentFrames': [10014, 1], - 'CkTableStartTime': 297088762.24158406, - 'CkTableEndTime': 297088762.9923841, - 'CkTableOriginalSize': 6, - 'EphemerisTimes': [297088762.24158406, 297088762.3917441, 297088762.5419041, 297088762.69206405, 297088762.84222406, 297088762.9923841], - 'Quaternions': [[-0.8371209459443085, 0.2996928944391797, 0.10720760458181891, 0.4448811306448063], - [-0.8371185783490869, 0.2996934649760026, 0.1072060096645597, 0.4448855856569007], - [-0.8371162107293473, 0.2996940355045328, 0.10720441474371896, 0.44489004065791765], - [-0.8371138430875174, 0.2996946060241849, 0.1072028198209324, 0.44489449564328926], - [-0.8371114754203602, 0.2996951765357392, 0.10720122489401934, 0.44489895061910595], - [-0.8371091077303039, 0.29969574703861046, 0.10719962996461516, 0.4449034055807993]], - 'AngularVelocity': [[3.16238646979841e-05, -2.880432898124293e-05, 5.6520131658726165e-05], - [3.1623864697983686e-05, -2.880432898124763e-05, 5.652013165872402e-05], - [3.162386469798325e-05, -2.880432898125237e-05, 5.652013165872185e-05], - [3.162386469798283e-05, -2.880432898125708e-05, 5.6520131658719694e-05], - [3.1623864697982405e-05, -2.8804328981261782e-05, 5.6520131658717505e-05], - [3.162386469798195e-05, -2.88043289812665e-05, 5.652013165871536e-05]]}, - 'InstrumentPosition': {'SpkTableStartTime': 297088762.24158406, - 'SpkTableEndTime': 297088762.9923841, - 'SpkTableOriginalSize': 6, - 'EphemerisTimes': [297088762.24158406, 297088762.3917441, 297088762.5419041, 297088762.69206405, 297088762.84222406, 297088762.9923841], - 'Positions': [[-1885.29806756, 913.1652236, -2961.966828], - [-1885.59280128, 912.7436266, -2961.91056824], - [-1885.88749707, 912.32201117, -2961.85424884], - [-1886.18215477, 911.90037749, -2961.79786985], - [-1886.47677475, 911.47872522, -2961.7414312], - [-1886.77135665, 911.05705456, -2961.68493293]], - 'Velocities': [[-1.9629237646703683, -2.80759072221274, 0.37446657801485306], - [-1.9626712192798401, -2.807713482051373, 0.3748636774173111], - [-1.9624186346660286, -2.807836185534424, 0.3752607691067297], - [-1.9621660109346446, -2.8079588326107823, 0.37565785291714804], - [-1.9619133478903363, -2.8080814233753033, 0.37605492915558875], - [-1.961660645638678, -2.8082039577768683, 0.37645199765665144]]}, - 'SunPosition': {'SpkTableStartTime': 297088762.61698407, - 'SpkTableEndTime': 297088762.61698407, - 'SpkTableOriginalSize': 1, - 'EphemerisTimes': [297088762.61698407], - 'Positions': [[-208246643.00357282, -7677078.093689713, 2103553.070434019]], - 'Velocities': [[-0.21020163267146563, -23.901883517440407, -10.957471339412034]]}} +from conftest import get_image_kernels, get_isd, convert_kernels, get_image_label, compare_dicts + +#@pytest.fixture +# def ctx_isf @pytest.fixture(scope='module') def test_kernels(): @@ -290,24 +24,17 @@ def test_kernels(): os.remove(kern) @pytest.mark.parametrize("label_type", ['pds3', 'isis3']) -@pytest.mark.parametrize("formatter", ['isis', 'usgscsm']) -def test_mro_load(test_kernels, label_type, formatter, usgscsm_compare_dict, isis_compare_dict): +def test_mro_load(test_kernels, label_type): label_file = get_image_label('B10_013341_1010_XN_79S172W', label_type) - usgscsm_isd_str = ale.loads(label_file, props={'kernels': test_kernels}, formatter=formatter) - usgscsm_isd_obj = json.loads(usgscsm_isd_str) - print(json.dumps(usgscsm_isd_obj, indent=4)) + isd_str = ale.loads(label_file, props={'kernels': test_kernels}) + isd_obj = json.loads(isd_str) + compare_isd = get_isd('ctx') + if label_type == 'isis3': + compare_isd['image_samples'] = 5000 - if formatter=='usgscsm': - # Check to change the line based on ISIS vs PDS3 - # This is due to a processing step in mroctx2isis that removes samples - # based on some flags on the label - if label_type == 'isis3': - usgscsm_compare_dict['image_samples'] = 5000 - assert compare_dicts(usgscsm_isd_obj, usgscsm_compare_dict) == [] - else: - assert compare_dicts(usgscsm_isd_obj, isis_compare_dict) == [] + assert compare_dicts(isd_obj, compare_isd) == [] # ========= Test isislabel and isisspice driver ========= class test_isis_isis(unittest.TestCase):