Skip to content

Commit

Permalink
Merge pull request #25 from AstarVienna/fh/emilines
Browse files Browse the repository at this point in the history
Fix emission line spectrum
  • Loading branch information
teutoburg authored Mar 19, 2024
2 parents fa197c1 + 82e6609 commit 41ba0bd
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions spextra/spextra.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,9 @@ def flat_spectrum(cls, amplitude=0, waves=None):
spex : Spextrum
New ``Spextrum`` instance.
"""
waves = waves or _default_waves()
if waves is None:
waves = _default_waves()
waves = _angstrom_value(waves)
amplitude = _abmag_qty(amplitude)

# The if-statement below also allowed amplitude.unit to be
Expand All @@ -411,8 +413,8 @@ def flat_spectrum(cls, amplitude=0, waves=None):
# system_name = amplitude.unit
else:
const = ConstFlux1D(amplitude=amplitude)
spex = cls(modelclass=Empirical1D, points=waves.value,
lookup_table=const(waves.value))
spex = cls(modelclass=Empirical1D, points=waves,
lookup_table=const(waves))
# system_name = amplitude.unit

spex.repr = f".flat_spectrum(amplitude={amplitude!r})"
Expand Down Expand Up @@ -514,8 +516,17 @@ def powerlaw(cls, alpha=1, x_0=5000, amplitude=0, filter_curve=None,
return spex

@classmethod
def emission_line_spectra(cls, center, fwhm, flux, amplitude=40*u.ABmag,
waves=None):
def emission_line_spectra(cls, *args, **kwargs):
warnings.warn(
"The 'emission_line_spectra' constructor is deprecated and will be"
" removed in a future version. Please use the identical "
"'emission_line_spectrum' instead.", DeprecationWarning,
stacklevel=2)
return cls.emission_line_spectrum(*args, **kwargs)

@classmethod
def emission_line_spectrum(cls, center, fwhm, flux, amplitude=40*u.ABmag,
waves=None):
"""
Create a emission line spextrum superimpossed to a faint continuum.
Expand All @@ -542,7 +553,7 @@ def emission_line_spectra(cls, center, fwhm, flux, amplitude=40*u.ABmag,
waves = np.arange(wmin, wmax, step) * u.AA

spex = cls.flat_spectrum(amplitude=amplitude, waves=waves)
spex.add_emi_lines(center=center, fwhm=fwhm, flux=flux)
spex = spex.add_emi_lines(center=center, fwhm=fwhm, flux=flux)

return spex

Expand Down Expand Up @@ -854,7 +865,8 @@ def add_emi_lines(self, center, fwhm, flux):

for cen, flx, fwh in zip(centers, fluxes, fwhms):
line = GaussianFlux1D(mean=cen, total_flux=flx, fwhm=fwh)
lam = line.sampleset(factor_step=0.3) # bit better than Nyquist
# lam = line.sampleset(factor_step=0.3) # bit better than Nyquist
lam = self.waveset.to(u.AA).value
g_em = SourceSpectrum(Empirical1D, points=lam,
lookup_table=line(lam))
self += g_em
Expand Down

0 comments on commit 41ba0bd

Please sign in to comment.