lair.geo.gridcell_area#

lair.geo.gridcell_area(grid, R=None)[source]#

Calculate the area of each grid cell in a grid.

On a lat-lon grid each cell is bounded by two meridians and two parallels, halfway between the cell centers, and its area is the exact area of that cell on the WGS84 ellipsoid: a**2 / 2 * dlon * (q(lat2) - q(lat1)), with q the function of the authalic latitude (Snyder 1987, eq. 3-12). With R, it is the area on a sphere of that radius instead, R**2 * dlon * (sin(lat2) - sin(lat1)). On a projected grid in meters it is dx * dy.

Parameters:
  • grid (xr.DataArray | xr.Dataset) – Grid data with a rioxarray CRS: geographic (any datum, e.g. EPSG:4326, OGC:CRS84, EPSG:4269) with 1-D lat/lon coordinates, or projected in meters.

  • R (float | np.ndarray | xr.DataArray, optional) – Radius of a sphere in kilometers to use instead of the WGS84 ellipsoid (lat-lon grids only), by default None. An array must broadcast against the grid, e.g. a DataArray along lat.

Returns:

xr.DataArray – grid-cell area in square-kilometers, with the grid’s (y, x) dims. Its only attribute is units ('km2'), so an array multiplied by it (Inventory.absolute_emissions) takes no description of the grid.

Raises:

ValueError – If the grid has no CRS, its CRS is neither geographic nor in meters, or a lat-lon grid’s lat or lon is not 1-D.

Return type:

DataArray

Notes

A sphere is close but not exact. With R=6371 a 1-degree cell is 0.45% too large at the equator, 0.12% too small at 40.5 N and 0.9% too small next to a pole; a 0.1-degree cell centered at 40.75 N is 93.668 km2 against 93.783 km2 on the ellipsoid. A sphere whose radius is the ellipsoid’s radius at the cell’s latitude (earth_radius()) is worse at 40.75 N (93.611 km2, 0.18% too small).

See also

gridcell_area_from_latlon

The same from latitudes and longitudes.

BaseGrid.gridcell_area

The areas of a grid’s cells.

Examples

>>> from lair import geo
>>> area = geo.gridcell_area_from_latlon([40.65, 40.75, 40.85], [-111.95, -111.85])
>>> round(float(area[1, 1]), 3)  # the 0.1-degree cell at 40.75 N, 111.85 W
93.783