temet.spectra
Synthetic absorption spectra.
temet.spectra.analysis
Synthetic absorption spectra: analysis and derived quantities.
- load_spectra_subset(sim, ion, instrument, mode, nRaysPerDim=1000, raysType='voronoi_fullbox', solar=False, num=None, inds=None, EW_minmax=None, dv=0.0, coldens=False)
Load a subset of spectra from a given simulation and ion.
- Parameters:
sim (
simParams) – simulation instance.ion (str) – space separated species name and ionic number e.g. ‘Mg II’.
instrument (str) – specify wavelength range and resolution, must be known in instruments dict.
mode (str) – either ‘all’, ‘random’, ‘evenly’, or ‘inds’.
nRaysPerDim (int) – number of rays per linear dimension (total is this value squared).
raysType (str) – either ‘voronoi_fullbox’ (equally spaced), ‘voronoi_rndfullbox’ (random), or ‘sample_localized’ (distributed around a given set of subhalos).
solar (bool) – if True, do not use simulation-tracked metal abundances, but instead use the (constant) solar value.
num (int) – how many individual spectra to show.
inds (list[int]) – if mode is ‘inds’, then the list of specific spectra indices to plot. num is ignored.
EW_minmax (list[float]) – minimum and maximum EW to plot [Ang].
dv (float) – if not zero, then take as a velocity window (+/-), convert the wavelength axis to velocity, and subset spectra to only this vel range.
coldens (bool) – if True, also load/compute total column densities for this ion along each ray.
- wave_to_dv(wave, flux, dv)
Convert a spectrum as a function of wavelength to velocity space, centering at the tau-weighted mean wavelength.
- Parameters:
sim (
simParams) – simulation instance.wave (np.ndarray) – wavelength array [Ang].
flux (np.ndarray) – flux array, shape (n_spectra, n_wave).
dv (float) – velocity window (+/-) [km/s].
- load_absorber_spectra(sim, line, instrument, solar, EW_minmax=None, dwave=0.0, dv=0.0)
Load the (local) spectra for each absorber, from a given simulation and ion.
Note that the absorber catalog is available for each line separately, so one must be specified, and this line is used for the EW_minmax restriction (and returned EW values). However, the flux is the observable i.e. the full spectrum including all lines of this ion.
- Parameters:
sim (
simParams) – simulation instance.line (str) – transition name e.g. ‘Mg II 2796’, since each line has its own absorber catalog.
instrument (str) – specify wavelength range and resolution, must be known in instruments dict.
solar (bool) – if True, do not use simulation-tracked metal abundances, but instead use the (constant) solar value.
EW_minmax (list[float]) – minimum and maximum EW to plot [Ang].
dwave (float) – if not zero, then take as a wavelength window (+/-) around each absorber.
dv (float) – if not zero, then take as a velocity window (+/-), convert the wavelength axis to velocity, and subset spectra to only this vel range.
- absorber_catalog(sP, ion, instrument, solar=False)
Detect and chatacterize absorbers, handling the possibility of one or possibly multiple per sightline.
Absorbers are defined as separated but contiguous regions of absorption. Create an absorber catalog, i.e. counts and offsets per sightline, and compute their EWs.
- Parameters:
sP (
simParams) – simulation instance.ion (str) – space separated species name and ionic number e.g. ‘Mg II’.
instrument (str) – specify wavelength range and resolution, must be known in instruments dict.
solar (bool) – if True, do not use simulation-tracked metal abundances, but instead use the (constant) solar value.
- cell_to_absorber_map(sP: simParams, ion: str, instrument: str, solar: bool = False) tuple
For each absorber, identify the gas cells that contribute to its optical depth.
Return ‘spec_index’ is an ordered list of global gas cell indices, stored with a length (counts_abs) and offset (offset_abs) approach, where the length and offset are per absorber. Also derived and returned: the column density per absorber, and the fraction of this (total) column density that is recovered by the cells included here as ‘significantly’ contributing to the absorber.
- Parameters:
sP – simulation instance.
ion – space separated species name and ionic number e.g. ‘Mg II’.
instrument – specify wavelength range and resolution, must be known in instruments dict.
solar – if True, do not use simulation-tracked metal abundances, but instead use the (constant) solar value.
- Returns:
- spec_index (ndarray[int]): an ordered list of global gas cell indices, stored with a length (counts_abs)
and offset (offset_abs) approach, where the length and offset are per absorber.
counts_abs (ndarray[int]): number of gas cell indices contributing to each absorber.
offset_abs (ndarray[int]): offset into spec_index for each absorber.
coldens_abs (ndarray[float]): column density per absorber.
colfrac_abs (ndarray[float]): fraction of the (total) column density that is recovered by the cells included here as ‘significantly’ contributing to the absorber.
- Return type:
tuple of (spec_index, counts_abs, offset_abs, coldens_abs, colfrac_abs)
- calc_statistics_from_saved_rays(sP, ion)
Calculate useful statistics based on already computed and saved rays.
Results depend on ion, independent of actual transition. Results depend on the physical properties along each sightline, not on the absorption spectra.
- Parameters:
sP (
simParams) – simulation instance.ion (str) – space separated species name and ionic number e.g. ‘Mg II’.
- test_abs_coldens(sim, ion, instrument)
Check if the column densities of all absorbers in a spectrum sum to its integrated total column density.
temet.spectra.plot
Diagnostic and production plots based on synthetic ray-traced absorption spectra.
- curve_of_growth(lines=('MgII 2803',), bvals=(5, 10, 15))
Plot relationship between EW and column density (N) for the given transition(s).
- profile_single_line()
Voigt profile deposition of a single absorption line: create spectrum and plot.
- profiles_multiple_lines(plotTau=True)
Deposit Voigt absorption profiles for a number of transitions: create spectrum and plot.
- profiles_multiple_lines_coldens()
Deposit Voigt absorption profiles for a number of transitions and N values: create spectrum and plot.
Celine Peroux JWST cycle 2/3 proposal.
- LyA_profiles_vs_coldens()
Reproduce Hummels+17 Figure 10 of LyA absorption profiles for various N_HI values.
- instrument_lsf(instrument)
Plot LSF(s) of a given instrument. For wavelength-dependent LSF matrices.
- cos_disptab()
Handle DISPTAB files, wavelength grids, and LSF files for HST-COS (pre-processing step).
- spectra_gallery_indiv(sim, ion='Mg II', instrument='4MOST-HRS', nRaysPerDim=1000, raysType='voronoi_fullbox', EW_minmax=(0.1, 1.0), num=10, mode='random', inds=None, style='offset', solar=False, SNR=None, dv=False, xlim=None)
Plot a gallery of individual absorption profiles within a given EW range.
- Parameters:
sim (
simParams) – simulation instance.ion (str, list[str]) – space separated species name and ionic number e.g. ‘Mg II’, or list of such.
instrument (str) – specify wavelength range and resolution, must be known in instruments dict.
nRaysPerDim (int) – number of rays per linear dimension (total is this value squared).
raysType (str) – either ‘voronoi_fullbox’ (equally spaced) or ‘voronoi_rndfullbox’ (random).
EW_minmax (list[float]) – minimum and maximum EW to plot [Ang].
num (int) – how many individual spectra to show.
mode (str) – either ‘random’, ‘evenly’, or ‘inds’.
inds (list[int]) – if mode is ‘inds’, then the list of specific spectra indices to plot. num is ignored.
style (str) – type of plot, ‘stacked’, ‘grid’, or ‘2d’.
solar (bool) – if True, do not use simulation-tracked metal abundances, but instead use the (constant) solar value.
SNR (float) – if not None, then add noise to achieve this signal to noise ratio.
dv (bool) – if False, x-axis in wavelength, else in velocity.
xlim (str, list[float]) – either ‘full’, a 2-tuple of [min,max], or automatic if None (default)
- spectrum_plot_single(file=None, ind=None, full=True, saveFilename=None, pStyle='white', output_fmt='png')
Plot a randomly selected spectrum.
- Parameters:
file (str) – if not None, the specific file to load.
ind (int) – if not None, the specific spectrum index to load.
full (bool) – show the full wavelength range in addition to zooming in on the absorption feature.
saveFilename (str) – if not None, the specific filename to save to (otherwise auto-generated).
pStyle (str) – either ‘white’ or ‘black’ for plot style.
output_fmt (str) – either ‘pdf’, ‘png’, or ‘jpg’.
- EW_distribution(sim_in, line='MgII 2796', instrument='SDSS-BOSS', redshifts=(0.5, 0.7, 1.0), xlim=None, solar=False, indivEWs=False, log=False, dX=False)
Plot the EW distribution (dN/dWdz) of a given absorption line.
- Parameters:
sim_in (
simParams) – simulation instance.line (str) – string specifying the line transition.
instrument (list[str]) – specify wavelength range and resolution, must be known in instruments dict.
xlim (list[float]) – min and max EW [Ang], or None for default.
solar (bool) – use the (constant) solar value instead of simulation-tracked metal abundances.
indivEWs (bool) – if True, then use/create absorber catalog, to handle multiple absorbers per sightline, otherwise use the available ‘global’ EWs, one per sightline.
log (bool) – plot log(EW) instead of linear EWs.
dX (bool) – if True, normalize by absorption distance dX instead of redshift path length dz.
- EW_vs_coldens(sim, line='CIV 1548', instrument='SDSS-BOSS', bvals=(5, 10, 25, 50, 100, 150), xlim=(12.5, 16.0), ylim=(-1.7, 0.5), solar=False, log=False, pSplit=None)
Plot the relationship between EW and column density, and compare to the CoG.
- Parameters:
sim (
simParams) – simulation instance.line (str) – string specifying the line transition.
instrument (str) – specify wavelength range and resolution, must be known in instruments dict.
bvals (list[float]) – set of Doppler values to calculate and overplot CoG for.
xlim (list[float]) – min and max column density [log 1/cm^2].
ylim (list[float]) – min and max equivalent width [log Ang].
solar (bool) – use the (constant) solar value instead of simulation-tracked metal abundances.
log (bool) – plot log(EW) instead of linear EWs.
- dNdz_evolution(sim_in, redshifts, line='MgII 2796', instrument='SDSS-BOSS', solar=False)
Plot the redshift evolution (i.e. dN/dz) and comoving incidence rate (dN/dX) of a given absorption line.
- Parameters:
sim_in (
simParams) – simulation instance.line (str) – string specifying the line transition.
instrument (list[str]) – specify wavelength range and resolution, must be known in instruments dict.
solar (bool) – use the (constant) solar value instead of simulation-tracked metal abundances.
log (bool) – plot log(EW) instead of linear EWs.
- n_cloud_distribution(sim, ion='Mg II', redshifts=(0.5, 0.7))
Plot the N_cloud distribution of a given ion based on a rays statistics file.
- n_clouds_vs_EW(sim)
Plot relationship between number of discrete clouds along a sightline, and the EW of the transition.
- Parameters:
sim (
simParams) – simulation instance.
temet.spectra.spectrum
Synthetic absorption spectra: generation.
- generate_rays_voronoi_fullbox(sP, projAxis=2, nRaysPerDim=1000, raysType='voronoi_fullbox', subhaloIDs=None, pSplit=None, integrateQuant=None, search=False)
Generate a large grid of (fullbox) rays by ray-tracing through the Voronoi mesh.
- Parameters:
sP (
simParams) – simulation instance.projAxis (int) – either 0, 1, or 2. only axis-aligned allowed for now.
nRaysPerDim (int) – number of rays per linear dimension (total is this value squared).
raysType (str) – either ‘voronoi_fullbox’ (equally spaced), ‘voronoi_rndfullbox’ (random), or ‘sample_localized’ (distributed around a given set of subhalos).
subhaloIDs (list) – if raysType is ‘sample_localized’ (only), then a list of subhalo IDs.
pSplit (list[int]) – standard parallelization 2-tuple of [cur_job_number, num_jobs_total]. Note that we follow a spatial subdivision, so the total job number should be an integer squared.
integrateQuant (str) – if None, save rays for future use. otherwise, directly perform and save the integral of the specified gas quantity along each ray.
search (bool) – if True, return existing data only, do not calculate new files.
- generate_spectra_from_saved_rays(sP, ion='Si II', instrument='4MOST-HRS', nRaysPerDim=1000, raysType='voronoi_fullbox', subhaloIDs=None, pSplit=None, solar=False)
Generate a large number of spectra, based on already computed and saved rays.
- Parameters:
sP (
simParams) – simulation instance.ion (str) – space separated species name and ionic number e.g. ‘Mg II’.
instrument (str) – specify wavelength range and resolution, must be known in instruments dict.
nRaysPerDim (int) – number of rays per linear dimension (total is this value squared).
raysType (str) – either ‘voronoi_fullbox’ (equally spaced), ‘voronoi_rndfullbox’ (random), or ‘sample_localized’ (distributed around a given set of subhalos).
subhaloIDs (ndarray[int]) – if raysType is ‘sample_localized’ (only), then a list of subhalo IDs.
pSplit (list[int]) – standard parallelization 2-tuple of [cur_job_number, num_jobs_total]. Note that we follow a spatial subdivision, so the total job number should be an integer squared.
solar (bool) – if True, do not use simulation-tracked metal abundances, but instead use the (constant) solar value.
- integrate_along_saved_rays(sP, field, nRaysPerDim=1000, raysType='voronoi_fullbox', subhaloIDs=None, pSplit=None)
Integrate a physical (gas) property along the line of sight, based on already computed and saved rays.
The result has units of [pc] * [field] where [field] is the original units of the physical field as loaded, unless field is a number density, in which case the result (column density) is in [cm^-2].
- Parameters:
sP (
simParams) – simulation instance.field (str) – any available gas field.
nRaysPerDim (int) – number of rays per linear dimension (total is this value squared).
raysType (str) – either ‘voronoi_fullbox’ (equally spaced), ‘voronoi_rndfullbox’ (random), or ‘sample_localized’ (distributed around a given set of subhalos).
subhaloIDs (list) – if raysType is ‘sample_localized’ (only), then a list of subhalo IDs.
pSplit (list[int]) – standard parallelization 2-tuple of [cur_job_number, num_jobs_total]. Note that we follow a spatial subdivision, so the total job number should be an integer squared.
- deposit_single_line(wave_edges_master, tau_master, f, gamma, wave0, N, b, z_eff, debug=False)
Add the absorption profile of a single transition, from a single cell, to a spectrum.
Global method, where the original master grid is assumed to be very high resolution, such that no sub-sampling is necessary (re-sampling onto an instrument grid done later).
- Parameters:
wave_edges_master (array[float]) – bin edges for master spectrum array [ang].
tau_master (array[float]) – master optical depth array.
N (float) – column density in [1/cm^2].
b (float) – doppler parameter in [km/s].
f (float) – oscillator strength of the transition
gamma (float) – sum of transition probabilities (Einstein A coefficients) [1/s]
wave0 (float) – central wavelength, rest-frame [ang].
z_eff (float) – effective redshift, i.e. including both cosmological and peculiar components.
debug (bool) – if True, return local grid info and do checks.
- Returns:
None.
- create_spectra_from_traced_rays(sP, line, instrument, rays_off, rays_len, rays_cell_dl, rays_cell_inds, cell_dens, cell_temp, cell_vellos, nThreads=60)
Generate a fullset of mock absorption spectra given the pre-existing set of rays.
The rays are a composite list of intersected cell pathlengths and indices. Using these, we extract the physical properties needed (dens, temp, vellos) and create the final absorption spectrum, depositing a Voigt absorption profile for each cell.
- Parameters:
sP (
simParams) – simulation instance.line (str) – string specifying the line transition.
instrument (str) – string specifying the instrumental setup.
rays_off (array[int]) – first entry from tuple return of
util.voronoiRay.rayTrace().rays_len (array[int]) – second entry from tuple return of
util.voronoiRay.rayTrace().rays_cell_dl (array[float]) – third entry from tuple return of
util.voronoiRay.rayTrace().rays_cell_inds (array[int]) – fourth entry from tuple return of
util.voronoiRay.rayTrace().cell_dens (array[float]) – gas per-cell densities of a given species [linear ions/cm^3]
cell_temp (array[float]) – gas per-cell temperatures [linear K]
cell_vellos (array[float]) – gas per-cell line of sight velocities [linear km/s]
z_lengths (array[float]) – the comoving distance to each z_vals relative to sP.redshift [pMpc]
z_vals (array[float]) – a sampling of redshifts, starting at sP.redshift
nThreads (int) – parallelize calculation using this threads (serial computation if one)
- concat_integrals(sP, field, nRaysPerDim=1000, raysType='voronoi_fullbox')
Combine split files for line-of-sight quantity integrals into a single file.
- Parameters:
sP (
simParams) – simulation instance.field (str) – any available gas field.
nRaysPerDim (int) – number of rays per linear dimension (total is this value squared).
raysType (str) – either ‘voronoi_fullbox’ (equally spaced), ‘voronoi_rndfullbox’ (random), or ‘sample_localized’ (distributed around a given set of subhalos).
- concat_spectra(sP, ion='Fe II', instrument='4MOST-HRS', nRaysPerDim=1000, raysType='voronoi_fullbox', solar=False)
Combine split files for spectra into a single file.
- Parameters:
sP (
simParams) – simulation instance.ion (str) – space separated species name and ionic number e.g. ‘Mg II’.
instrument (str) – specify wavelength range and resolution, must be known in instruments dict.
nRaysPerDim (int) – number of rays per linear dimension (total is this value squared).
raysType (str) – either ‘voronoi_fullbox’ (equally spaced), ‘voronoi_rndfullbox’ (random), or ‘sample_localized’ (distributed around a given set of subhalos).
solar (bool) – if True, do not use simulation-tracked metal abundances, but instead use the (constant) solar value.
- spectra_filepath(sim, ion, projAxis=2, nRaysPerDim=1000, raysType='voronoi_fullbox', instrument=None, pSplit=None, solar=False)
Return the path to a file of saved spectra.
- Parameters:
sim (
simParams) – simulation instance.ion (str) – space separated species name and ionic number e.g. ‘Mg II’.
projAxis (int) – either 0, 1, or 2. only axis-aligned allowed for now.
nRaysPerDim (int) – number of rays per linear dimension (total is this value squared).
raysType (str) – either ‘voronoi_fullbox’ (equally spaced), ‘voronoi_rndfullbox’ (random), or ‘sample_localized’ (distributed around a given set of subhalos).
instrument (str) – specify wavelength range and resolution, must be known in instruments dict.
pSplit (list[int]) – standard parallelization 2-tuple of [cur_job_number, num_jobs_total]. Note that we follow a spatial subdivision, so the total job number should be an integer squared.
solar (bool) – if True, do not use simulation-tracked metal abundances, but instead use the (constant) solar value.
temet.spectra.test
Synthetic absorption spectra generation (testing/non-production).
- create_spectrum_from_traced_ray(sP, line, instrument, cell_dens, cell_dx, cell_temp, cell_vellos)
Given a completed (single) ray traced through a volume, compute the final absorption spectrum.
Use the properties of all the intersected cells (dens, dx, temp, vellos) to deposit Voigt absorption profiles for each cell.
- deposit_single_line_local(wave_edges_master, tau_master, f, gamma, wave0, N, b, z_eff, debug=False)
Add the absorption profile of a single transition, from a single cell, to a spectrum.
Local method, where master grid is sub-sampled and optical depth is deposited back onto master.
- Parameters:
wave_edges_master (array[float]) – bin edges for master spectrum array [ang].
tau_master (array[float]) – master optical depth array.
N (float) – column density in [1/cm^2].
b (float) – doppler parameter in [km/s].
f (float) – oscillator strength of the transition
gamma (float) – sum of transition probabilities (Einstein A coefficients) [1/s]
wave0 (float) – central wavelength, rest-frame [ang].
z_eff (float) – effective redshift, i.e. including both cosmological and peculiar components.
debug (bool) – if True, return local grid info and do checks.
- Returns:
None.
- generate_spectrum_uniform_grid()
Generate an absorption spectrum by ray-tracing through a uniform grid (deposit using sphMap).
- generate_spectrum_voronoi(use_precomputed_mesh=True, compare=False, debug=1, verify=True)
Generate a single absorption spectrum by ray-tracing through the Voronoi mesh.
- Parameters:
use_precomputed_mesh (bool) – if True, use pre-computed Voronoi mesh connectivity from VPPP, otherwise use tree-based, connectivity-free method.
compare (bool) – if True, run both methods and compare results.
debug (int) – verbosity level for diagnostic outputs: 0 (silent), 1, 2, or 3 (most verbose).
verify (bool) – if True, brute-force distance calculation verify parent cell at each step.
- generate_spectra_voronoi_halo()
Generate a large grid of (halocentric) absorption spectra by ray-tracing through the Voronoi mesh.
temet.spectra.util
Synthetic absorption spectra: data and utilities.
- line_params(line)
Get physical atomic parameters for a given electronic (i.e. line) transition.
- Parameters:
line (str) – string specifying the line transition.
- Returns:
5-tuple of (f,Gamma,wave0,ion_amu,ion_mass).
- lsf_matrix(instrument)
Create a (wavelength-dependent) kernel, for the line spread function (LSF) of the given instrument.
- Parameters:
instrument (str) – string specifying the instrumental setup.
- Returns:
a 3-tuple composed of
lsf_mode (int): integer flag specifying the type of LSF.
lsf (
ndarray): 2d array, with dimensions corresponding to wavelength of the instrumental grid, and discrete/pixel kernel size, respectively. Each entry is normalized to unity.lsf_dlambda (
ndarray): 1d array, the LSF FWHM at the same wavelengths.
- create_wavelength_grid(line=None, instrument=None)
Create a wavelength grid (i.e. x-axis of a spectrum) to receieve absorption line depositions.
Must specify one, but not both, of either ‘line’ or ‘instrument’. In the first case, a local spectrum is made around its rest-frame central wavelength. In the second case, a global spectrum is made corresponding to the instrumental properties.
- varconvolve(arr, kernel)
Convolution (non-fft) with variable kernel.
- resample_spectrum(master_mid, tau_master, inst_waveedges)
Resample an input optical depth spectrum onto a new wavelength grid.
The input high-resolution spectrum is defined on the master_mid wavelength (midpoints) grid, with given optical depths at each wavelength point, onto a lower resolution inst_waveedges wavelength (bin edges) grid, preserving flux i.e. equivalent width.
- Parameters:
- Returns:
- optical depth array at the lower resolution, with total size
equal to (inst_waveedges.size - 1).
- Return type:
inst_tau (array[float])