I have 3 arrays, for longitude, latitude and temperature (so the observations are scattered in space). I want to apply interpolation on these data, but also extrapolation. I 've written the code beow, but I get an error about memory. Each of the three arrays has about 700 points.

The reason that I want to extrapolate is because i want to cover all of the region of the map.

This is the part of my code, which is about what I described:

m = Basemap(projection='merc',llcrnrlat=34,urcrnrlat=42,\

xi = np.arange(19,35,0.01)

yi = np.arange(34,42,0.01)

xi,yi = np.meshgrid(xi,yi)

lon = np.asarray(lon)

lat = np.asarray(lat)

temperature = np.asarray(temperature)

rbf = scipy.interpolate.Rbf(lon, lat, temperature, function='gaussian', smooth=0.)

zi = rbf(xi, yi)

x,y = m(xi, yi)






sc = m.contourf(x,y,mdata, np.arange(-15.0,40.01,1),cmap=jet,extend="both")

Does anyone have any ideas about the interpolation methods that I should use and how I could make it work?

I've already used griddata, which works fine, but it is just for interpolation, so the new matrix is limited and it doesn't cover the whole area. I've also read that rbf doesn't work for more than 20 points, but is there any other method for large datasets?

  • $\begingroup$ You're creating a 1400*800 = 1.12 million cell grid. That should be ok, but, just as a test, change 0.01 in xi = np.arange(19,35,0.01) and the next line to 0.05 or something. Extrapolating temperature data is a bad idea, btw, and I think using a smaller number to avoid the out of memory error might help you see that. $\endgroup$ – user967 Sep 1 '17 at 23:17
  • $\begingroup$ Unfortunately, this didn't work properly. The map appeared with very weird and extreme values. For the rest of the methods I got a "singleton error". Any other suggestions? $\endgroup$ – Stavros Keppas Sep 25 '17 at 21:49
  • $\begingroup$ Standard debugging tip: print every value you define to see if it looks reasonable. Try to find the line where things go wrong using a binary search. Also, if you can link to your whole code (eg, github), others could run it and perhaps help more. Or: reduce your code to minimal nonworking example. $\endgroup$ – user967 Sep 26 '17 at 3:46

Your Answer

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.