carpet_concentrations.xarray_utils
Tools for helping with xarray
check_dimensions
- check_dimensions(inp, exp_dims, extras_ok=False)[source]
Check dimensions of an
xr.DataArray
- Parameters
inp (
xarray.core.dataarray.DataArray
) – Data to checkexp_dims (
tuple
[collections.abc.Hashable
,...
]) – Dimensions we expect the data to haveextras_ok (
bool
) – Is it ok if there are other dimensions present in the data, beyond those specified inextra_dims
?
- Raises
CoordinateError – Dimensions aren’t as expected
- Return type
calculate_weighted_area_mean_latitude_only
- calculate_weighted_area_mean_latitude_only(inp, variables, bounds_dim_name='bounds', lat_name='lat', lat_bounds_name='lat_bounds')[source]
Calculate area mean based on only latitude information
See Kelly and Šavrič1
- Parameters
inp (
xarray.core.dataset.Dataset
) –xr.Dataset
to processvariables (
list
[str
]) – Variables of which to calculate the area-meanbounds_dim_name (
str
) – Name of the dimension which defines boundslat_name (
str
) – Name of the latitude dimensionlat_bounds_name (
str
) – Name of the latitude bounds variable
- Returns
xarray.core.dataset.Dataset
–xr.Dataset
with area-weighted mean ofvariables
check_all_units_compatible
- check_all_units_compatible(ds)[source]
Check all units in an
xr.Dataset
are compatibleThis only checks the data variables, not units of co-ordinates or dimensions.
Here compatible means the units can be converted into one another
- Parameters
ds (
xarray.core.dataset.Dataset
) – Dataset to check- Raises
DatasetIncompatibleUnitsError – Some of the units in the dataset are incompatible
- Return type
check_all_units_compatible_attrs
- check_all_units_compatible_attrs(ds)
Check all units in an
xr.Dataset
are compatibleThis only checks the data variables, not units of co-ordinates or dimensions.
Here compatible means the units can be converted into one another
- Parameters
ds (
xarray.core.dataset.Dataset
) – Dataset to check- Raises
DatasetIncompatibleUnitsError – Some of the units in the dataset are incompatible
- Return type
- 1
Kevin Kelly and Bojan Šavrič. Area and volume computation of longitude–latitude grids and three-dimensional meshes. Transactions in GIS, 25(1):6–24, 2021. URL: https://onlinelibrary.wiley.com/doi/abs/10.1111/tgis.12636, arXiv:https://onlinelibrary.wiley.com/doi/pdf/10.1111/tgis.12636, doi:https://doi.org/10.1111/tgis.12636.