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, Blackbody
from synthesizer.emission_models.attenuation import PowerLaw
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.log10ages,
grid.metallicities,
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 |
+--------------------+----------------------------------------------------------------------------------------------------+
| line2index | mappingproxy({np.str_('H 1 4861.32A'): 0, np.str_('O 3 5006.84A'): 1, np.str_('O 3 4958.91A'): 2}) |
+--------------------+----------------------------------------------------------------------------------------------------+
| ndim | 1 |
+--------------------+----------------------------------------------------------------------------------------------------+
| nlam | 3 |
+--------------------+----------------------------------------------------------------------------------------------------+
| shape | (3,) |
+--------------------+----------------------------------------------------------------------------------------------------+
| _available_ratios | [R3, ] |
+--------------------+----------------------------------------------------------------------------------------------------+
| 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.94210452e+44 9.97502265e+44 3.30099425e+44] erg/s |
+--------------------+----------------------------------------------------------------------------------------------------+
| continuum | [4.54450984e+31 5.47502918e+31 5.49657117e+31] erg/(Hz*s) |
+--------------------+----------------------------------------------------------------------------------------------------+
| cont | [4.54450984e+31 5.47502918e+31 5.49657117e+31] erg/(Hz*s) |
+--------------------+----------------------------------------------------------------------------------------------------+
| continuum_llam | [5.76500027e+42 6.54756343e+42 6.70100753e+42] erg/(s*Å) |
+--------------------+----------------------------------------------------------------------------------------------------+
| energy | [2.55042238 2.47629629 2.50023076] eV |
+--------------------+----------------------------------------------------------------------------------------------------+
| equivalent_width | [ 51.03390074 152.34709446 49.26116315] Å |
+--------------------+----------------------------------------------------------------------------------------------------+
| lum | [2.94210452e+44 9.97502265e+44 3.30099425e+44] erg/s |
+--------------------+----------------------------------------------------------------------------------------------------+
| nu | [6.16689414e+14 5.98765804e+14 6.04553134e+14] Hz |
+--------------------+----------------------------------------------------------------------------------------------------+
| vacuum_wavelengths | [4862.6779924 5008.23663693 4960.29390118] Å |
+--------------------+----------------------------------------------------------------------------------------------------+
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 Blackbody, 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"])
278
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| LINECOLLECTION |
+-------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Attribute | Value |
+-------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| nlines | 5 |
+-------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| line2index | mappingproxy({np.str_('H 1 4861.32A'): 0, np.str_('O 3 5006.84A'): 1, np.str_('O 3 4958.91A'): 2, np.str_('O 2 3726.03A, O 2 3728.81A'): 3, np.str_('O 3 4958.91A, O 3 5006.84A'): 4}) |
+-------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ndim | 1 |
+-------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| nlam | 5 |
+-------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| shape | (5,) |
+-------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| _available_ratios | [R2, R3, R23, O32] |
+-------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| available_ratios | [R2, R3, R23, 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,) | 2.05e+35 erg/s -> 9.66e+37 erg/s (Mean: 2.52e+37 erg/s) |
+-------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| continuum (5,) | 4.33e+27 erg/(Hz*s) -> 1.27e+28 erg/(Hz*s) (Mean: 7.02e+27 erg/(Hz*s)) |
+-------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| cont (5,) | 4.33e+27 erg/(Hz*s) -> 1.27e+28 erg/(Hz*s) (Mean: 7.02e+27 erg/(Hz*s)) |
+-------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| continuum_llam (5,) | 6.89e+38 erg/(s*Å) -> 1.53e+39 erg/(s*Å) (Mean: 9.36e+38 erg/(s*Å)) |
+-------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| energy (5,) | 2.48e+00 eV -> 3.33e+00 eV (Mean: 2.67e+00 eV) |
+-------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| equivalent_width (5,) | 2.63e-04 Å -> 1.03e-01 Å (Mean: 2.91e-02 Å) |
+-------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| lum (5,) | 2.05e+35 erg/s -> 9.66e+37 erg/s (Mean: 2.52e+37 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 |
+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| line2index | mappingproxy({np.str_('H 1 4861.32A'): 0, np.str_('O 3 5006.84A'): 1, np.str_('O 3 4958.91A'): 2, np.str_('O 2 3726.03A, O 2 3728.81A'): 3, np.str_('O 3 4958.91A, O 3 5006.84A'): 4}) |
+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ndim | 2 |
+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| nlam | 5 |
+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| shape | (278, 5) |
+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| _available_ratios | [R2, R3, R23, O32] |
+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| available_ratios | [R2, R3, R23, 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) | 3.92e+28 erg/s -> 4.35e+36 erg/s (Mean: 9.08e+34 erg/s) |
+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| continuum (278, 5) | 5.20e+24 erg/(Hz*s) -> 2.39e+26 erg/(Hz*s) (Mean: 2.52e+25 erg/(Hz*s)) |
+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| cont (278, 5) | 5.20e+24 erg/(Hz*s) -> 2.39e+26 erg/(Hz*s) (Mean: 2.52e+25 erg/(Hz*s)) |
+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 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) | 2.51e-08 Å -> 2.36e-01 Å (Mean: 2.64e-02 Å) |
+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| lum (278, 5) | 3.92e+28 erg/s -> 4.35e+36 erg/s (Mean: 9.08e+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 Å) |
+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
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()
Printing Used Parameters¶
During line generation, emission models cache the parameters they extract and use from the emitter. These cached parameters can be printed in a nicely formatted table to inspect which values were actually used by each model.
[4]:
# Print the cached parameters used by the models
stars.print_used_parameters()
+----------------------------------------------------------------------------------+
| MODEL: _NEBULAR_LINE_NO_FESC |
+---------------------------+------------------------------------------------------+
| Attribute | Value |
+---------------------------+------------------------------------------------------+
| extract | 'linecont' |
+---------------------------+------------------------------------------------------+
| emitter | 'stellar' |
+---------------------------+------------------------------------------------------+
| log10ages (278,) | 8.76e+00 -> 1.01e+01 (Mean: 9.75e+00) |
+---------------------------+------------------------------------------------------+
| log10metallicities (278,) | -5.00e+00 -> -1.67e+00 (Mean: -2.15e+00) |
+---------------------------+------------------------------------------------------+
| initial_masses (278,) | 1.02e+07 Msun -> 3.76e+07 Msun (Mean: 2.33e+07 Msun) |
+---------------------------+------------------------------------------------------+
+----------------------------------------------------------------------------------+
| MODEL: NEBULAR_CONTINUUM |
+---------------------------+------------------------------------------------------+
| Attribute | Value |
+---------------------------+------------------------------------------------------+
| extract | 'nebular_continuum' |
+---------------------------+------------------------------------------------------+
| emitter | 'stellar' |
+---------------------------+------------------------------------------------------+
| log10ages (278,) | 8.76e+00 -> 1.01e+01 (Mean: 9.75e+00) |
+---------------------------+------------------------------------------------------+
| log10metallicities (278,) | -5.00e+00 -> -1.67e+00 (Mean: -2.15e+00) |
+---------------------------+------------------------------------------------------+
| initial_masses (278,) | 1.02e+07 Msun -> 3.76e+07 Msun (Mean: 2.33e+07 Msun) |
+---------------------------+------------------------------------------------------+
+----------------------------------------------------------------------------------+
| MODEL: FULL_TRANSMITTED |
+---------------------------+------------------------------------------------------+
| Attribute | Value |
+---------------------------+------------------------------------------------------+
| extract | 'transmitted' |
+---------------------------+------------------------------------------------------+
| emitter | 'stellar' |
+---------------------------+------------------------------------------------------+
| log10ages (278,) | 8.76e+00 -> 1.01e+01 (Mean: 9.75e+00) |
+---------------------------+------------------------------------------------------+
| log10metallicities (278,) | -5.00e+00 -> -1.67e+00 (Mean: -2.15e+00) |
+---------------------------+------------------------------------------------------+
| initial_masses (278,) | 1.02e+07 Msun -> 3.76e+07 Msun (Mean: 2.33e+07 Msun) |
+---------------------------+------------------------------------------------------+
+----------------------------------------------------------------------------------+
| MODEL: INCIDENT |
+---------------------------+------------------------------------------------------+
| Attribute | Value |
+---------------------------+------------------------------------------------------+
| extract | 'incident' |
+---------------------------+------------------------------------------------------+
| emitter | 'stellar' |
+---------------------------+------------------------------------------------------+
| log10ages (278,) | 8.76e+00 -> 1.01e+01 (Mean: 9.75e+00) |
+---------------------------+------------------------------------------------------+
| log10metallicities (278,) | -5.00e+00 -> -1.67e+00 (Mean: -2.15e+00) |
+---------------------------+------------------------------------------------------+
| initial_masses (278,) | 1.02e+07 Msun -> 3.76e+07 Msun (Mean: 2.33e+07 Msun) |
+---------------------------+------------------------------------------------------+
+------------------------------------------------------------------+
| MODEL: NEBULAR_LINE |
+---------------+--------------------------------------------------+
| Attribute | Value |
+---------------+--------------------------------------------------+
| fesc_ly_alpha | 1.00 |
+---------------+--------------------------------------------------+
| apply_to | '_nebular_line_no_fesc' |
+---------------+--------------------------------------------------+
| transformer | "EscapedFraction(fesc_attrs=('fesc_ly_alpha',))" |
+---------------+--------------------------------------------------+
| emitter | 'stellar' |
+---------------+--------------------------------------------------+
+---------------------------------------------------------+
| MODEL: TRANSMITTED |
+-------------+-------------------------------------------+
| Attribute | Value |
+-------------+-------------------------------------------+
| fesc | 0.50 |
+-------------+-------------------------------------------+
| apply_to | 'full_transmitted' |
+-------------+-------------------------------------------+
| transformer | "ProcessedFraction(fesc_attrs=('fesc',))" |
+-------------+-------------------------------------------+
| emitter | 'stellar' |
+-------------+-------------------------------------------+
+-------------------------------------------------------+
| MODEL: ESCAPED |
+-------------+-----------------------------------------+
| Attribute | Value |
+-------------+-----------------------------------------+
| fesc | 0.50 |
+-------------+-----------------------------------------+
| apply_to | 'incident' |
+-------------+-----------------------------------------+
| transformer | "EscapedFraction(fesc_attrs=('fesc',))" |
+-------------+-----------------------------------------+
| emitter | 'stellar' |
+-------------+-----------------------------------------+
+----------------------------------------------+
| MODEL: NEBULAR |
+----------+-----------------------------------+
| Attribute | Value |
+----------+-----------------------------------+
| emitter | 'stellar' |
+----------+-----------------------------------+
| combine | [nebular_line, nebular_continuum] |
+----------+-----------------------------------+
+-----------------------------------+
| MODEL: REPROCESSED |
+----------+------------------------+
| Attribute | Value |
+----------+------------------------+
| emitter | 'stellar' |
+----------+------------------------+
| combine | [nebular, transmitted] |
+----------+------------------------+
+--------------------------------------+
| MODEL: ATTENUATED |
+-------------+------------------------+
| Attribute | Value |
+-------------+------------------------+
| tau_v | 0.70 |
+-------------+------------------------+
| apply_to | 'reprocessed' |
+-------------+------------------------+
| transformer | 'PowerLaw(slope=-1.3)' |
+-------------+------------------------+
| emitter | 'stellar' |
+-------------+------------------------+
+-----------------------------------+
| MODEL: INTRINSIC |
+----------+------------------------+
| Attribute | Value |
+----------+------------------------+
| emitter | 'stellar' |
+----------+------------------------+
| combine | [reprocessed, escaped] |
+----------+------------------------+
+---------------------------------------------------------------------------------------------+
| MODEL: DUST_EMISSION |
+-------------+-------------------------------------------------------------------------------+
| Attribute | Value |
+-------------+-------------------------------------------------------------------------------+
| generator | 'Blackbody(intrinsic=reprocessed, attenuated=attenuated, temperature=50.0 K)' |
+-------------+-------------------------------------------------------------------------------+
| emitter | 'stellar' |
+-------------+-------------------------------------------------------------------------------+
| temperature | 50.0 K |
+-------------+-------------------------------------------------------------------------------+
+----------------------------------+
| MODEL: EMERGENT |
+----------+-----------------------+
| Attribute | Value |
+----------+-----------------------+
| emitter | 'stellar' |
+----------+-----------------------+
| combine | [attenuated, escaped] |
+----------+-----------------------+
+--------------------------------------+
| MODEL: TOTAL |
+----------+---------------------------+
| Attribute | Value |
+----------+---------------------------+
| emitter | 'stellar' |
+----------+---------------------------+
| combine | [dust_emission, emergent] |
+----------+---------------------------+