Grid example

In this example we load a HDF5 (test) grid file into a corresponding Grid object, and use the inbuilt functionality to explore the grid.

[1]:
import matplotlib.pyplot as plt
import numpy as np
from unyt import angstrom

from synthesizer.grid import Grid

This object takes the location of the grids on your system (grid_dir) and the name of the grid you wish to load grid_name). Here we load a simple test grid provided with the module (hence the relative path).

[2]:
grid_dir = "../../../tests/test_grid"
grid_name = "test_grid"

grid = Grid(grid_name, grid_dir=grid_dir)
print(grid)
+-----------------------------------------------------------------------------+
|                                    GRID                                     |
+-----------------------------+-----------------------------------------------+
| Attribute                   | Value                                         |
+-----------------------------+-----------------------------------------------+
| grid_dir                    | '../../../tests/test_grid'                    |
+-----------------------------+-----------------------------------------------+
| grid_name                   | 'test_grid'                                   |
+-----------------------------+-----------------------------------------------+
| grid_ext                    | 'hdf5'                                        |
+-----------------------------+-----------------------------------------------+
| grid_filename               | '../../../tests/test_grid/test_grid.hdf5'     |
+-----------------------------+-----------------------------------------------+
| reprocessed                 | True                                          |
+-----------------------------+-----------------------------------------------+
| lines_available             | True                                          |
+-----------------------------+-----------------------------------------------+
| naxes                       | 2                                             |
+-----------------------------+-----------------------------------------------+
| has_lines                   | True                                          |
+-----------------------------+-----------------------------------------------+
| has_spectra                 | True                                          |
+-----------------------------+-----------------------------------------------+
| lines_available             | True                                          |
+-----------------------------+-----------------------------------------------+
| reprocessed                 | True                                          |
+-----------------------------+-----------------------------------------------+
| shape                       | (51, 13, 9244)                                |
+-----------------------------+-----------------------------------------------+
| available_lines             | [Al 2 1670.79A, Ar 3 7135.79A, Ar 3 7751.11A, |
|                             |  Ar 4 2853.66A, C 1 1657.91A, C 1 1992.01A,   |
|                             |  C 1 2582.90A, C 2 1334.53A, C 2 1335.66A,    |
|                             |  C 2 1335.71A, C 2 2325.40A, C 2 2326.93A,    |
|                             |  C 3 1906.68A, C 3 1908.73A, C 4 1548.19A,    |
|                             |  C 4 1550.77A, Ca 2 7291.47A, Ca 2 7323.89A,  |
|                             |  Cl 2 8578.70A, Fe 2 1.25668m, Fe 2 1.27877m, |
|                             |  Fe 2 1.29427m, Fe 2 1.32055m, Fe 2 1.32777m, |
|                             |  Fe 2 1.37181m, Fe 2 1.53348m, Fe 2 1.59948m, |
|                             |  Fe 2 1.64355m, Fe 2 1.66377m, Fe 2 1.67688m, |
|                             |  Fe 2 1.71113m, Fe 2 1.74494m, Fe 2 1.79711m, |
|                             |  Fe 2 1.80002m, Fe 2 1.80940m, Fe 2 1.89541m, |
|                             |  Fe 2 1.95361m, Fe 2 2395.63A, Fe 2 2399.24A, |
|                             |  Fe 2 2406.66A, Fe 2 2410.52A, Fe 2 2598.37A, |
|                             |  Fe 2 2607.09A, Fe 2 2611.87A, Fe 2 2613.82A, |
|                             |  Fe 2 2625.67A, Fe 2 2628.29A, Fe 2 2631.05A, |
|                             |  Fe 2 2631.32A, Fe 2 4243.97A, Fe 2 4276.84A, |
|                             |  Fe 2 4287.39A, Fe 2 4319.62A, Fe 2 4346.86A, |
|                             |  Fe 2 4352.79A, Fe 2 4358.37A, Fe 2 4359.33A, |
|                             |  Fe 2 4413.78A, Fe 2 4416.27A, Fe 2 4452.10A, |
|                             |  Fe 2 4474.90A, Fe 2 4814.54A, Fe 2 4874.50A, |
|                             |  Fe 2 4889.62A, Fe 2 4905.35A, Fe 2 4923.92A, |
|                             |  Fe 2 4947.39A, Fe 2 4973.40A, Fe 2 5005.52A, |
|                             |  Fe 2 5018.44A, Fe 2 5020.25A, Fe 2 5049.30A, |
|                             |  Fe 2 5072.41A, Fe 2 5111.64A, Fe 2 5158.01A, |
|                             |  Fe 2 5158.79A, Fe 2 5169.03A, Fe 2 5184.80A, |
|                             |  Fe 2 5261.63A, Fe 2 5273.36A, Fe 2 5284.10A, |
|                             |  Fe 2 5333.66A, Fe 2 5376.47A, Fe 2 5412.67A, |
|                             |  Fe 2 5433.15A, Fe 2 5527.36A, Fe 2 6516.08A, |
|                             |  Fe 2 7155.17A, Fe 2 7172.00A, Fe 2 7388.17A, |
|                             |  Fe 2 7452.56A, Fe 2 8616.95A, Fe 2 8891.93A, |
|                             |  Fe 2 9051.95A, Fe 2 9226.63A, Fe 2 9267.56A, |
|                             |  Fe 2 9399.04A, Fe 2 9470.94A, Fe 3 4658.05A, |
|                             |  Fe 3 4985.87A, Fe 3 5270.40A, Fe 4 2829.36A, |
|                             |  Fe 4 2835.74A, Fe 4 3094.96A, Fe 5 3891.28A, |
|                             |  Fe 6 3662.50A, Fe 6 5176.04A, Fe 7 3586.32A, |
|                             |  Fe 7 3758.92A, Fe 7 5720.71A, Fe 7 6086.97A, |
|                             |  H 1 1.00494m, H 1 1.09381m, H 1 1.28181m,    |
|                             |  H 1 1.87510m, H 1 1215.67A, H 1 2.16553m,    |
|                             |  H 1 3734.37A, H 1 3750.15A, H 1 3770.63A,    |
|                             |  H 1 3797.90A, H 1 3835.38A, H 1 3889.05A,    |
|                             |  H 1 3970.07A, H 1 4101.73A, H 1 4340.46A,    |
|                             |  H 1 4861.32A, H 1 6562.80A, H 1 9229.02A,    |
|                             |  H 1 9545.97A, He 1 1.08291m, He 1 1.08303m,  |
|                             |  He 1 3187.74A, He 1 3888.64A, He 1 5875.61A, |
|                             |  He 1 5875.64A, He 1 6678.15A, He 2 1025.27A, |
|                             |  He 2 1084.94A, He 2 1215.13A, He 2 1640.41A, |
|                             |  He 2 4685.68A, Mg 2 2795.53A, Mg 2 2802.71A, |
|                             |  Mg 5 2782.76A, Mg 6 1806.00A, Mg 7 2628.89A, |
|                             |  N 2 6548.05A, N 2 6583.45A, N 3 1749.67A,    |
|                             |  N 4 1486.50A, N 5 1238.82A, N 5 1242.80A,    |
|                             |  Ne 3 3868.76A, Ne 3 3967.47A, Ne 4 1601.45A, |
|                             |  Ne 5 3345.82A, Ne 5 3425.88A, Ni 2 1.19102m, |
|                             |  Ni 2 1.93877m, Ni 2 6666.80A, Ni 2 7377.83A, |
|                             |  Ni 2 7411.61A, O 1 1.12863m, O 1 1.12864m,   |
|                             |  O 1 1.12869m, O 1 1.12870m, O 1 1.12873m,    |
|                             |  O 1 1302.17A, O 1 1304.86A, O 1 1306.03A,    |
|                             |  O 1 1641.31A, O 1 6300.30A, O 1 6363.78A,    |
|                             |  O 1 8446.25A, O 1 8446.36A, O 1 8446.76A,    |
|                             |  O 2 3726.03A, O 2 3728.81A, O 3 1660.81A,    |
|                             |  O 3 1666.15A, O 3 2320.95A, O 3 4363.21A,    |
|                             |  O 3 4958.91A, O 3 5006.84A, O 4 1399.78A,    |
|                             |  O 4 1401.16A, O 4 1404.81A, O 4 1407.38A,    |
|                             |  O 5 1218.34A, O 6 1031.91A, O 6 1037.61A,    |
|                             |  S 2 1.02867m, S 2 1.03205m, S 2 1.03364m,    |
|                             |  S 2 4068.60A, S 2 4076.35A, S 2 6716.44A,    |
|                             |  S 2 6730.82A, S 3 9068.62A, S 3 9530.62A,    |
|                             |  Si 2 1179.59A, Si 2 1260.42A, Si 2 1264.74A, |
|                             |  Si 2 1265.00A, Si 2 1526.71A, Si 2 1533.43A, |
|                             |  Si 3 1206.50A, Si 3 1882.71A, Si 3 1892.03A, |
|                             |  Si 4 1393.75A, Si 4 1402.77A, Si 6 1.96247m, |
|                             |  Si 7 2.48071m, Si 7 2146.64A]                |
+-----------------------------+-----------------------------------------------+
| available_spectra           | [incident, linecont, nebular, transmitted,    |
|                             |  total, nebular_continuum]                    |
+-----------------------------+-----------------------------------------------+
| axes                        | [age, metallicity]                            |
+-----------------------------+-----------------------------------------------+
| lam (9244,)                 | 1.30e-04 Å -> 2.99e+11 Å (Mean: 9.73e+09 Å)   |
+-----------------------------+-----------------------------------------------+
| spectra                     | incident: ndarray                             |
|                             | linecont: ndarray                             |
|                             | nebular: ndarray                              |
|                             | transmitted: ndarray                          |
|                             | total: ndarray                                |
|                             | nebular_continuum: ndarray                    |
+-----------------------------+-----------------------------------------------+
| line_lams                   | Al 2 1670.79A: float64                        |
|                             | Ar 3 7135.79A: float64                        |
|                             | Ar 3 7751.11A: float64                        |
|                             | Ar 4 2853.66A: float64                        |
|                             | C 1 1657.91A: float64                         |
|                             | C 1 1992.01A: float64                         |
|                             | C 1 2582.90A: float64                         |
|                             | C 2 1334.53A: float64                         |
|                             | C 2 1335.66A: float64                         |
|                             | C 2 1335.71A: float64                         |
|                             | C 2 2325.40A: float64                         |
|                             | C 2 2326.93A: float64                         |
|                             | C 3 1906.68A: float64                         |
|                             | C 3 1908.73A: float64                         |
|                             | C 4 1548.19A: float64                         |
|                             | C 4 1550.77A: float64                         |
|                             | Ca 2 7291.47A: float64                        |
|                             | Ca 2 7323.89A: float64                        |
|                             | Cl 2 8578.70A: float64                        |
|                             | Fe 2 1.25668m: float64                        |
|                             | Fe 2 1.27877m: float64                        |
|                             | Fe 2 1.29427m: float64                        |
|                             | Fe 2 1.32055m: float64                        |
|                             | Fe 2 1.32777m: float64                        |
|                             | Fe 2 1.37181m: float64                        |
|                             | Fe 2 1.53348m: float64                        |
|                             | Fe 2 1.59948m: float64                        |
|                             | Fe 2 1.64355m: float64                        |
|                             | Fe 2 1.66377m: float64                        |
|                             | Fe 2 1.67688m: float64                        |
|                             | Fe 2 1.71113m: float64                        |
|                             | Fe 2 1.74494m: float64                        |
|                             | Fe 2 1.79711m: float64                        |
|                             | Fe 2 1.80002m: float64                        |
|                             | Fe 2 1.80940m: float64                        |
|                             | Fe 2 1.89541m: float64                        |
|                             | Fe 2 1.95361m: float64                        |
|                             | Fe 2 2395.63A: float64                        |
|                             | Fe 2 2399.24A: float64                        |
|                             | Fe 2 2406.66A: float64                        |
|                             | Fe 2 2410.52A: float64                        |
|                             | Fe 2 2598.37A: float64                        |
|                             | Fe 2 2607.09A: float64                        |
|                             | Fe 2 2611.87A: float64                        |
|                             | Fe 2 2613.82A: float64                        |
|                             | Fe 2 2625.67A: float64                        |
|                             | Fe 2 2628.29A: float64                        |
|                             | Fe 2 2631.05A: float64                        |
|                             | Fe 2 2631.32A: float64                        |
|                             | Fe 2 4243.97A: float64                        |
|                             | Fe 2 4276.84A: float64                        |
|                             | Fe 2 4287.39A: float64                        |
|                             | Fe 2 4319.62A: float64                        |
|                             | Fe 2 4346.86A: float64                        |
|                             | Fe 2 4352.79A: float64                        |
|                             | Fe 2 4358.37A: float64                        |
|                             | Fe 2 4359.33A: float64                        |
|                             | Fe 2 4413.78A: float64                        |
|                             | Fe 2 4416.27A: float64                        |
|                             | Fe 2 4452.10A: float64                        |
|                             | Fe 2 4474.90A: float64                        |
|                             | Fe 2 4814.54A: float64                        |
|                             | Fe 2 4874.50A: float64                        |
|                             | Fe 2 4889.62A: float64                        |
|                             | Fe 2 4905.35A: float64                        |
|                             | Fe 2 4923.92A: float64                        |
|                             | Fe 2 4947.39A: float64                        |
|                             | Fe 2 4973.40A: float64                        |
|                             | Fe 2 5005.52A: float64                        |
|                             | Fe 2 5018.44A: float64                        |
|                             | Fe 2 5020.25A: float64                        |
|                             | Fe 2 5049.30A: float64                        |
|                             | Fe 2 5072.41A: float64                        |
|                             | Fe 2 5111.64A: float64                        |
|                             | Fe 2 5158.01A: float64                        |
|                             | Fe 2 5158.79A: float64                        |
|                             | Fe 2 5169.03A: float64                        |
|                             | Fe 2 5184.80A: float64                        |
|                             | Fe 2 5261.63A: float64                        |
|                             | Fe 2 5273.36A: float64                        |
|                             | Fe 2 5284.10A: float64                        |
|                             | Fe 2 5333.66A: float64                        |
|                             | Fe 2 5376.47A: float64                        |
|                             | Fe 2 5412.67A: float64                        |
|                             | Fe 2 5433.15A: float64                        |
|                             | Fe 2 5527.36A: float64                        |
|                             | Fe 2 6516.08A: float64                        |
|                             | Fe 2 7155.17A: float64                        |
|                             | Fe 2 7172.00A: float64                        |
|                             | Fe 2 7388.17A: float64                        |
|                             | Fe 2 7452.56A: float64                        |
|                             | Fe 2 8616.95A: float64                        |
|                             | Fe 2 8891.93A: float64                        |
|                             | Fe 2 9051.95A: float64                        |
|                             | Fe 2 9226.63A: float64                        |
|                             | Fe 2 9267.56A: float64                        |
|                             | Fe 2 9399.04A: float64                        |
|                             | Fe 2 9470.94A: float64                        |
|                             | Fe 3 4658.05A: float64                        |
|                             | Fe 3 4985.87A: float64                        |
|                             | Fe 3 5270.40A: float64                        |
|                             | Fe 4 2829.36A: float64                        |
|                             | Fe 4 2835.74A: float64                        |
|                             | Fe 4 3094.96A: float64                        |
|                             | Fe 5 3891.28A: float64                        |
|                             | Fe 6 3662.50A: float64                        |
|                             | Fe 6 5176.04A: float64                        |
|                             | Fe 7 3586.32A: float64                        |
|                             | Fe 7 3758.92A: float64                        |
|                             | Fe 7 5720.71A: float64                        |
|                             | Fe 7 6086.97A: float64                        |
|                             | H 1 1.00494m: float64                         |
|                             | H 1 1.09381m: float64                         |
|                             | H 1 1.28181m: float64                         |
|                             | H 1 1.87510m: float64                         |
|                             | H 1 1215.67A: float64                         |
|                             | H 1 2.16553m: float64                         |
|                             | H 1 3734.37A: float64                         |
|                             | H 1 3750.15A: float64                         |
|                             | H 1 3770.63A: float64                         |
|                             | H 1 3797.90A: float64                         |
|                             | H 1 3835.38A: float64                         |
|                             | H 1 3889.05A: float64                         |
|                             | H 1 3970.07A: float64                         |
|                             | H 1 4101.73A: float64                         |
|                             | H 1 4340.46A: float64                         |
|                             | H 1 4861.32A: float64                         |
|                             | H 1 6562.80A: float64                         |
|                             | H 1 9229.02A: float64                         |
|                             | H 1 9545.97A: float64                         |
|                             | He 1 1.08291m: float64                        |
|                             | He 1 1.08303m: float64                        |
|                             | He 1 3187.74A: float64                        |
|                             | He 1 3888.64A: float64                        |
|                             | He 1 5875.61A: float64                        |
|                             | He 1 5875.64A: float64                        |
|                             | He 1 6678.15A: float64                        |
|                             | He 2 1025.27A: float64                        |
|                             | He 2 1084.94A: float64                        |
|                             | He 2 1215.13A: float64                        |
|                             | He 2 1640.41A: float64                        |
|                             | He 2 4685.68A: float64                        |
|                             | Mg 2 2795.53A: float64                        |
|                             | Mg 2 2802.71A: float64                        |
|                             | Mg 5 2782.76A: float64                        |
|                             | Mg 6 1806.00A: float64                        |
|                             | Mg 7 2628.89A: float64                        |
|                             | N 2 6548.05A: float64                         |
|                             | N 2 6583.45A: float64                         |
|                             | N 3 1749.67A: float64                         |
|                             | N 4 1486.50A: float64                         |
|                             | N 5 1238.82A: float64                         |
|                             | N 5 1242.80A: float64                         |
|                             | Ne 3 3868.76A: float64                        |
|                             | Ne 3 3967.47A: float64                        |
|                             | Ne 4 1601.45A: float64                        |
|                             | Ne 5 3345.82A: float64                        |
|                             | Ne 5 3425.88A: float64                        |
|                             | Ni 2 1.19102m: float64                        |
|                             | Ni 2 1.93877m: float64                        |
|                             | Ni 2 6666.80A: float64                        |
|                             | Ni 2 7377.83A: float64                        |
|                             | Ni 2 7411.61A: float64                        |
|                             | O 1 1.12863m: float64                         |
|                             | O 1 1.12864m: float64                         |
|                             | O 1 1.12869m: float64                         |
|                             | O 1 1.12870m: float64                         |
|                             | O 1 1.12873m: float64                         |
|                             | O 1 1302.17A: float64                         |
|                             | O 1 1304.86A: float64                         |
|                             | O 1 1306.03A: float64                         |
|                             | O 1 1641.31A: float64                         |
|                             | O 1 6300.30A: float64                         |
|                             | O 1 6363.78A: float64                         |
|                             | O 1 8446.25A: float64                         |
|                             | O 1 8446.36A: float64                         |
|                             | O 1 8446.76A: float64                         |
|                             | O 2 3726.03A: float64                         |
|                             | O 2 3728.81A: float64                         |
|                             | O 3 1660.81A: float64                         |
|                             | O 3 1666.15A: float64                         |
|                             | O 3 2320.95A: float64                         |
|                             | O 3 4363.21A: float64                         |
|                             | O 3 4958.91A: float64                         |
|                             | O 3 5006.84A: float64                         |
|                             | O 4 1399.78A: float64                         |
|                             | O 4 1401.16A: float64                         |
|                             | O 4 1404.81A: float64                         |
|                             | O 4 1407.38A: float64                         |
|                             | O 5 1218.34A: float64                         |
|                             | O 6 1031.91A: float64                         |
|                             | O 6 1037.61A: float64                         |
|                             | S 2 1.02867m: float64                         |
|                             | S 2 1.03205m: float64                         |
|                             | S 2 1.03364m: float64                         |
|                             | S 2 4068.60A: float64                         |
|                             | S 2 4076.35A: float64                         |
|                             | S 2 6716.44A: float64                         |
|                             | S 2 6730.82A: float64                         |
|                             | S 3 9068.62A: float64                         |
|                             | S 3 9530.62A: float64                         |
|                             | Si 2 1179.59A: float64                        |
|                             | Si 2 1260.42A: float64                        |
|                             | Si 2 1264.74A: float64                        |
|                             | Si 2 1265.00A: float64                        |
|                             | Si 2 1526.71A: float64                        |
|                             | Si 2 1533.43A: float64                        |
|                             | Si 3 1206.50A: float64                        |
|                             | Si 3 1882.71A: float64                        |
|                             | Si 3 1892.03A: float64                        |
|                             | Si 4 1393.75A: float64                        |
|                             | Si 4 1402.77A: float64                        |
|                             | Si 6 1.96247m: float64                        |
|                             | Si 7 2.48071m: float64                        |
|                             | Si 7 2146.64A: float64                        |
+-----------------------------+-----------------------------------------------+
| line_lums                   | incident: dict                                |
|                             | linecont: dict                                |
|                             | nebular: dict                                 |
|                             | transmitted: dict                             |
|                             | total: dict                                   |
|                             | nebular_continuum: dict                       |
+-----------------------------+-----------------------------------------------+
| line_conts                  | incident: dict                                |
|                             | linecont: dict                                |
|                             | nebular: dict                                 |
|                             | transmitted: dict                             |
|                             | total: dict                                   |
|                             | nebular_continuum: dict                       |
+-----------------------------+-----------------------------------------------+
| parameters                  | CMB: str                                      |
|                             | T_floor: int64                                |
|                             | abundance_scalings_carbon: str                |
|                             | abundance_scalings_nitrogen: str              |
|                             | alpha: float64                                |
|                             | axes: ndarray                                 |
|                             | axes_alternative: ndarray                     |
|                             | cloudy_version: str                           |
|                             | constant_density: bool                        |
|                             | cosmic_rays: bool                             |
|                             | depletion_model: str                          |
|                             | depletion_scale: float64                      |
|                             | geometry: str                                 |
|                             | grains: str                                   |
|                             | hydrogen_density: float64                     |
|                             | incident_axes: ndarray                        |
|                             | ionisation_parameter_model: str               |
|                             | iterate_to_convergence: bool                  |
|                             | log10age: ndarray                             |
|                             | metallicity: ndarray                          |
|                             | output_cont: bool                             |
|                             | output_linelist: str                          |
|                             | parameter_file: str                           |
|                             | radius: float64                               |
|                             | reference_abundance: str                      |
|                             | reference_ionisation_parameter: float64       |
|                             | reference_log10age: float64                   |
|                             | reference_log10age_index: int64               |
|                             | reference_metallicity: float64                |
|                             | reference_metallicity_index: int64            |
|                             | resolution: float64                           |
|                             | stop_T: int64                                 |
|                             | stop_efrac: int64                             |
|                             | turbulence: int64                             |
|                             | z: float64                                    |
+-----------------------------+-----------------------------------------------+
| log10_specific_ionising_lum | HI: ndarray                                   |
|                             | HeII: ndarray                                 |
+-----------------------------+-----------------------------------------------+

