/fake_spectra

A code for generating fake spectra from a cosmological simulation

Primary LanguageC++MIT LicenseMIT

= Flux extractor =

This is a small code for generating and analyzing simulated spectra from
Arepo/Gadget HDF5 simulation output. It is fast, parallel and written in C++ and Python 3.
It really has two parts: 
1) a C++/python 3 code which generates and analyses arbitrary spectra
2) A (slightly) maintained C++ command line program, extract, that generates 
Lyman-alpha spectra and outputs them to a binary file.

If you are reading these instructions, I will assume you are using the first part:
the second program is for compatibility with older spectral extraction codes, 
of which this is a rewrite, and so anyone who wants it should already know 
how to use it.

== Installation ==

*This is a python 3 code*
*Make sure you install the python 3 libraries!*

Required Python libraries:
- numpy (core functionality)
- h5py (for saving)

Optional libraries:
- matplotlib (if you want to plot)
- bigfile (to install, do 'pip install --user bigfile') for reading BigFile snapshot outputs from Yu Feng's MP-Gadget.

All these libraries can be installed with pip.

The easiest way to install the code is with pip:

pip3 install --user fake_spectra

If you need to use a pre-release version for any reason, you need this git repo.

First you need to check out the submodules:

git submodule update --init

Then compile it using:

python3 setup.py build
python3 setup.py install --user

On some systems you may have to add the directory it installs to
(usually $HOME/.local/lib) to your $PYTHONPATH

At time of writing, the code should compile with python2, once 
python3-config in the Makefile is replaced with python2-config. 
However, I do not guarantee bug-free operation, and strongly 
recommend using python 3.

The test suite for the C++ module (only required during development)
requires Boost::Test and can be used with "make test"

== Usage ==
The main spectral generation routines are used can be called with:

import fake_spectra.spectra
spectra.Spectra(...)

However, this requires you to specify the positions of each sightline.
I have created a number of convenient wrappers for common configurations.
Two of these are:

randspectra.py - Generate spectra at random locations. Can optionally discard spectra that
do not meet an HI column density threshold.
halospectra.py - Generate spectra through the center of halos.

Spectral generation routines take two arguments, base and num, which
specify where they should look for snapshot output. They will search:
$(base)/snapdir_$(num)/snap_$(num).hdf5
Note that num is padded with zeros to three characters, so passing '40' will result in '040'.

Column densities can be generated for arbitrary ions with the method get_col_density(elem, ion)
For neutral gas, pass ion 1. For the sum of all ionic species, pass ion -1.

Optical depths can be generated for arbitrary lines with the method get_tau(elem, ion, line)
Line data is loaded from a copy of atom.dat taken from VPFIT.

Thus, to generate randomly positioned Lyman-series spectra and associated HI column densities, 
one would use this script:

from fake_spectra.randspectra import RandSpectra

rr = RandSpectra(5, "MySim", thresh=0.)
rr.get_tau("H",1,1215)
#Lyman-beta
rr.get_tau("H",1,1025)
rr.get_col_density("H",1)
#Save spectra to file
rr.save_file()

Note that the wavelength of the transition always rounds down,
so lyman alpha at 1215.67 A is 1215, not 1216!

Generated spectra will be saved into HDF5 files, for ease of later analysis.
Each spectral generation routine saves spectra to a differently named file.

To load them again, use the PlottingSpectra routines:

from fake_spectra.plot_spectra import PlottingSpectra

ps = PlottingSpectra(5,"MySim", savefile="mysavefile.hdf5")
ps.plot_cddf("H",1)

You can also compute the temperature-density relation and mean IGM temperature with the tempdens module:

from fake_spectra.tempdens import fit_td_rel_plot

fit_td_rel_plot(5, "MySim", plot=True)