diff --git a/ale/rotation.py b/ale/rotation.py index 62bc3855a56d75bf98606ef5e1086673f3732d15..600ca3881348a1d40f5acd0cca597da46d602a7e 100644 --- a/ale/rotation.py +++ b/ale/rotation.py @@ -110,7 +110,7 @@ class ConstantRotation: new_rot = self._rot * other._rot return ConstantRotation(new_rot.as_quat(), other.source, self.dest) elif isinstance(other, TimeDependentRotation): - return TimeDependentRotation((self._rot * other._rots).as_quat(), other.times, other.source, self.dest, av=self._rot.apply(other.av)) + return TimeDependentRotation((self._rot * other._rots).as_quat(), other.times, other.source, self.dest, av=other.av) else: raise TypeError("Rotations can only be composed with other rotations.") @@ -325,13 +325,18 @@ class TimeDependentRotation: if self.source != other.dest: raise ValueError("Destination frame of first rotation {} is not the same as source frame of second rotation {}.".format(other.dest, self.source)) if isinstance(other, ConstantRotation): - return TimeDependentRotation((self._rots * other._rot).as_quat(), self.times, other.source, self.dest, av=self.av) + if self.av is not None: + other_inverse = other._rot.inv() + new_av = np.asarray([other_inverse.apply(av) for av in self.av]) + else: + new_av = None + return TimeDependentRotation((self._rots * other._rot).as_quat(), self.times, other.source, self.dest, av=new_av) elif isinstance(other, TimeDependentRotation): merged_times = np.union1d(np.asarray(self.times), np.asarray(other.times)) reinterp_self = self.reinterpolate(merged_times) reinterp_other = other.reinterpolate(merged_times) new_quats = (reinterp_self._rots * reinterp_other._rots).as_quat() - new_av = reinterp_self.av + reinterp_self._rots.apply(reinterp_other.av) + new_av = reinterp_other._rots.inv().apply(reinterp_self.av) + reinterp_other.av return TimeDependentRotation(new_quats, merged_times, other.source, self.dest, av=new_av) else: raise TypeError("Rotations can only be composed with other rotations.") diff --git a/tests/pytests/test_mdis_drivers.py b/tests/pytests/test_mdis_drivers.py index 424adffa6824fd4298b25b237523b339ee1401fb..b2ac9b2fae92bb9f7c6e59f5916704590d2165f7 100644 --- a/tests/pytests/test_mdis_drivers.py +++ b/tests/pytests/test_mdis_drivers.py @@ -20,57 +20,165 @@ def test_kernels(): for kern in binary_kernels: os.remove(kern) -@pytest.fixture() -def usgscsm_compare_dict(): - return { - 'radii': { - 'semimajor': 2439.4, - 'semiminor': 2439.4, - 'unit': 'km'}, - 'sensor_position': { - 'positions': np.array([[-629496.4862139452, -1582946.0091313303, 1783952.6403104223]]), - 'velocities': np.array([[1732.186663134826, 2502.768253236102, 2412.6523222267365]]), - 'unit': 'm'}, - 'sun_position': { - 'positions': np.array([[-4.68946673e+10, -5.36158427e+08, 2.71167863e+07]]), - 'velocities': np.array([[-4629.73346128, 256.72086237, 10.63960444]]), - 'unit': 'm'}, - 'sensor_orientation': { - 'quaternions': np.array([[-0.9341837162001089, -0.0014477307579469636, 0.0044938223368195815, 0.3567611161870253]])}, - 'detector_sample_summing': 2, - 'detector_line_summing': 2, - 'focal_length_model': { - 'focal_length': 549.5535053027719}, - 'detector_center': { - 'line': 512, - 'sample': 512}, - 'starting_detector_line': 1, - 'starting_detector_sample': 9, - 'focal2pixel_lines': [0.0, 0.0, 71.42857143], - 'focal2pixel_samples': [0.0, 71.42857143, 0.0], - 'optical_distortion': { - 'transverse': { - 'x': [0.0, 1.001854269623802, 0.0, 0.0, -0.0005094440474941111, 0.0, 1.004010471468856e-05, 0.0, 1.004010471468856e-05, 0.0], - 'y': [0.0, 0.0, 1.0, 0.0009060010594996751, 0.0, 0.0003574842626620758, 0.0, 1.004010471468856e-05, 0.0, 1.004010471468856e-05]}}, - 'image_lines': 512, - 'image_samples': 512, - 'name_platform': 'MESSENGER', - 'name_sensor': 'MERCURY DUAL IMAGING SYSTEM NARROW ANGLE CAMERA', - 'reference_height': { - 'maxheight': 1000, - 'minheight': -1000, - 'unit': 'm'}, - 'name_model': 'USGS_ASTRO_FRAME_SENSOR_MODEL', - 'center_ephemeris_time': 483122606.85252464} +image_dict = { + # MDIS NAC + 'EN1072174528M': { + 'isis': { + 'CameraVersion': 2, + 'NaifKeywords': { + 'BODY_CODE' : 199, + 'BODY199_RADII' : [2439.4, 2439.4, 2439.4], + 'BODY_FRAME_CODE' : 10011, + 'INS-236820_SWAP_OBSERVER_TARGET' : 'TRUE', + 'INS-236820_LIGHTTIME_CORRECTION' : 'LT+S', + 'INS-236820_LT_SURFACE_CORRECT' : 'FALSE', + 'INS-236820_REFERENCE_FRAME' : 'MSGR_SPACECRAFT', + 'INS-236820_FRAME' : 'MSGR_MDIS_NAC', + 'INS-236820_FOCAL_LENGTH' : 549.11781953727, + 'INS-236820_PIXEL_PITCH' : 0.014, + 'INS-236820_TRANSX' : [0.0, 0.014, 0.0], + 'INS-236820_TRANSY' : [0.0, 0.0, 0.014], + 'INS-236820_ITRANSS' : [0.0, 71.42857143, 0.0], + 'INS-236820_ITRANSL' : [0.0, 0.0, 71.42857143], + 'INS-236820_BORESIGHT_SAMPLE' : 512.5, + 'INS-236820_BORESIGHT_LINE' : 512.5, + 'INS-236820_OD_T_X' : [0.0, 1.0018542696238, 0.0, 0.0, -5.09444047494111e-04, 0.0, 1.00401047146886e-05, 0.0, 1.00401047146886e-05, 0.0], + 'INS-236820_OD_T_Y' : [0.0, 0.0, 1.0, 9.06001059499675e-04, 0.0, 3.57484262662076e-04, 0.0, 1.00401047146886e-05, 0.0, 1.00401047146886e-05], + 'INS-236820_FPUBIN_START_SAMPLE': 9.0, + 'INS-236820_CK_TIME_TOLERANCE': 1.0, + 'INS-236820_CK_REFERENCE_ID': 1.0, + 'INS-236820_FOV_CLASS_SPEC': 'ANGLES', + 'INS-236820_FOV_REF_VECTOR': [1.0,0.0,0.0], + 'INS-236820_CK_FRAME_ID': -236000.0, + 'INS-236820_FOV_SHAPE': 'RECTANGLE', + 'INS-236820_FOV_ANGLE_UNITS': 'DEGREES', + 'FRAME_-236820_CLASS': 4.0, + 'INS-236820_BORESIGHT_LINE': 512.5, + 'INS-236820_SWAP_OBSERVER_TARGET': 'TRUE', + 'INS-236820_LIGHTTIME_CORRECTION': 'LT+S', + 'INS-236820_FOV_FRAME': 'MSGR_MDIS_NAC', + 'INS-236820_PIXEL_SAMPLES': 1024.0, + 'INS-236820_REFERENCE_FRAME': 'MSGR_SPACECRAFT', + 'INS-236820_FL_UNCERTAINTY': 0.5, + 'INS-236820_ITRANSL': [0.0,0.0,71.42857143], + 'INS-236820_ITRANSS': [0.0,71.42857143,0.0], + 'INS-236820_FOV_CROSS_ANGLE': 0.7465, + 'TKFRAME_-236820_SPEC': 'MATRIX', + 'INS-236820_BORESIGHT_SAMPLE': 512.5, + 'INS-236820_PIXEL_LINES': 1024.0, + 'INS-236820_F/NUMBER': 22.0, + 'INS-236820_IFOV': 25.44, + 'INS-236820_SPK_TIME_BIAS': 0.0, + 'INS-236820_CCD_CENTER': [512.5,512.5], + 'FRAME_-236820_NAME': 'MSGR_MDIS_NAC', + 'INS-236820_FRAME': 'MSGR_MDIS_NAC', + 'INS-236820_PLATFORM_ID': -236000.0, + 'INS-236820_LT_SURFACE_CORRECT': 'FALSE', + 'INS-236820_TRANSX': [0.0,0.014,0.0], + 'INS-236820_TRANSY': [0.0,0.0,0.014], + 'INS-236820_FL_TEMP_COEFFS': [549.5120497341695,0.01018564339123439,0.0,0.0,0.0,0.0], + 'FRAME_-236820_CENTER': -236.0, + 'TKFRAME_-236820_RELATIVE': 'MSGR_MDIS_WAC', + 'INS-236820_WAVELENGTH_RANGE': [700.0,800.0], + 'INS-236820_CK_TIME_BIAS': 0.0, + 'INS-236820_FOV_REF_ANGLE': 0.7465, + 'TKFRAME_-236820_MATRIX': [-0.9998215487408793,-0.018816063038872958,0.001681203469647119,0.01881610195359367,-0.9998229614554359,7.33168257224375e-06,0.0016807678784302768,3.8964070113872887e-05,0.9999985867495713], + 'INS-236820_FPUBIN_START_LINE': 1.0, + 'FRAME_-236820_CLASS_ID': -236820.0, + 'INS-236820_PIXEL_PITCH': 0.014, + 'INS-236820_BORESIGHT': [0.0,0.0,1.0], + 'BODY199_PM': [329.5988,6.1385108,0.0], + 'BODY199_POLE_RA': [281.0103,-0.0328,0.0], + 'BODY199_NUT_PREC_PM': [0.01067257,-0.00112309,-0.0001104,-2.539e-05,-5.71e-06], + 'BODY199_LONG_AXIS': 0.0, + 'BODY199_POLE_DEC': [61.4155,-0.0049,0.0], + 'BODY199_NUT_PREC_RA': [0.0,0.0,0.0,0.0,0.0], + 'BODY199_NUT_PREC_DEC': [0.0,0.0,0.0,0.0,0.0] + }, + 'InstrumentPointing': { + 'TimeDependentFrames': [-236890, -236892, -236880, -236000, 1], + 'ConstantFrames': [-236820, -236800, -236890], + 'ConstantRotation': (0.001686595916635, 0.99996109494739, 0.0086581745086423, 6.3008625209968e-04, -0.0086592477671008, 0.99996230949942, 0.99999837919145, -0.0016810769512645, -6.44666390486019e-04), + 'CkTableStartTime': 483122606.85252, + 'CkTableEndTime': 483122606.85252, + 'CkTableOriginalSize': 1, + 'EphemerisTimes': [483122606.85252], + 'Quaternions': [[-0.38021468196247,-0.021997068513824,0.88129521110671,0.27977075522175]], + 'AngularVelocity' : [[3.70128511234226e-04,-0.0012069098299837,-6.64295531160265e-04]]}, + 'BodyRotation': { + 'TimeDependentFrames': [10011, 1], + 'CkTableStartTime': 483122606.85252, + 'CkTableEndTime': 483122606.85252, + 'CkTableOriginalSize': 1, + 'EphemerisTimes': [483122606.85252], + 'Quaternions': [[-0.58791736752687,0.18448696708541,-0.16404715837556,0.77032866866346]], + 'AngularVelocity' : [[1.13272180361114e-07,-5.82448215686951e-07,1.08896661936564e-06]]}, + 'InstrumentPosition': { + 'SpkTableStartTime': 483122606.85252, + 'SpkTableEndTime': 483122606.85252, + 'SpkTableOriginalSize': 1, + 'EphemerisTimes': [483122606.85252], + 'Positions': [[1844.0372753409,-966.47836059939,1322.8442926008]], + 'Velocities': [[-2.6146204621248,-0.30506719264668,2.8563617189104]]}, + 'SunPosition': { + 'SpkTableStartTime': 483122606.85252, + 'SpkTableEndTime': 483122606.85252, + 'SpkTableOriginalSize': 1, + 'EphemerisTimes': [483122606.85252], + 'Positions': [[11805115.780304,-39513889.220831,-22331586.824705]], + 'Velocities': [[56.903276907758496, 11.401211521119633, 0.19123815749182813]]}}, + 'usgscsm': { + 'radii': { + 'semimajor': 2439.4, + 'semiminor': 2439.4, + 'unit': 'km'}, + 'sensor_position': { + 'positions': np.array([[-629496.4862139452, -1582946.0091313303, 1783952.6403104223]]), + 'velocities': np.array([[1732.186663134826, 2502.768253236102, 2412.6523222267365]]), + 'unit': 'm'}, + 'sun_position': { + 'positions': np.array([[-4.68946673e+10, -5.36158427e+08, 2.71167863e+07]]), + 'velocities': np.array([[-4629.73346128, 256.72086237, 10.63960444]]), + 'unit': 'm'}, + 'sensor_orientation': { + 'quaternions': np.array([[-0.9341837162001089, -0.0014477307579469636, 0.0044938223368195815, 0.3567611161870253]])}, + 'detector_sample_summing': 2, + 'detector_line_summing': 2, + 'focal_length_model': { + 'focal_length': 549.5535053027719}, + 'detector_center': { + 'line': 512, + 'sample': 512}, + 'starting_detector_line': 1, + 'starting_detector_sample': 9, + 'focal2pixel_lines': [0.0, 0.0, 71.42857143], + 'focal2pixel_samples': [0.0, 71.42857143, 0.0], + 'optical_distortion': { + 'transverse': { + 'x': [0.0, 1.001854269623802, 0.0, 0.0, -0.0005094440474941111, 0.0, 1.004010471468856e-05, 0.0, 1.004010471468856e-05, 0.0], + 'y': [0.0, 0.0, 1.0, 0.0009060010594996751, 0.0, 0.0003574842626620758, 0.0, 1.004010471468856e-05, 0.0, 1.004010471468856e-05]}}, + 'image_lines': 512, + 'image_samples': 512, + 'name_platform': 'MESSENGER', + 'name_sensor': 'MERCURY DUAL IMAGING SYSTEM NARROW ANGLE CAMERA', + 'reference_height': { + 'maxheight': 1000, + 'minheight': -1000, + 'unit': 'm'}, + 'name_model': 'USGS_ASTRO_FRAME_SENSOR_MODEL', + 'center_ephemeris_time': 483122606.85252464}}} @pytest.mark.parametrize("label_type", ["pds3", "isis3"]) -def test_load(test_kernels, usgscsm_compare_dict, label_type): - label_file = get_image_label('EN1072174528M', label_type) +@pytest.mark.parametrize("formatter", ['usgscsm', 'isis']) +@pytest.mark.parametrize("image", image_dict.keys()) +def test_load(test_kernels, label_type, formatter, image): + label_file = get_image_label(image, label_type) - usgscsm_isd_str = ale.loads(label_file, props={'kernels': test_kernels}, formatter='usgscsm') + 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=2)) - assert compare_dicts(usgscsm_isd_obj, usgscsm_compare_dict) == [] + assert compare_dicts(usgscsm_isd_obj, image_dict[image][formatter]) == [] # ========= Test Pds3 Label and NAIF Spice driver ========= class test_pds3_naif(unittest.TestCase): diff --git a/tests/pytests/test_mro_drivers.py b/tests/pytests/test_mro_drivers.py index 205051f12855770da200d2bc55481f1869da4ac1..e1d96d601cdf1656ac028e36899c2463adc7fd9b 100644 --- a/tests/pytests/test_mro_drivers.py +++ b/tests/pytests/test_mro_drivers.py @@ -235,12 +235,12 @@ def isis_compare_dict(): [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': [[-5.797334508173795e-05, 0.0009339642673794059, -0.00011512424986625757], - [-5.872001786769966e-05, 0.0009343455952639878, -0.00011371124132355403], - [-6.244619825703372e-05, 0.000935616649435616, -0.00010584418382022431], - [-5.965469273385757e-05, 0.0009306551165985512, -0.00010670063014175982], - [-6.001692495046523e-05, 0.0009318842753552843, -0.00010732755544866732], - [-5.9466333983691536e-05, 0.0009375199811173681, -0.00010690951512741344]]}, + '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, diff --git a/tests/pytests/test_rotation.py b/tests/pytests/test_rotation.py index 249cf2d1b40ebbf8220efffee04ecce44df40fab..ff700a13a1f7672d46eaab12f27acd657a82f87e 100644 --- a/tests/pytests/test_rotation.py +++ b/tests/pytests/test_rotation.py @@ -24,10 +24,9 @@ def test_constant_time_dependent_composition(): assert rot1_3.source == 1 assert rot1_3.dest == 3 expected_quats = [[0.5, 0.5, -0.5, 0.5],[1.0/np.sqrt(2), 0, -1.0/np.sqrt(2), 0]] - expected_av = [[0, 0, -np.pi/2], [0, 0, -np.pi/2]] np.testing.assert_equal(rot1_3.times, times) np.testing.assert_almost_equal(rot1_3.quats, expected_quats) - np.testing.assert_almost_equal(rot1_3.av, expected_av) + np.testing.assert_almost_equal(rot1_3.av, av) def test_time_dependent_constant_composition(): rot1_2 = ConstantRotation([1.0/np.sqrt(2), 0, 0, 1.0/np.sqrt(2)], 1, 2)