This is a collection of code and notebooks for producing P1D mocks for the Lyman Alpha Forest.
This repo provides a suite of scripts for fitting the one dimensional flux power spectrum (P1D) and mean flux to observations of the Lyman-alpha forest, and generating mock spectra with these properties for relevant studies. The code supports creating customizable synthetic datasets and tuning their statistical properties (P1D and mean flux) to different models or obserational datasets.
-
Clone the repository:
git clone https://github.com/m-herbold/P1D_Mocks.git cd P1D_Mocks -
(Recommended) Set up a virtual environment:
conda create -n env_name conda activate env_name
-
Install dependencies (see below).
├── CF
│ ├── correlation functions # ouput by fit, used to calcualte P_G
│ │ ├── e.g. {redshift}_xiG_full_output.txt
│ │ ├── e.g. {redshift}_xiG_half_output.txt
├── Examples
│ ├── fit_power_by_redshift (plots)
│ ├── measured_power_by_redshift (plots)
│ ├── mock_fit_input_files # example alternative inputs for fit
│ └── xi_g_fit_by_redshift (plots)
│ └── figure8_qmle_desiedrp_results.txt # DESI EDR P1D measurement
├── Notebooks # interractive notebooks
│ ├── fitting_mocks_interractive.ipynb
│ ├── mock_generation_interactive.ipynb
└── P_G
│ ├── Gaussian Power # ouput by fit, used to generate mocks
│ │ ├── e.g. P_G-{redshift}.txt
└── scripts
│ ├── mock_fit.py # main fitting code
│ ├── mock_gen.py # main mock generation code
│ ├── convert_transmission_format.py # code to reformat mock_gen.py output
│ ├── QQ_format.py # helper code to format transmission output
│ ├── QQ_diagnostics.py # helper code to analyze reformatted output
└── transmission_files # output by mock_gen.py
│ ├── e.g. {redshift}
│ │ ├── e.g. transmission_{redshift}_{date}_{ID}txt
Python script designed to fitting of the 1D Lyman-alpha forest power spectrum (P1D) and associated mean flux evolution as a function of redshift.
The script accepts several types of inputs via command-line arguments:
-
Redshift Targets (
--z_target[required])- A single redshift value (e.g.,
3.0) - A comma-separated list of redshifts (e.g.,
"2.0,2.2,2.4") - A text file with one or more redshift values (one per line)
- A single redshift value (e.g.,
-
Power Spectrum Data (
--power_file[optional])- Path to a
.txtfile containing at least three columns: redshift (z), wavenumber (kin [km/s]⁻¹), and 1D power spectrum (P1D). - If not provided, a built-in DESI EDR model is used.
- Path to a
-
Mean Flux Data (
--flux_file[optional])- Path to a
.txtfile containing two columns: redshift (z) and mean flux (F). - If not provided, a model from Turner et al. (2024) is used.
- Path to a
-
Plotting Flags [optional]:
Use the following flags to generate plots after fitting:--plot_mean_flux--plot_target_power--plot_target_xif--plot_xig_fit--plot_xif_fit--plot_xif_recovered--plot_recovered_power
The script generates both data files and plots, depending on the chosen options:
-
Half and Full Gaussian Correlation Functions (
xi_G):- Saved under
../CF/{z}_xiG_half_output.txtand../CF/{z}_xiG_full_output.txt, where{z}is the redshift. - Format: Two columns (velocity [km/s], xi_G).
- Used for calculating Gaussian power spectrum
- Saved under
-
Gaussian Power Spectrum:
- Saved under
../P_G/P_G-{z}.txtfor each redshift. - Format: Two columns (k [km/s]⁻¹, P(k)).
- Used for mock generation
- Saved under
Depending on the flags, generates a number of plots.
Basic Example
python /.../scripts/mock_fit.py --z_target 3.0 --plot_mean_flux --plot_recovered_powerUsing Custom Data Files
python /.../scripts/mock_fit.py \
--z_target redshifts.txt \
--power_file input_power.txt \
--flux_file input_flux.txt \
--plot_mean_flux --plot_recovered_power- Replace
redshifts.txtwith a file containing redshift values. - Replace
input_power.txtwith a file containing [z, k, P1D] columns. - Replace
input_flux.txtwith a file containing [z, F] columns.
- Python 3.x
- Packages: numpy, matplotlib, scipy, astropy, iminuit, argparse
The script saves outputs in directories relative to the script's location:
- Power spectrum:
../P_G/ - Correlation functions:
../CF/ - Plots: Current working directory
Ensure these directories exist, or the script will create them as needed.
If using this script or its results for published work, please cite:
- Turner et al. (2024)
- Karacayli et al. (2020)
- DESI Early Data Release (EDR)
Python script for generating 1D lognormal mock Lyman-alpha forest spectra at user-specified redshifts.
The script generates mock transmitted flux fields by:
- Creating Gaussian random fields with a user-supplied or default power spectrum.
- Applying lognormal and physical transformations to model the Lyman-alpha forest.
- Outputting synthetic spectra and diagnostic plots for further analysis.
--z_target:- File path to a
.txtfile containing redshift values (one per line), - or a single float (e.g.,
2.2), - or a comma-separated list of redshifts (e.g.,
2.0,2.2,2.4).
- File path to a
-
--power_files:- Comma-separated list of power spectrum files (one per redshift),
- or leave blank to use the default power spectrum for each redshift.
-
--fit_params:- Comma-separated string or filename containing four lognormal fitting parameters:
tau0, tau1, nu, sigma2. - If omitted, uses defaults from the script.
- Comma-separated string or filename containing four lognormal fitting parameters:
-
--N_mocks:- Number of mocks to generate per redshift (default: 1).
-
--output_dir:- Optionally provide an output directory for the plots and files.
- Will create a path if one does not exist already.
- If not specified, will default to the current working directory.
-
Plotting flags (all optional, default off):
--plot_gaussian_field--plot_gaussian_power--plot_delta_k--plot_delta_v--plot_delta_z--plot_nz--plot_optical_depth--plot_transmission_v--plot_transmission_w
-
Transmission Files:
For each mock and redshift, a file is saved in../transmission_files/{z}containing two columns: velocity [km/s] and transmitted flux. -
Diagnostic Plots:
Saved to the current working directory. -
Console Output:
Information on progress, timing, and key statistics for each redshift.
Basic, defaults to DESI-like mean flux and P1D:
python /.../scripts/mock_gen.py \
--z_target 2.0,2.2,2.4 \
--N_mocks 100 \
--plot_transmission_wUsing user-specified redshift, power, and mean flux parameter information:
python /.../scripts/mock_gen.py \
--z_target redshifts.txt \
--power_files "P_G-2-2.txt,P_G-2-4.txt,P_G-2-6.txt" \
--N_mocks 100 \
--fit_params 0.67,5.31,2.16,1.50 \
--plot_transmission_w- Python 3.x
- Packages: numpy, matplotlib, pandas, scipy
scripts/mock_gen.py: Main script.P_G/: Default location for power spectrum files.transmission_files/{z}/: Output transmission files.Examples/figure8_qmle_desiedrp_results.txt: Sample DESI EDR results for direct comparison.
- All output files are saved in the working directory or in the
transmission_files/folder. - For custom power spectra or parameter files, ensure each file matches the number/order of redshifts.
########################################################################################################
Python script for converting transmission file format output by mock_gen.py into a format expected by desisim code, QuickQuasars (QQ), which can be found here.
--spec_path:- File path to a folder containing transmission files, such as the output generated by mock_gen.py
- e.g.
--spec_path /.../transmission_files/
--zmin:- Minimum redshift bin (expects
/spec_path/redshift_bin/, e.g./spec_path/2-0/for z = 2.0)
- Minimum redshift bin (expects
--zmax:- Maximum redshift bin (expects
/spec_path/redshift_bin/, e.g./spec_path/2-0/for z = 2.0)
- Maximum redshift bin (expects
--dz:- Redshift bin separation (expects multiple redshift bins; e.g. for bins 2.0,2.2, dz = 0.2)
--outdir:- Directory to write output files
-
--catalog:- Path to (optional) quasar catalog (e.g. DESI EDR QSO catalog)
- If provided, gathers metadata (e.g. ID, RA, DEC, etc.)
- If not provided, a randomized, fake catalog is uesed
-
--z_template:- Applies a redshift distribution downsampling to match given catalog (if provided)
- Catalog must also be provided for this option
-
--seed:- Optional seed for repeatability
-
--N:- Number of QSO per redshift bin to sample
-
--nside:- optional, default 16
-
--pixel:- optional, default 1
-
--wmin:- Minimum output wavelength (default 3600)
-
--wmax:- Maximum output wavelength (default 9800)
-
--dwave:- Output wavelenth spacing (default 0.2, mimcks original DESI P1D mocks)
-
Plotting flags (all optional, default off):
--diag_plot
-
Transmission Files:
Writes a QQ-format transmission FITS file to --outdir (transmission--_.fits), and (if --z_template is used) writes a downsampled version. -
Diagnostic Plots:
Saved to the current working directory. -
Console Output:
Information on progress, timing, and key statistics for each redshift.
Basic usage, can use output from mock_gen.py, defaults to DESI-like catalog:
python convert_transmission.py \
--spec_path '/.../transmission_files/' \
--zmin 2.0 \
--zmax 3.8\
--dz 0.2 \
--outdir '/.../desired_output'Using user-specified catalog, redshift-distribution, etc.:
python convert_transmission.py \
--spec_path '/.../transmission_files/' \
--z_template True \
--catalog '/.../path_to_catalog.fits' \
--zmin 2.0 \
--zmax 3.8\
--dz 0.2 \
--seed 123 \
--N 10 \
--wmin 3500 \
--wmax 10000 \
--dwave 0.2 \
--diag_plot True \
--outdir '/.../output'- Python 3.x
- Packages: numpy, fitsio, pandas, scipy, matplotlib, iminuit, astropy, etc. (see script for full dependencies)