Reputation: 185
I want to use scipy.interpolate.SmoothSphereBivariateSpline to interpolate temperature on a map (I'm not familiar with data interpolation, so this maybe not a good choice but I'd like to give it a go).
These are what I did:
latitude longitude temperature city
30.22 120.14 39 2caves
30.26 120.13 39 3caves
30.23 120.13 39 Anlong
33.48 108.5 30 Anda
37.2 100.74 15 Anan
...
into pandas
data = pandas.read_table('temp.tsv')
Get radians from lat, lon:
theta = numpy.array(data.latitude) / 180 * numpy.pi # the lat, lon domain is safe here so
phi = numpy.array(data.longitude) / 180 * numpy.pi # I won't adjust for the output range
temp = numpy.array(data.temperature)
Feed them into scipy:
lut = SmoothSphereBivariateSpline(theta, phi, temps)
Then the function throws a ValueError:
ValueError: The required storage space exceeds the available storage space: nxest or nyest too small, or s too small. The weighted least-squares spline corresponds to the current set of knots.
I've tried to adjust the s parameter with different values, from 1, 2, 3 to 7000, 8000, it just kept being too small. What should I do to make the interpolation work?
Upvotes: 7
Views: 1323
Reputation: 129
Actually, I tried an alternative method that worked. RectSphereBivariateSpline
from the same library. It took u,v
or theta, phi grid
and interpolate it from the grid.
It seems your data sample also falls on a grid, this should work for you too!
Note that the north pole and south pole need some special treatment in this function.
https://scipy.github.io/devdocs/reference/generated/scipy.interpolate.RectSphereBivariateSpline.html
I tried with a few examples and it seems the problem SmoothSphereBivariateSpline
faces is the memory scaling. So if we have too many points on our grid it will memory overflow. This seems to be a more flexible method suitable for points irregularly dropped on sphere instead of regular grid like ours.
Upvotes: 0
Reputation: 153
Just for the records: following the documentation there is a smoothing parameter s
to be chosen; the default value is s=0
, but sometimes it is critical to select it manually as suggested in the documentation.
Upvotes: 1