简体   繁体   中英

Why does scipy.interpolate.interp1d() tell me my xnew value is out of range?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM