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=Trueto 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, orx/y).crs (Any) – The CRS of the data, anything
CRStakes. It is written to the data and kept as thecrsattribute.
See also
lair.inventories.InventoryThe 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
Calculate the grid cell area in km^2. |
Methods
|
Clip the data to the given bounds. |
|
Create a copy of the grid. |
|
Regrid the data to a new grid. |
|
Reproject the data to a lat lon rectilinear grid. |
|
Resample the data to a new resolution. |