Load supported SSP templates#
This notebook shows how to load and use the supported SSP templates. Currently we have support for custom build SSP templates stored in hdf5 format for which we provide a template based on Bruzual&Charlot2003 models. Additionally we support all SSP templates that the pyPipe3D project uses. Those templates come in astronomy friendly fits file format.
# NBVAL_SKIP
import os
os.environ['SPS_HOME'] = '/home/annalena/sps_fsps'
# NBVAL_SKIP
import os
os.environ['SPS_HOME'] = '/home/annalena/sps_fsps'
# NBVAL_SKIP
from rubix.spectra.ssp.templates import BruzualCharlot2003
BruzualCharlot2003
# NBVAL_SKIP
print(BruzualCharlot2003.age)
Load SSP template via custom config#
This shows how to use a custom configuration to load an SSP template that is stored under some file location on your disk.
# NBVAL_SKIP
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
}
}
}
# NBVAL_SKIP
from rubix.spectra.ssp.grid import HDF5SSPGrid
ssp = HDF5SSPGrid.from_file(config, file_location="../../rubix/spectra/ssp/templates")
ssp
# NBVAL_SKIP
ssp.age.shape
# NBVAL_SKIP
ssp.metallicity.shape
# NBVAL_SKIP
ssp.wavelength.shape
# NBVAL_SKIP
ssp.flux.shape
Let’s plot some example spectra#
# NBVAL_SKIP
import matplotlib.pyplot as plt
import numpy as np
# NBVAL_SKIP
plt.plot(ssp.wavelength,ssp.flux[0][0])
plt.xlabel(r'$\lambda$ [%s]'%config["fields"]["wavelength"]["units"])
plt.ylabel(r'Flux [%s]'%config["fields"]["flux"]["units"])
#plt.yscale("log")
# NBVAL_SKIP
plt.plot(ssp.wavelength,ssp.flux[-1][-1])
plt.xlabel(r'$\lambda$ [%s]'%config["fields"]["wavelength"]["units"])
plt.ylabel(r'Flux [%s]'%config["fields"]["flux"]["units"])
#plt.yscale("log")
# NBVAL_SKIP
for i in range(len(ssp.metallicity)):
plt.plot(ssp.wavelength,ssp.flux[i][0], label=r'Z=%0.3f'%ssp.metallicity[i])
plt.xlabel(r'$\lambda$ [%s]'%config["fields"]["wavelength"]["units"])
plt.ylabel(r'Flux [%s]'%config["fields"]["flux"]["units"])
#plt.yscale("log")
plt.xlim(0,10000)
plt.legend()
# NBVAL_SKIP
ages = np.linspace(0,len(ssp.age),10)
for age in ages:
plt.plot(ssp.wavelength,ssp.flux[0][int(age)], label='%.2f %s'%(ssp.age[int(age)], config["fields"]["age"]["units"]))
plt.xlabel(r'$\lambda$ [%s]'%config["fields"]["wavelength"]["units"])
plt.ylabel(r'Flux [%s]'%config["fields"]["flux"]["units"])
#plt.yscale("log")
plt.xlim(0,5000)
plt.legend()
Automatic download supported SSP template#
Rubix supports automatic download of a supported SSP template from a specified url in case the template can’t be found on disk under the file_location specified.
# NBVAL_SKIP
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
}
}
}
# NBVAL_SKIP
from rubix.spectra.ssp.grid import pyPipe3DSSPGrid
ssp = pyPipe3DSSPGrid.from_file(config, file_location="../../rubix/spectra/ssp/templates")
ssp
# NBVAL_SKIP
ssp.age.shape
# NBVAL_SKIP
ssp.metallicity.shape
# NBVAL_SKIP
ssp.wavelength.shape
# NBVAL_SKIP
ssp.flux.shape
Lets plot some example spectra#
Example for Mastar templates
# NBVAL_SKIP
import matplotlib.pyplot as plt
import numpy as np
# NBVAL_SKIP
plt.plot(ssp.wavelength,ssp.flux[0][0])
plt.xlabel(r'$\lambda$ [%s]'%config["fields"]["wavelength"]["units"])
plt.ylabel(r'Flux [%s]'%config["fields"]["flux"]["units"])
#plt.yscale("log")
# NBVAL_SKIP
plt.plot(ssp.wavelength,ssp.flux[-1][-1])
plt.xlabel(r'$\lambda$ [%s]'%config["fields"]["wavelength"]["units"])
plt.ylabel(r'Flux [%s]'%config["fields"]["flux"]["units"])
#plt.yscale("log")
# NBVAL_SKIP
for i in range(len(ssp.metallicity)):
plt.plot(ssp.wavelength,ssp.flux[i][0], label=r'Z=%0.3f'%ssp.metallicity[i])
plt.xlabel(r'$\lambda$ [%s]'%config["fields"]["wavelength"]["units"])
plt.ylabel(r'Flux [%s]'%config["fields"]["flux"]["units"])
#plt.yscale("log")
plt.xlim(2000,10000)
plt.legend()
# NBVAL_SKIP
ages = np.linspace(0,len(ssp.age),10)
for age in ages:
plt.plot(ssp.wavelength,ssp.flux[0][int(age)], label='%.2f %s'%(ssp.age[int(age)], config["fields"]["age"]["units"]))
plt.xlabel(r'$\lambda$ [%s]'%config["fields"]["wavelength"]["units"])
plt.ylabel(r'Flux [%s]'%config["fields"]["flux"]["units"])
#plt.yscale("log")
plt.xlim(2000,5000)
plt.legend()