Basic operations (pyzome.basic)
These functions extend operations that can be done with xarray, but provide your code with some additional readability, convenience, and safety. For instance, while:
>>> ds.mean("lon")
will take the mean over the “lon” dimension regardless of
what lon contains:
>>> import pyzome as pzm
>>> pzm.zonal_mean(ds)
will infer the dimension name, and check to ensure that the
corresponding longitude dimension is regularly spaced and spans
a full 360 degrees. The check on the longitudes can be disabled
by passing strict=False as a keyword argument.
The functions in this module are also provided as pyzome xarray accessor methods. The above example could also be achieved with:
>>> ds.pzm.zonal_mean()
Functions
- pyzome.basic.zonal_mean(dat: Dataset, lon_coord: str = '', strict: bool = False) Dataset
- pyzome.basic.zonal_mean(dat: DataArray, lon_coord: str = '', strict: bool = False) DataArray
Compute the zonal mean.
This is primarily a convenience function that will make other code more explicit/readable. This function is imported at the top level of the package by default.
- Parameters:
dat (
xarray.DataArrayorxarray.Dataset) – data containing a dimension named longitude that spans all 360 degreeslon_coord (str, optional) – The coordinate name of the longitude dimension. If given an empty string (the default), the function tries to infer which coordinate corresponds to the longitude
strict (bool, optional) – If True (the default), the function will check whether the longitudes span 360 degrees with regular spacing. If False this check is skipped.
- Returns:
zonal average – The mean across the longitude dimension
- Return type:
xarray.DataArrayorxarray.Dataset
- pyzome.basic.meridional_mean(dat: Dataset, lat1: float, lat2: float, lat_coord: str = '', strict: bool = False) Dataset
- pyzome.basic.meridional_mean(dat: DataArray, lat1: float, lat2: float, lat_coord: str = '', strict: bool = False) DataArray
Compute the cos(lat) weighted mean of data between two latitudes.
This function is imported at the top level of the package by default.
- Parameters:
dat (
xarray.DataArrayorxarray.Dataset) – data containing a latitude dimension that spans lat1 and lat2. The cos(lat) weighting assumes that the latitudes are equally spaced. If given a dataset, the function assumes all variables are on the same latitude grid.lat1 (float) – The beginning latitude limit of the band average
lat2 (float) – The ending latitude limit of the band average
lat_coord (str, optional) – The coordinate name of the latitude dimension. If given an empty string (the default), the function tries to infer which coordinate corresponds to the latitude
strict (bool, optional) – If True (the default), the function will check whether the latitudes on dat span lat1 and lat2 inclusive. If False this check is skipped.
- Returns:
meridional average – the weighted mean across the latitude dimension limited by lat1 and lat2
- Return type:
xarray.DataArrayorxarray.Dataset