Note
Go to the end to download the full example code.
Generating Lines from a Parametric Galaxy¶
In this example we’re going to generate emission line predictions for a parametric galaxy.
+-------------------------------------------------------------------------------+
| GALAXY |
+---------------+---------------------------------------------------------------+
| Attribute | Value |
+---------------+---------------------------------------------------------------+
| galaxy_type | 'Parametric' |
+---------------+---------------------------------------------------------------+
| stars | <synthesizer.parametric.stars.Stars object at 0x7f42983632e0> |
+---------------+---------------------------------------------------------------+
| name | 'parametric galaxy' |
+---------------+---------------------------------------------------------------+
| sfzh (51, 13) | 0.00e+00 -> 5.84e+07 (Mean: 4.77e+05) |
+---------------+---------------------------------------------------------------+
+-----------------------------------------------------------------------------------------------+
| LINECOLLECTION |
+-------------------------+---------------------------------------------------------------------+
| Attribute | Value |
+-------------------------+---------------------------------------------------------------------+
| nlines | 5 |
+-------------------------+---------------------------------------------------------------------+
| ndim | 1 |
+-------------------------+---------------------------------------------------------------------+
| nlam | 5 |
+-------------------------+---------------------------------------------------------------------+
| shape | (5,) |
+-------------------------+---------------------------------------------------------------------+
| available_ratios | [R3, ] |
+-------------------------+---------------------------------------------------------------------+
| elements | [H, O, O, O, O] |
+-------------------------+---------------------------------------------------------------------+
| line_ids (5,) | [H 1 4861.32A, O 3 4958.91A, O 3 5006.84A, ...] |
+-------------------------+---------------------------------------------------------------------+
| lam (5,) | 4.86e+03 Å -> 5.01e+03 Å (Mean: 4.96e+03 Å) |
+-------------------------+---------------------------------------------------------------------+
| luminosity (5,) | 3.61e+41 erg/s -> 1.47e+42 erg/s (Mean: 8.58e+41 erg/s) |
+-------------------------+---------------------------------------------------------------------+
| continuum (5,) | 2.04e+27 erg/(Hz*s) -> 2.10e+27 erg/(Hz*s) (Mean: 2.09e+27 erg) |
+-------------------------+---------------------------------------------------------------------+
| cont (5,) | 2.04e+27 erg/(Hz*s) -> 2.10e+27 erg/(Hz*s) (Mean: 2.09e+27 erg) |
+-------------------------+---------------------------------------------------------------------+
| continuum_llam (5,) | 2.51e+38 erg/(s*Å) -> 2.59e+38 erg/(s*Å) (Mean: 2.54e+38 erg/(s*Å)) |
+-------------------------+---------------------------------------------------------------------+
| energy (5,) | 2.48e+00 eV -> 2.55e+00 eV (Mean: 2.50e+00 eV) |
+-------------------------+---------------------------------------------------------------------+
| equivalent_width (5,) | 1.39e+03 Å -> 5.86e+03 Å (Mean: 3.40e+03 Å) |
+-------------------------+---------------------------------------------------------------------+
| lum (5,) | 3.61e+41 erg/s -> 1.47e+42 erg/s (Mean: 8.58e+41 erg/s) |
+-------------------------+---------------------------------------------------------------------+
| nu (5,) | 5.99e+14 Hz -> 6.17e+14 Hz (Mean: 6.05e+14 Hz) |
+-------------------------+---------------------------------------------------------------------+
| vacuum_wavelengths (5,) | 4.86e+03 Å -> 5.01e+03 Å (Mean: 4.96e+03 Å) |
+-------------------------+---------------------------------------------------------------------+
+-------------------------------------------------------------------------------+
| GALAXY |
+---------------+---------------------------------------------------------------+
| Attribute | Value |
+---------------+---------------------------------------------------------------+
| galaxy_type | 'Parametric' |
+---------------+---------------------------------------------------------------+
| stars | <synthesizer.parametric.stars.Stars object at 0x7f42983632e0> |
+---------------+---------------------------------------------------------------+
| name | 'parametric galaxy' |
+---------------+---------------------------------------------------------------+
| sfzh (51, 13) | 0.00e+00 -> 5.84e+07 (Mean: 4.77e+05) |
+---------------+---------------------------------------------------------------+
+-----------------------------------------------------------------------------------------------+
| LINECOLLECTION |
+-------------------------+---------------------------------------------------------------------+
| Attribute | Value |
+-------------------------+---------------------------------------------------------------------+
| nlines | 5 |
+-------------------------+---------------------------------------------------------------------+
| ndim | 1 |
+-------------------------+---------------------------------------------------------------------+
| nlam | 5 |
+-------------------------+---------------------------------------------------------------------+
| shape | (5,) |
+-------------------------+---------------------------------------------------------------------+
| available_ratios | [R3, ] |
+-------------------------+---------------------------------------------------------------------+
| elements | [H, O, O, O, O] |
+-------------------------+---------------------------------------------------------------------+
| line_ids (5,) | [H 1 4861.32A, O 3 4958.91A, O 3 5006.84A, ...] |
+-------------------------+---------------------------------------------------------------------+
| lam (5,) | 4.86e+03 Å -> 5.01e+03 Å (Mean: 4.96e+03 Å) |
+-------------------------+---------------------------------------------------------------------+
| luminosity (5,) | 1.17e+41 erg/s -> 4.91e+41 erg/s (Mean: 2.85e+41 erg/s) |
+-------------------------+---------------------------------------------------------------------+
| continuum (5,) | 6.59e+26 erg/(Hz*s) -> 7.00e+26 erg/(Hz*s) (Mean: 6.88e+26 erg) |
+-------------------------+---------------------------------------------------------------------+
| cont (5,) | 6.59e+26 erg/(Hz*s) -> 7.00e+26 erg/(Hz*s) (Mean: 6.88e+26 erg) |
+-------------------------+---------------------------------------------------------------------+
| continuum_llam (5,) | 8.37e+37 erg/(s*Å) -> 8.41e+37 erg/(s*Å) (Mean: 8.39e+37 erg/(s*Å)) |
+-------------------------+---------------------------------------------------------------------+
| energy (5,) | 2.48e+00 eV -> 2.55e+00 eV (Mean: 2.50e+00 eV) |
+-------------------------+---------------------------------------------------------------------+
| equivalent_width (5,) | 1.39e+03 Å -> 5.86e+03 Å (Mean: 3.40e+03 Å) |
+-------------------------+---------------------------------------------------------------------+
| lum (5,) | 1.17e+41 erg/s -> 4.91e+41 erg/s (Mean: 2.85e+41 erg/s) |
+-------------------------+---------------------------------------------------------------------+
| nu (5,) | 5.99e+14 Hz -> 6.17e+14 Hz (Mean: 6.05e+14 Hz) |
+-------------------------+---------------------------------------------------------------------+
| vacuum_wavelengths (5,) | 4.86e+03 Å -> 5.01e+03 Å (Mean: 4.96e+03 Å) |
+-------------------------+---------------------------------------------------------------------+
from unyt import Msun, Myr
from synthesizer.emission_models import AttenuatedEmission, NebularEmission
from synthesizer.emission_models.attenuation import PowerLaw
from synthesizer.emissions import O3, Hb, O3b, O3r
from synthesizer.grid import Grid
from synthesizer.parametric import SFH, Stars, ZDist
from synthesizer.parametric.galaxy import Galaxy
if __name__ == "__main__":
# Begin by defining and initialising the grid.
grid_name = "test_grid"
grid_dir = "../../tests/test_grid/"
grid = Grid(grid_name, grid_dir=grid_dir)
# Define the emission model
nebular = NebularEmission(grid)
# Let's now build a galaxy following the other tutorials:
# Define the functional form of the star formation and metal
# enrichment histories
# Constant star formation
sfh = SFH.Constant(max_age=100 * Myr)
# Constant metallicity
metal_dist = ZDist.DeltaConstant(log10metallicity=-2.0)
# Get the 2D star formation and metal enrichment history
# for the given SPS grid. This is (age, Z).
stars = Stars(
grid.log10age,
grid.metallicity,
sf_hist=sfh,
metal_dist=metal_dist,
initial_mass=10**8.5 * Msun,
)
# Create the Galaxy object
galaxy = Galaxy(stars)
# Print a summary of the Galaxy object
print(galaxy)
# Let's define a list of lines that we're interested in. To do this we'll
# first extract some line ratios from the `line_ratios` module, and then
# Extract the individual lines from each ratio
line_ids = [
Hb, # "H 1 4861.32A"
O3b, # "O 3 4958.91A"
O3r, # "O 3 5006.84A"
O3, # ["O 3 4958.91A", "O 3 5006.84A"]
]
line_ids = [lid.strip() for lids in line_ids for lid in lids.split(",")]
# Next, let's get the intrinsic line properties:
lines = galaxy.stars.get_lines(line_ids, nebular)
# This produces a LineCollection object which has some useful methods and
# information.
print(lines)
# Those lines are now associated with the `Galaxy` object, revealed by
# using the print function:
print(galaxy)
# Next, lets get the attenuated line properties:
model = AttenuatedEmission(
emitter="stellar",
tau_v=1.0,
dust_curve=PowerLaw(slope=-1),
apply_to=nebular,
)
lines_att = galaxy.stars.get_lines(
line_ids,
model,
)
print(lines_att)
Total running time of the script: (0 minutes 0.136 seconds)