0

I am trying to use scipy.interpolate.interp1dto plot longitude and latitude values to x-coordinate and y-coordinate pixels of a map image. I have sample values:

y = [0, 256, 512, 768, 1024, 1280, 1536] 
lat = [615436414755, 615226949459, 615017342897, 614807595000, 614597705702, 614387674936, 614177502635] 
x = [0, 256, 512, 768, 1024, 1280, 1536, 1792, 2048, 2304] 
lon = [235986328125, 236425781250, 236865234375, 237304687500, 237744140625, 238183593750, 238623046875, 239062500000, 239501953125, 239941406250]

when I pass to the function like this:

xInterpolation = interp1d(xDegree, xPixel)
    yInterpolation = interp1d(yDegree, yPixel)

    return (int(xInterpolation(lon)),int(yInterpolation(lat)))

I get value error:

ValueError("A value in x_new is above the interpolation " ValueError: A value in x_new is above the interpolation range.

No matter what value I try, it throws value error, I have even tried giving the same lat or lon values that are in the input list but that didn't work either. Does anybody know whats happening here? Or if I am using the wrong Interpolation.

Alicia Garcia-Raboso
  • 13,193
  • 1
  • 43
  • 48
Omayr
  • 1,949
  • 4
  • 22
  • 35

1 Answers1

1

From interp1d docs:

bounds_error : bool, optional If True, a ValueError is raised any time interpolation is attempted on a value outside of the range of x (where extrapolation is necessary). If False, out of bounds values are assigned fill_value. By default, an error is raised.

So, some of yours interpolated data is above interpolation bound. You are trying to extrapolate, not interpolate.

When you use interpolation like

xInterpolation = interp1d(xDegree, xPixel) xInterpolation(lon)

all values from lon must belong to the interval [xDegree.min, xDegree.max].

So, you need to correct your data for interpolation or use extrapolation.

Community
  • 1
  • 1
ShabashP
  • 578
  • 2
  • 10
  • No, it is not above interpolation bound. I have double checked that and also mentioned this piece of information in the question. – Omayr Sep 29 '16 at 12:11
  • @Omayr well, then, can you give samples for all arrays from your question? – ShabashP Sep 29 '16 at 15:42