Skip to content

Commit

Permalink
Provide correct slope for color ratios with SpectralGradient.from_color
Browse files Browse the repository at this point in the history
  • Loading branch information
mkelley committed Jan 12, 2024
1 parent 1315915 commit 0e39958
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
14 changes: 7 additions & 7 deletions sbpy/spectroscopy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,14 @@ def from_color(cls, wfb, color):

lambda_eff = SpectralGradient._lambda_eff(wfb)

try:
# works for u.Magnitudes and dimensionless u.Quantity
if isinstance(color, u.Magnitude):
alpha = u.Quantity(-color, u.dimensionless_unscaled)
elif u.Quantity(color).unit.is_equivalent(u.mag):
alpha = (-color).to(u.dimensionless_unscaled, u.logarithmic())
else:
alpha = u.Quantity(color, u.dimensionless_unscaled)
except u.UnitConversionError:
# works for u.mag
alpha = color.to(u.dimensionless_unscaled, u.logarithmic())

dw = lambda_eff[0] - lambda_eff[1]
dw = lambda_eff[1] - lambda_eff[0]
S = ((2 / dw * (alpha - 1) / (alpha + 1))
.to(u.percent / hundred_nm))

Expand Down Expand Up @@ -446,7 +446,7 @@ def fit(self, spec):
Examples
--------
>>> spec_model = SpectralModel(type='Haser', molecule='H2O') # doctest: +SKIP
>>> spec_model = SpectralModel(type='Haser', molecule='H2O') # doctest: +SKIP
>>> spec.fit(spec_model) # doctest: +SKIP
>>> print(spec.fit_info) # doctest: +SKIP
Expand Down
1 change: 1 addition & 0 deletions sbpy/spectroscopy/tests/test_specgrad.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test_new_wave_error(self):
0.21 * u.mag, 12 * u.percent / hundred_nm, 2),
((bandpass('SDSS g'), bandpass('SDSS r')),
-0.15 * u.mag, -10 * u.percent / hundred_nm, 0.5),
((500, 600) * u.nm, 3, 100 * u.percent / hundred_nm, 0.01),
))
def test_from_color(self, wfb, color, S0, atol):
"""Test from color to spectral gradient.
Expand Down

0 comments on commit 0e39958

Please sign in to comment.