diff --git a/spextra/spextra.py b/spextra/spextra.py index 995899b..93c18ac 100644 --- a/spextra/spextra.py +++ b/spextra/spextra.py @@ -443,7 +443,9 @@ def flat_spectrum( 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 @@ -509,7 +511,9 @@ def black_body_spectrum( ------- 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) blackbody = BlackBody1D(temperature=temperature.to(u.K).value) spex = cls(modelclass=Empirical1D, points=waves, @@ -558,7 +562,9 @@ def powerlaw( 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) power = SourceSpectrum( PowerLawFlux1D, amplitude=1, x_0=x_0, alpha=alpha) spex = cls(modelclass=Empirical1D, points=waves, diff --git a/spextra/tests/test_spextra.py b/spextra/tests/test_spextra.py index 1940251..96b2939 100644 --- a/spextra/tests/test_spextra.py +++ b/spextra/tests/test_spextra.py @@ -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): @@ -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)