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:#

  1. read shapefile to geopandas.GeoDataFrame

    states = gpd.read_file(shp_dir)

  2. 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))))

  3. 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.

wktbox(center_lon, center_lat, width=100, height=100, ellps='WGS84')[source]#
Parameters:
  • center_lon – decimal longitude

  • center_lat – decimal latitude

  • width – width of the box in m

  • height – height of the box in m

Returns:

wkt of the box centered on provided coordinates