Meteo station point data to raster interpolation in Python, pandas and geopandas

100 views Asked by At

I'm looking for assistance to solve a spatial Kriging problem in Python (or any other solution you might suggest) that involves integrating multiple variables from the columns of the same dataframe and a digital elevation model (DEM). I'm trying to use libraries like scikit-gstat, PyKrige, or similar ones to perform a prediction that works as interpolation based on a defined dimension through a GeoDataFrame or a raster. Weather data is contained in a dataframe, and I want to predict data from one specific column using the others to enhance the prediction. However, I'm facing some challenges in properly integrating all the information. Here's an overview of the challenges I'm encountering:

Here's an example of the data structure I have access to:

index name lat lon h_sea B11001
0 Bologna urbana 11.32879 44.50075 78.0 227.705601
1 Ferrara urbana 11.62114 44.83250 26.0 198.142529
2 Finale Emilia 11.28402 44.83906 12.0 177.565454
3 Forli' urbana 12.04182 44.22039 51.0 223.155397
4 Granarolo Faentino 11.92193 44.36161 15.0 228.395657
5 Martorano 12.26798 44.16614 25.0 218.178186
6 Modena urbana 10.91699 44.65639 73.0 228.691860
7 Parma urbana 10.33049 44.80800 79.0 204.097518
8 Piacenza urbana 9.67965 45.05492 71.0 209.698362
9 Reggio nell'Emilia urbana 10.63370 44.69781 72.0 204.874015
10 Rimini urbana 12.57354 44.05919 16.0 217.934321
11 San Pietro Capofiume 11.62264 44.65378 11.0 223.010690
index B11002 B12101_C B13003
0 1.916224 5.802898 74.152932
1 2.229462 5.061348 79.357680
2 1.811290 3.764022 80.027007
3 1.848094 5.767242 76.988415
4 2.143994 4.222029 85.696343
5 2.224553 5.377731 80.022900
6 2.077067 4.990518 74.163372
7 1.365618 5.175278 76.194010
8 1.345687 4.610513 74.584989
9 1.280448 5.221846 73.971977
10 2.137484 6.226524 74.544494
11 2.285721 3.531839 84.784460

Here an example of code I tried to use but not working

def geodataframe_to_kriging_raster(geodataframe, column_name, pixel_size, covariates, dem, variogram_model="linear"):

    if geodataframe.crs != dem.crs:
        area_bounds_gdf = dem.to_crs(geodataframe.crs)
        print('Modificato il sistema di riferimento')

    file_bounds = box(*dem.bounds)
    min_x, min_y, max_x, max_y = file_bounds.bounds
    width = int((max_x - min_x) / pixel_size)
    height = int((max_y - min_y) / pixel_size)
    transform = from_origin(min_x, max_y, pixel_size, pixel_size)

    coordinates = np.column_stack((geodataframe.geometry.x, geodataframe.geometry.y))
    data = geodataframe[column_name].values
    
    dem_values = dem.read(1)

    OK = UniversalKriging(
        coordinates[:, 0],
        coordinates[:, 1],
        data,
        variogram_model=variogram_model,
        verbose=False,
        enable_plotting=False,
        drift_terms=covariates,
        external_drift=dem_values
    )
    z, _ = OK.execute("grid", np.linspace(min_x, max_x, width), np.linspace(max_y, min_y, height))

    return z, transform

I have a geospatial dataset in GeoDataFrame format that includes a variable of interest (e.g., weather data) and some covariates (other related variables).

I want to perform spatial Kriging to estimate the value of the variable of interest on a raster grid.

I also want to include a digital elevation model (DEM) as an external covariate in Kriging to influence the estimation of the variable of interest.

I've tried to use libraries like scikit-gstat and PyKrige, but I'm experiencing difficulties in integrating covariates and DEM into the Kriging process. Specifically, I'm trying to define the experimental variogram for each variable, but I'm struggling with the correct configuration.

I've already attempted different variations of code, but I keep receiving errors related to the configuration of experimental variograms and the specification of covariates and DEM in the Kriging process.

I'm seeking assistance and advice on the correct setup to perform this spatial Kriging while considering all the involved variables. Any help, suggestions, or example code would be highly appreciated.

0

There are 0 answers