rubix.spectra.ssp package#

Submodules#

rubix.spectra.ssp.factory module#

rubix.spectra.ssp.factory.get_ssp_template(template: str) SSPGrid[source]#

Get the SSP template from the configuration file.

Parameters:

template (str) – The template name of the SSP template.

Returns:

The SSP template as SSPGrid.

Example

>>> from rubix.spectra.ssp.factory import get_ssp_template
>>> ssp = get_ssp_template("FSPS")
>>> ssp.age.shape

rubix.spectra.ssp.fsps_grid module#

Use python-fsps to retrieve a block of Simple Stellar Population (SSP) data adapted from ArgonneCPAC/dsps

rubix.spectra.ssp.fsps_grid.retrieve_ssp_data_from_fsps(add_neb_emission: bool = True, imf_type: int = 2, zmet=None, tage: float = 0.0, peraa: bool = True, **kwargs) SSPGrid[source]#

Use python-fsps to populate arrays and matrices of data for the default simple stellar populations (SSPs) in the shapes expected by DSPS adapted from ArgonneCPAC/dsps

Parameters:
  • add_neb_emission (bool, optional) – Argument passed to fsps.StellarPopulation. Default is True.

  • imf_type (int, optional) – Argument passed to fsps.StellarPopulation to specify the IMF type. Default is 2 and specifies Chabrier (2003). See https://dfm.io/python-fsps/current/stellarpop_api/#example for more details.

  • zmet (int, optional) – Argument passed to fsps.StellarPopulation to specify the metallicity index. Default is None.

  • tage (float, optional) – Argument passed to fsps.StellarPopulation to specify the age of the SSP. Default is 0.0.

  • peraa (bool, optional) – Argument passed to fsps.StellarPopulation to specify whether the spectrum should be returned in Lsun/Angstrom (True) or Lsun/Hz (False). Default is True.

  • kwargs (optional) – Any keyword arguments passed to the retrieve_ssp_data_from_fsps function will be passed on to fsps.StellarPopulation.

Returns:

  • ssp_lgmet (ndarray of shape (n_met, )) – Array of log10(Z) of the SSP templates where dimensionless Z is the mass fraction of elements heavier than He

  • ssp_lg_age_gyr (ndarray of shape (n_ages, )) – Array of log10(age/Gyr) of the SSP templates

  • ssp_wave (ndarray of shape (n_wave, ))

  • ssp_flux (ndarray of shape (n_met, n_ages, n_wave)) – SED of the SSP in units of Lsun/Hz/Msun

Notes

The retrieve_ssp_data_from_fsps function is just a wrapper around python-fsps without any other dependencies. This standalone function should be straightforward to modify to use python-fsps to build alternate SSP data blocks.

All DSPS functions operate on plain ndarrays, so user-supplied data storing alternate SSP models is supported. You will just need to pack your SSP data into arrays with shapes matching the shapes of the arrays returned by this function.

rubix.spectra.ssp.fsps_grid.write_fsps_data_to_disk(outname: str, file_location='/home/annalena/rubix/rubix/spectra/ssp/templates', add_neb_emission: bool = True, imf_type: int = 2, peraa: bool = True, **kwargs)[source]#

Write FSPS ssp template data to disk in HDF5 format. adapted from ArgonneCPAC/dsps

Parameters:
  • outname (str) – The name of the output file.

  • file_location (str, optional) – The location where the file will be saved. Defaults to TEMPLATE_PATH.

Returns:

None

rubix.spectra.ssp.grid module#

class rubix.spectra.ssp.grid.HDF5SSPGrid(age, metallicity, wavelength, flux)[source]#

Bases: SSPGrid

Class for SSP models stored in HDF5 format. Mainly used for custom collection of Bruzual & Charlot 2003 models and MILES models.

Example

>>> config = {
...     "name": "Bruzual & Charlot (2003)",
...     "format": "HDF5",
...     "source": "https://www.bruzual.org/bc03/",
...     "file_name": "BC03lr.h5",
...     "fields": {
...         "age": {
...             "name": "age",
...             "units": "Gyr",
...             "in_log": False
...         },
...         "metallicity": {
...             "name": "metallicity",
...             "units": "",
...             "in_log": False
...         },
...         "wavelength": {
...             "name": "wavelength",
...             "units": "Angstrom",
...             "in_log": False
...         },
...         "flux": {
...             "name": "flux",
...             "units": "Lsun/Angstrom",
...             "in_log": False
...         }
...     }
... }
>>> from rubix.spectra.ssp.grid import HDF5SSPGrid
>>> ssp = HDF5SSPGrid.from_file(config, file_location="../rubix/spectra/ssp/templates")
>>> ssp.age.shape
>>> ssp.metallicity.shape
>>> ssp.wavelength.shape
>>> ssp.flux.shape
classmethod from_file(config: dict, file_location: str) SSPGrid[source]#

Load a SSP grid from a HDF5 file.

Parameters:

config (dict) – Configuration dictionary.

Returns:

The SSP grid SSPGrid in the correct units.

class rubix.spectra.ssp.grid.SSPGrid(age, metallicity, wavelength, flux, _logger=None)[source]#

Bases: object

Base class for all SSP models.

static checkout_SSP_template(config: dict, file_location: str) str[source]#

Check if the SSP template exists on disk, if not download it from the given URL in the configuration dictionary.

Parameters:
  • config (dict) – Configuration dictionary.

  • file_location (str) – Location to save the template file.

  • Returns – The path to the file as str.

static convert_units(data: Float[Array, '...'] | Int[Array, '...'], from_units: str, to_units: str) Float[Array, '...'][source]#

Convert the units of the data from from_units to to_units.

