Lines from Galaxy
objects¶
To generate lines from components of a Galaxy
(i.e. parametric or particle based stars or black holes) Synthesizer provides get_lines
methods on component and galaxy objects. These methods are analogous to those on a grid, and return a LineCollection
containing the requested lines (which can either be singular, doublets, triplets, or more).
[1]:
from unyt import Msun, Myr, kelvin
from synthesizer import TEST_DATA_DIR
from synthesizer.emission_models import BimodalPacmanEmission
from synthesizer.emission_models.attenuation import PowerLaw
from synthesizer.emission_models.dust.emission import Blackbody
from synthesizer.emissions.utils import O2, O3, Hb, O3b, O3r
from synthesizer.grid import Grid
from synthesizer.parametric import SFH, Stars, ZDist
# Get a grid
grid_name = "test_grid"
grid = Grid(grid_name)
# Make a parametric galaxy
stellar_mass = 10**12 * Msun
sfh = SFH.Constant(max_age=100 * Myr)
metal_dist = ZDist.Normal(mean=0.01, sigma=0.05)
stars = Stars(
grid.log10age,
grid.metallicity,
sf_hist=sfh,
metal_dist=metal_dist,
initial_mass=stellar_mass,
)
# Set up the emission model
model = BimodalPacmanEmission(
grid=grid,
tau_v_ism=0.5,
tau_v_birth=0.7,
dust_curve_ism=PowerLaw(slope=-1.3),
dust_curve_birth=PowerLaw(slope=-0.7),
dust_emission_ism=Blackbody(temperature=100 * kelvin),
dust_emission_birth=Blackbody(temperature=30 * kelvin),
fesc=0.2,
fesc_ly_alpha=0.9,
)
# To get the dust emission at a line we need to first run the
# spectra generation
stars.get_spectra(model)
# Get the lines
lines = stars.get_lines((Hb, O3r, O3b), model)
print(stars.lines["emergent"])
+--------------------------------------------------------------------------------+
| LINECOLLECTION |
+--------------------+-----------------------------------------------------------+
| Attribute | Value |
+--------------------+-----------------------------------------------------------+
| nlines | 3 |
+--------------------+-----------------------------------------------------------+
| ndim | 1 |
+--------------------+-----------------------------------------------------------+
| nlam | 3 |
+--------------------+-----------------------------------------------------------+
| shape | (3,) |
+--------------------+-----------------------------------------------------------+
| available_ratios | [R3, ] |
+--------------------+-----------------------------------------------------------+
| elements | [H, O, O] |
+--------------------+-----------------------------------------------------------+
| line_ids | ['H 1 4861.32A' 'O 3 5006.84A' 'O 3 4958.91A'] |
+--------------------+-----------------------------------------------------------+
| lam | [4861.32 5006.84 4958.91] Å |
+--------------------+-----------------------------------------------------------+
| luminosity | [2.41350821e+44 8.44537141e+44 2.79460058e+44] erg/s |
+--------------------+-----------------------------------------------------------+
| continuum | [4.52160792e+31 5.45418895e+31 5.47515517e+31] erg/(Hz*s) |
+--------------------+-----------------------------------------------------------+
| cont | [4.52160792e+31 5.45418895e+31 5.47515517e+31] erg/(Hz*s) |
+--------------------+-----------------------------------------------------------+
| continuum_llam | [5.73594772e+42 6.52264070e+42 6.67489875e+42] erg/(s*Å) |
+--------------------+-----------------------------------------------------------+
| energy | [2.55042238 2.47629629 2.50023076] eV |
+--------------------+-----------------------------------------------------------+
| equivalent_width | [ 42.0768864 129.47779589 41.86731037] Å |
+--------------------+-----------------------------------------------------------+
| lum | [2.41350821e+44 8.44537141e+44 2.79460058e+44] erg/s |
+--------------------+-----------------------------------------------------------+
| nu | [6.16689414e+14 5.98765804e+14 6.04553134e+14] Hz |
+--------------------+-----------------------------------------------------------+
| vacuum_wavelengths | [4862.6779924 5008.23663693 4960.29390118] Å |
+--------------------+-----------------------------------------------------------+
/opt/hostedtoolcache/Python/3.10.17/x64/lib/python3.10/site-packages/unyt/array.py:1832: RuntimeWarning: overflow encountered in exp
out_arr = func(np.asarray(inp), out=out_func, **kwargs)
/opt/hostedtoolcache/Python/3.10.17/x64/lib/python3.10/site-packages/unyt/array.py:1972: RuntimeWarning: overflow encountered in multiply
out_arr = func(
In the case of a particle based galaxy you can either get the integrated line emission or per-particle line emission (by using a per particle model) with get_lines
method.
[2]:
from synthesizer.emission_models import PacmanEmission
from synthesizer.load_data.load_camels import load_CAMELS_IllustrisTNG
# Get the stars from a particle based galaxy
stars = load_CAMELS_IllustrisTNG(
TEST_DATA_DIR,
snap_name="camels_snap.hdf5",
group_name="camels_subhalo.hdf5",
physical=True,
)[0].stars
# Set up the emission model
model = PacmanEmission(
grid=grid,
tau_v=0.7,
dust_curve=PowerLaw(slope=-1.3),
dust_emission=Blackbody(temperature=50 * kelvin),
fesc=0.5,
fesc_ly_alpha=1.0,
per_particle=True,
)
# Get the spectra and lines
print(stars.nstars)
stars.get_spectra(model)
stars.get_lines((Hb, O3r, O3b, O2, O3), model)
print(stars.lines["emergent"])
print(stars.particle_lines["emergent"])
/opt/hostedtoolcache/Python/3.10.17/x64/lib/python3.10/site-packages/unyt/array.py:1972: RuntimeWarning: invalid value encountered in divide
out_arr = func(
278
+-----------------------------------------------------------------------------------------------+
| LINECOLLECTION |
+-------------------------+---------------------------------------------------------------------+
| Attribute | Value |
+-------------------------+---------------------------------------------------------------------+
| nlines | 5 |
+-------------------------+---------------------------------------------------------------------+
| ndim | 1 |
+-------------------------+---------------------------------------------------------------------+
| nlam | 5 |
+-------------------------+---------------------------------------------------------------------+
| shape | (5,) |
+-------------------------+---------------------------------------------------------------------+
| available_ratios | [R2, R3, O32] |
+-------------------------+---------------------------------------------------------------------+
| elements | [H, O, O, O, O, O, O] |
+-------------------------+---------------------------------------------------------------------+
| line_ids (5,) | [H 1 4861.32A, O 3 5006.84A, O 3 4958.91A, ...] |
+-------------------------+---------------------------------------------------------------------+
| lam (5,) | 3.73e+03 Å -> 5.01e+03 Å (Mean: 4.71e+03 Å) |
+-------------------------+---------------------------------------------------------------------+
| luminosity (5,) | 6.95e+32 erg/s -> 2.64e+37 erg/s (Mean: 5.51e+36 erg/s) |
+-------------------------+---------------------------------------------------------------------+
| continuum (5,) | 4.33e+27 erg/(Hz*s) -> 1.27e+28 erg/(Hz*s) (Mean: 7.02e+27 erg) |
+-------------------------+---------------------------------------------------------------------+
| cont (5,) | 4.33e+27 erg/(Hz*s) -> 1.27e+28 erg/(Hz*s) (Mean: 7.02e+27 erg) |
+-------------------------+---------------------------------------------------------------------+
| continuum_llam (5,) | 6.89e+38 erg/(s*Å) -> 1.53e+39 erg/(s*Å) (Mean: 9.37e+38 erg/(s*Å)) |
+-------------------------+---------------------------------------------------------------------+
| energy (5,) | 2.48e+00 eV -> 3.33e+00 eV (Mean: 2.67e+00 eV) |
+-------------------------+---------------------------------------------------------------------+
| equivalent_width (5,) | 8.90e-07 Å -> 3.83e-02 Å (Mean: 7.91e-03 Å) |
+-------------------------+---------------------------------------------------------------------+
| lum (5,) | 6.95e+32 erg/s -> 2.64e+37 erg/s (Mean: 5.51e+36 erg/s) |
+-------------------------+---------------------------------------------------------------------+
| nu (5,) | 5.99e+14 Hz -> 8.04e+14 Hz (Mean: 6.45e+14 Hz) |
+-------------------------+---------------------------------------------------------------------+
| vacuum_wavelengths (5,) | 3.73e+03 Å -> 5.01e+03 Å (Mean: 4.71e+03 Å) |
+-------------------------+---------------------------------------------------------------------+
+-------------------------------------------------------------------------------------------------+
| LINECOLLECTION |
+---------------------------+---------------------------------------------------------------------+
| Attribute | Value |
+---------------------------+---------------------------------------------------------------------+
| nlines | 5 |
+---------------------------+---------------------------------------------------------------------+
| ndim | 2 |
+---------------------------+---------------------------------------------------------------------+
| nlam | 5 |
+---------------------------+---------------------------------------------------------------------+
| shape | (278, 5) |
+---------------------------+---------------------------------------------------------------------+
| available_ratios | [R2, R3, O32] |
+---------------------------+---------------------------------------------------------------------+
| elements | [H, O, O, O, O, O, O] |
+---------------------------+---------------------------------------------------------------------+
| line_ids (5,) | [H 1 4861.32A, O 3 5006.84A, O 3 4958.91A, ...] |
+---------------------------+---------------------------------------------------------------------+
| lam (5,) | 3.73e+03 Å -> 5.01e+03 Å (Mean: 4.71e+03 Å) |
+---------------------------+---------------------------------------------------------------------+
| luminosity (278, 5) | 2.37e+27 erg/s -> 9.77e+35 erg/s (Mean: 1.98e+34 erg/s) |
+---------------------------+---------------------------------------------------------------------+
| continuum (278, 5) | 5.20e+24 erg/(Hz*s) -> 2.39e+26 erg/(Hz*s) (Mean: 2.53e+25 erg) |
+---------------------------+---------------------------------------------------------------------+
| cont (278, 5) | 5.20e+24 erg/(Hz*s) -> 2.39e+26 erg/(Hz*s) (Mean: 2.53e+25 erg) |
+---------------------------+---------------------------------------------------------------------+
| continuum_llam (278, 5) | 7.54e+35 erg/(s*Å) -> 2.89e+37 erg/(s*Å) (Mean: 3.37e+36 erg/(s*Å)) |
+---------------------------+---------------------------------------------------------------------+
| energy (5,) | 2.48e+00 eV -> 3.33e+00 eV (Mean: 2.67e+00 eV) |
+---------------------------+---------------------------------------------------------------------+
| equivalent_width (278, 5) | 1.30e-09 Å -> 9.40e-02 Å (Mean: 7.40e-03 Å) |
+---------------------------+---------------------------------------------------------------------+
| lum (278, 5) | 2.37e+27 erg/s -> 9.77e+35 erg/s (Mean: 1.98e+34 erg/s) |
+---------------------------+---------------------------------------------------------------------+
| nu (5,) | 5.99e+14 Hz -> 8.04e+14 Hz (Mean: 6.45e+14 Hz) |
+---------------------------+---------------------------------------------------------------------+
| vacuum_wavelengths (5,) | 3.73e+03 Å -> 5.01e+03 Å (Mean: 4.71e+03 Å) |
+---------------------------+---------------------------------------------------------------------+
/opt/hostedtoolcache/Python/3.10.17/x64/lib/python3.10/site-packages/unyt/array.py:1832: RuntimeWarning: overflow encountered in exp
out_arr = func(np.asarray(inp), out=out_func, **kwargs)
/opt/hostedtoolcache/Python/3.10.17/x64/lib/python3.10/site-packages/unyt/array.py:1972: RuntimeWarning: overflow encountered in multiply
out_arr = func(
The line luminosities themselves are extracted and stored in the "nebular"
key of the lines dictionaries. Below we plot the line luminosities and continuum luminosities to compare the different emissions.
Note that we have skipped any lines with little or no contribution.
[3]:
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.grid(True)
ax.set_axisbelow(True)
# Get the colours
colors = {}
for ind, key in enumerate(stars.lines):
colors[key] = plt.cm.tab10(ind)
for key in stars.lines:
# Don't plot dust emission since it's effectively 0
# for these lines
if key == "dust_emission":
continue
ax.semilogy(
stars.lines[key].lam,
stars.lines[key].continuum,
color=colors[key],
marker="+",
linestyle="None",
)
ax.set_xlabel("Wavelength (Angstrom)")
ax.set_ylabel("Continuum (erg/s/Hz)")
# Create the legend
legend_handles = []
for key in stars.lines:
# Don't plot dust emission since it's effectively 0
# for these lines
if key == "dust_emission":
continue
legend_handles.append(
plt.Line2D(
[0],
[0],
color=colors[key],
label=key,
marker="+",
linestyle="None",
)
)
ax.legend(
handles=legend_handles,
loc="upper center",
bbox_to_anchor=(0.5, -0.15),
ncol=3,
)
plt.show()
fig = plt.figure()
ax = fig.add_subplot(111)
ax.grid(True)
ax.set_axisbelow(True)
# Get the colours
colors = {}
for ind, key in enumerate(stars.lines):
colors[key] = plt.cm.tab10(ind)
for key in stars.lines:
ax.semilogy(
stars.lines[key].lam,
stars.lines[key].luminosity,
color=colors[key],
marker="+",
linestyle="None",
)
ax.set_xlabel("Wavelength (Angstrom)")
ax.set_ylabel("Luminosity (erg/s)")
# Create the legend
legend_handles = []
for key in stars.lines:
# Skip all spectra types where lines are 0
if stars.lines[key].luminosity.sum() == 0:
continue
legend_handles.append(
plt.Line2D(
[0],
[0],
color=colors[key],
label=key,
marker="+",
linestyle="None",
)
)
ax.legend(
handles=legend_handles,
loc="upper center",
bbox_to_anchor=(0.5, -0.15),
ncol=3,
)
plt.show()

