SpatioTemp#
- class GRSdriver.utils.SpatioTemp[source]#
Bases:
object- static clip_raster(raster, lat, lon, extent_m)[source]#
:param raster as rioxarray object with documented coordinate system :param lat: latitude (float) of central point of buffer :param lon: longitude (float) of central point of buffer :param extent_m: extent of square centered on lat/lon :param crs: crs for reprojection, use lat/lon epsg4326 otherwise. :return: clipped raster
- rasterize(shapes, coords, latitude='lat', longitude='lon', fill=nan, **kwargs)[source]#
Rasterize a list of (geometry, fill_value) tuples onto the given xray coordinates. This only works for 1d latitude and longitude arrays.
usage:#
- read shapefile to geopandas.GeoDataFrame
states = gpd.read_file(shp_dir)
- encode the different shapefiles that capture those lat-lons as different
- numbers i.e. 0.0, 1.0 … and otherwise np.nan
shapes = (zip(states.geometry, range(len(states))))
- Assign this to a new coord in your original xarray.DataArray
ds[‘states’] = rasterize(shapes, ds.coords, longitude=’X’, latitude=’Y’)
arguments:#
: **kwargs (dict): passed to rasterio.rasterize function
attrs:#
- transform (affine.Affine):
how to translate from latlon to …?
- raster (numpy.ndarray):
use rasterio.features.rasterize fill the values outside the .shp file with np.nan
- spatial_coords (dict):
dictionary of {“X”:xr.DataArray, “Y”:xr.DataArray()} with “X”, “Y” as keys, and xr.DataArray as values
returns:#
- (xr.DataArray):
DataArray with values of nan for points outside shapefile and coords Y = latitude, ‘X’ = longitude.