You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add Functionality to convert gdf and point data to xarray #1035
Is your feature request related to a problem? Please describe.
There are regular requests about writing intensity maps / exceedance intensity maps / return period maps to xarray raster data (and then netcdf files), e.g., #854, #857, #1013. The functionality is essentially already there, see util.plot.geo_im_from_array()
Describe the solution you'd like
We could separate the rasterize functionality from util.plot.geo_im_from_array() to a new function, if the interpolation used there (scipy.interpolate.griddata) is what we think makes sense. We could also make rasterizing optional, i.e. one could simply transform the point data to a 1d xarray if one wants.
def xarray_from_gdf(gdf, rasterize=True):
or more generally
def xarray_from_points(values, lon, lat, rasterize=True):
one could simply transform the point data to a 1d xarray if one wants.
This appears rather trivial to me. Why would we need that?
We could separate the rasterize functionality from util.plot.geo_im_from_array() to a new function, if the interpolation used there (scipy.interpolate.griddata) is what we think makes sense.
The geo_im_from_array() tries to guess if the grid is regular. If it is, it reshapes the data into a suitable 2D array. If not, it interpolates onto a fixed resolution regular grid. I think this is what we want and what the user should be able to control:
defto_grid(
gdf: geopandas.GeoDataFrame,
interpolate: Optional[bool] =None,
resolution: int=250
) ->xr.DataArray:
regular, _, _=grid_is_regular(gdf.geometry)
ifnotregular: # We must interpolateifinterpolateisNone: # User does not carelogger.warning("Interpolating non-regular grid")
interpolate=TrueelifinterpolateisFalse: # User does not want interpolationraiseRuntimeError("Cannot reshape non-regular grid")
ifinterpolate:
data, coords=interpolate(gdf, resolution)
else:
data, coords=reshape(gdf)
returnto_xarray(data, coords)
Activity
peanutfun commentedon Apr 7, 2025
This appears rather trivial to me. Why would we need that?
The
geo_im_from_array()tries to guess if the grid is regular. If it is, it reshapes the data into a suitable 2D array. If not, it interpolates onto a fixed resolution regular grid. I think this is what we want and what the user should be able to control: