NASA-Planetary-Science / sbpy

A Python package for small bodies research
https://sbpy.org/
Other
66 stars 34 forks source link

SpectralGradient.from_color is inverted for linear inputs #389

Open mkelley opened 8 months ago

mkelley commented 8 months ago

High-level problem description The color is wrong for linear inputs:

>>> wavelengths = [1, 2] * u.um
>>> red_color = 2
>>> SpectralGradient.from_color([1, 2] * u.um, red_color)
<SpectralGradient -6.66666667 % / 100 nm>
>>> blue_color = 0.5
>>> SpectralGradient.from_color([1, 2] * u.um, blue_color)
<SpectralGradient 6.66666667 % / 100 nm>

The colors are inverted. There are two problems:

1) The wavelengths are reversed on line 201: dw = lambda_eff[0] - lambda_eff[1], the convention for the array is [blue, red], so this should instead by [1] - [0]

2) Fixing that will cause a problem for magnitude inputs. The current behavior is correct:

>>> SpectralGradient.from_color([1, 2] * u.um, 1 * u.mag)
<SpectralGradient 8.61011004 % / 100 nm>

The convention for color in magnitudes is blue - red, so 1 mag is a red color, and results in a red spectral gradient. However, if (1) is fixed, the code will return a blue gradient for a red color index. This must also be addressed.