Note
Go to the end to download the full example code.
Get lines example¶
This example demonstrates how to: - get a list of lines associated with a grid - initialise a grid object with lines - get line quantities for a single grid point - ad hoc load an additional line
['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']
----------
SUMMARY OF H 1 4861.32A
wavelength: 4861.3 Å
Npart: 1
<log10(luminosity/erg/s)>: 34.52
<equivalent width>: 1193 Å
----------
----------
LINE COLLECTION
number of lines: 3
lines: ['H 1 4861.32A' 'O 3 4958.91A' 'O 3 5006.84A']
available ratios: ['R3']
available diagrams: []
----------
----------
LINE COLLECTION
number of lines: 215
lines: ['He 2 1025.27A' 'O 6 1031.91A' 'O 6 1037.61A' 'He 2 1084.94A'
'Si 2 1179.59A' 'Si 3 1206.50A' 'He 2 1215.13A' 'H 1 1215.67A'
'O 5 1218.34A' 'N 5 1238.82A' 'N 5 1242.80A' 'Si 2 1260.42A'
'Si 2 1264.74A' 'Si 2 1265.00A' 'O 1 1302.17A' 'O 1 1304.86A'
'O 1 1306.03A' 'C 2 1334.53A' 'C 2 1335.66A' 'C 2 1335.71A'
'Si 4 1393.75A' 'O 4 1399.78A' 'O 4 1401.16A' 'Si 4 1402.77A'
'O 4 1404.81A' 'O 4 1407.38A' 'N 4 1486.50A' 'Si 2 1526.71A'
'Si 2 1533.43A' 'C 4 1548.19A' 'C 4 1550.77A' 'Ne 4 1601.45A'
'He 2 1640.41A' 'O 1 1641.31A' 'C 1 1657.91A' 'O 3 1660.81A'
'O 3 1666.15A' 'Al 2 1670.79A' 'N 3 1749.67A' 'Mg 6 1806.00A'
'Si 3 1882.71A' 'Si 3 1892.03A' 'C 3 1906.68A' 'C 3 1908.73A'
'C 1 1992.01A' 'Si 7 2146.64A' 'O 3 2320.95A' 'C 2 2325.40A'
'C 2 2326.93A' 'Fe 2 2395.63A' 'Fe 2 2399.24A' 'Fe 2 2406.66A'
'Fe 2 2410.52A' 'C 1 2582.90A' 'Fe 2 2598.37A' 'Fe 2 2607.09A'
'Fe 2 2611.87A' 'Fe 2 2613.82A' 'Fe 2 2625.67A' 'Fe 2 2628.29A'
'Mg 7 2628.89A' 'Fe 2 2631.05A' 'Fe 2 2631.32A' 'Mg 5 2782.76A'
'Mg 2 2795.53A' 'Mg 2 2802.71A' 'Fe 4 2829.36A' 'Fe 4 2835.74A'
'Ar 4 2853.66A' 'Fe 4 3094.96A' 'He 1 3187.74A' 'Ne 5 3345.82A'
'Ne 5 3425.88A' 'Fe 7 3586.32A' 'Fe 6 3662.50A' 'O 2 3726.03A'
'O 2 3728.81A' 'H 1 3734.37A' 'H 1 3750.15A' 'Fe 7 3758.92A'
'H 1 3770.63A' 'H 1 3797.90A' 'H 1 3835.38A' 'Ne 3 3868.76A'
'He 1 3888.64A' 'H 1 3889.05A' 'Fe 5 3891.28A' 'Ne 3 3967.47A'
'H 1 3970.07A' 'S 2 4068.60A' 'S 2 4076.35A' 'H 1 4101.73A'
'Fe 2 4243.97A' 'Fe 2 4276.84A' 'Fe 2 4287.39A' 'Fe 2 4319.62A'
'H 1 4340.46A' 'Fe 2 4346.86A' 'Fe 2 4352.79A' 'Fe 2 4358.37A'
'Fe 2 4359.33A' 'O 3 4363.21A' 'Fe 2 4413.78A' 'Fe 2 4416.27A'
'Fe 2 4452.10A' 'Fe 2 4474.90A' 'Fe 3 4658.05A' 'He 2 4685.68A'
'Fe 2 4814.54A' 'H 1 4861.32A' 'Fe 2 4874.50A' 'Fe 2 4889.62A'
'Fe 2 4905.35A' 'Fe 2 4923.92A' 'Fe 2 4947.39A' 'O 3 4958.91A'
'Fe 2 4973.40A' 'Fe 3 4985.87A' 'Fe 2 5005.52A' 'O 3 5006.84A'
'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 6 5176.04A' 'Fe 2 5184.80A' 'Fe 2 5261.63A' 'Fe 3 5270.40A'
'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 7 5720.71A'
'He 1 5875.61A' 'He 1 5875.64A' 'Fe 7 6086.97A' 'O 1 6300.30A'
'O 1 6363.78A' 'Fe 2 6516.08A' 'N 2 6548.05A' 'H 1 6562.80A'
'N 2 6583.45A' 'Ni 2 6666.80A' 'He 1 6678.15A' 'S 2 6716.44A'
'S 2 6730.82A' 'Ar 3 7135.79A' 'Fe 2 7155.17A' 'Fe 2 7172.00A'
'Ca 2 7291.47A' 'Ca 2 7323.89A' 'Ni 2 7377.83A' 'Fe 2 7388.17A'
'Ni 2 7411.61A' 'Fe 2 7452.56A' 'Ar 3 7751.11A' 'O 1 8446.25A'
'O 1 8446.36A' 'O 1 8446.76A' 'Cl 2 8578.70A' 'Fe 2 8616.95A'
'Fe 2 8891.93A' 'Fe 2 9051.95A' 'S 3 9068.62A' 'Fe 2 9226.63A'
'H 1 9229.02A' 'Fe 2 9267.56A' 'Fe 2 9399.04A' 'Fe 2 9470.94A'
'S 3 9530.62A' 'H 1 9545.97A' 'H 1 1.00494m' 'S 2 1.02867m'
'S 2 1.03205m' 'S 2 1.03364m' 'He 1 1.08291m' 'He 1 1.08303m'
'H 1 1.09381m' 'O 1 1.12863m' 'O 1 1.12864m' 'O 1 1.12869m'
'O 1 1.12870m' 'O 1 1.12873m' 'Ni 2 1.19102m' 'Fe 2 1.25668m'
'Fe 2 1.27877m' 'H 1 1.28181m' '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'
'H 1 1.87510m' 'Fe 2 1.89541m' 'Ni 2 1.93877m' 'Fe 2 1.95361m'
'Si 6 1.96247m' 'H 1 2.16553m' 'Si 7 2.48071m']
available ratios: ['BalmerDecrement', 'N2', 'S2', 'O1', 'R2', 'R3', 'R23', 'O32', 'Ne3O2']
available diagrams: ['OHNO', 'BPT-NII']
----------
BalmerDecrement: 2.92
BalmerDecrement: 2.92
N2: 0.08
S2: 0.06
O1: 0.01
R2: 0.97
R3: 5.97
R23: 9.77
O32: 6.13
Ne3O2: 0.48
import matplotlib.pyplot as plt
from synthesizer.grid import Grid
from synthesizer.line import get_diagram_labels, get_ratio_label
if __name__ == "__main__":
# Get the location of this script, __file__ is the absolute path of this
# script, however we just want to directory
# script_path = os.path.abspath(os.path.dirname(__file__))
# Define the grid
grid_name = "test_grid"
grid_dir = "../../tests/test_grid/"
# initialise grid
grid = Grid(grid_name, grid_dir=grid_dir, read_lines=True)
# get list of lines
print(grid.available_lines)
# choose age and metallicity
log10age = 6.0 # log10(age/yr)
metallicity = 0.01 # metallicity
# get the grid point for this log10age and metallicity
grid_point = grid.get_grid_point(
log10ages=log10age,
metallicity=metallicity,
)
# get information on one line
line = grid.get_line(grid_point, "H 1 4861.32A")
print(line)
# or a combination of lines, e.g. a doublet
line = grid.get_lines(
grid_point, ["H 1 4861.32A", "O 3 4958.91A", "O 3 5006.84A"]
)
print(line)
# create a line collection from all lines
lines = grid.get_lines(grid_point, grid.available_lines)
print(lines)
# we can measure line ratios
ratio_id = "BalmerDecrement"
ratio = lines.get_ratio(ratio_id) # R23, R2, R3, ...
print(f"{ratio_id}: {ratio:.2f}")
# or loop over availalable ratios
for ratio_id in lines.available_ratios:
ratio = lines.get_ratio(ratio_id)
print(f"{ratio_id}: {ratio:.2f}")
# we can plot a ratio against metallicity by looping over the metallicity
# grid
ratio_id = "R23"
ia = 0 # 1 Myr old for test grid
ratios = []
for iZ, Z in enumerate(grid.metallicity):
grid_point = (ia, iZ)
lines = grid.get_lines(grid_point, grid.available_lines)
ratios.append(lines.get_ratio(ratio_id))
Zsun = grid.metallicity / 0.0124
plt.plot(Zsun, ratios)
plt.xlim([0.01, 1])
plt.ylim([1, 20])
plt.xscale("log")
plt.yscale("log")
plt.xlabel(r"$Z/Z_{\odot}$")
plt.ylabel(rf"${get_ratio_label(ratio_id)}$")
plt.show()
# we can also generate "diagrams" pairs of line ratios like the BPT diagram
diagram_id = "BPT-NII"
ia = 0 # 1 Myr old for test grid
x = []
y = []
for iZ, Z in enumerate(grid.metallicity):
grid_point = (ia, iZ)
lines = grid.get_lines(grid_point, grid.available_lines)
x_, y_ = lines.get_diagram(diagram_id)
x.append(x_)
y.append(y_)
plt.plot(x, y)
plt.xlim([0.01, 10])
plt.ylim([0.05, 20])
plt.xscale("log")
plt.yscale("log")
# grab x and y labels, this time use "fancy" label ids
xlabel, ylabel = get_diagram_labels(diagram_id)
plt.xlabel(rf"${xlabel}$")
plt.ylabel(rf"${ylabel}$")
plt.show()
Total running time of the script: (0 minutes 3.009 seconds)