rubix.spectra.ssp package#

Submodules#

rubix.spectra.ssp.factory module#

rubix.spectra.ssp.fsps_grid module#

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:
  • (dict) (config)

  • (str) (file_location)

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:
  • Args – 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:
  • (dict) (config)

  • (str) (file_location)

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 Interp2D.

  • 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:
  • Args – 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:
  • (dict) (config)

  • (str) (file_location)

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

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

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

  • 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#

Module contents#