def test_find_path_to_frame(self): halo = mnt.CartesianCoordinateFrame() halo.name = 'HALO' vnir = mnt.CartesianCoordinateFrame() vnir.name = 'VNIR' halo.add_child(vnir) universe = mnt.CoordinateUniverse('universe', halo) path = universe.find_path_to_frame('VNIR') self.assertIs(vnir, path[0]) self.assertEqual(len(path), 1)
def test_forward_shift(self): a = mnt.CartesianCoordinateFrame() b = mnt.CartesianCoordinateFrame() a.name = 'a' b.name = 'b' b.pos = [1, 2, 0] a.add_child(b) universe = mnt.CoordinateUniverse('uni', a) transform = universe.get_transformation('b', 'a') npt.assert_almost_equal(transform.apply_point(1, 0, 0), [2, 2, 0])
def test_backward_rotation(self): halo = mnt.CartesianCoordinateFrame() halo.name = 'HALO' vnir = mnt.CartesianCoordinateFrame() vnir.name = 'VNIR' vnir.rotation = mnt.Rotation.fromAngle(np.pi / 2, 'z') halo.add_child(vnir) universe = mnt.CoordinateUniverse('universe', halo) transform = universe.get_transformation('HALO', 'VNIR') npt.assert_almost_equal(transform.apply_direction(0, 1, 0), [1, 0, 0])
def test_double_transform(self): halo = mnt.CartesianCoordinateFrame() halo.name = 'HALO' intermediate = mnt.CartesianCoordinateFrame() intermediate.name = 'INTER' intermediate.rotation = mnt.Rotation.fromAngle(np.pi / 2, 'z') swir = mnt.CartesianCoordinateFrame() swir.name = 'SWIR' swir.rotation = mnt.Rotation.fromAngle(np.pi / 2, 'z') intermediate.add_child(swir) halo.add_child(intermediate) universe = mnt.CoordinateUniverse('uni', halo) transform = universe.get_transformation('HALO', 'SWIR') npt.assert_almost_equal(transform.apply_direction(0, 1, 0), [0, -1, 0])
def _add_reference_frame(self, time): frame=mnt.CartesianCoordinateFrame() frame.pos=[float(self.orientation['lat'].sel(time=time, method='nearest')),float(self.orientation['lon'].sel(time=time, method='nearest')),0] frame.euler=[0,0,0] frame.name='intersection_reference' self.coord_universe.get_frame('EARTH').add_child(frame) self.reference_available=True
def setUp(self): ball = mnt.OblateEllipsoidFrame(1, 1) ball.name = 'ball' local = mnt.CartesianCoordinateFrame() local.name = 'local' ball.add_child(local) self.universe = mnt.CoordinateUniverse('uni', ball) self.tr1 = self.universe.get_transformation('local', 'ball')
def test_find_path_to_frame_deep(self): halo = mnt.CartesianCoordinateFrame() halo.name = 'HALO' vnir = mnt.CartesianCoordinateFrame() vnir.name = 'VNIR' swir = mnt.CartesianCoordinateFrame() swir.name = 'SWIR' containment = mnt.CartesianCoordinateFrame() containment.name = 'CONTAINMENT' containment.add_child(vnir) containment.add_child(swir) halo.add_child(containment) universe = mnt.CoordinateUniverse('universe', halo) path = universe.find_path_to_frame('SWIR') path2 = universe.find_path_to_frame('VNIR') self.assertIs(swir, path[1]) self.assertIs(vnir, path2[1]) self.assertIs(containment, path[0]) self.assertEqual(len(path), 2)
def setUp(self): earth = mnt.coordinate_lib['WGS-84']() earth.name = 'earth' stabilized = mnt.CartesianCoordinateFrame() stabilized.name = 'stabilized' self.lat = 10. self.lon = 15. self.height = 7000. self.roll = np.pi / 6. self.pitch = 0 # np.pi/9. self.yaw = -np.pi stabilized.pos = [self.lat, self.lon, self.height] stabilized.euler = [0, 0, mnt.rad2deg(self.yaw)] halo = mnt.CartesianCoordinateFrame() halo.name = 'HALO' halo.euler = [mnt.rad2deg(self.roll), mnt.rad2deg(self.pitch), 0] stabilized.add_child(halo) earth.add_child(stabilized) self.universe = mnt.CoordinateUniverse('uni', earth)
def test_position_transform_nested_on_north_pole(self): ball = mnt.OblateEllipsoidFrame(1, 1) ball.name = 'ball' intermediate = mnt.CartesianCoordinateFrame() intermediate.name = 'intermediate' local = mnt.CartesianCoordinateFrame() local.name = 'local' local.pos = [1, 0, 1] intermediate.add_child(local) ball.add_child(intermediate) universe = mnt.CoordinateUniverse('uni', ball) tr1 = universe.get_transformation('local', 'ball') res1 = tr1.apply_point(0., 0., 0.) npt.assert_almost_equal(res1, [0, 0, 1]) res2 = tr1.apply_point(1., 0., 0.) npt.assert_almost_equal(res2, [0, 0, 2]) res3 = tr1.apply_point(0., 1., 0.) npt.assert_almost_equal(res3, [0, 1, 1]) res4 = tr1.apply_point(-1, 0, 0) npt.assert_almost_equal(np.linalg.norm(res4), 1e-9)
def test_get_origin_of_subframes(self): earth = mnt.coordinate_lib['WGS-84']() earth.name = 'earth' local = mnt.CartesianCoordinateFrame() local.name = 'local' local.pos = [45, 45, 0] earth.add_child(local) universe = mnt.CoordinateUniverse('uni', earth) transform = universe.get_transformation('local', 'earth') res = transform.apply_point(0, 0, 0) npt.assert_almost_equal( res, universe.get_frame('earth').toCartesian([45, 45, 0]))
def test_direction(self): ned2enu = (mnt.Rotation.fromAngle(np.pi / 2, 'z') * mnt.Rotation.fromAngle(np.pi, 'x')) earth = mnt.coordinate_lib['WGS-84']() earth.name = 'earth' local = mnt.CartesianCoordinateFrame() local.name = 'local' local.pos = [45, 45, 0] local.rotation = ned2enu earth.add_child(local) check_result = [-0.5, -0.5, np.sqrt(0.5)] universe = mnt.CoordinateUniverse('uni', earth) transform = universe.get_transformation('local', 'earth') npt.assert_almost_equal(transform.apply_direction(0, 1, 0), check_result)
def create_from_yaml(mounttree): try: rhs = mnt.coordinate_lib[mounttree['framespec']]() except KeyError: rhs = mnt.CartesianCoordinateFrame() rhs.name = mounttree['framename'] if 'position' in mounttree: rhs.pos = mounttree['position'] if 'rotation' in mounttree: rot_input = mounttree['rotation'] if isinstance(rot_input, list): assert(len(rot_input) == 3) rhs.euler = rot_input if isinstance(rot_input, str): rhs.rotation = convert_rot_string(rot_input) if 'subframes' in mounttree: for subframe in mounttree['subframes']: rhs.add_child(create_from_yaml(subframe)) return rhs
def test_plane2plane(self): plane2 = mnt.CartesianCoordinateFrame() plane2.name = 'plane2' plane2.pos = [10.1, 15.2, 7500.] plane2.euler = [0, 0.1, 0.2] self.universe.get_frame('earth').add_child(plane2) tr1 = self.universe.get_transformation("HALO", 'plane2') tr2 = self.universe.get_transformation("plane2", "HALO") res1 = tr1.apply_point(0, 0, 0) res2 = tr2.apply_point(0, 0, 0) res3 = tr2.apply_point(100, 0, 0) res4 = tr2.apply_point(*tr1.apply_point(24, 745., 812)) res2 = np.array(res2) res3 = np.array(res3) res4 = np.array(res4) npt.assert_almost_equal(np.linalg.norm(res1), np.linalg.norm(res2)) npt.assert_almost_equal(np.linalg.norm(res3 - res2), 100) npt.assert_almost_equal( np.linalg.norm(res4 - np.array([24, 745., 812])), 0)