pythonscipyinterpolationspatial-interpolation

Python geospatial interpolation (meteorological data)


My aim is to interpolate meteorological data from neighboring meteorological stations into the point with exact coordinates. In SciPy docs I found information about multidimensional interpolation ( from scipy.interpolate import griddata ). But honestly, I didn't understand how to make this code sutable for my task.

I have df with coordinates of stations and values of atmospheric pressure as input (and coordinates of a place without station)

Could anyone help me with this issue, please?

(https://docs.scipy.org/doc/scipy/reference/tutorial/interpolate.html#id4) - Multivariate data interpolation (griddata)¶


Solution

  • Found solution here:

    Inverse Distance Weighted (IDW) Interpolation with Python

    IDW interpolation is more than enough in my case, but @user6386471, thanks for your contribution!

    def linear_rbf(x, y, z, xi, yi):
    dist = distance_matrix(x,y, xi,yi)
    
    # Mutual pariwise distances between observations
    internal_dist = distance_matrix(x,y, x,y)
    
    # Now solve for the weights such that mistfit at the observations is minimized
    weights = np.linalg.solve(internal_dist, z)
    
    # Multiply the weights for each interpolated point by the distances
    zi =  np.dot(dist.T, weights)
    return zi
    

    (Using the distance_matrix function here:)

    def distance_matrix(x0, y0, x1, y1):
    obs = np.vstack((x0, y0)).T
    interp = np.vstack((x1, y1)).T
    
    # Make a distance matrix between pairwise observations
    # Note: from <http://stackoverflow.com/questions/1871536>
    # (Yay for ufuncs!)
    d0 = np.subtract.outer(obs[:,0], interp[:,0])
    d1 = np.subtract.outer(obs[:,1], interp[:,1])
    
    return np.hypot(d0, d1)