A Grid can also take various arguments to limit the size of the grid, e.g. by isolating the Grid to a wavelength region of interest. This is particularly useful when making a large number of spectra from a high resolution Grid, where the memory footprint can become large.

Passing a wavelength array

If you only care about a grid of specific wavelength values, you can pass this array and the Grid will automatically be interpolated onto the new wavelength array using spectres:

[3]:
# Define a new set of wavelengths
new_lams = np.logspace(2, 5, 1000) * angstrom

# Create a new grid
grid = Grid(grid_name, grid_dir=grid_dir, new_lam=new_lams)
print(grid.shape)
(51, 13, 1000)

Passing wavelength limits

If you don’t want to modify the underlying grid resolution, but only care about a specific wavelength range, you can pass limits to truncate the grid at:

[4]:
# Create a new grid
grid = Grid(
    grid_name, grid_dir=grid_dir, lam_lims=(10**3 * angstrom, 10**4 * angstrom)
)
print(grid.shape)
(51, 13, 691)

Plot a single grid point

We can plot the spectra at the location of a single point in our grid. First, we choose some age and metallicity

[5]:
# Return to the unmodified grid
grid = Grid(grid_name, grid_dir=grid_dir)

log10age = 6.0  # log10(age/yr)
Z = 0.01  # metallicity

