Gaussian Overlap Illustration#
This notebook implements a very simple widget to illustrate that when we have two lines (with a Gaussian shape) that overlap, the peak of the resulting spectra is dependent on the distance between the line centers and relative widths and amplitudes. Thus, estimating whether the line is falling in the “correct” place or not is difficult to do unless you’re confident the line is in fact relatively well isolated (this never happens).
[1]:
import ipywidgets
import astropy.modeling
import numpy as np
import matplotlib.pyplot as plt
[2]:
a1_slider = ipywidgets.FloatSlider(
value=1.0,
min=0.0,
max=1.0,
step=0.01,
description=r'$A_1$',
readout_format='.2f',
)
a2_slider = ipywidgets.FloatSlider(
value=1.0,
min=0.0,
max=1.0,
step=0.01,
description=r'$A_2$',
readout_format='.2f',
)
m1_slider = ipywidgets.FloatSlider(
value=.25,
min=0.0,
max=1.0,
step=0.01,
description=r'$\mu_1$',
readout_format='.2f',
)
m2_slider = ipywidgets.FloatSlider(
value=.75,
min=0.0,
max=1.0,
step=0.01,
description=r'$\mu_2$',
readout_format='.2f',
)
sigma1_slider = ipywidgets.FloatSlider(
value=.1,
min=0.01,
max=1.0,
step=0.01,
description=r'$\sigma_1$',
readout_format='.2f',
)
sigma2_slider = ipywidgets.FloatSlider(
value=.1,
min=0.01,
max=1.0,
step=0.01,
description=r'$\sigma_2$',
readout_format='.2f',
)
[3]:
def plot_gaussians(a1, a2, m1, m2, sigma1, sigma2):
g1 = astropy.modeling.models.Gaussian1D(amplitude=a1, mean=m1, stddev=sigma1)
g2 = astropy.modeling.models.Gaussian1D(amplitude=a2, mean=m2, stddev=sigma2)
x = np.linspace(0,1,1000)
fig = plt.figure()
ax = fig.add_subplot()
l1, = ax.plot(x, g1(x), label=r'$g_1$')
l2, = ax.plot(x, g2(x), label=r'$g_2$')
total = g1(x)+g2(x)
l3, = ax.plot(x, total, label=r'$g_1+g_2$')
ax.axvline(x=x[np.argmax(g1(x))], color=l1.get_color(), ls='--')
ax.axvline(x=x[np.argmax(g2(x))], color=l2.get_color(), ls='--')
ax.axvline(x=x[np.argmax(total)], color=l3.get_color(), ls='--')
ax.legend()
[4]:
ipywidgets.interact(plot_gaussians, a1=a1_slider, a2=a2_slider, m1=m1_slider, m2=m2_slider, sigma1=sigma1_slider, sigma2=sigma2_slider)
[4]:
<function __main__.plot_gaussians(a1, a2, m1, m2, sigma1, sigma2)>
[ ]: