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:

  • FSPS
  • BC03 (Galaxev) [see here]
  • BPASS [see here]

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:

  1. Spectra
    1. Intrinsic
    2. Dust
  2. Photometry
    1. Intrinsic
      1. M_g
      2. M_r
    2. Dust
      1. M_g
      2. M_r
  3. Star Particles
    1. Formation Time
    2. Initial Mass
    3. Metallicity
  4. Subhalos
    1. Gas Metallicity
    2. ID
    3. Index Length
    4. Index Start
    5. SFR
    6. SFR 100Myr
    7. SFR 10Myr
    8. SFR 1Gyr
    9. SFR 500Myr
    10. SFR 50Myr
    11. Star Forming Gas Mass
    12. Stellar Mass
    13. Stellar Mass 30kpc
    14. Stellar Metallicity
    15. Stellar Metallicity 30kpc

Contributors

Author:

License & Attribution

Copyright 2019 Christopher Lovell and contributors.

spectacle is free software made available under the MIT License. For details see the LICENSE.

Changelog

0.2 (26-11-2019)

  • Grids converted to HDF5.

0.1 (23-09-2019)

  • Initial release.

Indices and tables