SPEC1D¶
- class spec1d.AGN_BLR(config, hbeta_flux=100.0, hbeta_fwhm=2000.0, ebv=0.1, vel=0.0, lam_range=[500, 15000])¶
Generate emission line spectra of AGN broad-line region based on empirical Balmer line ratios.
The model constructs a set of broad Balmer emission lines (from Hε to Hα) with fixed ratios and user-specified Hβ line flux and FWHM. Dust extinction and redshift are applied afterward.
- Parameters
config (object) – Configuration object defining the target wavelength grid (e.g., output wave sampling).
hbeta_flux (float, optional) – Observed flux of the Hβ broad component in units of 1e-17 erg/s/cm² (default: 100.0).
hbeta_fwhm (float, optional) – Full width at half maximum (FWHM) of the broad lines in km/s (default: 2000.0). Must be positive; if invalid, warning is printed and reset to 2000.
ebv (float, optional) – Dust extinction E(B–V) applied using the Calzetti law (default: 0.1). If negative, will be reset to 0 with warning.
vel (float, optional) – Line-of-sight velocity in km/s for redshifting the broad lines (default: 0.0).
lam_range (list, optional) – Wavelength range [min, max] in Å for constructing the rest-frame line spectrum (default: [500, 15000]).
- class spec1d.AGN_FeII(config, hbeta_broad=100.0, r4570=0.4, ebv=0.1, vel=100.0)¶
Generate Fe II pseudo-continuum emission for AGN using empirical template.
The Fe II emission is scaled using the observed flux of broad Hβ and the empirical flux ratio between the Fe4570 blend and Hβ (commonly denoted R4570). The flux is then corrected for dust extinction and redshifted to the observed frame.
- Parameters
config (object) – Configuration object defining the output wavelength grid.
hbeta_broad (float, optional) – Observed flux of the broad Hβ line in units of 1e-17 erg/s/cm² (default: 100.0).
r4570 (float, optional) – Flux ratio of Fe4570 blend (4434–4684 Å) to broad Hβ (default: 0.4).
ebv (float, optional) – Dust extinction E(B–V), applied using the Calzetti law (default: 0.1). If negative, will be reset to 0 with warning.
vel (float, optional) – Line-of-sight velocity in km/s for redshifting the Fe II emission (default: 100.0).
- class spec1d.AGN_NLR(config, temp, halpha=100.0, logz=0.0, vel=100.0, vdisp=120.0, ebv=0.1)¶
Generate emission line spectra of AGN narrow-line region using template flux ratios.
The model uses a specified Hα flux (in units of 1e-17 erg/s/cm²) to scale the emission lines. It applies optional dust extinction, velocity broadening, and line-of-sight redshift.
- Parameters
config (object) – Configuration object that defines the target output wavelength grid.
temp (object) – Emission line template object for AGN narrow-line regions.
halpha (float, optional) – Observed flux of the Hα line in units of 1e-17 erg/s/cm² (default: 100.0).
logz (float, optional) – Gas-phase metallicity (in log Z/Z☉), used to select emission line ratios (default: 0.0). Values outside the range [-2.3, 0.54] will be clipped and a warning will be printed.
vel (float, optional) – Line-of-sight velocity in km/s for redshifting the emission lines (default: 100.0).
vdisp (float, optional) – Velocity dispersion in km/s, used to apply Gaussian broadening (default: 120.0).
ebv (float, optional) – Dust extinction E(B–V), applied using the Calzetti law (default: 0.1).
- class spec1d.AGN_PhysicalModel(config, nlr_template, bhmass, edd_ratio, z, logz=0.0, vpec=0.0, ebv=0.1, agn_type=1)¶
- Generate a physical AGN spectrum including:
Power-law continuum
Broad emission lines (BLR)
Narrow emission lines (NLR)
FeII pseudo-continuum
- Parameters
config (object) – Configuration object defining the target output wavelength grid.
nlr_template (object) – Emission line template for narrow-line regions (e.g. AGN_NLR or HII).
bhmass (float) – Black hole mass in solar masses. Must be > 0.
edd_ratio (float) – Eddington ratio (L_bol / L_edd). Must be > 0.
z (float) – Redshift used for luminosity distance.
logz (float, optional) – Gas-phase metallicity (log Z/Z☉) for the NLR (default: 0.0).
vpec (float, optional) – Peculiar velocity in km/s for redshift shift (default: 0).
ebv (float, optional) – Dust extinction E(B–V) applied to all components (default: 0.1).
agn_type (int, optional) – AGN type indicator (1=type 1, 2=type 2), controls whether BLR/FeII/powerlaw are included (default: 1).
- class spec1d.AGN_Powerlaw(config, m5100=18.0, alpha=-1.5, vel=100.0, ebv=0.1)¶
Generate a power-law continuum spectrum for AGN.
- The AGN continuum is modeled as a simple power-law:
F(λ) ∝ λ^α
The flux is normalized using the AB magnitude at 5100 Å (m5100), then corrected for dust extinction and redshift.
- Parameters
config (object) – Configuration object defining the output wavelength grid.
m5100 (float, optional) – AB magnitude at rest-frame 5100 Å used for flux normalization (default: 18.0).
alpha (float, optional) – Power-law index such that F(λ) ∝ λ^α (default: -1.5).
vel (float, optional) – Line-of-sight velocity in km/s for redshifting the spectrum (default: 100.0).
ebv (float, optional) – Dust extinction E(B–V), applied using the Calzetti law (default: 0.1). If negative, it will be reset to 0 with warning.
Output –
------ –
self.wave (ndarray) – Observed wavelength grid (same as config.wave).
self.flux (ndarray) – Flux density in units of erg/s/cm²/Å at each wavelength.
- spec1d.Calzetti_Law(wave, Rv=4.05)¶
Dust Extinction Curve of Calzetti et al. (2000)
- Parameters
wave (float, or float array) – Wavelength
Rv (float, optional) – Extinction coefficient, by default 4.05
- Returns
Extinction value corresponding to the input wavelength
- Return type
float
- class spec1d.EmissionLineTemplate(config, lam_range=[500, 15000], dlam=0.1, model='hii')¶
Template for the emission lines
- Parameters
config (class) – The class of configuration.
lam_range (list, optional) – Wavelength range, by default [500, 15000]
dlam (float, optional) – Wavelength width per pixel, by default 0.1A
model (str, optional) – Emission line model, including ‘hii’ for HII region and ‘nlr’ for narrow line region of AGN, by default ‘hii’
- class spec1d.HII_Region(config, temp, halpha=100.0, sfr=None, z=None, vpec=None, logz=0.0, vel=100.0, vdisp=120.0, ebv=0.1)¶
Generate emission line spectra of a star-forming HII region using pre-defined emission line templates.
Two working modes are supported for flux calibration:
1. Hα-calibrated mode: If halpha is provided (default), the total flux of Hα (in units of 1e-17 erg/s/cm²) is used to scale the emission lines. In this case, the output spectrum is normalized such that the integrated Hα line matches the given value.
2. SFR-calibrated mode: If halpha is set to None and both sfr, z, and vpec are provided, the Hα luminosity is estimated from the SFR using the Kennicutt (1998) relation:
L(Hα) [erg/s] = 7.9 × 10⁴¹ × SFR [M☉/yr],
which is then converted to observed flux via the luminosity distance (based on z), and corrected for cosmic dimming. This mode allows physically motivated scaling based on star formation activity.
Input flexibility:
If halpha is not None, the model uses Hα-calibration mode and ignores sfr, z, and vpec.
If halpha is None, the model enters SFR-calibrated mode and requires all of: sfr, z, and vpec.
logz determines gas-phase metallicity and selects the closest template in the pre-computed grid.
The output flux includes optional dust extinction, velocity broadening, and redshift correction.
- Parameters
config (object) – Configuration object that defines the target output wavelength grid.
temp (object) – Emission line template object precomputed for HII or AGN narrow-line regions.
halpha (float or None, optional) – Observed flux of the Hα line in units of 1e-17 erg/s/cm² (default: 100.0). If None, enter SFR-calibrated mode.
sfr (float, optional) – Star formation rate in M☉/yr, used only when halpha is None.
z (float, optional) – Cosmological redshift, used for luminosity distance and cosmic dimming in SFR-calibrated mode.
vpec (float, optional) – Peculiar velocity in km/s, used together with z to compute line-of-sight redshift.
logz (float, optional) – Gas-phase metallicity (in log Z/Z☉), required to select the emission line ratios from the template (default: 0.0). Must be within [-2.0, 0.5], otherwise a ValueError is raised.
vel (float, optional) – Line-of-sight velocity in km/s for redshifting the emission lines (default: 100.0). Only used if vpec is not provided.
vdisp (float, optional) – Velocity dispersion in km/s, used to apply Gaussian broadening to emission lines (default: 120.0).
ebv (float, optional) – Dust extinction E(B–V), applied using the Calzetti law (default: 0.1).
- spec1d.SingleEmissinoLine(wave, line_wave, FWHM_inst)¶
Profile of single emission line (Gaussian profile)
- Parameters
wave (float array) – Wavelength of spectrum
line_wave (float) – Wavelength of emission line at the line center
FWHM_inst (float) – Intrinsic broadening of emission line, units: A
- Returns
Spectra of single emission line
- Return type
float array
- class spec1d.SingleStar(config, template, mag=15.0, teff=10000.0, logg=4.5, feh=0.0, vel=100.0, ebv=0.0)¶
Generate a single stellar spectrum using input stellar atmospheric parameters.
This class interpolates the closest-matching stellar template from a grid defined by effective temperature (Teff), surface gravity (logg), and metallicity ([Fe/H]), and returns a redshifted, extincted, and magnitude-calibrated spectrum.
- Parameters
config (object) – Configuration object describing the wavelength grid and filter system.
template (object) – Template object from SingleStarTemplate class, containing wavelength, flux grid, and parameter arrays.
mag (float, optional) – Apparent SDSS r-band magnitude for flux calibration (default is 15.0). Range: 8–26.
teff (float, optional) – Effective temperature in Kelvin. Will be clipped to template bounds if outside range.
logg (float, optional) – Surface gravity in log10(cm/s^2). Will be clipped to template bounds if outside range.
feh (float, optional) – Metallicity [Fe/H] in dex. Will be clipped to template bounds if outside range.
vel (float, optional) – Line-of-sight velocity in km/s (default is 100). Used for Doppler shifting.
ebv (float, optional) – Dust extinction E(B-V). Negative values are reset to 0. Default is 0.0.
- class spec1d.SingleStarTemplate(config, velscale=20, template='Munari2005')¶
Class for handling single stellar templates from different libraries.
Supports observed XSL templates and theoretical Munari+2005 templates.
- Parameters
config (object) – Configuration object containing instrument settings.
velscale (float, optional) – Velocity scale in km/s per pixel. Default is 20.
template (str, optional) – Template library to use: ‘Munari2005’ (default) or ‘XSL’. Case-insensitive.
- class spec1d.StellarContinuum(config, template, mag=15, sfh=1.0, ceh=-0.3, vel=100, vdisp=100.0, ebv=0.1, z=None, vpec=None)¶
Generate galaxy stellar continuum spectra using input Star Formation History (SFH) and Chemical Enrichment History (CEH), based on a grid of pre-computed Simple Stellar Population (SSP) templates.
Two working modes are supported:
1. Magnitude-calibrated mode: If mag is provided, the output spectrum is flux-calibrated using the given SDSS r-band magnitude. In this case, the input sfh only determines the shape of the star formation history (normalized SFH profile), and does not affect the flux amplitude.
2. Physically-calibrated mode: If mag is None, the spectrum is calibrated based on the physical star formation rate (SFR) in units of M☉/yr. The total formed stellar mass is integrated from the input SFH and used to scale the template. This mode requires both z (cosmological redshift, for cosmic dimming) and vpec (peculiar velocity), which together define the line-of-sight redshift.
Input flexibility:
Both sfh and ceh can be scalars or (N, 2) arrays.
Scalar inputs indicate a single SSP population and are only allowed in magnitude-calibrated mode.
In physically-calibrated mode, both sfh and ceh must be arrays, and the SFR values must be in physical units (M☉/yr).
- Parameters
config (object) – Configuration object describing the format of the output spectrum (e.g., wavelength grid).
template (object) – Template object containing a grid of SSP spectra (wavelength × age × metallicity).
mag (float, optional) – Observed SDSS r-band magnitude for flux calibration (default 15.0). Recommended range: 8–26. If None, the model enters physically-calibrated mode.
sfh (array-like or float, optional) – Star Formation History. Either a scalar age (Gyr), or an (N,2) array of [age (Gyr), SFR (M☉/yr)]. In mag-mode, only the normalized SFH shape is used. In physical mode, the total SFR determines luminosity.
ceh (array-like or float, optional) – Chemical Enrichment History. Either a scalar [Fe/H] (dex), or an (N,2) array of [age (Gyr), [Fe/H] (dex)].
vel (float, optional) – Line-of-sight velocity in km/s, used to redshift the spectrum (default 100). Required in mag-mode.
vdisp (float, optional) – Stellar velocity dispersion in km/s, used to apply spectral broadening (default 100).
ebv (float, optional) – Dust extinction E(B–V), applied using the Calzetti law (default 0.1).
z (float, optional) – Cosmological redshift. Required in physically-calibrated mode (used for luminosity distance and cosmic dimming).
vpec (float, optional) – Galaxy peculiar velocity in km/s. Required in physically-calibrated mode.
- class spec1d.StellarContinuumTemplate(config, velscale=50, pathname='GEHONG_PATH/data/EMILES/Ech*_baseFe.fits', normalize=False)¶
Class of single stellar population template.
- Parameters
config (class) – Class of configuration
velscale (array) – velocity scale in km/s per pixels, by default 50.0km/s
pathname (string, optional) – path with wildcards returning the list files to use, by default data_path+’/data/EMILES/Ech*_baseFe.fits’
normalize (bool, optional) – Set to True to normalize each template to mean=1, by default False
- spec1d.age_metal(filename)¶
Extract the age and metallicity from the name of a file of the MILES library of Single Stellar Population models.
- Parameters
filename (string) – Full path of template files
- Returns
age (float) – Age of SSP (Gyr)
FeH (float) – Metallicity of SSP
- Raises
ValueError – This is not a standard MILES filename
- spec1d.calibrate(wave, flux, mag, filtername='SLOAN_SDSS.r')¶
Flux calibration of spectrum
- Parameters
wave (float array) – Wavelength of input spectrum
flux (float array) – Flux of input spectrum
mag (float) – Magnitude used for flux calibration
filtername (str, optional) – Filter band name, by default ‘SLOAN_SDSS.r’
- Returns
Spectrum after flux calibration
- Return type
float array
- spec1d.gaussian_filter1d(spec, sig)¶
One-dimensional Gaussian convolution
- Parameters
spec (float array) – vector with the spectrum to convolve
sig (float) – vector of sigma values (in pixels) for every pixel
- Returns
Spectrum after convolution
- Return type
float array
- spec1d.log_rebin(lamRange, spec, oversample=False, velscale=None, flux=False)¶
Logarithmically rebin a spectrum, while rigorously conserving the flux. This function is taken from ppxf.
- Parameters
lamRange (array) – Two elements vector containing the central wavelength of the first and last pixels in the spectrum
spec (array) – Input spectrum
oversample (bool, optional) – Oversampling can be done, not to loose spectral resolution, especally for extended wavelength ranges and to avoid aliasing, by default False
velscale (float, optional) – velocity scale in km/s per pixels, by default None
flux (bool, optional) – True to preserve total flux, by default False
- Returns
specNew (array) – Output spectrum
logLam (array) – Wavelength array in logarithm
velscale (array) – velocity scale in km/s per pixels
- spec1d.readcol(filename, **kwargs)¶
readcol, taken from ppxf.
- Parameters
filename (string) – The name of input ascii file
- Returns
The value of each columns
- Return type
float
- spec1d.reddening(wave, flux, ebv=0.0, law='calzetti', Rv=4.05)¶
Reddening an input spectra through a given reddening curve.
- Parameters
wave (float array) – Wavelength of input spectra
flux (float array) – Flux of input spectra
ebv (float, optional) – E(B-V) value, by default 0
law (str, optional) – Extinction curve, by default ‘calzetti’
Rv (float, optional) – Extinction coefficient, by default 4.05
- Returns
Flux of spectra after reddening
- Return type
float array