gridmarthe.operasem.gis
GIS utility for marthe grids
- gridmarthe.operasem.gis.to_geodataframe(ds, epsg='EPSG:27572', fmt='long')[source]
Convert marthegrid.Dataset to a geodataframe
- Parameters:
- Returns:
geopandas.GeoDataFrame – The converted GeoDataFrame.
- gridmarthe.operasem.gis.clip_dataset(ds, gdf, crs=27572, engine='gdf')[source]
Clip a xarray Dataset with a gpd.GeoDataFrame
Needs rioxarray. If not installed, raise ModuleNotFoundError please install it or reinstall gridmarthe with optional dependancies: pip install gridmarthe[opt]
See: https://corteva.github.io/rioxarray/html/examples/clip_geom.html Todo: shapely version
- Parameters:
ds (xarray.Dataset) – The dataset to clip.
gdf (geopandas.GeoDataFrame) – The GeoDataFrame containing the geometry to clip with.
crs (int, optional) – The coordinate reference system to use for the clipping, by default 27572.
engine (str, optional) – The engine to use for clipping, by default ‘gdf’.
- Returns:
xarray.DataArray or xarray.Dataset – The clipped dataset.
- gridmarthe.operasem.gis.subset_with_coords(da, dims=['x', 'y'], gdf=None, xmin=None, ymin=None, xmax=None, ymax=None)[source]
subset DataArray or Dataset on rectangular shape, with gpd.GeoDataFrame or bounds
- Parameters:
da (xarray.DataArray or xarray.Dataset) – The data to subset.
dims (list of str, optional) – The dimensions to use for subsetting, by default [‘x’, ‘y’].
gdf (geopandas.GeoDataFrame, optional) – A GeoDataFrame containing the geometry to use for subsetting, by default None.
xmin (float, optional) – The manual bounds to use for subsetting, by default None.
ymin (float, optional) – The manual bounds to use for subsetting, by default None.
xmax (float, optional) – The manual bounds to use for subsetting, by default None.
ymax (float, optional) – The manual bounds to use for subsetting, by default None.
- Returns:
xarray.DataArray or xarray.Dataset – The subsetted data.
- gridmarthe.operasem.gis.transf_proj(ds, from_epsg='EPSG:27572', to_epsg='EPSG:2154', engine='rioxarray')[source]
Transform grid of a dataset using pyproj
engine: rioxarray, meshgrid, xy
Data (ds) needs to be a 2D array with xy as coords dimensions and time sliced. If needed, use
gridmarthe.assign_coords()first.Warning: IN DEVELOPMENT, not tested yet // USE WITH CAUTION
- gridmarthe.operasem.gis.to_raster(ds, varname=None, x_dim='x', y_dim='y', time=None, epsg=27572, filename_tpl='raster')[source]
Write a xr.DataArray to a raster file
Notes
Warning, only functionnal for regular grids
Requires rasterio/rioxarray packages
TODO: add support for irregular grids, using PostMARTHE QGIS plugin code.
- Parameters:
ds (xarray.Dataset, xarray.DataArray) – The dataset/dataArray to write to a raster file
x_dim (str, optional) – The name of the x dimension, by default ‘x’.
y_dim (str, optional) – The name of the y dimension, by default ‘y’.
epsg (int, optional) – The EPSG code for the coordinate reference system, by default 27572.
filename_tpl (str, optional) – The output file template for the raster file, by default ‘raster’. Final name will be ‘{filename_tpl}_{time}.tiff’
- Returns:
None – The function writes the raster file and returns None.