.
Project description
Overview
SPECWIZARD is a Python package to compute and analyze mock quasar absorption spectra from cosmological simulations.
This repository provides:
Tools to build and validate simulation input dictionaries (“Wizard” dictionaries).
Routines to generate short spectra for single sightlines.
Routines to assemble full long spectra across a redshift path.
HDF5 I/O helpers to save and read spectra in a consistent format.
Citing SPECWIZARD
If you use SPECWIZARD in scientific work, please cite the relevant code/paper for your release.
Installation Notes
SPECWIZARD is written in python3 and stable versions are available on PyPI. The easiest installation method is:
pip install specwizard
The code is constantly updated. Feedback and bug reports are welcome through email or GitHub.
Quick Start
Most users follow this flow:
Create a YAML configuration file.
Load it with Build_Input.read_from_yml.
Generate spectra.
Save to HDF5.
Read the file back for analysis.
Minimal Configuration (Wizard YAML)
Save a file such as Wizard.yml:
file_type:
sim_type: swift
snap_type: snapshot
snapshot_params:
directory: /path/to/snapshots
file: snapshot_012.hdf5
sightline:
ProjectionAxes: [simx, simy, simz]
ProjectionStart: [0.5, 0.5, 0.0]
ProjectionLength: 1
SightLength: null
ProjectionExtend:
extend: false
extendfactor: 3
nsight: 0
ionparams:
table_type: specwizard_cloudy
iondir: /path/to/ion_tables
fname: null
ions:
- [Hydrogen, H I]
- [Carbon, C IV]
SFR_properties:
modify_particle: true
ignore_particle: false
Temperature [K]: 1.0E+4
atomfile: /path/to/atomic_info.hdf5
ODParams:
VelOffset_kms: 0
PecVelEffectsOff: false
ThermalEffectsOff: false
VoigtOff: false
extraparams:
periodic: true
pixkms: 1
ReadIonFrac:
ReadIonFrac: false
ReadHydrogen: true
HI: NeutralHydrogenAbundance
ReadHelium: false
He: ""
fname_urchin: ""
Output:
directory: ./outputs/
fname: shortspec.hdf5
Notes:
Build_Input.read_from_yml reads file_type, snapshot_params, sightline, ionparams, ODParams and optional LongSpectra, extraparams, and Output sections.
Output is required if you plan to use OpticalDepth_IO to save data.
Generate And Save A Short Spectrum
import specwizard as spw
# 1) Build Wizard dictionary from YAML
builder = spw.Build_Input()
wizard = builder.read_from_yml("Wizard.yml")
# 2) Generate short-spectrum products
opticaldepth, projected_los, particles = spw.GenerateShortSpectra(wizard)
# 3) Save to HDF5 using the package writer
io = spw.OpticalDepth_IO(wizard=wizard, create=True)
payload = {
"nsight": wizard["sightline"]["nsight"],
"Projection": projected_los,
"OpticaldepthWeighted": opticaldepth,
}
io.write_shortspectra_to_file(payload)
Read A Saved Short Spectrum
import specwizard as spw
builder = spw.Build_Input()
wizard = builder.read_from_yml("Wizard.yml")
io = spw.OpticalDepth_IO(wizard=wizard, create=False)
short_data = io.read_shortspectra_from_file()
# Examples of access:
header = short_data["Header"]
one_los = next(iter(short_data["Data"]))
los_data = short_data["Data"][one_los]
Generate, Save, And Read A Long Spectrum
To generate a long spectrum, include a LongSpectra block in your YAML:
LongSpectra:
lambda_min: 945.0
lambda_max: 8000.0
dlambda: 0.5
z_qsr: 3.0
delta_z: 0.01
all_contaminants: false
file_dir: /path/to/los/files/
Then run:
import specwizard as spw
builder = spw.Build_Input()
wizard = builder.read_from_yml("Wizard.yml")
long_builder = spw.LongSpectra(wizard)
coven, redshifts = long_builder.create_coven()
long_spectra = long_builder.do_long_spectra(coven)
# Optional post-processing
# long_spectra = long_builder.add_contaminants(long_spectra)
# long_spectra = long_builder.add_HI_damping_wings(long_spectra, n=2)
# Save
io = spw.OpticalDepth_IO(wizard=wizard, create=True)
io.write_fullspectrum_to_file(long_spectra)
# Read
io_read = spw.OpticalDepth_IO(wizard=wizard, create=False)
long_data = io_read.read_fullspectrum_from_file()
Data Fields: What You Can Read
This project writes structured HDF5 groups for both short and long spectra. Below are the common fields and where to find them.
- Short spectra (per LOS):
Top-level groups: LOS_<n>/ and Header/.
Element-weighted properties: LOS_<n>/<Element>/Element-weighted/<field> (e.g. Velocities, Densities, Temperatures).
Ion-weighted properties: LOS_<n>/<Element>/<Ion>/Ion-weighted/<field>.
Optical-depth-weighted properties for each ion: LOS_<n>/<Element>/<Ion>/Ion optical depth-weighted/<field> (includes Optical depths, Velocities, Densities, Temperatures, Metallicities, HydrogenDensities where present).
If the simulation includes non-equilibrium / tracked ionic abundances, additional groups are written under SimIon-weighted and SimIon optical depth-weighted with the same fields as the tabulated ions.
- Long spectra (full-spectrum accumulation):
Global grids: FullSpectrum/Velocities and FullSpectrum/Wavelengths.
Per-ion data: FullSpectrum/<Element>/<Ion>/... with datasets for lambda0, f-value and fields such as Optical depths, Velocities, Densities, Temperatures, Metallicities, HydrogenDensities (each saved together with metadata/attributes when available).
The long-spectrum writer prefers simulation-tracked ion optical-depth-weighted fields when present: if SimIons optical-depth-weighted quantities exist they will be used (and saved) in preference to tabulated ion optical-depth-weighted values.
- Access helpers:
Use OpticalDepth_IO.ReadVariable(path) to read a specific dataset and its attributes.
OpticalDepth_IO.ReadHeader() returns header attributes and any stored global datasets.
Output And File Layout
Output path is controlled by wizard['Output']['directory'] and wizard['Output']['fname'].
Short-spectrum files contain LOS-based groups such as LOS_0/... plus Header/....
Full long-spectrum files are stored under FullSpectrum/....
OpticalDepth_IO.ReadVariable(path) can be used to load a specific dataset with metadata.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file specwizard-0.9.9.2.tar.gz.
File metadata
- Download URL: specwizard-0.9.9.2.tar.gz
- Upload date:
- Size: 104.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a209c211f11292f7b5150ddc74c82af32b6d531201d20527619de626e949f101
|
|
| MD5 |
6a4f624eca64a563c228e1653b2257ba
|
|
| BLAKE2b-256 |
ae839861271fc372f52fa41e3900281811bb451325dfdbfb261d2f46cea0fbb4
|
File details
Details for the file specwizard-0.9.9.2-py3-none-any.whl.
File metadata
- Download URL: specwizard-0.9.9.2-py3-none-any.whl
- Upload date:
- Size: 110.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40818e3f285af2993a17d329d0a23e1ee1f3312371286ce31c769cfe7fe5a9af
|
|
| MD5 |
1f5cc1c2111266604520aed307b2768b
|
|
| BLAKE2b-256 |
b6c88164dae8dcf53c22277c4508c95c13502913c0a832b17c21da184d812c35
|