The conversion of wavelength to reduced wavelength for Legendre polynomials currently happens in 3 different places in the Redrock code:
py/redrock/targets.py:186: self._legendre = { hs:np.array([scipy.special.legendre(i)( (w-wmin)/(wmax-wmin)*2.) for i in range(nleg)]) for hs, w in dwave.items() }
py/redrock/archetypes.py:161: legendre = np.array([scipy.special.legendre(i)( (wave-wave_min)/(wave_max-wave_min)*2.-1. ) for i in range(deg_legendre)])
py/redrock/fitz.py:115: legendre = { hs:np.array([scipy.special.legendre(i)( (w-wmin)/(wmax-wmin)*2.) for i in range(nleg)]) for hs, w in dwave.items() }
The definition in archetypes.py line 161 is correct to transform it to a [-1,1] range:
where I added extra parentheses to emphasize that the division happens before the *2 multiplication, i.e. the 2 is multiplied by the numerator, not the denominator.
The other two definitions are missing the "-1" term and thus have a range of [0,2].
Clean this up to be both correct and consistent. I suggest that we add a utility function to do this transformation in a single place, e.g.
The conversion of wavelength to reduced wavelength for Legendre polynomials currently happens in 3 different places in the Redrock code:
The definition in archetypes.py line 161 is correct to transform it to a [-1,1] range:
(wave - wave_min) / (wave_max - wave_min) * 2 - 1
which is the same as
((wave - wave_min) / (wave_max - wave_min)) * 2 - 1
where I added extra parentheses to emphasize that the division happens before the *2 multiplication, i.e. the 2 is multiplied by the numerator, not the denominator.
The other two definitions are missing the "-1" term and thus have a range of [0,2].
Clean this up to be both correct and consistent. I suggest that we add a utility function to do this transformation in a single place, e.g.