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 0x7f1af2b89600> |
+---------------+---------------------------------------------------------------+
| name          | 'parametric galaxy'                                           |
+---------------+---------------------------------------------------------------+
| sfzh (51, 13) | 0.00e+00 -> 5.84e+07 (Mean: 4.77e+05)                         |
+---------------+---------------------------------------------------------------+
+----------------------------------------------------------------------------------------------+
|                                        LINECOLLECTION                                        |
+------------------+---------------------------------------------------------------------------+
| Attribute        | Value                                                                     |
+------------------+---------------------------------------------------------------------------+
| nlines           | 5                                                                         |
+------------------+---------------------------------------------------------------------------+
| available_ratios | [R3, ]                                                                    |
+------------------+---------------------------------------------------------------------------+
| line_ids (5,)    | [H 1 4861.32A, O 3 4958.91A,O 3 5006.84A,H 1 4861.32A, O 3 4958.91A, ...] |
+------------------+---------------------------------------------------------------------------+
| wavelengths (5,) | 4.86e+03 Å -> 5.01e+03 Å (Mean: 4.95e+03 Å)                               |
+------------------+---------------------------------------------------------------------------+
| lines            | H 1 4861.32A: Line                                                        |
|                  | O 3 4958.91A: Line                                                        |
|                  | O 3 5006.84A: Line                                                        |
|                  | O 3 4958.91A,O 3 5006.84A: Line                                           |
|                  | O 3 4958.91A,O 3 5006.84A,H 1 4861.32A: Line                              |
+------------------+---------------------------------------------------------------------------+
+------------------------------------------------------+
|                         LINE                         |
+-------------------+----------------------------------+
| Attribute         | Value                            |
+-------------------+----------------------------------+
| id                | 'H 1 4861.32A'                   |
+-------------------+----------------------------------+
| individual_lines  | [Line, ]                         |
+-------------------+----------------------------------+
| element           | [H, ]                            |
+-------------------+----------------------------------+
| wavelength        | 4861.32 Å                        |
+-------------------+----------------------------------+
| luminosity        | 0.0 erg/s                        |
+-------------------+----------------------------------+
| continuum         | 2.706355892290555e+28 erg/(Hz*s) |
+-------------------+----------------------------------+
| vacuum_wavelength | 4862.677992404623 Å              |
+-------------------+----------------------------------+
| continuum_llam    | 3.433184871890094e+39 erg/(s*Å)  |
+-------------------+----------------------------------+
| equivalent_width  | 0.0 Å                            |
+-------------------+----------------------------------+
+----------------------------------------------------------------+
|                              LINE                              |
+-------------------+--------------------------------------------+
| Attribute         | Value                                      |
+-------------------+--------------------------------------------+
| id                | 'O 3 4958.91A, O 3 5006.84A, H 1 4861.32A' |
+-------------------+--------------------------------------------+
| individual_lines  | [Line, Line, Line]                         |
+-------------------+--------------------------------------------+
| element           | [O, O, H]                                  |
+-------------------+--------------------------------------------+
| wavelength        | 4942.356666666667 Å                        |
+-------------------+--------------------------------------------+
| luminosity        | 0.0 erg/s                                  |
+-------------------+--------------------------------------------+
| continuum         | 9.048229650578058e+28 erg/(Hz*s)           |
+-------------------+--------------------------------------------+
| vacuum_wavelength | 4943.736171021297 Å                        |
+-------------------+--------------------------------------------+
| continuum_llam    | 1.110493833575809e+40 erg/(s*Å)            |
+-------------------+--------------------------------------------+
| equivalent_width  | 0.0 Å                                      |
+-------------------+--------------------------------------------+
+-------------------------------------------------------+
|                         LINE                          |
+-------------------+-----------------------------------+
| Attribute         | Value                             |
+-------------------+-----------------------------------+
| id                | 'O 3 4958.91A'                    |
+-------------------+-----------------------------------+
| individual_lines  | [Line, ]                          |
+-------------------+-----------------------------------+
| element           | [O, ]                             |
+-------------------+-----------------------------------+
| wavelength        | 4958.91 Å                         |
+-------------------+-----------------------------------+
| luminosity        | 0.0 erg/s                         |
+-------------------+-----------------------------------+
| continuum         | 3.1857378180409696e+28 erg/(Hz*s) |
+-------------------+-----------------------------------+
| vacuum_wavelength | 4960.293901181077 Å               |
+-------------------+-----------------------------------+
| continuum_llam    | 3.883812734837866e+39 erg/(s*Å)   |
+-------------------+-----------------------------------+
| equivalent_width  | 0.0 Å                             |
+-------------------+-----------------------------------+
+------------------------------------------------------+
|                         LINE                         |
+-------------------+----------------------------------+
| Attribute         | Value                            |
+-------------------+----------------------------------+
| id                | 'O 3 4958.91A, O 3 5006.84A'     |
+-------------------+----------------------------------+
| individual_lines  | [Line, Line]                     |
+-------------------+----------------------------------+
| element           | [O, O]                           |
+-------------------+----------------------------------+
| wavelength        | 4982.875 Å                       |
+-------------------+----------------------------------+
| luminosity        | 0.0 erg/s                        |
+-------------------+----------------------------------+
| continuum         | 6.341873758287503e+28 erg/(Hz*s) |
+-------------------+----------------------------------+
| vacuum_wavelength | 4984.265268174917 Å              |
+-------------------+----------------------------------+
| continuum_llam    | 7.657346688645555e+39 erg/(s*Å)  |
+-------------------+----------------------------------+
| equivalent_width  | 0.0 Å                            |
+-------------------+----------------------------------+
+-------------------------------------------------------+
|                         LINE                          |
+-------------------+-----------------------------------+
| Attribute         | Value                             |
+-------------------+-----------------------------------+
| id                | 'O 3 5006.84A'                    |
+-------------------+-----------------------------------+
| individual_lines  | [Line, ]                          |
+-------------------+-----------------------------------+
| element           | [O, ]                             |
+-------------------+-----------------------------------+
| wavelength        | 5006.84 Å                         |
+-------------------+-----------------------------------+
| luminosity        | 0.0 erg/s                         |
+-------------------+-----------------------------------+
| continuum         | 3.1561359402465332e+28 erg/(Hz*s) |
+-------------------+-----------------------------------+
| vacuum_wavelength | 5008.23663693076 Å                |
+-------------------+-----------------------------------+
| continuum_llam    | 3.7744091582577183e+39 erg/(s*Å)  |
+-------------------+-----------------------------------+
| equivalent_width  | 0.0 Å                             |
+-------------------+-----------------------------------+
+-------------------------------------------------------------------------------+
|                                    GALAXY                                     |
+---------------+---------------------------------------------------------------+
| Attribute     | Value                                                         |
+---------------+---------------------------------------------------------------+
| galaxy_type   | 'Parametric'                                                  |
+---------------+---------------------------------------------------------------+
| stars         | <synthesizer.parametric.stars.Stars object at 0x7f1af2b89600> |
+---------------+---------------------------------------------------------------+
| name          | 'parametric galaxy'                                           |
+---------------+---------------------------------------------------------------+
| sfzh (51, 13) | 0.00e+00 -> 5.84e+07 (Mean: 4.77e+05)                         |
+---------------+---------------------------------------------------------------+
+----------------------------------------------------------------------------------------------+
|                                        LINECOLLECTION                                        |
+------------------+---------------------------------------------------------------------------+
| Attribute        | Value                                                                     |
+------------------+---------------------------------------------------------------------------+
| nlines           | 5                                                                         |
+------------------+---------------------------------------------------------------------------+
| available_ratios | [R3, ]                                                                    |
+------------------+---------------------------------------------------------------------------+
| line_ids (5,)    | [H 1 4861.32A, O 3 4958.91A,O 3 5006.84A,H 1 4861.32A, O 3 4958.91A, ...] |
+------------------+---------------------------------------------------------------------------+
| wavelengths (5,) | 4.86e+03 Å -> 5.01e+03 Å (Mean: 4.95e+03 Å)                               |
+------------------+---------------------------------------------------------------------------+
| lines            | H 1 4861.32A: Line                                                        |
|                  | O 3 4958.91A: Line                                                        |
|                  | O 3 5006.84A: Line                                                        |
|                  | O 3 4958.91A,O 3 5006.84A: Line                                           |
|                  | O 3 4958.91A,O 3 5006.84A,H 1 4861.32A: Line                              |
+------------------+---------------------------------------------------------------------------+

