import math
from scipy import optimize

def x_to_lambda(x):
	"""returns a wavelength in Angstrom for a spectrum offset in um.

	Christlieb 2000 gives the following relationship
	between the scan length in μm and λ in Angstrom:

		x = -2953.588 + 8.218377e10 / λ^2 + 7.675455e16 / λ^4
	
	This is the inversion of that relationship with y=1/λ^2.
	"""
	a = 7.675455e16
	b = 8.218377e10
	c = -2953.588-x

	y = -b + math.sqrt(b**2-4*a*c)/2/a
	return 1/math.sqrt(y)


def lamb_to_x(lamb):
	a = 7.675455e16
	b = 8.218377e10
	c = -2953.588

	return a/lamb**4+b/lamb**2+c


if __name__=="__main__":
	print(", ".join([
		str(optimize.brentq(lambda lamb: lamb_to_x(lamb)-x, 3000, 6000))
			for x in range(-400, 5601, 20)]))

