Question

I'm trying to interpolate data in Python but it's just not working.

The specific problem is as follows: I have BminV colour data for a sample of stars (around 70 of them). I have generated these values for theoretical black-body emitters as well, by interpolation.

#BminV is the data from the stars.
temperatures = np.arange(1000.0, 80000.0, 50.0)
#I generate for each of these temperatures a BminV colour. these are stored in BminVblack.
f = interpolate.interp1d(BminVblack, temperatures, kind='cubic')
print f(BminV)

For each and every value of BminV this returns an error saying it's out of the interpolation range. I thought I'd check these ranges

print np.min(BminVblack), np.max(BminVblack)
print np.min(BminV), np.max(BminV)

This works out to have the BminVblack range as -.38 to 3.2, and the BminV range from -.36 to 1.8. Why does it still say that some values of BminV are out of range for the interpolation?

Was it helpful?

Solution

check that BminVblack is a monotonically increasing array.

It is monotonically increasing if np.all(np.diff(BminVblack)>0) evaluates to True.

If it is not monotonically increasing, an 'out of range' error can be raised. The same happens if the input array is monotonically decreasing, as was your case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top