Parameters:
  • data (array-like) – The data to convert.

  • from_units (str) – The units of the data.

  • to_units (str) – The units to convert to.

Returns:

The data converted to the new units.

classmethod from_file(config: dict, file_location: str)[source]#

Template function to load a SSP grid from a file.

Parameters:
  • config (dict) – Configuration dictionary.

  • file_location (str) – Location of the file.

Returns:

The SSP grid SSPGrid in the correct units.

get_lookup_interpolation(method: str = 'cubic', extrap: int = 0) Partial[source]#

Returns a 2D interpolation function for the SSP grid.

The function can be called with metallicity and age as arguments to get the flux at that metallicity and age.

Parameters:
  • method (str) – The method to use for interpolation. Default is “cubic”.

  • extrap (float, bool or tuple) – The value to return for points outside the interpolation domain. Default is 0. See https://interpax.readthedocs.io/en/latest/_api/interpax.Interpolator2D.html#interpax.Interpolator2D

  • Returns – The 2D interpolation function Ìnterp2D`.

  • 1 (Example)

  • ----------

  • SSPGrid(...) (>>> grid =)

  • grid.get_lookup_interpolation() (>>> lookup =)

  • 0.02 (>>> metallicity =)

  • 1e9 (>>> age =)

  • lookup(metallicity (>>> flux =)

  • age)

  • 2 (Example)

  • ----------

  • plt (>>> import matplotlib.pyplot as)

  • BruzualCharlot2003 (>>> ssp =)

  • jit (>>> from jax import)

  • BruzualCharlot2003

  • ssp.wavelength (>>> wave =)

  • 0 (>>> age_index =)

  • 3 (>>> met_index =)

  • ssp.age[age_index]) (>>> target_age = ssp.age[age_index] + 0.5*(ssp.age[age_index+1] -)

  • ssp.metallicity[met_index]) (>>> target_met = ssp.metallicity[met_index] + 0.5*(ssp.metallicity[met_index+1] -)

  • ssp.get_lookup_interpolation() (>>> lookup =)

  • lookup(target_met (>>> spec_calc =)

  • target_age)

  • ssp.flux[met_index (>>> spec_true =)

  • age_index

:param : :type : ] :param >>> plt.plot(wave: :param spec_calc: :param label=’calc’): :param >>> plt.plot(wave: :param spec_true: :param label=’true’): :param >>> plt.legend(): :param >>> plt.yscale(‘log’):

keys() List[str][source]#

Returns the keys of the dataclass.

Parameters:

None

Returns:

List of keys of the dataclass.

class rubix.spectra.ssp.grid.pyPipe3DSSPGrid(age, metallicity, wavelength, flux)[source]#

Bases: SSPGrid

Class for all SSP models supported by the pyPipe3D project. See http://ifs.astroscu.unam.mx/pyPipe3D/templates/ for more information.

Example

>>> config = {
...     "name": "Mastar Charlot & Bruzual (2019)",
...     "format": "pyPipe3D",
...     "source": "https://ifs.astroscu.unam.mx/pyPipe3D/templates/",
...     "file_name": "MaStar_CB19.slog_1_5.fits.gz",
...     "fields": {
...         "age": {
...             "name": "age",
...             "units": "Gyr",
...             "in_log": False
...         },
...         "metallicity": {
...             "name": "metallicity",
...             "units": "",
...             "in_log": False
...         },
...         "wavelength": {
...             "name": "wavelength",
...             "units": "Angstrom",
...             "in_log": False
...         },
...         "flux": {
...             "name": "flux",
...             "units": "Lsun/Angstrom",
...             "in_log": False
...         }
...     }
... }
>>> from rubix.spectra.ssp.grid import pyPipe3DSSPGrid
>>> ssp = pyPipe3DSSPGrid.from_file(config, file_location="../rubix/spectra/ssp/templates")
classmethod from_file(config: dict, file_location: str) SSPGrid[source]#

Load a SSP grid from a fits file in pyPipe3D format.

Parameters:
  • config (dict) – Configuration dictionary.

  • file_location (str) – Location of the file.

Returns:

The SSP grid SSPGrid in the correct units.

static get_tZ_models(header, n_models: int) Tuple[Float[Array, '...'], Float[Array, '...'], Float[Array, '...']][source]#

Reads the values of age, metallicity and mass-to-light at the normalization flux from the SSP models FITS file.

adapted from reginasar/TNG_MaNGA_mocks

Parameters:
  • header (astropy.io.fits.header.Header) – FITS header with spectral data.

  • n_models (int, number of models in the SSP grid.)

Returns:

  • array like – Ages, in Gyr, in the sequence as they appear in FITS data.

  • array like – Metallicities in the sequence as they appear in FITS data.

  • array like – Mass-to-light value at the normalization wavelength.

static get_wavelength_from_header(header, wave_axis=None) Array[source]#

Generates a wavelength array using header, a astropy.io.fits.header.Header instance, at axis wave_axis.

wavelengths = CRVAL + CDELT*([0, 1, …, NAXIS] + 1 - CRPIX)

adapted from reginasar/TNG_MaNGA_mocks

Parameters:
  • header (astropy.io.fits.header.Header) – FITS header with spectral data.

  • wave_axis (int, optional) – The axis where the wavelength information is stored in header, (CRVAL, CDELT, NAXIS, CRPIX). Defaults to 1.

  • Returns – Wavelengths array: wavelengths = CRVAL + CDELT*([0, 1, …, NAXIS] + 1 - CRPIX)

rubix.spectra.ssp.templates module#

This module contains the supported templates for the SSP grid.

Example

>>> from rubix.spectra.ssp.templates import BruzualCharlot2003
>>> BruzualCharlot2003
>>> print(BruzualCharlot2003.age)

Module contents#