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
Raises

CoordinateError – Dimensions aren’t as expected

Return type

None

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 process

  • variables (list[str]) – Variables of which to calculate the area-mean

  • bounds_dim_name (str) – Name of the dimension which defines bounds

  • lat_name (str) – Name of the latitude dimension

  • lat_bounds_name (str) – Name of the latitude bounds variable

Returns

xarray.core.dataset.Datasetxr.Dataset with area-weighted mean of variables

check_all_units_compatible

check_all_units_compatible(ds)[source]

Check all units in an xr.Dataset are compatible

This 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

None

check_all_units_compatible_attrs

check_all_units_compatible_attrs(ds)

Check all units in an xr.Dataset are compatible

This 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

None

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.