pypeit.core.flux_calib module
Module for fluxing routines
- pypeit.core.flux_calib.Flam_to_Nlam(wave, zeropoint, zp_min=5.0, zp_max=30.0)[source]
The factor that when multiplied into F_lam converts to N_lam, i.e. 1/S_lam where S_lam equiv F_lam/N_lam
- Parameters:
wave (numpy.ndarray) – Wavelength array, float, shape (nspec,)
zeropoint (numpy.ndarray) – zeropoint array, float, shape (nspec,)
- Returns:
factor – Factor that when multiplied into F_lam converts to N_lam, i.e. 1/S_lam
- Return type:
- pypeit.core.flux_calib.Nlam_to_Flam(wave, zeropoint, zp_min=5.0, zp_max=30.0)[source]
The factor that when multiplied into N_lam converts to F_lam, i.e. S_lam where S_lam equiv F_lam/N_lam
- Parameters:
wave (numpy.ndarray) – Wavelength vector for zeropoint
zeropoint (numpy.ndarray) – zeropoint
zp_min (float, optional) – Minimum allowed value of the ZP. For smaller values the S_lam factor is set to zero
zp_max (float, optional) – Maximum allowed value of the ZP. For larger values the S_lam factor is set to zero
- Returns:
factor – S_lam factor
- Return type:
- pypeit.core.flux_calib.compute_zeropoint(wave, N_lam, N_lam_gpm, flam_std_star, tellmodel=None)[source]
Routine to compute the zeropoint and zeropoint_gpm from the N_lam (counts/s/A) of a standard star
- Parameters:
wave (numpy.ndarray) – Wavelength array, float, shape (nspec,)
N_lam (numpy.ndarray) – N_lam spectrum of standard star, float, shape (nspec,)
N_lam_gpm (numpy.ndarray) – N_lam mask, good pixel mask, boolean, shape (nspec,)
flam_std_star (numpy.ndarray) – True standard star spectrum in units of PYPEIT_FLUX_SCALE erg/s/cm^2/Angstrom
tellmodel (numpy.ndarray) – Telluric absorption model, optional, shape (nspec,)
- Returns:
zeropoint (numpy.ndarray) – Spectroscopic zeropoint, float, shape (nspec,)
zeropoint_gpm (numpy.ndarray) – Zeropoint good pixel mask, bool, shape (nspec,)
- pypeit.core.flux_calib.counts2Nlam(wave, counts, counts_ivar, counts_mask, exptime, airmass, atmext)[source]
Convert counts to counts/s/Angstrom Used for flux calibration and to apply extinction correction
- Parameters:
wave (numpy.ndarray) – Wavelength of the star. Shape (nspec,)
counts (numpy.ndarray) – Flux (in counts) of the star. Shape (nspec,)
counts_ivar (numpy.ndarray) – Inverse variance of the star counts. Shape (nspec,)
counts_mask (numpy.ndarray) – Good pixel mask for the counts.
exptime (float) – Exposure time in seconds
airmass (float) – Airmass
atmext (
AtmosphericExtinction) – Class that provides the interface to the atmospheric extinction data.
- Returns:
- Three items:
Nlam_star (numpy.ndarray) counts/second/Angstrom
Nlam_ivar_star (numpy.ndarray) inverse variance of Nlam_star
gpm_star (numpy.ndarray) good pixel mask for Nlam_star
- Return type:
- pypeit.core.flux_calib.eval_zeropoint(theta, func, wave, wave_min, wave_max, log10_blaze_func_per_ang=None)[source]
Evaluate the zeropoint model.
- Parameters:
theta (numpy.ndarray) – Parameter vector for the zeropoint model
func (callable) – Function for the zeropoint model from the set of available functions in
evaluate_fit().wave (numpy.ndarray, shape = (nspec,)) – Wavelength vector for zeropoint.
wave_min (float) – Minimum wavelength for the zeropoint fit to be passed as an argument to
evaluate_fit()wave_max (float) – Maximum wavelength for the zeropoint fit to be passed as an argument to
evaluate_fit()log10_blaze_func_per_ang (numpy.ndarray, optional, shape = (nspec,)) – Log10 blaze function per angstrom. This option is used if the zeropoint model is relative to the non-parametric blaze function determined from flats. The blaze function is defined on the wavelength grid wave.
- Returns:
zeropoint – Zeropoint evaluated on the wavelength grid wave.
- Return type:
numpy.ndarray, shape = (nspec,)
- pypeit.core.flux_calib.find_standard(specobj_list)[source]
Routine to identify the standard star given a list of spectra
Take the median boxcar and then take the max flux object (in BOX_COUNTS) as the standard
- pypeit.core.flux_calib.fit_zeropoint(wave, Nlam_star, Nlam_ivar_star, gpm_star, std_spec, mask_hydrogen_lines=True, mask_helium_lines=False, polyorder=4, hydrogen_mask_wid=10.0, nresln=20.0, resolution=3000.0, trans_thresh=0.9, polycorrect=True, polyfunc=False, debug=False)[source]
Function to generate the sensitivity function. This function fits a bspline to the 2.5*log10(flux_std/flux_counts). The break points spacing, which determines the scale of variation of the sensitivity function is determined by the nresln parameter.
- Parameters:
wave (numpy.ndarray) – Wavelength of the star. Shape (nspec,)
Nlam_star (numpy.ndarray) – counts/second/Angstrom
Nlam_ivar_star (numpy.ndarray) – Inverse variance of Nlam_star
gpm_star (numpy.ndarray) – Good pixel mask for Nlam_star
std_spec (
Spectrum) – Spectrum of the flux-calibration standard.mask_hydrogen_lines (bool, optional) – If True, mask stellar hydrogen absorption lines before fitting sensitivity function. Default = True
mask_helium_lines (bool, optional) – If True, mask stellar helium absorption lines before fitting sensitivity function. Default = False
hydrogen_mask_wid (float, optional) – Parameter describing the width of the mask for or stellar absorption lines (i.e.,
mask_hydrogen_lines=True) in Angstroms. A region equal tohydrogen_mask_widon either side of the line center is masked. Default = 10Apolycorrect (bool, optional) – Whether you want to interpolate the zeropoint with polynomial in the stellar absortion line regions before fitting with the bspline
nresln (float, optional) – Parameter governing the spacing of the bspline breakpoints. default = 20.0
resolution (float, optional) – Expected resolution of the standard star spectrum. This should probably be determined from the grating, but is currently hard wired. default=3000.0
trans_thresh (float, optional) – Parameter for selecting telluric regions which are masked. Locations below this transmission value are masked. If you have significant telluric absorption you should be using telluric.sensnfunc_telluric. default = 0.9
polyfunc (bool, optional) – If True, the zeropoint was a polynomial and not a bspline
- Returns:
zeropoint_data (numpy.ndarray) – Sensitivity function with same shape as wave (nspec,)
zeropoint_data_gpm (numpy.ndarray) – Good pixel mask for sensitivity function with same shape as wave (nspec,)
zeropoint_fit (numpy.ndarray) – Fitted sensitivity function with same shape as wave (nspec,)
zeropoint_fit_gpm (numpy.ndarray) – Good pixel mask for fitted sensitivity function with same shape as wave (nspec,)
- Return type:
- pypeit.core.flux_calib.get_mask(wave_star, flux_star, ivar_star, mask_star, mask_hydrogen_lines=True, mask_helium_lines=False, mask_telluric=True, hydrogen_mask_wid=10.0, trans_thresh=0.9)[source]
Generate a set of masks from your observed standard spectrum. e.g. Balmer absorption
- Parameters:
wave_star (numpy.ndarray) – wavelength array of your spectrum
flux_star (numpy.ndarray) – flux array of your spectrum
ivar_star (numpy.ndarray) – ivar array of your spectrum
mask_star (bool, optional) – whether you need to mask Hydrogen recombination line region. If False, the returned msk_star are all good.
mask_hydrogen_lines (bool, optional) – whether you need to mask hydrogen absorption lines, mask width set by
hydrogen_mask_widmask_helium_lines (bool, optional) – whether you need to mask hydrogen absorption lines, mask width set to \(0.5 \times\)
hydrogen_mask_widmask_telluric (bool, optional) – whether you need to mask telluric region. If False, the returned msk_tell are all good.
hydrogen_mask_wid (float, optional) – in units of angstrom Mask parameter for hydrogen recombination absorption lines. A region equal to
hydrogen_mask_widon either side of the line center is masked.trans_thresh (float, optional) – parameter for selecting telluric regions.
- Returns:
gpm_star (bool numpy.ndarray) – mask for good pixels (True = good pixel).
mask_recomb (bool numpy.ndarray) – mask for recombination lines in star spectrum.
mask_tell (bool numpy.ndarray) – mask for telluric regions.
- pypeit.core.flux_calib.get_sensfunc_factor(wave, wave_zp, zeropoint, exptime, tellmodel=None, delta_wave=None, atmext=None, airmass=None, extrap_sens=False)[source]
Get the final sensitivity function factor that will be multiplied into a spectrum in units of counts to flux calibrate it. This code interpolates the sensitivity function and can also multiply in extinction and telluric corrections.
FLAM, FLAM_SIG, and FLAM_IVAR are generated
- Parameters:
wave (float numpy.ndarray) – shape = (nspec,) Wavelength vector for the spectrum to be flux calibrated
wave_zp (float numpy.ndarray) – Zeropoint wavelength vector shape = (nsens,)
zeropoint (float numpy.ndarray) – shape = (nsens,) Zeropoint, i.e. sensitivity function
exptime (float) – Exposure time in seconds
tellmodel (float numpy.ndarray, optional) – Apply telluric correction if it is passed it (shape = (nspec,)). Note this is only used to generate the std fluxed QA plot. It should be None otherwise. To telluric correct the data, use the telluric correct method.
delta_wave (float, numpy.ndarray, optional) – The wavelength sampling of the spectrum to be flux calibrated.
atmext (
AtmosphericExtinction, optional) – Class that provides the interface to the atmospheric extinction data.airmass (float, optional) – Airmass used if extinct_correct=True. This is required if extinct_correct=True
extrap_sens (bool, optional) – Extrapolate the sensitivity function (instead of crashing out)
- Returns:
sensfunc_factor – This quantity is defined to be sensfunc_interp/exptime/delta_wave. shape = (nspec,)
- Return type:
- pypeit.core.flux_calib.load_filter_file(filter)[source]
Load a system response curve for a given filter. All supported filters can be found at pypeit.data.filters
- Parameters:
filter (str) – Name of filter
- Returns:
wave (numpy.ndarray) – wavelength in units of Angstrom
instr (numpy.ndarray) – filter throughput
- pypeit.core.flux_calib.mask_stellar_helium(wave_star, mask_width=5.0, mask_star=None)[source]
Routine to mask stellar helium recombination lines
Note
This function is pulled out separate from
get_mask()because it is used in thetelluricmodule, independent of the remainder of the functionality inget_mask().- Parameters:
wave_star (numpy.ndarray) – Wavelength of the stellar spectrum shape (nspec,) or (nspec, nimgs)
mask_width (float, optional) – width to mask on either side of each line center in Angstroms
mask_star (numpy.ndarray, optional) – Incoming star mask to which to add the ionized helium lines
- Returns:
boolean mask. Same shape as
wave_star, True=Good (i.e. does not hit a stellar absorption line).- Return type:
- pypeit.core.flux_calib.mask_stellar_hydrogen(wave_star, mask_width=10.0, mask_star=None)[source]
Routine to mask stellar hydrogen recombination lines
Note
This function is pulled out separate from
get_mask()because it is used in thetelluricmodule, independent of the remainder of the functionality inget_mask().- Parameters:
wave_star (numpy.ndarray) – Wavelength of the stellar spectrum shape (nspec,) or (nspec, nimgs)
mask_width (float, optional) – width to mask on either side of each line center in Angstroms
mask_star (numpy.ndarray, optional) – Incoming star mask to which to add the hydrogen lines
- Returns:
boolean mask. Same shape as
wave_star, True=Good (i.e. does not hit a stellar absorption line).- Return type:
- pypeit.core.flux_calib.scale_in_filter(wave, flux, gpm, scale_dict)[source]
Scale spectra to input magnitude in a given filter
- Parameters:
wave (numpy.ndarray) – spectral wavelength array
flux (numpy.ndarray) – flux density array
gpm (boolean numpy.ndarray) – Good pixel mask array
scale_dict (
Coadd1DPar) – Object with filter and magnitude data.
- Returns:
scale – scale value for the flux, i.e.
newflux = flux * scale- Return type:
- pypeit.core.flux_calib.sensfunc(wave, counts, counts_ivar, counts_mask, exptime, airmass, std_spec, atmext, ech_orders=None, mask_hydrogen_lines=True, mask_helium_lines=False, polyorder=4, hydrogen_mask_wid=10.0, nresln=20.0, resolution=3000.0, trans_thresh=0.9, polycorrect=True, polyfunc=False, debug=False)[source]
Function to generate the sensitivity function. This function fits a bspline to the 2.5*log10(flux_std/flux_counts). The break points spacing, which determines the scale of variation of the sensitivity function is determined by the nresln parameter. This code can work in different regimes, but NOTE THAT TELLURIC MODE IS DEPRECATED, use telluric.sensfunc_telluric instead
- Parameters:
wave (numpy.ndarray) – Wavelength of the star. Shape (nspec,) or (nspec, norders)
counts (numpy.ndarray) – Flux (in counts) of the star. Shape (nspec,) or (nspec, norders)
counts_ivar (numpy.ndarray) – Inverse variance of the star counts. Shape (nspec,) or (nspec, norders)
counts_mask (numpy.ndarray) – Good pixel mask for the counts. Shape (nspec,) or (nspec, norders)
exptime (float) – Exposure time in seconds
airmass (float) – Airmass
std_spec (
Spectrum) – Spectrum of the flux-calibration standard.atmext (
AtmosphericExtinction) – Class that provides the interface to the atmospheric extinction data.ech_orders (int numpy.ndarray) – If passed the echelle orders will be added to the meta_table. ech_orders must be a numpy array of integers with the shape (norders,) giving the order numbers
mask_hydrogen_lines (bool) – If True, mask stellar hydrogen absorption lines before fitting sensitivity function. Default = True
mask_helium_lines (bool) – If True, mask stellar helium absorption lines before fitting sensitivity function. Default = False
balm_mask_wid (float) – Parameter describing the width of the mask for or stellar absorption lines (i.e. mask_hydrogen_lines=True). A region equal to balm_mask_wid*resln is masked where resln is the estimate for the spectral resolution in pixels per resolution element.
polycorrect (bool) – Whether you want to interpolate the sensfunc with polynomial in the stellar absortion line regions before fitting with the bspline
nresln (float) – Parameter governing the spacing of the bspline breakpoints. default = 20.0
resolution (float) – Expected resolution of the standard star spectrum. This should probably be determined from the grating, but is currently hard wired. default=3000.0
trans_thresh (float) – Parameter for selecting telluric regions which are masked. Locations below this transmission value are masked. If you have significant telluric absorption you should be using telluric.sensnfunc_telluric. default = 0.9
- Returns:
Returns the following: - meta_table: astropy.table.Table Table containing meta data for the sensitivity function - out_table: astropy.table.Table Table containing the sensitivity function
- Return type:
- pypeit.core.flux_calib.standard_zeropoint(wave, Nlam, Nlam_ivar, Nlam_gpm, flam_true, mask_recomb=None, mask_tell=None, maxiter=35, upper=3.0, lower=3.0, func='polynomial', polyorder=5, balm_mask_wid=50.0, nresln=20.0, resolution=2700.0, polycorrect=True, debug=False, polyfunc=False)[source]
Generate a sensitivity function based on observed flux and standard spectrum.
- Parameters:
wave (numpy.ndarray) – wavelength as observed
Nlam (numpy.ndarray) – counts/s/Angstrom as observed
Nlam_ivar (numpy.ndarray) – inverse variance of counts/s/Angstrom
Nlam_gpm (numpy.ndarray) – mask for bad pixels. True is good.
flam_true (astropy.units.Quantity) – array with true standard star flux (erg/s/cm^2/A)
mask_recomb (numpy.ndarray) – mask for hydrogen (and/or helium II) recombination lines. True is good.
mask_tell (numpy.ndarray) – mask for telluric regions. True is good.
maxiter (int) – maximum number of iterations for polynomial fit
upper (int) – number of sigma for rejection in polynomial
lower (int) – number of sigma for rejection in polynomial
polyorder (int) – order of polynomial fit
balm_mask_wid (float) – Mask parameter for Balmer absorption. A region equal to balm_mask_wid in units of angstrom is masked.
nresln (int, float) – number of resolution elements between breakpoints
resolution (int, float) – The spectral resolution. This paramters should be removed in the future. The resolution should be estimated from spectra directly.
debug (bool) – if True shows some dubugging plots
- Returns:
zeropoint_data (numpy.ndarray) – Sensitivity function with same shape as wave (nspec,)
zeropoint_data_gpm (numpy.ndarray) – Good pixel mask for sensitivity function with same shape as wave (nspec,)
zeropoint_fit (numpy.ndarray) – Fitted sensitivity function with same shape as wave (nspec,)
zeropoint_fit_gpm (numpy.ndarray) – Good pixel mask for fitted sensitivity function with same shape as wave (nspec,)
- pypeit.core.flux_calib.zeropoint_qa_plot(wave, zeropoint_data, zeropoint_data_gpm, zeropoint_fit, zeropoint_fit_gpm, title='Zeropoint QA', axis=None, show=False)[source]
QA plot for zeropoint
- Parameters:
wave (numpy.ndarray) – Wavelength array
zeropoint_data (numpy.ndarray) – Zeropoint data array
zeropoint_data_gpm (boolean numpy.ndarray) – Good pixel mask array for zeropoint_data
zeropoint_fit (numpy.ndarray) – Zeropoint fitting array
zeropoint_fit_gpm (boolean numpy.ndarray) – Good pixel mask array for zeropoint_fit
title (str, optional) – Title for the QA plot
axis (matplotlib.axes.Axes, optional) – axis used for ploting. If None, a new plot is created
show (bool, optional) – Whether to show the QA plot
- pypeit.core.flux_calib.zeropoint_to_throughput(wave, zeropoint, eff_aperture)[source]
Routine to compute the spectrograph throughput from the zeropoint and effective aperture.
- Parameters:
wave (numpy.ndarray) – Wavelength array shape (nspec,) or (nspec, norders)
zeropoint (numpy.ndarray) – Zeropoint array shape (nspec,) or (nspec, norders)
eff_aperture (float) – Effective aperture of the telescope in m^2. See spectrograph object
- Returns:
throughput – Throughput of the spectroscopic setup. Same shape as wave and zeropoint
- Return type:
- pypeit.core.flux_calib.zp_unit_const()[source]
This constant defines the units for the spectroscopic zeropoint. See Flux Calibration.