def test_plot_coordinate_system(): """Test executing all possible code paths.""" lcs_constant = tf.LocalCoordinateSystem() time = pd.TimedeltaIndex([10, 11, 12], "s") orientation_tdp = [ [[1, 0, 0], [0, 1, 0], [0, 0, 1]], [[0, 1, 0], [-1, 0, 0], [0, 0, 1]], [[-1, 0, 0], [0, -1, 0], [0, 0, 1]], ] coordinates_tdp = [[0, 0, 1], [0, 0, 2], [0, -1, 0]] lcs_tdp = tf.LocalCoordinateSystem(orientation=orientation_tdp, coordinates=coordinates_tdp, time=time) fig = plt.figure() ax = fig.gca(projection="3d") vs.draw_coordinate_system_matplotlib(lcs_constant, ax, "g") vs.draw_coordinate_system_matplotlib(lcs_tdp, ax, "r", "2016-01-10") vs.draw_coordinate_system_matplotlib(lcs_tdp, ax, "b", "2016-01-11", time_idx=1) vs.draw_coordinate_system_matplotlib(lcs_tdp, ax, "y", "2016-01-12", pd.TimedeltaIndex([12], "s")) # exceptions ------------------------------------------ # label without color with pytest.raises(Exception): vs.draw_coordinate_system_matplotlib(lcs_constant, ax, label="label")
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 test_local_coordinate_system_shape_violation(): """Test if the shape validators work as expected.""" # coordinates have wrong shape ------------------------ orientation = xr.DataArray( data=[[1, 2, 3], [4, 5, 6], [7, 8, 9]], dims=["u", "v"], coords={ "u": ["x", "y", "z"], "v": [0, 1, 2] }, ) coordinates = xr.DataArray( data=[1, 2], dims=["c"], coords={"c": ["x", "y"]}, ) lcs = tf.LocalCoordinateSystem(orientation=orientation, coordinates=coordinates, construction_checks=False) with pytest.raises(ValidationError): write_buffer({"lcs": lcs}) # orientations have wrong shape ----------------------- orientation = xr.DataArray( data=[[1, 2], [3, 4]], dims=["c", "v"], coords={ "c": ["x", "y"], "v": [0, 1] }, ) coordinates = xr.DataArray( data=[1, 2, 3], dims=["u"], coords={"u": ["x", "y", "z"]}, ) lcs = tf.LocalCoordinateSystem(orientation=orientation, coordinates=coordinates, construction_checks=False) with pytest.raises(ValidationError): write_buffer({"lcs": lcs})
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 test_coordinate_system_manager_time_dependencies(copy_arrays, lazy_load, csm_time_ref): """Test serialization of time components from CSM and its attached LCS.""" lcs_tdp_1_time_ref = None if csm_time_ref is None: lcs_tdp_1_time_ref = pd.Timestamp("2000-03-17") lcs_tdp_1 = tf.LocalCoordinateSystem( coordinates=[[1, 2, 3], [4, 5, 6]], time=pd.TimedeltaIndex([1, 2], "D"), time_ref=lcs_tdp_1_time_ref, ) lcs_tdp_2 = tf.LocalCoordinateSystem( coordinates=[[3, 7, 3], [9, 5, 8]], time=pd.TimedeltaIndex([1, 2], "D"), time_ref=pd.Timestamp("2000-03-21"), ) csm_root = tf.CoordinateSystemManager("root", "csm_root", csm_time_ref) csm_root.add_cs("cs_1", "root", lcs_tdp_2) csm_sub_1 = tf.CoordinateSystemManager("cs_2", "csm_sub_1", csm_time_ref) csm_sub_1.add_cs("cs_1", "cs_2", lcs_tdp_2) csm_sub_1.add_cs("cs_3", "cs_2", lcs_tdp_1) csm_sub_2 = tf.CoordinateSystemManager("cs_4", "csm_sub_2") csm_sub_2.create_cs("cs_1", "cs_4") csm_root.merge(csm_sub_1) csm_root.merge(csm_sub_2) tree = {"cs_hierarchy": csm_root} data = write_read_buffer(tree, open_kwargs={ "copy_arrays": copy_arrays, "lazy_load": lazy_load }) csm_file = data["cs_hierarchy"] assert csm_root == csm_file
def get_coordinate_system_manager_with_subsystems(nested: bool): lcs = [ tf.LocalCoordinateSystem(coordinates=[i, -i, -i]) for i in range(12) ] # create global system csm_global = tf.CoordinateSystemManager("base", "Global System", "2000-06-08") csm_global.add_cs("robot", "base", lcs[0]) csm_global.add_cs("specimen", "base", lcs[1]) # robot system csm_robot = tf.CoordinateSystemManager("robot", "Robot system") csm_robot.add_cs("head", "robot", lcs[2]) # robot head system csm_head = tf.CoordinateSystemManager("head", "Head system") csm_head.add_cs("torch tcp", "head", lcs[3]) csm_head.add_cs("camera tcp", "head", lcs[4], lsc_child_in_parent=False) csm_head.add_cs("scanner 1 tcp", "head", lcs[5]) csm_head.add_cs("scanner 2 tcp", "head", lcs[6]) # scanner system 1 csm_scanner_1 = tf.CoordinateSystemManager("scanner 1", "Scanner 1 system") csm_scanner_1.add_cs("scanner 1 tcp", "scanner 1", lcs[7]) # scanner system 2 csm_scanner_2 = tf.CoordinateSystemManager("scanner 2", "Scanner 2 system") csm_scanner_2.add_cs("scanner 2 tcp", "scanner 2", lcs[8]) # specimen system csm_specimen = tf.CoordinateSystemManager("specimen", "Specimen system") csm_specimen.add_cs("thermocouple 1", "specimen", lcs[9]) csm_specimen.add_cs("thermocouple 2", "specimen", lcs[10]) csm_specimen.add_cs("thermocouple 3", "thermocouple 2", lcs[11]) if nested: csm_head.merge(csm_scanner_1) csm_head.merge(csm_scanner_2) csm_robot.merge(csm_head) csm_global.merge(csm_robot) csm_global.merge(csm_specimen) else: csm_global.merge(csm_specimen) csm_global.merge(csm_robot) csm_global.merge(csm_head) csm_global.merge(csm_scanner_1) csm_global.merge(csm_scanner_2) return csm_global
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]), ) -> tf.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 = tf.rotation_matrix_x(angle_x) r_y = tf.rotation_matrix_y(angle_y) r_z = tf.rotation_matrix_z(angle_z) r_tot = np.matmul(r_z, np.matmul(r_y, r_x)) rotated_orientation = np.matmul(r_tot, orientation) return tf.LocalCoordinateSystem(rotated_orientation, np.array(coordinates))