We then get the index location of that grid point for this age and metallicity

[6]:
grid_point = grid.get_grid_point(log10ages=log10age, metallicity=Z)

We can then loop over the available spectra (contained in grid.spec_names) and plot

[7]:
for spectra_id in grid.available_spectra:
    # Get `Sed` object
    sed = grid.get_spectra(grid_point, spectra_id=spectra_id)

    # Mask zero valued elements
    mask = sed.lnu > 0
    plt.plot(
        np.log10(sed.lam[mask]),
        np.log10(sed.lnu[mask]),
        lw=1,
        alpha=0.8,
        label=spectra_id,
    )

plt.legend(fontsize=8, labelspacing=0.0)
plt.xlabel(r"$\rm log_{10}(\lambda/\AA)$")
plt.ylabel(r"$\rm log_{10}(L_{\nu}/erg\ s^{-1}\ Hz^{-1} M_{\odot}^{-1})$")
[7]:
Text(0, 0.5, '$\\rm log_{10}(L_{\\nu}/erg\\ s^{-1}\\ Hz^{-1} M_{\\odot}^{-1})$')
../_images/grids_grids_example_13_1.png

Plot ionising luminosities

We can also plot properties over the entire age and metallicity grid, such as the ionising luminosity.

In the examples below we plot ionising luminosities for HI and HeII

