{ "cells": [ { "cell_type": "markdown", "id": "7d698060-620b-4c81-87af-3931c3eb4ab1", "metadata": {}, "source": [ "# How to work with torque data\n", "\n", "Be careful when working with torque. The unit `Nm` (Newton meter) is not a SI-unit but a product of `N` and `m`, so you need to use it in this way i.e. mind the space or provide a multiplipaction: \"N m\" or \"N*m\". Here's an example:" ] }, { "cell_type": "code", "execution_count": 1, "id": "70300325-dd6a-4aa8-b9fb-a8220e37ab74", "metadata": {}, "outputs": [], "source": [ "import h5rdmtoolbox as h5tbx" ] }, { "cell_type": "markdown", "id": "0f1bf180-499a-40d3-adf1-61476fb35cbe", "metadata": {}, "source": [ "**incorrect** usage:" ] }, { "cell_type": "code", "execution_count": 3, "id": "0adaef45-87fe-49ea-a958-6a7e42a1225f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Cannot convert variables:\n", " incompatible units for variable 'torque': Cannot convert from 'number_meter' ([length] / [mass]) to 'kilogram * meter ** 2 / second ** 2' ([length] ** 2 * [mass] / [time] ** 2)\n" ] } ], "source": [ "h5tbx.use('h5tbx')\n", "\n", "with h5tbx.File() as h5:\n", " h5.create_dataset('torque', data=[1,2, 3], units='Nm')\n", " t = h5['torque'][:]\n", "\n", "try: # check by converting to SI:\n", " t.pint.quantify().pint.to('m^2/s^2*kg')\n", "except Exception as e:\n", " print(e)" ] }, { "cell_type": "markdown", "id": "8e4942bf-990f-4b76-a250-34744f052b1b", "metadata": {}, "source": [ "**correct** usage:" ] }, { "cell_type": "code", "execution_count": 4, "id": "f8adf390-7f76-4139-b8c2-7e9ea3d9502f", "metadata": {}, "outputs": [], "source": [ "with h5tbx.File() as h5:\n", " h5.create_dataset('torque', data=[1,2, 3], units='N*m') # incorrect would be using \"Nm\"\n", " t = h5['torque'][:]" ] }, { "cell_type": "code", "execution_count": 5, "id": "16204386-bb4e-4bec-8fca-cfd33a64903d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
<xarray.DataArray 'torque' (dim_0: 3)>\n",
"1 2 3\n",
"Dimensions without coordinates: dim_0\n",
"Attributes:\n",
" units: N*m\n",
" PROVENANCE: {'HDF': {'root': {'__h5rdmtoolbox_version__': '0.9.0a0'}, 'g...<xarray.DataArray 'torque' (dim_0: 3)>\n",
"[kg·m²/s²] 1.0 2.0 3.0\n",
"Dimensions without coordinates: dim_0\n",
"Attributes:\n",
" PROVENANCE: {'HDF': {'root': {'__h5rdmtoolbox_version__': '0.9.0a0'}, 'g...