# Interpolation and extrapolation of unstructured data in python: memory error

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,\
llcrnrlon=19,urcrnrlon=35,lat_ts=20,resolution='h')

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)

zi=np.array(zi)

m.drawcoastlines()

m.drawcountries()

m.drawmapboundary(fill_color="#cce6ff")

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?

• 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. – Barry Carter Sep 1 '17 at 23:17
• 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? – Stavros Keppas Sep 25 '17 at 21:49
• 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. – Barry Carter Sep 26 '17 at 3:46