Origin of the variance#
Many sources contribute to the variance of an observation (detector noise, photon noise, etc.).
slicersim lets you study their respective contributions: you can switch off any of them
when generating a spectrum, and see how much the variance decreases.
List of the variance sources#
The core slicersim.Simulation object (on which the Lazuli targets are built) holds the list
of implemented contributions:
import slicersim
slicersim.Simulation.VARIANCE_SOURCES
['dark',
'roic_glow',
'thermal_dark',
'ron',
'pointsource',
'background',
'host',
'thermal']
import numpy as np
import matplotlib.pyplot as plt
Switch off the readout noise (ron)#
To illustrate this, let us generate a supernova spectrum while switching off the detector readout noise contribution.
# load a type Ia supernova
lazuli_snia = slicersim.LazuliSupernova(redshift=1.2)
# set the detector to a single long ramp (64 groups of 8 frames)
lazuli_snia.change_detector(nmd=(64, 8, 0), nramps=1)
print(lazuli_snia.get_exposure_time()) # [s]
1448.96
# with readout noise (normal case)
lbda, flux, variance = lazuli_snia.get_spectrum()
# without readout noise
lbda, flux_noron, variance_noron = lazuli_snia.get_spectrum(switch_off="ron")
fig, (ax, ax_var) = plt.subplots(nrows=2, sharex=True)
# with readout noise
ax.plot(lbda, flux, lw=1, label="with ron")
ax.fill_between(lbda,
flux + np.sqrt(variance),
flux - np.sqrt(variance), alpha=0.5)
# without readout noise
ax.plot(lbda, flux_noron, lw=1, label="no ron")
ax.fill_between(lbda,
flux_noron + np.sqrt(variance_noron),
flux_noron - np.sqrt(variance_noron), alpha=0.5)
ax.set_ylabel("flux [adu]")
# variances
ax_var.plot(lbda, variance, label="with ron")
ax_var.plot(lbda, variance_noron, label="no ron")
ax_var.set_ylabel("variance [adu$^2$]")
ax_var.set_xlabel("wavelength [Å]")
ax.legend()
<matplotlib.legend.Legend at 0x178481d30>
In this example, switching off the readout noise reduces the variance by about 30% at all wavelengths.
Detailed variance contributions#
You could repeat this exercise, switching off each contribution one at a time and comparing
the resulting variances. For convenience, this is what get_variance_contribution() does
for you:
%%time
variance_source_df = lazuli_snia.get_variance_contribution()
CPU times: user 1.14 s, sys: 172 ms, total: 1.31 s
Wall time: 1.31 s
variance_source_df.head()
| lbda | flux | variance | dark | roic_glow | thermal_dark | ron | pointsource | background | host | thermal | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 3999.990000 | 0.021391 | 62.891914 | 29.868499 | 11.308114 | 0.786200 | 20.709015 | 0.030890 | 0.189196 | 0.0 | 0.0 |
| 1 | 4004.709303 | 0.022569 | 62.944620 | 29.891838 | 11.316950 | 0.786815 | 20.725196 | 0.032371 | 0.191451 | 0.0 | 0.0 |
| 2 | 4009.444426 | 0.024573 | 62.999955 | 29.915289 | 11.325829 | 0.787432 | 20.741456 | 0.035201 | 0.194750 | 0.0 | 0.0 |
| 3 | 4014.195551 | 0.027213 | 63.056651 | 29.938852 | 11.334749 | 0.788052 | 20.757793 | 0.038995 | 0.198210 | 0.0 | 0.0 |
| 4 | 4018.962861 | 0.030051 | 63.113784 | 29.962529 | 11.343714 | 0.788675 | 20.774209 | 0.043077 | 0.201581 | 0.0 | 0.0 |
Use simulation.show_variance_sources(variance_source_df) for a quick view:
fig = lazuli_snia.simulation.show_variance_sources(variance_source_df)
The detector terms (dark current, readout noise and ROIC glow) dominate the variance at all
wavelengths, dark current being the largest. The source photon noise (pointsource) only becomes
significant in the 7000–14 000 Å range, where the redshifted supernova is the brightest.