This notebook shows how to load the output for Eric's survey simulator ztf_sim
and generate SN Ia lightcurves using the SALT2 template. (Check out the other notebooks for examples how to simulate other transients.)
Note: You need to download Eric's newest sample output here. The link was also included in Eric's email, so you will likely only need to change the path below.
Furthermore you'll require the dust map from Schlegel, Finkbeiner & Davis (1998) for full functionality. It can be found here.
In [1]:
import os
home_dir = os.environ.get('HOME')
# Please enter the filename of the ztf_sim output file you would like to use. The example first determines
# your home directory and then uses a relative path (useful if working on several machines with different usernames)
survey_file = os.path.join(home_dir, 'data/ZTF/test_schedule_v6.db')
# Please enter the path to where you have placed the Schlegel, Finkbeiner & Davis (1998) dust map files
# You can also set the environment variable SFD_DIR to this path (in that case the variable below should be None)
sfd98_dir = os.path.join(home_dir, 'data/sfd98')
In [2]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import simsurvey
import sncosmo
from astropy.cosmology import Planck15
import simsurvey_tools as sst
In [3]:
# Load the ZTF CCD corners and filters
ccds = sst.load_ztf_ccds()
sst.load_ztf_filters()
In [4]:
# Load simulated survey from file (download from ftp://ftp.astro.caltech.edu/users/ebellm/one_year_sim_incomplete.db)
# Currently DES filters are used as proxies for ZTF filters
plan = simsurvey.SurveyPlan(load_opsim=survey_file, band_dict={'g': 'ztfg', 'r': 'ztfr', 'i': 'desi'}, ccds=ccds)
mjd_range = (plan.cadence['time'].min() - 30, plan.cadence['time'].max() + 30)
In [5]:
# To review the pointing schedule, you can use this table
plan.pointings
Out[5]:
The transient generator combines a model and a distribution representing the transient population, and randomly draws all parameters needed to simulate the lightcurves. For well studied transient types, e.g. SNe Ia, models and generators have been predefined for easy use.
Here the maximum redshift has been kept very low in order make the simulation short. In reality $z_{max} = 0.2$ would be more realistic.
In [6]:
tr = simsurvey.get_transient_generator((0.0, 0.05),
transient='Ia',
template='salt2',
dec_range=(-30,90),
mjd_range=(mjd_range[0],
mjd_range[1]),
sfd98_dir=sfd98_dir)
In [7]:
survey = simsurvey.SimulSurvey(generator=tr, plan=plan)
lcs = survey.get_lightcurves(
#progress_bar=True, notebook=True # If you get an error because of the progress_bar, delete this line.
)
In [8]:
len(lcs.lcs)
Out[8]:
In [9]:
lcs[0]
Out[9]:
In [ ]:
In [10]:
lcs.save('lcs_tutorial.pkl')
In [11]:
lcs = simsurvey.LightcurveCollection(load='lcs_tutorial.pkl')
You can inspect the lightcurves manually. This example should return the lightcurve with the most points with S/N > 5.
In [12]:
_ = sncosmo.plot_lc(lcs[0])
The two figures below show how early the MNe are detected and at what redshifts. The simulation input parameters of transients that were not detected are also kept, so can check completeness.
In [13]:
plt.hist(lcs.stats['p_det'], lw=2, histtype='step', range=(-20,0), bins=20)
plt.xlabel('Detection phase (observer-frame)', fontsize='x-large')
_ = plt.ylabel(r'$N_{SNe}$', fontsize='x-large')
In [14]:
plt.hist(lcs.meta_full['z'], lw=1, histtype='step', range=(0,0.05), bins=20, label='all')
plt.hist(lcs.meta['z'], lw=2, histtype='step', range=(0,0.05), bins=20, label='detected')
plt.xlabel('Redshift', fontsize='x-large')
plt.ylabel(r'$N_{SNe}$', fontsize='x-large')
plt.xlim((0, 0.05))
plt.legend()
Out[14]:
In [ ]: