Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strict quantities #731

Merged
merged 49 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
4253220
Enforce units in LCS and fix some tests
vhirtham Mar 30, 2022
7bcfa47
Fix all csm tests
vhirtham Mar 30, 2022
9b5150b
Fix lcs tests
vhirtham Mar 30, 2022
b96d8b1
Fix geometry and visualization tests
vhirtham Mar 30, 2022
8b2ca27
Fix asdf core tests
vhirtham Mar 30, 2022
995962a
Fix all remaining tests
vhirtham Mar 31, 2022
c3426b2
fix tutorials
vhirtham Mar 31, 2022
82fa6d5
Run pre-commit
vhirtham Mar 31, 2022
5b5703a
Fix tests
vhirtham Mar 31, 2022
559953a
Try docfix
vhirtham Mar 31, 2022
bf32890
Enforce length units in TimeSeries coords
vhirtham Apr 1, 2022
068e2a2
Enforce length units in SpatialSeries
vhirtham Apr 1, 2022
2f30b87
cleanup
vhirtham Apr 1, 2022
d909f3d
Fix tutorials
vhirtham Apr 4, 2022
a5b74cc
cleanup
vhirtham Apr 4, 2022
dd0abd1
Try fix schema example
vhirtham Apr 4, 2022
4a13880
Try fix schema example
vhirtham Apr 4, 2022
d4bc05a
Try fix schema example
vhirtham Apr 4, 2022
6c5e5cb
Try fix schema example
vhirtham Apr 4, 2022
0332ef1
Try fix schema example
vhirtham Apr 4, 2022
dd7599a
Try fix schema example
vhirtham Apr 4, 2022
23e7418
Try fix schema example
vhirtham Apr 4, 2022
800123b
Try fix schema example
vhirtham Apr 4, 2022
5c2473d
Try fix schema example
vhirtham Apr 4, 2022
8e32700
Try fix schema example
vhirtham Apr 4, 2022
50f163e
Update pre-commit
vhirtham Apr 4, 2022
98bada0
Update changelog
vhirtham Apr 4, 2022
1bb922b
pin pint version
vhirtham Apr 4, 2022
2ceb283
pin pint version
vhirtham Apr 4, 2022
cc94004
Merge branch 'master' into strict_quantities
vhirtham Apr 5, 2022
1a9ccaa
Update setup.cfg
vhirtham Apr 5, 2022
e41dd79
Merge branch 'master' into strict_quantities
vhirtham Apr 8, 2022
610009b
Merge branch 'master' into strict_quantities
vhirtham Apr 11, 2022
4af2887
Merge branch 'master' into strict_quantities
vhirtham Apr 13, 2022
2bff051
Apply suggestions from PR
vhirtham Apr 13, 2022
f84a2ac
Add new LCS schema version
vhirtham Apr 13, 2022
9cf7472
Fix tests
vhirtham Apr 13, 2022
3a7a2bc
Remove print
vhirtham Apr 13, 2022
75342db
Fix pre-commit
vhirtham Apr 13, 2022
92ac6aa
Update tag version in examples
vhirtham Apr 13, 2022
724ee91
Merge branch 'master' into strict_quantities
vhirtham Apr 21, 2022
8405777
Merge branch 'master' into strict_quantities
vhirtham Apr 28, 2022
2b78a36
use default length unit
vhirtham Apr 28, 2022
f5cd3ab
cleanup
vhirtham Apr 28, 2022
990bc24
Run pre-commit
vhirtham Apr 28, 2022
a621372
Update geometry.py
CagtayFabry Apr 28, 2022
2ffb490
add units parameter for file import/export
CagtayFabry Apr 28, 2022
a1fe7ce
remove ndarray and fix shape for SpatialData schema
CagtayFabry Apr 28, 2022
0aad9d2
compat by tag version, cleanup
CagtayFabry Apr 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ changes

- Reshape `SpatialData` coordinates to ``(-1, 3)`` before exporting with ``meshio`` for compatibility. [:pull:`723`]

- `SpatialData`, `LocalCoordinateSystem` and `CoordinateSystemManager` now require units [:pull:`731`]

fixes
=====

Expand Down
2 changes: 1 addition & 1 deletion tutorials/01_01_introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.12"
"version": "3.10.4"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion tutorials/01_03_geometry.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.9"
"version": "3.8.12"
}
},
"nbformat": 4,
Expand Down
50 changes: 29 additions & 21 deletions tutorials/transformations_01_coordinate_systems.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import\n",
"\n",
"import weldx.transformations as tf\n",
"import weldx.visualization as vs"
"import weldx.visualization as vs\n",
"from weldx import Q_"
]
},
{
Expand Down Expand Up @@ -83,11 +84,13 @@
"outputs": [],
"source": [
"# create a translated coordinate system\n",
"lcs_01 = tf.LocalCoordinateSystem(coordinates=[2, 4, -1])\n",
"lcs_01 = tf.LocalCoordinateSystem(coordinates=Q_([2, 4, -1], \"mm\"))\n",
"\n",
"# create a rotated coordinate system using a rotation matrix as basis\n",
"rotation_matrix = tf.WXRotation.from_euler(\"z\", np.pi / 3).as_matrix()\n",
"lcs_02 = tf.LocalCoordinateSystem(orientation=rotation_matrix, coordinates=[0, 0, 3])"
"lcs_02 = tf.LocalCoordinateSystem(\n",
" orientation=rotation_matrix, coordinates=Q_([0, 0, 3], \"mm\")\n",
")"
]
},
{
Expand Down Expand Up @@ -132,11 +135,13 @@
"e_y = [-2, 1, 0]\n",
"e_z = [0, 0, 5]\n",
"lcs_03 = tf.LocalCoordinateSystem.from_axis_vectors(\n",
" x=e_x, y=e_y, z=e_z, coordinates=[1, 1, 0]\n",
" x=e_x, y=e_y, z=e_z, coordinates=Q_([1, 1, 0], \"mm\")\n",
")\n",
"\n",
"# create a negatively oriented coordinate system with 2 vectors\n",
"lcs_04 = tf.LocalCoordinateSystem.from_axis_vectors(y=e_y, z=e_z, coordinates=[1, 1, 2])"
"lcs_04 = tf.LocalCoordinateSystem.from_axis_vectors(\n",
" y=e_y, z=e_z, coordinates=Q_([1, 1, 2], \"mm\")\n",
")"
]
},
{
Expand Down Expand Up @@ -178,10 +183,10 @@
"source": [
"# create a coordinate system by a 90° rotation around the x axis and subsequent 45° rotation around the y axis\n",
"lcs_05 = tf.LocalCoordinateSystem.from_euler(\n",
" sequence=\"x\", angles=90, degrees=True, coordinates=[1, -1, 0]\n",
" sequence=\"x\", angles=90, degrees=True, coordinates=Q_([1, -1, 0], \"mm\")\n",
")\n",
"lcs_06 = tf.LocalCoordinateSystem.from_euler(\n",
" sequence=\"xy\", angles=[90, 45], degrees=True, coordinates=[2, -2, 0]\n",
" sequence=\"xy\", angles=[90, 45], degrees=True, coordinates=Q_([2, -2, 0], \"mm\")\n",
")"
]
},
Expand Down Expand Up @@ -340,7 +345,7 @@
" rot_z = tf.WXRotation.from_euler(\"z\", rot_angles[2]).as_matrix()\n",
"\n",
" orientation = np.matmul(rot_z, np.matmul(rot_y, rot_x))\n",
" location = [t_x, t_y, t_z]\n",
" location = Q_([t_x, t_y, t_z], \"mm\")\n",
" return [orientation, location]\n",
"\n",
"\n",
Expand Down Expand Up @@ -582,7 +587,7 @@
"outputs": [],
"source": [
"lcs_child_in_parent = tf.LocalCoordinateSystem.from_euler(\n",
" sequence=\"xy\", angles=[90, 45], degrees=True, coordinates=[2, 3, 0]\n",
" sequence=\"xy\", angles=[90, 45], degrees=True, coordinates=Q_([2, 3, 0], \"mm\")\n",
")\n",
"lcs_parent_in_child = lcs_child_in_parent.invert()"
]
Expand Down Expand Up @@ -691,7 +696,7 @@
"time = [\"2010-02-01\", \"2010-02-02\"]\n",
"\n",
"orientation_mov = [[0, -1, 0], [1, 0, 0], [0, 0, 1]]\n",
"coordinates_mov = [[-3, 0, 0], [0, 0, 2]]\n",
"coordinates_mov = Q_([[-3, 0, 0], [0, 0, 2]], \"mm\")\n",
"lcs_mov_in_ref = tf.LocalCoordinateSystem(\n",
" orientation=orientation_mov, coordinates=coordinates_mov, time=time\n",
")\n",
Expand All @@ -700,12 +705,12 @@
" [[1, 0, 0], [0, 1, 0], [0, 0, 1]],\n",
" [[0, -1, 0], [1, 0, 0], [0, 0, 1]],\n",
"]\n",
"coordinates_rot = [1, 0, 2]\n",
"coordinates_rot = Q_([1, 0, 2], \"mm\")\n",
"lcs_rot_in_ref = tf.LocalCoordinateSystem(\n",
" orientation=orientation_rot, coordinates=coordinates_rot, time=time\n",
")\n",
"\n",
"coordinates_movrot = [[0, 3, 0], [-2, 3, 2]]\n",
"coordinates_movrot = Q_([[0, 3, 0], [-2, 3, 2]], \"mm\")\n",
"orientation_movrot = [\n",
" [[1, 0, 0], [0, 1, 0], [0, 0, 1]],\n",
" [[0, -1, 0], [1, 0, 0], [0, 0, 1]],\n",
Expand Down Expand Up @@ -768,7 +773,7 @@
"# original coordinate system\n",
"time = [\"2010-02-02\", \"2010-02-07\"]\n",
"\n",
"coordinates_tdp = [[0, 3, 0], [-2, 3, 2]]\n",
"coordinates_tdp = Q_([[0, 3, 0], [-2, 3, 2]], \"mm\")\n",
"orientation_tdp = [\n",
" [[1, 0, 0], [0, 1, 0], [0, 0, 1]],\n",
" [[0, -1, 0], [1, 0, 0], [0, 0, 1]],\n",
Expand Down Expand Up @@ -867,13 +872,16 @@
"outputs": [],
"source": [
"lcs_target_in_ref = tf.LocalCoordinateSystem.from_euler(\n",
" sequence=\"zy\", angles=[90, 45], degrees=True, coordinates=[2, -2, 0]\n",
" sequence=\"zy\", angles=[90, 45], degrees=True, coordinates=Q_([2, -2, 0], \"mm\")\n",
")\n",
"lcs_ref_in_target = lcs_target_in_ref.invert()\n",
"\n",
"points_in_ref = np.array(\n",
" [[-1, 1, 0], [1, 1, 0], [1, -1, 0], [-1, -1, 0], [-1, 1, 0]], dtype=float\n",
").transpose()\n",
"points_in_ref = Q_(\n",
" np.array(\n",
" [[-1, 1, 0], [1, 1, 0], [1, -1, 0], [-1, -1, 0], [-1, 1, 0]], dtype=float\n",
" ).transpose(),\n",
" \"mm\",\n",
")\n",
"\n",
"# Transform points to target system\n",
"points_in_target = (\n",
Expand Down Expand Up @@ -908,7 +916,7 @@
" limits=(-3, 3),\n",
" title=\"Data in original system\",\n",
")\n",
"ax_0_trans.plot(points_in_ref[0], points_in_ref[1], points_in_ref[2])\n",
"ax_0_trans.plot(points_in_ref[0].m, points_in_ref[1].m, points_in_ref[2].m)\n",
"\n",
"\n",
"# second plot\n",
Expand All @@ -921,7 +929,7 @@
" limits=(-3, 3),\n",
" title=\"Data in original system\",\n",
")\n",
"ax_1_trans.plot(points_in_target[0], points_in_target[1], points_in_target[2])"
"ax_1_trans.plot(points_in_target[0].m, points_in_target[1].m, points_in_target[2].m)"
]
},
{
Expand All @@ -946,7 +954,7 @@
"outputs": [],
"source": [
"time = pd.TimedeltaIndex([0, 5], \"D\")\n",
"coordinates_tdp = [[0, 3, 0], [-2, 3, 2]]\n",
"coordinates_tdp = Q_([[0, 3, 0], [-2, 3, 2]], \"mm\")\n",
"orientation_tdp = [\n",
" [[1, 0, 0], [0, 1, 0], [0, 0, 1]],\n",
" [[0, -1, 0], [1, 0, 0], [0, 0, 1]],\n",
Expand Down Expand Up @@ -1020,7 +1028,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.4"
"version": "3.8.12"
}
},
"nbformat": 4,
Expand Down
75 changes: 43 additions & 32 deletions tutorials/transformations_02_coordinate_system_manager.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import\n",
"\n",
"import weldx.transformations as tf\n",
"import weldx.visualization as vs"
"import weldx.visualization as vs\n",
"from weldx import Q_"
]
},
{
Expand Down Expand Up @@ -80,12 +81,17 @@
"metadata": {},
"outputs": [],
"source": [
"lcs_specimen_in_root = tf.LocalCoordinateSystem(coordinates=[0, 1, -2])\n",
"lcs_specimen_in_root = tf.LocalCoordinateSystem(coordinates=Q_([0, 1, -2], \"mm\"))\n",
"\n",
"csm.create_cs_from_euler(\n",
" \"flange\", \"root\", sequence=\"x\", angles=20, degrees=True, coordinates=[-1, -1, 2]\n",
" \"flange\",\n",
" \"root\",\n",
" sequence=\"x\",\n",
" angles=20,\n",
" degrees=True,\n",
" coordinates=Q_([-1, -1, 2], \"mm\"),\n",
")\n",
"csm.create_cs(\"torch\", \"flange\", coordinates=[0, 0, -1])\n",
"csm.create_cs(\"torch\", \"flange\", coordinates=Q_([0, 0, -1], \"mm\"))\n",
"csm.add_cs(\"specimen\", \"root\", lcs_specimen_in_root)"
]
},
Expand Down Expand Up @@ -265,7 +271,9 @@
"metadata": {},
"outputs": [],
"source": [
"csm.add_cs(\"torch\", \"flange\", tf.LocalCoordinateSystem(coordinates=[0, 0, -2]))"
"csm.add_cs(\n",
" \"torch\", \"flange\", tf.LocalCoordinateSystem(coordinates=Q_([0, 0, -2], \"mm\"))\n",
")"
]
},
{
Expand Down Expand Up @@ -381,24 +389,27 @@
"outputs": [],
"source": [
"sensor_positions_in_root = xr.DataArray(\n",
" [[0, -1, 0], [0, -2, 0]], dims=[\"n\", \"c\"], coords={\"c\": [\"x\", \"y\", \"z\"]}\n",
" Q_([[0, -1, 0], [0, -2, 0]], \"mm\"), dims=[\"n\", \"c\"], coords={\"c\": [\"x\", \"y\", \"z\"]}\n",
")\n",
"\n",
"specimen_geometry_in_specimen = xr.DataArray(\n",
" [\n",
" [0, 1, 0],\n",
" [1, 1, 0],\n",
" [2, 1, 0],\n",
" [0, 2, 0],\n",
" [1, 2, 0],\n",
" [2, 2, 0],\n",
" [0, 3, 0],\n",
" [1, 3, 0],\n",
" [2, 3, 0],\n",
" [0, 4, 0],\n",
" [1, 4, 0],\n",
" [2, 4, 0],\n",
" ],\n",
" Q_(\n",
" [\n",
" [0, 1, 0],\n",
" [1, 1, 0],\n",
" [2, 1, 0],\n",
" [0, 2, 0],\n",
" [1, 2, 0],\n",
" [2, 2, 0],\n",
" [0, 3, 0],\n",
" [1, 3, 0],\n",
" [2, 3, 0],\n",
" [0, 4, 0],\n",
" [1, 4, 0],\n",
" [2, 4, 0],\n",
" ],\n",
" \"mm\",\n",
" ),\n",
" dims=[\"n\", \"c\"],\n",
" coords={\"c\": [\"x\", \"y\", \"z\"]},\n",
")\n",
Expand Down Expand Up @@ -506,16 +517,16 @@
"outputs": [],
"source": [
"parent_time = pd.TimedeltaIndex([1, 6], \"D\")\n",
"parent_coords = [[1, -1, 0], [0, -1, 0]]\n",
"parent_coords = Q_([[1, -1, 0], [0, -1, 0]], \"mm\")\n",
"parent_orientation = -tf.WXRotation.from_euler(\"z\", [0, np.pi / 2]).as_matrix()\n",
"\n",
"child_time = pd.TimedeltaIndex([2, 5], \"D\")\n",
"child_coords = [0, 2, 0]\n",
"child_coords = Q_([0, 2, 0], \"mm\")\n",
"child_orientation = tf.WXRotation.from_euler(\"z\", [0, np.pi / 2]).as_matrix()\n",
"\n",
"\n",
"childchild_time = pd.TimedeltaIndex([3, 4], \"D\")\n",
"childchild_coords = [2, 0, 0]\n",
"childchild_coords = Q_([2, 0, 0], \"mm\")\n",
"childchild_orientation = tf.WXRotation.from_euler(\"z\", [0, np.pi / 2]).as_matrix()\n",
"\n",
"\n",
Expand Down Expand Up @@ -689,9 +700,9 @@
"outputs": [],
"source": [
"csm_robot = tf.CoordinateSystemManager(\"robot head\", \"robot coordinate systems\")\n",
"csm_robot.create_cs(\"torch\", \"robot head\", coordinates=[0, 0, -2])\n",
"csm_robot.create_cs(\"mount point 1\", \"robot head\", coordinates=[0, 1, -1])\n",
"csm_robot.create_cs(\"mount point 2\", \"robot head\", coordinates=[0, -1, -1])\n",
"csm_robot.create_cs(\"torch\", \"robot head\", coordinates=Q_([0, 0, -2], \"mm\"))\n",
"csm_robot.create_cs(\"mount point 1\", \"robot head\", coordinates=Q_([0, 1, -1], \"mm\"))\n",
"csm_robot.create_cs(\"mount point 2\", \"robot head\", coordinates=Q_([0, -1, -1], \"mm\"))\n",
"csm_robot"
]
},
Expand All @@ -709,7 +720,7 @@
"outputs": [],
"source": [
"csm_scanner = tf.CoordinateSystemManager(\"scanner\", \"scanner coordinate systems\")\n",
"csm_scanner.create_cs(\"mount point 1\", \"scanner\", coordinates=[0, 0, 2])\n",
"csm_scanner.create_cs(\"mount point 1\", \"scanner\", coordinates=Q_([0, 0, 2], \"mm\"))\n",
"csm_scanner"
]
},
Expand Down Expand Up @@ -746,8 +757,8 @@
"outputs": [],
"source": [
"csm_specimen = tf.CoordinateSystemManager(\"specimen\", \"specimen coordinate systems\")\n",
"csm_specimen.create_cs(\"thermocouple 1\", \"specimen\", coordinates=[1, 1, 0])\n",
"csm_specimen.create_cs(\"thermocouple 2\", \"specimen\", coordinates=[1, 4, 0])\n",
"csm_specimen.create_cs(\"thermocouple 1\", \"specimen\", coordinates=Q_([1, 1, 0], \"mm\"))\n",
"csm_specimen.create_cs(\"thermocouple 2\", \"specimen\", coordinates=Q_([1, 4, 0], \"mm\"))\n",
"csm_specimen"
]
},
Expand All @@ -758,8 +769,8 @@
"outputs": [],
"source": [
"csm_global = tf.CoordinateSystemManager(\"root\", \"global coordinate systems\")\n",
"csm_global.create_cs(\"specimen\", \"root\", coordinates=[1, 2, 3])\n",
"csm_global.create_cs(\"robot head\", \"root\", coordinates=[4, 5, 6])\n",
"csm_global.create_cs(\"specimen\", \"root\", coordinates=Q_([1, 2, 3], \"mm\"))\n",
"csm_global.create_cs(\"robot head\", \"root\", coordinates=Q_([4, 5, 6], \"mm\"))\n",
"csm_global"
]
},
Expand Down Expand Up @@ -907,7 +918,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.2"
"version": "3.8.12"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions weldx/asdf/cli/welding_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def single_pass_weld_example(

rot = WXRotation.from_euler(seq="x", angles=180, degrees=True)

coords = [tcp_start_point.magnitude, tcp_end_point.magnitude]
coords = Q_([tcp_start_point.magnitude, tcp_end_point.magnitude], "mm")

tcp_wire = lcs(coordinates=coords, orientation=rot, time=[t_start, t_end])

Expand All @@ -109,7 +109,7 @@ def single_pass_weld_example(
lcs=tcp_wire,
)

tcp_contact = lcs(coordinates=[0, 0, -10])
tcp_contact = lcs(coordinates=Q_([0, 0, -10], "mm"))

# add the workpiece coordinate system
csm.add_cs(
Expand Down
Loading