lair.geo.BaseGrid#

class lair.geo.BaseGrid(data, crs, **kwargs)[source]#

Base class for working with gridded data.

This class is a wrapper around xarray DataArray and Dataset objects, with additional methods for clipping, regridding, resampling, and reprojection. Operations return a new grid by default; pass inplace=True to modify this one instead. Either way the grid object is returned, for chaining.

Parameters:
  • data (xr.DataArray | xr.Dataset) – The gridded data, with its spatial dimensions set for rioxarray (lat/lon, or x/y).

  • crs (Any) – The CRS of the data, anything CRS takes. It is written to the data and kept as the crs attribute.

See also

lair.inventories.Inventory

The grid of an emission inventory.

Examples

>>> from lair.geo import BaseGrid, generate_regular_grid
>>> data = generate_regular_grid(
...     -112.2, -111.8, 0.1, 40.6, 41.0, 0.1, x_label="lon", y_label="lat"
... ).rio.set_spatial_dims(x_dim="lon", y_dim="lat")
>>> grid = BaseGrid(data, "EPSG:4326")
>>> grid.crs.epsg
4326
>>> box = grid.clip(bbox=(-112.1, 40.7, -111.9, 40.9))
>>> dict(box.data.sizes)
{'lat': 2, 'lon': 2}

Attributes

gridcell_area

Calculate the grid cell area in km^2.

Methods

clip([bbox, extent, geom, crs, inplace])

Clip the data to the given bounds.

copy()

Create a copy of the grid.

regrid(out_grid[, method, inplace])

Regrid the data to a new grid.

reproject(resolution[, regrid_method, inplace])

Reproject the data to a lat lon rectilinear grid.

resample(resolution[, regrid_method, inplace])

Resample the data to a new resolution.