[8]:
fig, ax = grid.plot_specific_ionising_lum(ion="HI")
../_images/grids_grids_example_15_0.png
[9]:
fig, ax = grid.plot_specific_ionising_lum(ion="HeII")
../_images/grids_grids_example_16_0.png

Resampling Grids

If you want to resample a grid after instantiation, you can apply the intrep_spectra method:

[10]:
# Define a new set of wavelengths
new_lams = np.logspace(2, 5, 10000) * angstrom

print("The old grid had dimensions:", grid.spectra["incident"].shape)

# Get the grid interpolated onto the new wavelength array
grid.interp_spectra(new_lam=new_lams)

print("The interpolated grid has dimensions:", grid.spectra["incident"].shape)
The old grid had dimensions: (51, 13, 9244)
The interpolated grid has dimensions: (51, 13, 10000)

Note that this will overwrite the spectra and wavelengths read from the file in place. To get back to the original arrays, a separate Grid can be instatiated without the modified wavelength array.

Converting a Grid into an Sed

Any of the spectra arrays stored within a Grid can be returned as Sed objects (see the Sed docs). This enables all of the analysis methods provide on an Sed to be used on the whole spectra grid. To do this we simply call get_sed with the spectra type we want to extract, and then use any of the included methods.

[11]:
# Get the sed object
sed = grid.get_sed(spectra_type="incident")

# Measure the balmer break for all spectra in the grid (limiting the output)
sed.measure_balmer_break()[5:10, 5:10]
[11]:
array([[0.99095578, 1.00851607, 1.00394175, 0.99979438, 0.94348793],
       [1.01696748, 1.01627346, 1.0026636 , 0.97766383, 0.97755911],
       [1.04712358, 1.03816692, 1.02788439, 1.0014771 , 0.9827252 ],
       [1.12597668, 1.08081315, 1.05479005, 1.02042145, 1.01481675],
       [1.09623435, 1.06834097, 1.05297887, 1.04633496, 1.03886266]])