lair.geo.cosine_weights#

lair.geo.cosine_weights(lats)[source]#

Calculate cosine weights from latitude.

Parameters:

lats (np.ndarray) – Latitude values

Returns:

np.ndarray – Cosine weighting

Return type:

ndarray

See also

gridcell_area

The exact area of each cell, for a grid.

Examples

The mean of a field weighted by the area of each latitude band:

>>> import xarray as xr
>>> from lair.geo import cosine_weights
>>> field = xr.DataArray([1.0, 3.0], coords={"lat": [0.0, 60.0]}, dims="lat")
>>> weights = cosine_weights(field.lat)
>>> weights.values.round(3)
array([1. , 0.5])
>>> round(float(field.weighted(weights).mean()), 3)
1.667