from unyt import Msun, Myr

import synthesizer.line_ratios as line_ratios
from synthesizer.emission_models import AttenuatedEmission, IncidentEmission
from synthesizer.emission_models.attenuation import PowerLaw
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
    incident = IncidentEmission(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. Note that we can
    # provide multiples which are automatically summed as if they were blended.
    line_ids = [
        line_ratios.Hb,  # "H 1 4861.32A"
        line_ratios.O3b,  # "O 3 4958.91A"
        line_ratios.O3r,  # "O 3 5006.84A"
        line_ratios.O3,  # ["O 3 4958.91A", "O 3 5006.84A"]
        line_ratios.O3
        + ","
        + line_ratios.Hb,  # ["O 3 4958.91A", "O 3 5006.84A", "H 1 4861.32A"]
    ]

    # Next, let's get the intrinsic line properties:
    lines = galaxy.stars.get_lines(line_ids, incident)

    # This produces a LineCollection object which has some useful methods and
    # information.
    print(lines)

    # Let's now examine individual lines (or doublets):
    for line in lines:
        print(line)

    # 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_dust_to=incident,
    )

    lines_att = galaxy.stars.get_lines(
        line_ids,
        model,
    )
    print(lines_att)

Total running time of the script: (0 minutes 0.356 seconds)

Gallery generated by Sphinx-Gallery