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 optionnal 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(da, x_dim='x', y_dim='y', epsg=27572, fout='raster.tiff')[source]
Write a xr.DataArray to a raster file
need xarray with rioxarray installed. Only for regular grids.
TODO: add support for irregular grids, using PostMARTHE QGIS plugin code.
- Parameters:
da (xarray.DataArray) – The DataArray to write to a raster file (only 2D, i.e. no time dimension, select a variable and timestep before).
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.
fout (str, optional) – The output file path for the raster file, by default ‘raster.tiff’.
- Returns:
None – The function writes the raster file and returns None.