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

2.3.1 release candidate #148

Merged
merged 33 commits into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d47559a
assume BRZ cameras; bug if one camera is masked on first spectrum
moustakas Aug 8, 2023
5ed0431
initialize stacked photometric parameter file
moustakas Aug 8, 2023
6cfb7d3
restore support for fitting stacked spectra
moustakas Aug 8, 2023
6764927
fix fastqa with stacked spectra
moustakas Aug 8, 2023
ce3284d
hard-code SNR GRZ cameras
moustakas Aug 10, 2023
ae824c5
use mp spawn method in get-cutouts
moustakas Aug 10, 2023
4da80d3
oops do not hard-code hsc-dr3 layer
moustakas Aug 10, 2023
d8a3851
bug fix (see sv3-bright-25918-39627758090851408): use default xtol an…
moustakas Aug 10, 2023
a0d43d0
implement matched-filter Gaussian flux and flux_ivar
moustakas Aug 13, 2023
073b5c1
require at least one broad line to have S/N>3
moustakas Aug 14, 2023
1eeb19d
nicer/faster plotting of the individual emission lines
moustakas Aug 14, 2023
e664da2
add heii_1640 and aliii_1857
moustakas Aug 14, 2023
f78d62e
update data model and webapp
moustakas Aug 14, 2023
5a7f6c4
write FPHOTO_DIR not LEGACYSURVEY_DIR to headers
moustakas Aug 14, 2023
17e4ad6
emission lines parameter file now an optional input
moustakas Aug 14, 2023
d267e58
update change log and requirements.txt dependencies
moustakas Aug 14, 2023
56e1cb6
tighten xtol even more, to 1e-10, otherwise objects like fuji/sv3-dar…
moustakas Aug 14, 2023
105193e
require just Balmer - not helium - lines to assess broad-line model; …
moustakas Aug 14, 2023
3e8dad5
update emlines.ecsv used for unit tests
moustakas Aug 14, 2023
74c139d
address first bug in #149
moustakas Aug 15, 2023
27736e2
more informative log
moustakas Aug 15, 2023
a3093c2
smooth continuum enhancements documented in #128
moustakas Aug 16, 2023
0192624
new templates: one more age bin with more sensible boundaries; extend…
moustakas Aug 18, 2023
f08583c
update template version for unit tests
moustakas Aug 18, 2023
34ccb67
minor QA fix; prepare for 2.4.0 tag
moustakas Aug 18, 2023
55bfa8f
Merge branch 'main' into 1.3.1-candidate
moustakas Aug 18, 2023
f92c9e3
start k-corrections tutorial nb (#89, #74)
moustakas Aug 18, 2023
d7633c4
create constants for the template pixel sizes and share them across a…
moustakas Aug 18, 2023
b204e68
fix typos; make sure templates are identical
moustakas Aug 18, 2023
91365f4
pull restframe_photometry calculations into dedicated function
moustakas Aug 19, 2023
34da74d
more cleanup
moustakas Aug 19, 2023
261b57d
add K-corrections tutorial notebook to address #89 and #74
moustakas Aug 19, 2023
f7d0359
add vmax notebook to address #74
moustakas Aug 19, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
python-version: ['3.10']
fitsio-version: ['==1.1.7']
env:
DESIUTIL_VERSION: 3.2.6
DESIUTIL_VERSION: 3.3.1
FASTSPECFIT: ${GITHUB_WORKSPACE}/fastspecfit
DESI_ROOT: ${FASTSPECFIT}/desi

Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
python-version: ['3.10']
fitsio-version: ['==1.1.7']
env:
DESIUTIL_VERSION: 3.2.6
DESIUTIL_VERSION: 3.3.1
FASTSPECFIT: ${GITHUB_WORKSPACE}/fastspecfit
DESI_ROOT: ${FASTSPECFIT}/desi

Expand Down
62 changes: 27 additions & 35 deletions bin/build-fsps-templates
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import matplotlib.pyplot as plt

from desispec.interpolation import resample_flux
from fastspecfit.util import C_LIGHT
from fastspecfit.continuum import PIXKMS_BLU, PIXKMS_RED, PIXKMS_WAVESPLIT

irfactor = int(PIXKMS_RED / PIXKMS_BLU)

def smooth_continuum(wave, flux, medbin=1000, smooth_window=200,
smooth_step=50, png=None):
Expand Down Expand Up @@ -103,8 +106,8 @@ def smooth_continuum(wave, flux, medbin=1000, smooth_window=200,

return smooth

def build_templates(models, logages, agebins, imf='chabrier', pixkms=25.0,
wavesplit=1e4, irfactor=4, include_nebular=True):
def build_templates(models, logages, agebins, imf='chabrier',
include_nebular=True):

nsed = len(models)

Expand Down Expand Up @@ -187,10 +190,10 @@ def build_templates(models, logages, agebins, imf='chabrier', pixkms=25.0,
# Resample to constant log-lambda / velocity. In the IR (starting at ~1
# micron), take every fourth sampling, to save space.
if imodel == 0:
dlogwave = pixkms / C_LIGHT / np.log(10) # pixel size [log-lambda]
dlogwave = PIXKMS_BLU / C_LIGHT / np.log(10) # pixel size [log-lambda]
newwave = 10**np.arange(np.log10(np.min(wave)), np.log10(np.max(wave)), dlogwave)

isplit = np.argmin(np.abs(newwave-wavesplit)) + 1
isplit = np.argmin(np.abs(newwave-PIXKMS_WAVESPLIT)) + 1
newwave = np.hstack((newwave[:isplit], newwave[isplit:][::irfactor]))
npix = len(newwave)

Expand All @@ -217,17 +220,12 @@ def build_templates(models, logages, agebins, imf='chabrier', pixkms=25.0,

def main(args):

version = '1.0.0'

# pixel resampling choices
pixkms = 25.0 # pixel size [km/s]
irfactor = 4
wavesplit = 1e4 # [A]
version = '1.1.0'

# velocity dispersion grid
vdispmin = 100.0
vdispmax = 350.0
dvdisp = 25.0
vdispmin = 50.
vdispmax = 350.
dvdisp = 25.
nvdisp = int(np.ceil((vdispmax - vdispmin) / dvdisp)) + 1
vdisp = np.linspace(vdispmin, vdispmax, nvdisp)

Expand All @@ -239,14 +237,10 @@ def main(args):
#logages = np.linspace(minlogage, maxlogage, nages)

# Choose lookback time bins.
nages = 7
tuniv = 13.7 # [Gyr]
tbinmax = (tuniv * 0.85) * 1e9
lim1, lim2 = 7.4772, 8.0
agelims = np.hstack(((0, lim1), np.linspace(lim2, np.log10(tbinmax), nages-2), np.log10(tuniv*1e9)))
agelims = 10**agelims / 1e9
agebins = np.array([agelims[:-1], agelims[1:]]).T # [Gyr]
agelims = np.array([0., 0.01, 0.03, 0.1, 0.33, 1.1, 3.6, 12., 14.]) # [Gyr]
nages = len(agelims) - 1

agebins = np.array([agelims[:-1], agelims[1:]]).T # [Gyr]
logages = np.log10(1e9*np.sum(agebins, axis=1) / 2) # mean age [yr] in each bin

#logmets = np.array([-1.0, -0.3, 0.0, 0.3])
Expand Down Expand Up @@ -325,12 +319,8 @@ def main(args):
models = models.flatten()

# Build models with and without line-emission.
meta, wave, flux = build_templates(models, logages, agebins, pixkms=pixkms,
wavesplit=wavesplit, include_nebular=True,
imf=args.imf)
_, _, fluxnolines = build_templates(models, logages, agebins, pixkms=pixkms,
wavesplit=wavesplit, include_nebular=False,
imf=args.imf)
meta, wave, flux = build_templates(models, logages, agebins, include_nebular=True, imf=args.imf)
_, _, fluxnolines = build_templates(models, logages, agebins, include_nebular=False, imf=args.imf)
lineflux = flux - fluxnolines

#I = (wave > 3500) * (wave < 9000)
Expand All @@ -345,7 +335,7 @@ def main(args):

# Select just the line-free models trimmed to the 1200-10000 A wavelength
# range.
I = np.where((wave > 1200) * (wave < wavesplit))[0]
I = np.where((wave > 1200) * (wave < PIXKMS_WAVESPLIT))[0]
#J = np.where(meta['fagn'] == 0)[0]
vdispwave = wave[I]
#nvdispmodel = len(J)
Expand All @@ -358,18 +348,18 @@ def main(args):
# normflux[:, imodel] = fluxnolines[I, J[imodel]] / smooth

vdispflux = []
for sigma in vdisp / pixkms:
for sigma in vdisp / PIXKMS_BLU:
vdispflux.append(gaussian_filter1d(fluxnolines[I, :], sigma=sigma, axis=0))
vdispflux = np.stack(vdispflux, axis=-1) # [npix,nvdispmodel,nvdisp]

#vdispflux = []
#for sigma in vdisp / pixkms:
#for sigma in vdisp / PIXKMS_BLU:
# vdispflux.append(gaussian_filter1d(fluxnolines[I, :][:, J], sigma=sigma, axis=0))
# #vdispflux.append(gaussian_filter1d(normflux, sigma=sigma, axis=0))
#vdispflux = np.stack(vdispflux, axis=-1) # [npix,nvdispmodel,nvdisp]

#vdispflux = []
#for sigma in vdisp / pixkms:
#for sigma in vdisp / PIXKMS_BLU:
# vdispflux.append(gaussian_filter1d(fluxnolines, sigma=sigma, axis=0))
#vdispflux = np.stack(vdispflux, axis=-1) # [npix,nvdispmodel,nvdisp]

Expand All @@ -381,7 +371,9 @@ def main(args):
#pdb.set_trace()

# Write out.
outdir = os.path.join(os.environ.get('DESI_ROOT'), 'science', 'gqp', 'templates', 'fastspecfit')
outdir = os.path.join(os.environ.get('DESI_ROOT'), 'science', 'gqp', 'templates', 'fastspecfit', version)
if not os.path.isdir(outdir):
os.makedirs(outdir, exist_ok=True)
outfile = os.path.join(outdir, 'ftemplates-{}-{}.fits'.format(args.imf, version))

hduflux1 = fits.PrimaryHDU(flux)
Expand All @@ -402,21 +394,21 @@ def main(args):
hduflux3.header['VDISPRES'] = (dvdisp, 'velocity dispersion spacing [km/s]')
hduflux3.header['BUNIT'] = 'erg/(s cm2 Angstrom)'

isplit = np.argmin(np.abs(wave-wavesplit)) + 1
isplit = np.argmin(np.abs(wave-PIXKMS_WAVESPLIT)) + 1

hduwave1 = fits.ImageHDU(wave)
hduwave1.header['EXTNAME'] = 'WAVE'
hduwave1.header['BUNIT'] = 'Angstrom'
hduwave1.header['AIRORVAC'] = ('vac', 'vacuum wavelengths')
hduwave1.header['PIXSZBLU'] = (pixkms, 'pixel size blueward of PIXSZSPT [km/s]')
hduwave1.header['PIXSZRED'] = (irfactor*pixkms, 'pixel size redward of PIXSZSPT [km/s]')
hduwave1.header['PIXSZBLU'] = (PIXKMS_BLU, 'pixel size blueward of PIXSZSPT [km/s]')
hduwave1.header['PIXSZRED'] = (PIXKMS_RED, 'pixel size redward of PIXSZSPT [km/s]')
hduwave1.header['PIXSZSPT'] = (wave[isplit], 'wavelength where pixel size changes [Angstrom]')

hduwave2 = fits.ImageHDU(vdispwave)
hduwave2.header['EXTNAME'] = 'VDISPWAVE'
hduwave2.header['BUNIT'] = 'Angstrom'
hduwave2.header['AIRORVAC'] = ('vac', 'vacuum wavelengths')
hduwave2.header['PIXSZ'] = (pixkms, 'pixel size [km/s]')
hduwave2.header['PIXSZ'] = (PIXKMS_BLU, 'pixel size [km/s]')

hdutable = fits.convenience.table_to_hdu(meta)
hdutable.header['EXTNAME'] = 'METADATA'
Expand Down
5 changes: 5 additions & 0 deletions bin/get-cutouts
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,11 @@ def main():
except ImportError:
comm = None

# https://docs.nersc.gov/development/languages/python/parallel-python/#use-the-spawn-start-method
if args.mp > 1 and 'NERSC_HOST' in os.environ:
import multiprocessing
multiprocessing.set_start_method('spawn')

if args.coadd_type == 'healpix':
args.survey = args.survey.split(',')
args.program = args.program.split(',')
Expand Down
10 changes: 9 additions & 1 deletion doc/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@
Change Log
==========

2.3.1 (not released yet)
2.4.1 (not released yet)
------------------------

*

2.4.0 (2023-08-18)
------------------

* Bug fixes and miscellaneous feature requests for next VACs, including modified
SPS templates and a user-friendly refactor of the K-correction code [`PR #148`_].

.. _`PR #148`: https://github.com/desihub/fastspecfit/pull/148

2.3.0 (2023-08-07)
------------------

Expand Down
34 changes: 34 additions & 0 deletions doc/fastspec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,40 @@ Name Type Units Descript
CIV_1549_EW_LIMIT float32 Angstrom One-sigma upper limit on the emission line equivalent width.
CIV_1549_CHI2 float32 Chi-squared of the line-fit.
CIV_1549_NPIX int32 Number of pixels attributed to the emission line.
HEII_1640_MODELAMP float32 1e-17 erg / (Angstrom cm2 s) Model emission line amplitude.
HEII_1640_AMP float32 1e-17 erg / (Angstrom cm2 s) Emission line amplitude.
HEII_1640_AMP_IVAR float32 1e+34 Angstrom2 cm4 s2 / erg2 Inverse variance of line-amplitude.
HEII_1640_FLUX float32 1e-17 erg / (cm2 s) Gaussian-integrated emission-line flux.
HEII_1640_FLUX_IVAR float32 1e+34 cm4 s2 / erg2 Inverse variance of integrated flux.
HEII_1640_BOXFLUX float32 1e-17 erg / (cm2 s) Boxcar-integrated emission-line flux.
HEII_1640_BOXFLUX_IVAR float32 1e+34 cm4 s2 / erg2 Inverse variance of boxcar-integrated flux.
HEII_1640_VSHIFT float32 km / s Velocity shift relative to Z.
HEII_1640_SIGMA float32 km / s Gaussian emission-line width.
HEII_1640_CONT float32 1e-17 erg / (Angstrom cm2 s) Continuum flux at line center.
HEII_1640_CONT_IVAR float32 1e+34 Angstrom2 cm4 s2 / erg2 Inverse variance of continuum flux.
HEII_1640_EW float32 Angstrom Rest-frame emission-line equivalent width.
HEII_1640_EW_IVAR float32 1 / Angstrom2 Inverse variance of equivalent width.
HEII_1640_FLUX_LIMIT float32 erg / (cm2 s) One-sigma upper limit on the emission line flux.
HEII_1640_EW_LIMIT float32 Angstrom One-sigma upper limit on the emission line equivalent width.
HEII_1640_CHI2 float32 Chi-squared of the line-fit.
HEII_1640_NPIX int32 Number of pixels attributed to the emission line.
AlIII_1857_MODELAMP float32 1e-17 erg / (Angstrom cm2 s) Model emission line amplitude.
AlIII_1857_AMP float32 1e-17 erg / (Angstrom cm2 s) Emission line amplitude.
AlIII_1857_AMP_IVAR float32 1e+34 Angstrom2 cm4 s2 / erg2 Inverse variance of line-amplitude.
AlIII_1857_FLUX float32 1e-17 erg / (cm2 s) Gaussian-integrated emission-line flux.
AlIII_1857_FLUX_IVAR float32 1e+34 cm4 s2 / erg2 Inverse variance of integrated flux.
AlIII_1857_BOXFLUX float32 1e-17 erg / (cm2 s) Boxcar-integrated emission-line flux.
AlIII_1857_BOXFLUX_IVAR float32 1e+34 cm4 s2 / erg2 Inverse variance of boxcar-integrated flux.
AlIII_1857_VSHIFT float32 km / s Velocity shift relative to Z.
AlIII_1857_SIGMA float32 km / s Gaussian emission-line width.
AlIII_1857_CONT float32 1e-17 erg / (Angstrom cm2 s) Continuum flux at line center.
AlIII_1857_CONT_IVAR float32 1e+34 Angstrom2 cm4 s2 / erg2 Inverse variance of continuum flux.
AlIII_1857_EW float32 Angstrom Rest-frame emission-line equivalent width.
AlIII_1857_EW_IVAR float32 1 / Angstrom2 Inverse variance of equivalent width.
AlIII_1857_FLUX_LIMIT float32 erg / (cm2 s) One-sigma upper limit on the emission line flux.
AlIII_1857_EW_LIMIT float32 Angstrom One-sigma upper limit on the emission line equivalent width.
AlIII_1857_CHI2 float32 Chi-squared of the line-fit.
AlIII_1857_NPIX int32 Number of pixels attributed to the emission line.
SILIII_1892_MODELAMP float32 1e-17 erg / (Angstrom cm2 s) Model emission line amplitude.
SILIII_1892_AMP float32 1e-17 erg / (Angstrom cm2 s) Emission line amplitude.
SILIII_1892_AMP_IVAR float32 1e+34 Angstrom2 cm4 s2 / erg2 Inverse variance of line-amplitude.
Expand Down
Loading
Loading