Open
Description
@jthielen proposed a rough accessor API in pint/#849, to which I've added a couple of things:
DataArray:
-
da.pint.to(...)
: return dataarray with converted units (clean-up and implement the conversion methods #11) -
da.pint.to_base_units()
: return dataarray with base units -
da.pint.units
: units of quantity (as a Unit) -
da.pint.magnitude
: magnitude of quantity -
da.pint.quantify(unit_registry=None, unit=None)
: create DataArray wrapping a Quantity based on string unit attribute of DataArray or specified unit -
da.pint.dequantify()
: replace data with the Quantity's magnitude, and add back string unit attribute from Quantity's unit -
da.pint.sel()
: wrap da.sel to handle indexing with Quantities (by casting to magnitude in the coordinate's units similar to how MetPy does it, since true unit-aware indexing is not available yet in xarray) -
da.pint.loc
: wrap da.loc likewise -
da.pint.to_system(system)
: convert all variables to be expressed in the (base?) units of a different system. Might require upstream additions to pint.
Dataset:
-
ds.pint.to(...)
: return Dataset with converted units (clean-up and implement the conversion methods #11) -
ds.pint.to_base_units()
: return dataset with base units -
ds.pint.quantify(unit_registry=None)
: convert all data variables to quantities -
ds.pint.dequantify()
: convert all data variables from quantities to magnitudes with units as an attribute -
ds.pint.sel()
: wrap ds.sel to handle indexing with Quantities -
ds.pint.loc
: wrap ds.loc likewise -
ds.pint.to_system(system)
: convert all variables to be expressed in the (base?) units of a different system.
(this may be modified as things change on xarray's and pint's end, especially involving Dask arrays (xref #883))
Anything else?
At some point when the integration is more solidified (but before official release) we should change the accessor from pint
to units
, to get a interface more like what's described here.
This would be:
a) More intuitive
b) Units-library agnostic
c) A good fit for potentially using an entrypoint to choose which units library you want to use. There's already an entrypoint for plotting backends in xarray, and plans to add one for storage backends too.
Metadata
Metadata
Assignees
Labels
No labels