geopfa.extrapolation.update_gdf_with_predictions

update_gdf_with_predictions(gdf, Y_grid, x_grid, y_grid)[source]

Update a GeoDataFrame with prediction values taken from a 2D grid.

The function extracts each point’s (x, y) coordinates, rounds them slightly to reduce floating-point mismatch, and looks up the corresponding predicted value from a flattened 2D prediction grid. Points whose rounded coordinates do not appear in the grid receive NaN.

Parameters:
  • gdf (geopandas.GeoDataFrame) – Input GeoDataFrame containing point geometries.

  • Y_grid (numpy.ndarray) – Predicted values arranged on a 2-D grid of shape (n_y, n_x).

  • x_grid (numpy.ndarray) – 2-D X-coordinates for each grid cell; must match Y_grid.shape.

  • y_grid (numpy.ndarray) – 2-D Y-coordinates for each grid cell; must match Y_grid.shape.

Returns:

geopandas.GeoDataFrame – Copy of the input GeoDataFrame with an added column 'value_extrapolated' containing predictions aligned by coordinate.

Notes

  • Coordinates are matched exactly after rounding to 6 decimal places. Consider adjusting this value if coordinates are stored at a different precision.

  • Uses DataFrame.apply for readability; preserves your original behavior.

  • Temporary x and y columns are removed before return.

Examples

>>> import geopandas as gpd
>>> import numpy as np
>>> from shapely.geometry import Point
>>> gdf = gpd.GeoDataFrame(geometry=[Point(0, 0), Point(1, 1)])
>>> x, y = np.meshgrid([0, 1], [0, 1])
>>> Y = np.array([[10, 20], [30, 40]])
>>> update_gdf_with_predictions(gdf, Y, x, y)
   geometry  value_extrapolated
0   POINT (0 0)               10.0
1   POINT (1 1)               40.0