spectrum
- class Spectrum(catrow, wave, flux, ivar, mask, reso, idx)[source]
Bases:
objectAn object to represent one spectrum.
- Parameters:
catrow (
ndarray) – Catalog row.wave (dict(
ndarray)) – Dictionary of arrays specifying the wavelength grid. Static variable!flux (dict(
ndarray)) – Dictionary of arrays specifying the flux.ivar (dict(
ndarray)) – Dictionary of arrays specifying the inverse variance.mask (dict(
ndarray)) – Dictionary of arrays specifying the bitmask. Not storedreso (dict(
ndarray)) – Dictionary of 2D arrays specifying the resolution matrix.idx (int) – Index to access in flux, ivar, mask and reso that corresponds to the quasar in catrow.
- rsnr
Average SNR above Lya. Calculated in
set_forest_region().- Type:
- _f1, _f2
Forest indices. Set up using
set_forest_region()method. Then use property functions to access forest wave, flux, ivar instead.
- _fits_colnames = ['LAMBDA', 'DELTA', 'IVAR', 'WEIGHT', 'CONT']
Column names to save in delta files.
- static _set_wave(wave, check_consistency=False)[source]
Set the common wavelength grid.
- Parameters:
check_consistency (bool) – Asserts each time key and values are the same if True.
- static set_blinding(maxlastnight, args)[source]
Set the blinding strategy.
‘LASTNIGHT’ column, args.mock_analysis, args.forest_w1 decide the blinding strategy. Mock, side band and SV analyses are not blinded.
- Parameters:
maxlastnight (int) – Maximum LASTNIGHT column of the entire quasar catalog.
args (argparse.Namespace) – Should have
mock_analysis (bool)andforest_w1 (floar).
- classmethod from_dictionary(catrow, data, idx)[source]
Create a Spectrum from dictionary. See
Spectrumfor argument details.If
contkey is present indata,cont_paramsdictionary gains the following:cont_params['true_data_w1'] (float): First wavelength cont_params['true_data_dwave'] (float): Wavelength spacing cont_params['true_data'] (ndarray): True continuum
- Return type:
Calculates the mean SNR in the forest region and an initial guess for the continuum amplitude.
- set_forest_region(w1, w2, lya1, lya2)[source]
Sets slices for the forest region. Also calculates the mean SNR in the forest and an initial guess for the continuum amplitude. This is currently turned off, but it can mask outliers in each arm separately based on moving median statistics (see
qsonic.mathtools.get_median_outlier_mask()).
- drop_short_arms(lya1=0, lya2=0, skip_ratio=0)[source]
Arms that have less than
skip_ratiopixels are removed from forest dictionary.
- remove_nonforest_pixels()[source]
Remove non-forest pixels from storage.
This sets
flux,ivarandresoto empty dictionary, butwaveis not modified, since it is a static variable. Good practive is to loop using, e.g.,for arm, wave_arm in self.forestwave.items():.
- get_real_size()[source]
- Returns:
int
- Return type:
Sum of number of pixels with
forestivar > 0for all arms.
- get_effective_meansnr()[source]
Calculate a weighted average of
mean_snrover arms. Only call ifset_forest_region()has been called.\[\langle\mathrm{SNR}\rangle = \sum_{i} \mathrm{SNR}_i^3 \bigg/ {\sum_{i} \mathrm{SNR}_i^2}\]- Returns:
float
- Return type:
Effective mean SNR.
- is_long(dforest_wave, skip_ratio)[source]
Determine if spectrum is long enough to be accepted.
The condition is
get_real_size()>skip_ratio * npixels, wherenpixels\(=(1 + z_\mathrm{qso}) \times\)dforest_wave\(/ \mathrm{d}\lambda\) and \(\mathrm{d}\lambda\) is wavelength spacing in the observed frame in A.
- set_smooth_forestivar(smoothing_size=16.0)[source]
Set
forestivar_smto smoothed inverse variance. Before this callforestivar_smpoints toforestivar. Ifsmoothing_size <= 0, smoothing is undone such that ivar_sm points to ivar. Also,forestweightpoints to this.smoothing_sizeis saved to a private_smoothing_scalevariable for future use.- Parameters:
smoothing_size (float, default: 16) – Gaussian smoothing spread in A.
- set_forest_weight(varlss_interp=<function _zero_function>, eta_interp=<function _one_function>)[source]
Sets
forestweightfor a given var_lss and eta correction. Always usesforestivar_sm, which is not actually smoothed ifset_smooth_forestivar()is not called.\[w = i / (\eta + i \sigma^2_\mathrm{LSS} C^2),\]where i is IVAR and C is the continuum.
- Parameters:
varlss_interp (Callable[[ndarray], ndarray], default: 0) – LSS variance interpolator.
eta_interp (Callable[[ndarray], ndarray], default: 1) – eta interpolator.
- calc_continuum_chi2()[source]
Calculate the chi2 of the continuum fitting. This is just a sum of weight * (flux - cont)^2.
- Returns:
chi2
- Return type:
- simple_coadd()[source]
Coadding without continuum and var_lss terms on the full spectrum. Weights, forests etc. will not be set. Replaces
wave,flux,ivarandresoattributes with dictionaries that has a single armbrzas key to access the coadded data.We first set the static coadded wavelength grid if it is not set. Then we add each arm using
ivar(not smoothed). Ifresois set, we coadd the resolution matrix using the same inverse variance weights. If these weights are zero for both arms, resolution matrix coadding reverts to equal weights. Final private assignments are done at the end to keep using arm by arm values ofivar.
- coadd_arms_forest(varlss_interp=<function _zero_function>, eta_interp=<function _one_function>)[source]
Coadds different arms using
forestweight. Interpolators are needed to resetforestweight.Replaces
forestvariables andcont_params['cont']with a dictionary that has a single armbrzas key to access coadded data.- Parameters:
varlss_interp (Callable[[ndarray], ndarray], default: 0) – LSS variance interpolator or function.
eta_interp (Callable[[ndarray], ndarray], default: 1) – eta interpolator or function.
- mean_resolution(arm, weight=None)[source]
Returns the weighted mean Gaussian sigma of the spectrograph resolution in the forest.
- Parameters:
arm (str) – Arm.
weight (None or ndarray, default: None) – Weights. If
None,forestweightis used.
- Returns:
mean_reso – Gaussian sigma. None if forestreso is not set.
- Return type:
float or None
- write(fts_file)[source]
Writes each arm to FITS file separately.
Writes ‘LAMBDA’, ‘DELTA’, ‘IVAR’, ‘WEIGHT’, ‘CONT’ columns and ‘RESOMAT’ column if resolution matrix is present to extension name
targetid-arm. FITS file must be initialized before. Each arm has its own MEANSNR.- Parameters:
fts_file (FITS file) – The file handler, not filename.
- property forestivar_sm
Forest smoothed inverse variance field.
Initially equal to
forestivar. Smoothed ifset_smooth_forestivar()is called.- Type:
dict(
ndarray)
- property forestweight
Forest weight field. Initially equal to
forestivar.- Type:
dict(
ndarray)
- class Delta(hdu)[source]
Bases:
objectAn object to read one delta from HDU.
- Parameters:
hdu (fitsio.TableHDU) – Table containing delta data.
- Raises:
RuntimeError – If
hdudoesn’t have neither “LAMBDA” nor “LOGLAM” columns.RuntimeError – If
hdudoesn’t have neither “DELTA” nor “DELTA_BLIND” columns.RuntimeError – If
hdudoesn’t have none of “MOCKID”, “TARGETID” and “THING_ID” header keys.
- header
Header.
- Type:
FITS header
- _accepted_targetid_keys = {'MOCKID', 'TARGETID', 'THING_ID'}
Supported header keys for unique ID.
- Type:
- _accepted_colums_map = {'delta': {'DELTA', 'DELTA_BLIND'}, 'wave': {'LAMBDA', 'LOGLAM'}}
- write(fts_file)[source]
Writes to FITS file. This function is aimed at saving coadded deltas.
Writes ‘LAMBDA’, ‘DELTA’, ‘IVAR’, ‘WEIGHT’, ‘CONT’ columns and ‘RESOMAT’ column if resolution matrix is present to extension name
targetid. FITS file must be initialized before. Note thatarmis lost in the extension name.- Parameters:
fts_file (FITS file) – The file handler, not filename.
Arguments
- add_wave_region_parser(parser=None)[source]
Adds wavelength analysis related arguments to parser. These arguments are grouped under ‘Wavelength analysis region’. All of them come with defaults, none are required.
- Parameters:
parser (argparse.ArgumentParser, default: None) –
- Returns:
parser
- Return type:
usage: foo [-h] [--wave1 WAVE1] [--wave2 WAVE2] [--forest-w1 FOREST_W1]
[--forest-w2 FOREST_W2]
Wavelength analysis region
- --wave1
First observed wavelength edge.
Default: 3600.0
- --wave2
Last observed wavelength edge.
Default: 6000.0
- --forest-w1
First forest wavelength edge.
Default: 1050.0
- --forest-w2
Last forest wavelength edge.
Default: 1180.0