Changing the target properties#

Once you have loaded a target (and possibly fine-tuned the detector or spectrograph setup), you may want to see how the observation changes when the target itself changes.

This is done with change_properties(), which lets you modify any property of the target without rebuilding it.

Type Ia supernovae#

Let us load a SN Ia at redshift 1.0 with a SALT color c=0.3 and stretch x1=0.2, and set up the instrument to reach an average signal-to-noise ratio (SNR) of 20 per wavelength bin, in the rest-frame 6000–7000 Å range.

import slicersim
import numpy as np
lazuli_snia = slicersim.LazuliSupernova(redshift=1.0, c=0.3, x1=0.2)
_ = lazuli_snia.setup_to_snr(20, per_resolution=False, 
                             lbda_range=[6000, 7000], 
                             frame="rest")

Check the reached SNR#

# get the spectrum and compute the SNR per wavelength bin
lbda, flux, variance = lazuli_snia.get_spectrum()
snr_spec = flux / np.sqrt(variance)

# rest-frame 6000-7000 Å converted to the observer frame
redshift = lazuli_snia.get_properties("redshift")
flag_in = (lbda > 6000 * (1 + redshift)) & (lbda < 7000 * (1 + redshift))
np.mean(snr_spec[flag_in])
np.float64(19.783163258441785)

This is close to 20: the readout configuration is discrete (integer numbers of groups and ramps), so the requested SNR can only be approximately reached.

Change the target and recompute the SNR#

The instrument has been set up for the properties expected when the target was triggered. In reality, the actual properties of the target may differ. Say the true redshift is 1.05, with c=0.2 and x1=-2.

# the true target parameters, slightly different from the expected ones
lazuli_snia.change_properties(redshift=1.05, c=0.2, x1=-2.)
lbda, flux, variance = lazuli_snia.get_spectrum()
snr_spec = flux/np.sqrt(variance)

Let us now look at the resulting signal-to-noise ratio. The instrument setup has not changed, so the SNR is now lower than the requested 20.

redshift = lazuli_snia.get_properties("redshift")
flag_in = (lbda > 6000 * (1 + redshift)) & (lbda < 7000 * (1 + redshift))
np.mean(snr_spec[flag_in])
np.float64(16.957475993953814)
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot(lbda, snr_spec)
ax.set_xlabel("wavelength [Å]")
ax.set_ylabel("SNR per wavelength bin")
Text(0, 0.5, 'SNR per wavelength bin')
../_images/00b87b4ee6fbac325ddd559d0b747ac2aebe7614119a65994ef08dab7e6b3fe8.png

Any spectrum or CalSpec star#

For generic targets (defined by their spectrum), one of the things you can change is the observed magnitude in a given band. The band must be an sncosmo bandpass (e.g. "lssti", "sdssr", "bessellb").

lazuli_star = slicersim.LazuliCalSpec("gd71")
lazuli_star.change_properties(mag=22, band="lssti")
lbda, flux_22, variance_22 = lazuli_star.get_spectrum(unit="flambda", incl_error=False)

lazuli_star.change_properties(mag=21, band="lssti")
lbda, flux_21, variance_21 = lazuli_star.get_spectrum(unit="flambda", incl_error=False)
fig, ax = plt.subplots()
ax.plot(lbda, flux_22, label="mag=22 in lssti")
ax.plot(lbda, flux_21, label="mag=21 in lssti")
ax.set_xlabel("wavelength [Å]")
ax.set_ylabel("flux [erg/s/cm$^2$/Å]")
ax.legend()
<matplotlib.legend.Legend at 0x31af827b0>
../_images/d97aae26da8a96fd4eb19fd1344f4f73cdb3cee770ee442974923c05c882507a.png