def test_local_coordinate_system_coords_timeseries(copy_arrays, lazy_load, has_ref_time, has_tdp_orientation): """Test reading and writing a LCS with a `TimeSeries` as coordinates to asdf.""" # create inputs to lcs __init__ me = ME("a*t", dict(a=Q_([[1, 0, 0]], "1/s"))) ts = TimeSeries(data=me) ref_time = None if has_ref_time: ref_time = pd.Timestamp("13:37") time = None orientation = None if has_tdp_orientation: time = Q_([1, 2], "s") orientation = WXRotation.from_euler("x", [0, 90], degrees=True).as_matrix() # create lcs lcs = tf.LocalCoordinateSystem(orientation=orientation, coordinates=ts, time=time, time_ref=ref_time) # round trip and compare lcs_buffer = write_read_buffer({"lcs": lcs}, open_kwargs={ "copy_arrays": copy_arrays, "lazy_load": lazy_load })["lcs"] assert lcs_buffer == lcs
def from_tree(cls, tree, ctx): """ Converts basic types representing YAML trees into custom types. Parameters ---------- tree : An instance of a basic Python type (possibly nested) that corresponds to a YAML subtree. ctx : An instance of the 'AsdfFile' object that is being constructed. Returns ------- Dimension : An instance of the 'Dimension' type. """ if "quaternions" in tree: return WXRotation.from_quat(tree["quaternions"]) elif "matrix" in tree: return WXRotation.from_matrix(tree["matrix"]) elif "rotvec" in tree: return WXRotation.from_rotvec(tree["rotvec"]) elif "angles" in tree: if "degree" in str(tree["angles"].units): angles = tree["angles"].to("degree").magnitude degrees = True else: angles = tree["angles"].to("rad").magnitude degrees = False return WXRotation.from_euler(seq=tree["sequence"], angles=angles, degrees=degrees)
def test_rotation_euler_prefix(inputs): """Test unit prefix handling.""" degrees = "degree" in str(inputs.u) rot = WXRotation.from_euler(seq="x", angles=inputs) data = write_read_buffer({"rot": rot}) r = data["rot"].as_euler("xyz", degrees=degrees)[0] r = Q_(r, "degree") if degrees else Q_(r, "rad") assert np.allclose(inputs, r)
def get_example_coordinate_system_manager(): """Get a consistent CoordinateSystemManager instance for test purposes.""" csm = tf.CoordinateSystemManager("root") csm.create_cs("lcs_01", "root", coordinates=[1, 2, 3]) csm.create_cs( "lcs_02", "root", orientation=WXRotation.from_euler("z", np.pi / 3).as_matrix(), coordinates=[4, -7, 8], ) csm.create_cs( "lcs_03", "lcs_02", orientation=WXRotation.from_euler("y", np.pi / 11), coordinates=[4, -7, 8], ) return csm
def get_local_coordinate_system(time_dep_orientation: bool, time_dep_coordinates: bool): """ Get a local coordinate system. Parameters ---------- time_dep_orientation : If True, the coordinate system has a time dependent orientation. time_dep_coordinates : If True, the coordinate system has a time dependent coordinates. Returns ------- weldx.transformations.LocalCoordinateSystem: A local coordinate system """ if not time_dep_coordinates: coords = Q_([2.0, 5.0, 1.0], "mm") else: coords = Q_( [[2.0, 5.0, 1.0], [1.0, -4.0, 1.2], [0.3, 4.4, 4.2], [1.1, 2.3, 0.2]], "mm", ) if not time_dep_orientation: orientation = WXRotation.from_euler("z", np.pi / 3).as_matrix() else: orientation = WXRotation.from_euler( "z", np.pi / 2 * np.array([1, 2, 3, 4])).as_matrix() if not time_dep_orientation and not time_dep_coordinates: return tf.LocalCoordinateSystem(orientation=orientation, coordinates=coords) time = pd.DatetimeIndex( ["2000-01-01", "2000-01-02", "2000-01-03", "2000-01-04"]) return tf.LocalCoordinateSystem(orientation=orientation, coordinates=coords, time=time)
def rotated_coordinate_system( angle_x=np.pi / 3, angle_y=np.pi / 4, angle_z=np.pi / 5, coordinates=np.array([0, 0, 0]), # noqa B008 ) -> LocalCoordinateSystem: """Get a coordinate system with rotated orientation. The transformation order is x-y-z Parameters ---------- angle_x : Rotation angle around the x axis (Default value = np.pi / 3) angle_y : Rotation angle around the y axis (Default value = np.pi / 4) angle_z : Rotation angle around the z axis (Default value = np.pi / 5) coordinates : Coordinates of the coordinate system (Default value = np.array([0, 0, 0])) Returns ------- weldx.transformations.LocalCoordinateSystem Coordinate system with rotated orientation """ orientation = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) # rotate axes to produce a more general test case r_x = WXRotation.from_euler("x", angle_x).as_matrix() r_y = WXRotation.from_euler("y", angle_y).as_matrix() r_z = WXRotation.from_euler("z", angle_z).as_matrix() r_tot = np.matmul(r_z, np.matmul(r_y, r_x)) rotated_orientation = np.matmul(r_tot, orientation) if not isinstance(coordinates, Q_): coordinates = np.array(coordinates) return LocalCoordinateSystem(rotated_orientation, coordinates)
def r_mat_z(factors) -> np.ndarray: """Get an array of rotation matrices that represent a rotation around the z-axis. The rotation angles are the provided factors times pi. Parameters ---------- factors: List of factors that are multiplied with pi to get the rotation angles. Returns ------- numpy.ndarray: An array of rotation matrices """ return WXRotation.from_euler("z", np.array(factors) * np.pi).as_matrix()
def test_rotation_euler_exception(): with pytest.raises(ValueError): WXRotation.from_euler(seq="XyZ", angles=[10, 20, 60], degrees=True)
from weldx.transformations import WXRotation # WXRotation --------------------------------------------------------------------- _base_rotation = Rotation.from_euler(seq="xyz", angles=[[10, 20, 60], [25, 50, 175]], degrees=True) @pytest.mark.parametrize( "inputs", [ _base_rotation, WXRotation.from_quat(_base_rotation.as_quat()), WXRotation.from_matrix(_base_rotation.as_matrix()), WXRotation.from_rotvec(_base_rotation.as_rotvec()), WXRotation.from_euler(seq="xyz", angles=[10, 20, 60], degrees=True), WXRotation.from_euler( seq="xyz", angles=[0.2, 1.3, 3.14], degrees=False), WXRotation.from_euler(seq="xyz", angles=Q_([10, 20, 60], "degree")), WXRotation.from_euler(seq="xyz", angles=Q_([0.2, 1.3, 3.14], "rad")), WXRotation.from_euler(seq="xyz", angles=Q_([0.2, 1.3, 3.14], "")), WXRotation.from_euler(seq="XYZ", angles=[10, 20, 60], degrees=True), WXRotation.from_euler(seq="y", angles=[10, 60, 40, 90], degrees=True), WXRotation.from_euler(seq="Z", angles=[10, 60, 40, 90], degrees=True), WXRotation.from_euler(seq="xy", angles=[[10, 10], [60, 60], [40, 40], [70, 75]], degrees=True), WXRotation.from_euler( seq="xy", angles=Q_([[10, 10], [60, 60], [40, 40], [70, 75]], "degree")), ],