0
$\begingroup$

Is there a package that interpolates precipitation data taking into account mountains and oceans? I have so far used Numpy and Basemap but as you can see in the code, the data from Europe affect the data from North America! This distorts the results and must be prevented at all costs.

(I am aware that my interpolation is just very simplified)

import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import griddata
from mpl_toolkits.basemap import Basemap
from matplotlib.colors import LinearSegmentedColormap
from matplotlib.patches import Path, PathPatch

# data coordinates and values
x = np.array([6.47, 4.8, 1.94, -4.57, 5.78, 3.95, 5.45, 0.38, 7.13, 12.43, 11.59, -1.083333333, -60.996, -83.144 ])
y = np.array([46.37, 43.9, 47.83, 48.36, 44.95, 43.57, 43.45, 43.12, 43.92, 51.35, 48.22, 52.88333333, 50.958, 37.02])
z = np.array([-29.5, -27.6, -32.5, -32.4, -16.0, -0.1, -12.3, -15.2, -36.2,  -20.6,-38.2, -38.2, -2.0, -4.0  ])

# target grid to interpolate to
xi =np.arange(-100, 100, 1, dtype='float64')
yi =np.arange(-100,100, 1, dtype='float64')
xi, yi = np.meshgrid(xi, yi)

# interpolate
zi = griddata((x,y),z,(xi,yi),method='cubic')

fig, ax = plt.subplots(figsize=(10,10))
m = Basemap(llcrnrlon=x.min()-0.1,llcrnrlat=y.min()-0.1,urcrnrlon=x.max()+0.1,urcrnrlat=y.max()+0.1, projection='merc', resolution='h',area_thresh=1000.,ax=ax)

m.drawcoastlines() #draw coastlines on the map
x,y=m(xi, yi) # convert the coordinates into the map scales
cs=ax.contourf(x, y, zi, np.linspace(-40, 0),extend='both',cmap='jet') #plot the data on the map.
plt.scatter(x, y)
plt.show()

Oh and if someone knows how I can delete these meshgrid points from Numpy, I would be very happy about a short answer, because this I have somehow not found (which I myself find very strange)

Edit: Normally the ocean is covered with a mask, but this would make the code much too long

Result:enter image description here

New contributor
Weiss is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$
1
  • $\begingroup$ I think that the problem is that the other region (somehow) is within the convex hull of the data and gets interpolated. $\endgroup$
    – nicoguaro
    May 14 at 17:18

0

Your Answer

Weiss is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.