Skip to content

Commit

Permalink
Merge pull request #186 from desihub/smooth_cont
Browse files Browse the repository at this point in the history
rewrite of the smooth continuum algorithm for speed and stability
  • Loading branch information
moustakas authored Oct 30, 2024
2 parents bdec78b + 9f9269c commit 4f02981
Show file tree
Hide file tree
Showing 10 changed files with 566 additions and 277 deletions.
3 changes: 3 additions & 0 deletions doc/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Change Log
3.0.0 (not released yet)
------------------------

* Rewrite of the smooth continuum and continuum-flux algorithms [`PR #186`_].
* Miscellaneous bug fixes [`PR #185`_].
* Use Numba-based Resolution implementation with faster multiply.
Also tweak parameters of continuum least_squares optimizer for
Expand All @@ -20,6 +21,8 @@ Change Log
.. _`PR #180`: https://github.com/desihub/fastspecfit/pull/180
.. _`PR #181`: https://github.com/desihub/fastspecfit/pull/181
.. _`PR #185`: https://github.com/desihub/fastspecfit/pull/185
.. _`PR #186`: https://github.com/desihub/fastspecfit/pull/186


2.5.2 (2024-04-28)
------------------
Expand Down
6 changes: 3 additions & 3 deletions doc/fastspec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ Name Type Units Descript
SNR_B float32 Median signal-to-noise ratio per pixel in *b* camera.
SNR_R float32 Median signal-to-noise ratio per pixel in *r* camera.
SNR_Z float32 Median signal-to-noise ratio per pixel in *z* camera.
SMOOTHCORR_B float32 percent Mean value of the smooth continuum correction divided by the best-fitting continuum model in the *b* camera.
SMOOTHCORR_R float32 percent Mean value of the smooth continuum correction divided by the best-fitting continuum model in the *r* camera.
SMOOTHCORR_Z float32 percent Mean value of the smooth continuum correction divided by the best-fitting continuum model in the *z* camera.
SMOOTHCORR_B float32 percent Mean value of the smooth continuum correction relative to the data in the *b* camera.
SMOOTHCORR_R float32 percent Mean value of the smooth continuum correction relative to the data in the *r* camera.
SMOOTHCORR_Z float32 percent Mean value of the smooth continuum correction relative to the data in the *z* camera.
VDISP float32 km / s Stellar velocity dispersion.
VDISP_IVAR float32 s2 / km2 Inverse variance of VDISP.
AV float32 mag Attenuation of the integrated stellar population.
Expand Down
477 changes: 306 additions & 171 deletions py/fastspecfit/continuum.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion py/fastspecfit/data/emlines.ecsv
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ name restwave patch isbalmer ishelium isbroad isstrong nicename plotgroup
civ_1549 1549.06 d False False True True CIV-$\lambda$1549+HeII-$\lambda$1640 civ_1549_heii_1640
heii_1640 1640.42 e False True True False CIV-$\lambda$1549+HeII-$\lambda$1640 civ_1549_heii_1640
aliii_1857 1857.40 f False False True False AlIII-$\lambda$1857+SiIII]-$\lambda$1892+CIII]-$\lambda$1908 aliii_1857_siliii_1892_ciii_1908
siliii_1892 1892.03 f False False True False AlIII-$\lambda$1857+SiIII]-$\lambda$1892+CIII]-$\lambda$1908 aliii_1857_siliii_1892_ciii_1908
siliii_1892 1892.03 f False False True True AlIII-$\lambda$1857+SiIII]-$\lambda$1892+CIII]-$\lambda$1908 aliii_1857_siliii_1892_ciii_1908
ciii_1908 1908.73 f False False True True AlIII-$\lambda$1857+SiIII]-$\lambda$1892+CIII]-$\lambda$1908 aliii_1857_siliii_1892_ciii_1908
mgii_2796 2796.352 g False False True True MgII-$\lambda\lambda$2796,2803 mgii_2796_2803
mgii_2803 2803.530 g False False True True MgII-$\lambda\lambda$2796,2803 mgii_2796_2803
Expand Down
6 changes: 3 additions & 3 deletions py/fastspecfit/emlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def _initial_guesses_and_bounds(self, linepix, coadd_flux, contpix=None,
from fastspecfit.util import quantile, median

initials = np.empty(len(self.param_table), dtype=np.float64)
bounds = np.empty((len(self.param_table), 2), dtype=np.float64)
bounds = np.empty((len(self.param_table), 2), dtype=np.float64)

# a priori initial guesses and bounds
minsigma_broad = 1. # 100.
Expand Down Expand Up @@ -927,7 +927,7 @@ def get_boundaries(A, v_lo, v_hi):

cmed, civar = 0., 0.
if len(borderindx) >= nminpix: # require at least XX pixels to get the continuum level
clipflux, _, _ = sigmaclip(specflux_nolines_s[borderindx], low=3, high=3)
clipflux, _ = sigmaclip(specflux_nolines_s[borderindx], low=3, high=3)

if len(clipflux) > 0:
clo, cmed, chi = quantile(clipflux, (0.25, 0.50, 0.75))
Expand Down Expand Up @@ -1316,7 +1316,7 @@ def emline_specfit(data, result, continuummodel, smooth_continuum,
dwave = np.round(dwave, decimals=3)

npix = int(np.round((maxwave-minwave)/dwave)) + 1
modelwave = minwave + dwave * np.arange(npix)
modelwave = minwave + dwave * np.arange(npix, dtype=np.float64)

wavesrt = np.argsort(emlinewave)
sorted_waves = emlinewave[wavesrt]
Expand Down
Loading

0 comments on commit 4f02981

Please sign in to comment.