Welcome to spectacle’s documentation!¶
Version: | 0.1 |
---|
For generating spectra from cosmological simulations. Uses Schwimmbad for flexible parallelisation.
Grid Generation¶
Any SPS model can be used to generate an age-metallicity grid. We provide scripts for generating grids for the following:
For BC03 and BPASS you need to download the original spectra from the respective home pages.
For FSPS you can simply run the script as-is. You will need python-FSPS, astropy and numpy installed.
cd grids
python grid_fsps.py
This will generate two grids, one including the nebular contribution from young stars and one without (See Byler+17 for details on how the nebular contribution is calculated self-consistently in FSPS).
Generating Spectra¶
We provide a number of example scripts in the example
directory that demonstrate how to run Spectacle to generate spectra. To get started, first download some example data from the Illustris API:
python download_illustris.py
The main component of spectacle is the spectacle
class, which must be instantiated with the location of the hdf5 file containing the particle data:
tacle = spectacle.spectacle(fname='example_data.h5')
We can then load a grid as so:
grid = tacle.load_grid(name='fsps_neb')
grid = tacle.redshift_grid(grid,tacle.redshift)
The most expensive part of the spectra generation is calculating the grid weights. We use the schwimmbad
pool syntax to do this flexibly in parallel (we discuss the parallelisation in more detail in FlexPara_). The partial
syntax allows us to specify additional arguments to the pool, such as the age and metallicty grid values, and whether we wish to resample. It’s then simply a case of calling pool.map
and converting the output to an array, before closing the pool.
lg = partial(tacle.weights_grid, Z=grid['metallicity'],
A=grid['age'][tacle.redshift], resample=True)
weights = np.array(list(pool.map(lg,shids)))
pool.close()
Now we have our weights we can use these to directly calculate the intrinsic spectra
intrinsic_spectra = tacle.calc_intrinsic_spectra(weights,grid,z=tacle.redshift)
There are also a number of functions available for applying a dust-screen, using the subhalo properties of each galaxy.
Flexible Parallelisation¶
Thanks to schwimmbad
we have a lot of flexibility in the form of parallelisation we wish to perform. The example script contains a nice example from the schwimmbad docs using command line arguments to select between these, shown below for completeness. The main
code block then runs agnostic to the chocie of paralleisation (threaded, MPI, etc.).
if __name__ == '__main__':
from argparse import ArgumentParser
parser = ArgumentParser(description="Schwimmbad example.")
group = parser.add_mutually_exclusive_group()
group.add_argument("--ncores", dest="n_cores", default=1,
type=int, help="Number of processes (uses multiprocessing).")
group.add_argument("--mpi", dest="mpi", default=False,
action="store_true", help="Run with MPI.")
args = parser.parse_args()
pool = schwimmbad.choose_pool(mpi=args.mpi, processes=args.n_cores)
print(pool)
main(pool)
print("All done. Spec-tacular!")
File Format¶
The HDF5 file containing all data can have a flexible format depending on what the user wishes to achieve, but for most of the spectacle
class functionality the following layout is expected:
- Spectra
- Intrinsic
- Dust
- Photometry
- Intrinsic
- M_g
- M_r
- Dust
- M_g
- M_r
- Star Particles
- Formation Time
- Initial Mass
- Metallicity
- Subhalos
- Gas Metallicity
- ID
- Index Length
- Index Start
- SFR
- SFR 100Myr
- SFR 10Myr
- SFR 1Gyr
- SFR 500Myr
- SFR 50Myr
- Star Forming Gas Mass
- Stellar Mass
- Stellar Mass 30kpc
- Stellar Metallicity
- Stellar Metallicity 30kpc
License & Attribution¶
Copyright 2019 Christopher Lovell and contributors.
spectacle is free software made available under the MIT License. For details see the LICENSE.