Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > About a value error called 'ValueError: A value in x_new is below theinterpolation range'

Thread Tools

About a value error called 'ValueError: A value in x_new is below theinterpolation range'

Isaac Won
Posts: n/a
Dear all,

I am trying to calculate correlation coefficients between one time series data and other time series. However,there are some missing values. So, I interploated each time series with 1d interpolation in scipy and got correlation coefficients between them. This code works well for some data sets, but doesn't for some others. Following is actual error I got:
Traceback (most recent call last):
File "", line 56, in <module>
i2 = interp(indices)
File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/", line 394, in __call__
out_of_bounds = self._check_bounds(x_new)
File "/lustre/work/apps/python-2.7.1/lib/python2.7/site-packages/scipy/interpolate/", line 449, in _check_bounds
raise ValueError("A value in x_new is below the interpolation "
ValueError: A value in x_new is below the interpolation range.
This time is 'x_new is below the interpolation range", but some times, it shows
"above interpolation range.'

I would like to make some self-contained code, but, I am not sure how to make it to represent my case well.
I just put all of my code here. I apologize for this inconvenience.
a = []
c = 4
with open(filin1, 'r') as f1:
arrays = [map(float, line.split()) for line in f1]
newa = [[x[1],x[2]] for x in arrays]

o = newa[58]
f = open(filin, "r")
percent1 = []
for columns in ( raw.strip().split() for raw in f ):
x = np.array(a, float)

not_nan = np.logical_not(np.isnan(x))
indices = np.arange(len(x))
interp = interp1d(indices[not_nan], x[not_nan])
#interp = np.interp(indices, indices[not_nan], x[not_nan])
i1 = interp(indices)

h1 = []
p1 = []
while c <278:
c = c + 1
d = c - 5
b = [],0)
for columns in ( raw.strip().split() for raw in f ):

y = np.array(b, float)
h = haversine.distance(o, newa[d])
n = len(y)
l = b.count('nan')
percent = l/8760.
percent1 = percent1 + [percent]
#print l, percent

if percent < 0.1:
not_nan = np.logical_not(np.isnan(y))
indices = np.arange(len(y))

interp = interp1d(indices[not_nan], y[not_nan])
#interp = np.interp(indices, indices[not_nan], x[not_nan])
i2 = interp(indices)

pearcoef = sp.pearsonr(i1,i2)
p = pearcoef[0]
p1 = p1 + [p]
h1 = h1 + [h]
print percent

print h1
print p1
print len(p1)
plt.plot(h1, p1, 'o')
plt.ylabel('Correlation coefficient')
For any help or advice, I will really appreciate.

Best regards,

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Browser crashes with below code.What is wrong in below code. kiran Javascript 12 12-07-2011 02:38 PM
Why is a button Click event also called when a textbox TextChanged event is called??? S_K ASP .Net 6 11-08-2007 07:44 PM
What is called carry chain structure in FPGA is called in IC? Weng Tianxiang VHDL 6 09-12-2007 07:19 AM
Could someone scan me a picture of the below? (Read Below) DVD Video 1 08-28-2006 05:42 AM
three times copy ctor called, one ctor called, why? Apricot C++ 4 04-16-2004 07:55 AM