xcdat.create_grid#
- xcdat.create_grid(x=None, y=None, z=None, attrs=None)[source]#
Creates a grid dataset using the specified axes.
- Parameters:
x (
xr.DataArray | Tuple[xr.DataArray
,xr.DataArray | None] | None
) – An optional dataarray or tuple of a datarray with optional bounds to use for the “X” axis, by default None.y (
xr.DataArray | Tuple[xr.DataArray
,xr.DataArray | None] | None = None,
) – An optional dataarray or tuple of a datarray with optional bounds to use for the “Y” axis, by default None.z (
xr.DataArray | Tuple[xr.DataArray
,xr.DataArray | None] | None
) – An optional dataarray or tuple of a datarray with optional bounds to use for the “Z” axis, by default None.attrs (
Optional[Dict[str
,str]]
) – Custom attributes to be added to the generated xr.Dataset.
- Returns:
xr.Dataset
– Dataset with grid axes.
Examples
Create uniform 2.5 x 2.5 degree grid using
create_axis
:>>> # NOTE: `create_axis` returns (axis, bnds) >>> lat_axis = create_axis("lat", np.arange(-90, 90, 2.5)) >>> lon_axis = create_axis("lon", np.arange(1.25, 360, 2.5)) >>> >>> grid = create_grid(x=lon_axis, y=lat_axis)
With custom attributes:
>>> grid = create_grid( >>> x=lon_axis, y=lat_axis, attrs={"created": str(datetime.date.today())} >>> )
Create grid using existing xr.DataArray’s:
>>> lat = xr.DataArray(...) >>> lon = xr.DataArray(...) >>> >>> grid = create_grid(x=lon, x=lat)
With existing bounds:
>>> lat_bnds = xr.DataArray(...) >>> lon_bnds = xr.DataArray(...) >>> >>> grid = create_grid(x=(lat, lat_bnds), y=(lon, lon_bnds))
Create vertical grid:
>>> z = create_axis( >>> "lev", np.linspace(1000, 1, 20), attrs={"units": "meters", "positive": "down"} >>> ) >>> grid = create_grid(z=z)