Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix waves check #57

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions spextra/spextra.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,9 @@
spex : Spextrum
New ``Spextrum`` instance.
"""
waves = (waves or _default_waves()).to(u.AA).value
if waves is None:
waves = _default_waves()
waves = waves.to(u.AA).value

# The if-statement below also allowed amplitude.unit to be
# u.Unit("vegamag"). Vegamag is removed from astropy, so the
Expand Down Expand Up @@ -509,7 +511,9 @@
-------
a scaled black-body spectrum
"""
waves = (waves or _default_waves()).to(u.AA)
if waves is None:
waves = _default_waves()
waves = waves.to(u.AA)

Check warning on line 516 in spextra/spextra.py

View check run for this annotation

Codecov / codecov/patch

spextra/spextra.py#L514-L516

Added lines #L514 - L516 were not covered by tests
blackbody = BlackBody1D(temperature=temperature.to(u.K).value)

spex = cls(modelclass=Empirical1D, points=waves,
Expand Down Expand Up @@ -558,7 +562,9 @@
spex : Spextrum
New ``Spextrum`` instance.
"""
waves = (waves or _default_waves()).to(u.AA)
if waves is None:
waves = _default_waves()
waves = waves.to(u.AA)

Check warning on line 567 in spextra/spextra.py

View check run for this annotation

Codecov / codecov/patch

spextra/spextra.py#L565-L567

Added lines #L565 - L567 were not covered by tests
power = SourceSpectrum(
PowerLawFlux1D, amplitude=1, x_0=x_0, alpha=alpha)
spex = cls(modelclass=Empirical1D, points=waves,
Expand Down
42 changes: 40 additions & 2 deletions spextra/tests/test_spextra.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,12 @@ def test_add_abs_lines(self, spec):
assert isinstance(sp2, Spextrum)

@pytest.mark.parametrize("unit", [u.mag, u.STmag, u.ABmag])
def test_flat_spectrum(self, unit):
sp = Spextrum.flat_spectrum(amplitude=10*unit)
@pytest.mark.parametrize("waves", [np.arange(1e4, 2.7e4, 100) * u.AA, None])
def test_flat_spectrum(self, unit, waves):
sp = Spextrum.flat_spectrum(
waves=waves,
amplitude=10*unit,
)
assert isinstance(sp, Spextrum)

def test_mul_with_scalar(self, spec):
Expand Down Expand Up @@ -129,6 +133,40 @@ def test_get_magnitude(self):
def test_black_body_spectrum(self, bb_spec):
assert isinstance(bb_spec, Spextrum)

@pytest.mark.webtest
def test_black_body_spectrum_units(self):
bb = Spextrum.black_body_spectrum(
temperature=9500 * u.K,
amplitude=0*u.ABmag,
filter_curve="V",
waves=np.arange(3e3, 8e3, 100)*u.AA,
)
assert isinstance(bb, Spextrum)
bb = Spextrum.black_body_spectrum(
temperature=9500*u.K,
amplitude=0*u.ABmag,
filter_curve="V",
waves=None,
)
assert isinstance(bb, Spextrum)

@pytest.mark.webtest
def test_powerlaw_units(self):
spec = Spextrum.powerlaw(
x_0=9500*u.AA,
amplitude=0*u.ABmag,
filter_curve="V",
waves=np.arange(3e3, 8e3, 100)*u.AA,
)
assert isinstance(spec, Spextrum)
spec = Spextrum.powerlaw(
x_0=9500*u.AA,
amplitude=0*u.ABmag,
filter_curve="V",
waves=None,
)
assert isinstance(spec, Spextrum)

@pytest.mark.webtest
def test_photons_in_range(self, bb_spec):
counts = bb_spec.photons_in_range(wmin=4000, wmax=5000)
Expand Down