gwexpy.interop.metpy_
Interoperate with MetPy xarray data arrays.
Interoperability with MetPy xarray DataArrays.
MetPy uses Pint quantities via .metpy.quantify() / .metpy.dequantify()
and CF Convention axis attributes (_metpy_axis). This module strips the
Pint layer, converts units to astropy via gwexpy.utils.units, and
delegates to gwexpy.interop.xarray_.from_xarray_field().
References
https://unidata.github.io/MetPy/latest/
Functions
|
Convert a MetPy-enhanced |
- gwexpy.interop.metpy_.from_metpy_dataarray(cls: type, da: Any, *, dequantify: bool = True, axis0_domain: Literal['time', 'frequency'] = 'time') ScalarField[source]
Convert a MetPy-enhanced
xarray.DataArrayto aScalarField.MetPy attaches Pint units to data arrays via
.metpy.quantify(). This function strips the Pint layer (dequantify) and converts the unit toastropy.unitsbefore creating a ScalarField.- Parameters:
cls (type) –
ScalarFieldclass.da (xarray.DataArray) – MetPy-enhanced DataArray. May have Pint-backed data or plain
float64data with a"units"attribute.dequantify (bool, default True) – Call
.metpy.dequantify()to strip Pint units and move them toattrs["units"]. Set toFalseif the array is already plain.axis0_domain ({"time", "frequency"}, default "time") – Physical domain of axis0.
- Return type:
ScalarField
Notes
MetPy must be installed for full functionality, but the converter also works with plain xarray DataArrays that have
"units"and"_metpy_axis"attributes.