- Code: Select all
`# Define pixel-to-wavelength conversion function.`

def px_to_wl(numPixels,instNum):

# Define coefficients in descending order.

coef = {6:[-5.339937e-3,-1.095702e-1,-2.125161,6.740874e+1,4.124978e+2],

37:[9.082226e-3,-1.188136e-1,-2.582489,7.705425e+1,4.278468e+2]}

# Apply the Pixel Scaler (E1 in Pan Manual)

pixs = [3.46*((n/numPixels) - 0.5) for n in xrange(1,numPixels+1)]

c = coef[instNum]

wl = [c[0]*r**4 + c[1]*r**3 + c[2]*r**2 + c[3]*r + c[4] for r in pixs]

return np.array(wl)

I am calling the function via:

- Code: Select all
`wl6 = px_to_wl(1024,6)`

However, if I look at wl6 I get:

- Code: Select all
`>>> wl6`

array([ 290.03977671, 290.03977671, 290.03977671, ..., 290.03977671,

290.03977671, 522.13937013])

As you can see, all values, except the last, are identical. Worse yet, the spectrometer does not see 290.039xxxx.

Here's the problem: If I take the function lines and run them outside the function, i.e.

- Code: Select all
`numPixels = 1024`

instNum = 6

# Define coefficients in descending order.

coef = {6:[-5.339937e-3,-1.095702e-1,-2.125161,6.740874e+1,4.124978e+2],

37:[9.082226e-3,-1.188136e-1,-2.582489,7.705425e+1,4.278468e+2]}

# Apply the Pixel Scaler (E1 in Pan Manual)

pixs = [3.46*((n/numPixels) - 0.5) for n in xrange(1,numPixels+1)]

c = coef[instNum]

wl = [c[0]*r**4 + c[1]*r**3 + c[2]*r**2 + c[3]*r + c[4] for r in pixs]

everything works as desired. Now,

- Code: Select all
`>>> wl6`

array([ 290.28942047, 290.53902649, 290.78859474, ..., 521.74079343,

521.94011362, 522.13937013])

I have deleted px_to_wl, deleted wl6, deleted wl, even restarted Python to no avail. Why is the function call failing, but the same lines work outside the function?