Physical units and coordinate reference systems
A mesh can say what its numbers mean: the physical unit of each data array, and the coordinate reference system its points are in (roadmap 9.10). Both are field data, so every format that keeps field data carries them, and the formats that have a slot of their own map them onto it.
Field units (meshio:unit:<array>)
set_field_unit(mesh, "stress", "MPa") stores the unit of the point or cell array stress as field_data["meshio:unit:stress"], eight float64 values: the scale to SI and the exponents of metre, kilogram, second, kelvin, ampere, mole and candela (MPa is [1e6, -1, 1, -2, 0, 0, 0, 0]). field_unit(mesh, name) reads it back. The unit names known are 1, dimensionless, m, mm, cm, km, in, ft, kg, g, t, s, ms, K, A, Pa, kPa, MPa, GPa, bar, psi, N, kN, m/s, mm/s, m/s^2, mm/s^2, kg/m^3, t/mm^3, J and W; any other unit is given as the eight numbers.
convert_units(mesh, system) rescales every declared array, and the points by the length unit (meshio:length_unit), into one of the consistent systems SI, mm-t-s, mm-kg-ms, cm-g-s and mm-g-ms. With strict=True (the default) an undeclared point or cell array is an error; strict=False leaves it and warns.
import meshioplusplus as mp
mesh = mp.read("part.vtu")
mp.set_field_unit(mesh, "stress", "Pa")
mp.set_field_unit(mesh, "u", "m")
mm = mp.convert_units(mesh, "mm-t-s") # stress in MPa, u and the points in mmFormats with a unit slot
| format | read | write |
|---|---|---|
| Selafin | a variable's 16-character unit, when it names a known unit (Telemac's upper case, M/S, KG/M3, is understood) | the declared unit's name, when the variable has no selafin:unit:<name> of its own |
| MED | a field's UNI attribute, when every component names the same known unit (Python reader) | the declared unit's name in UNI, 16 characters per component (both engines) |
| CGNS | a solution array's DimensionalExponents_t, AdditionalExponents_t, DataConversion_t and DimensionalUnits_t (raw HDF5, cgnslib and Python readers) | the same SIDS nodes, in SI DimensionalUnits with the scale as ConversionScale; the array's unit is then left out of FieldData |
EnSight Gold, UNV and every other format without a per-array unit slot carry the units as ordinary field data where they keep field data at all. UNV's dataset 164 states the file's system of units (kept as unv:units and unv:unit_factors), not a unit per dataset, so it is not mapped.
Coordinate reference systems (meshio:crs)
set_mesh_crs(mesh, "EPSG:4326") records a CRS (an EPSG:<code> string or WKT2) as UTF-8 bytes in field_data["meshio:crs"]; mesh_crs(mesh) reads it. convert_coordinates(mesh, "crs", target_crs="EPSG:3857") reprojects the points, easting or longitude first, and records the target CRS. The reprojection goes through the core's CRS provider, PROJ when the build has it (-DMESHIOPLUSPLUS_WITH_PROJ=ON, has_crs_provider()); without one the Python twin uses the optional pyproj package, and the flat bindings report MIO_ERR_UNSUPPORTED.
Formats with a CRS slot
| format | read | write |
|---|---|---|
| LAS | the WKT of a LASF_Projection 2112 record, else EPSG:<code> from the GeoTIFF ProjectedCSType (3072) or GeographicType (2048) key of a 34735 record | the existing VLRs when they already state the CRS; otherwise the projection records are replaced by a 2112 WKT record. An EPSG:<code> CRS is not written (with a warning): the LAS 1.4 point formats 6 to 10 this writer uses take WKT only |
| UGRID netCDF | the CF grid_mapping variable the node coordinates name: crs_wkt or spatial_ref, else epsg_code/EPSG_code, else an integer epsg | a mesh_crs grid-mapping variable with crs_wkt (WKT) or epsg_code and epsg (EPSG), named by every coordinate variable |
AFLR's UGRID and ADCIRC's fort.14 have no CRS field; the CRS travels with them only through formats that keep field data.
Surfaces
C++ operations/units.hpp (set_field_unit, get_field_unit, field_unit_from_name, field_unit_from_text, field_unit_name, convert_units), detail/crs.hpp and convert_coordinates; Python set_field_unit, field_unit, convert_units, mesh_crs, set_mesh_crs, has_crs_provider; C mio_set_field_unit, mio_field_unit, mio_convert_units, mio_mesh_crs, mio_set_mesh_crs, mio_convert_coordinates_crs, mio_has_crs_provider; the same names in Fortran (mesh%set_field_unit, mesh%convert_units, mesh%crs, ...), Julia, R (mio_*) and Octave/MATLAB (mio.*); WASM setFieldUnit, fieldUnit, convertUnits, meshCrs, setMeshCrs and convertCoordinates({targetCrs}); both CLIs convert-units and coordinates --system crs --target-crs; the pipeline steps ConvertUnits and ConvertCoordinates (TargetCrs); the MCP tools convert_units, set_field_unit, convert_coordinates.