capytaine icon indicating copy to clipboard operation
capytaine copied to clipboard

Feature request: Units

Open cmichelenstrofer opened this issue 3 years ago • 3 comments

It would be helpful if the results Included units as attributes for the different data variables and coordinates, e.g. , for ds.added_mass, ds.omega, etc.

cmichelenstrofer avatar Jul 28 '22 19:07 cmichelenstrofer

Yes, it would be nice. It is not straightfoward though: even for a single rigid body, the translation and rotation dofs have different units in the equation of motion. In other word, each component of e.g. the inertia matrix or the added mass matrix may have a different unit.

mancellin avatar Jul 29 '22 10:07 mancellin

Oh right! That complicates things a bit. Maybe it can be added only for the rigid body DOFS. The code already deals with these (e.g., "Heave", "Pitch", etc) separately anyways. Would be a bit more work than I thought but it is doable and maybe worth it. One of the nice things about xarray is having that sort of metadata. In particular the name and units get used by the plotting functionality, which is really nice.

Xarray uses the coordinate name along with metadata attrs.long_name, attrs.standard_name, DataArray.name and attrs.units (if available) to label the axes. The names long_name, standard_name and units are copied from the CF-conventions spec. When choosing names, the order of precedence is long_name, standard_name and finally DataArray.name.

cmichelenstrofer avatar Jul 29 '22 16:07 cmichelenstrofer

A quick update:

  1. There is a new feature in xarray to better support units
  2. It might be possible to define the ampitude of motion of translation and rotation dof with the same unit to have a matrix that is dimensionnally homogeneous. What is missing in the documentation is a clear definition of the amplitude of the dofs and the motion. (Been thinking about that because of #215)

mancellin avatar Oct 17 '22 08:10 mancellin