def main_depth_wide( instr_name='LSSTPG', # bands=['g', 'r', 'i', 'z'], SNR=dict(zip(['LSSTPG::' + b for b in "griz"], [30., 40., 30., 20.])), target={ 'LSSTPG::g': (24.83, 3.), # 23.86 'LSSTPG::r': (24.35, 3.), # 23.82 'LSSTPG::i': (23.88, 3.), # 23.51 'LSSTPG::z': (23.30, 3.), # }): instr = psf.find(instr_name) bands = SNR.keys() # Wide survey logs = [ snsim.OpSimObsLog(NTuple.fromtxt(fn)) for fn in glob.glob('OpSimLogs/*_WFD_*.txt') ] m = np.hstack([log.median_values() for log in logs]) lims = f5_cadence_lims(zs=[0.1, 0.2, 0.3, 0.4, 0.5], SNR=SNR) # bands=[instr_name + '::' + b for b in bands]) for bn in bands: f5_cadence_plot( instr, bn, # instr_name + '::' + bn, lims, mag_range=(21., 24.8), dt_range=(0.5, 30.), median_log_summary=m, target=target) pl.gcf().savefig('m5_cadence_limits_wide_%s.png' % bn.split(':')[-1], bbox_inches='tight') pl.gcf().savefig('m5_cadence_limits_wide_%s.pdf' % bn.split(':')[-1], bbox_inches='tight')
def check_m5sigma_depth(): """ Compare Philippe Gris' m5 with mine. """ log = snsim.OpSimObsLog(NTuple.fromtxt('Observations_DD_290_LSSTPG.txt')) lsstpg = psf.find('LSSTPG') sky_flux = lsstpg.mag_to_flux(log.mag_sky, log.band) m5 = lsstpg.mag_lim(30., sky_flux, log.seeing, log.band) pl.figure() pl.plot(log.mjd, log.m5sigmadepth, marker='.', color='gray', ls='') pl.plot(log.mjd, m5, marker='.', color='r', ls='') pl.xlabel('MJD') for b in np.unique(log.band): idx = log.band == b pl.figure() pl.plot(log.mjd[idx], m5[idx] - log.m5sigmadepth[idx], marker='.', color='gray', ls='') pl.title(b) pl.xlabel('MJD') pl.xlabel('$\Delta m_{5\sigma} [%s]$' % b)
def main_opsim_log(filename='Observations_DD_290_LSSTPG.txt', i_season=0, X1=0., Color=0., label=None, tofile=None, zlim=None): d = NTuple.fromtxt(filename) cut = (d['band'] != 'LSSTPG::u') log = snsim.OpSimObsLog(d[cut]) # update_log_with_seeing_and_sky(log, # seeing = {'LSSTPG::u': 0.92, 'LSSTPG::g': 0.87, 'LSSTPG::r': 0.83, 'LSSTPG::i': 0.80, 'LSSTPG::z': 0.78, 'LSSTPG::y': 0.76}, # mag_sky= {'LSSTPG::u': 22.95, 'LSSTPG::g': 22.24, 'LSSTPG::r': 21.20 , 'LSSTPG::i': 20.47, 'LSSTPG::z': 19.60, 'LSSTPG::y': 18.63}) # update_log_with_seeing_and_sky(log, # mag_sky= {'LSSTPG::y': 18.63}) seasons = log.split() log = seasons[i_season] lcmodel = init_lcmodel(log) instr = [get_instrument(nm) for nm in np.unique(log.instrument)] s = snsim.SnSurveyMC(obslog=log, filename='lsst_survey.conf', instruments=instr) sne = s.generate_sample() sne['X1'] = X1 # -3. sne['Color'] = Color # 0.3 lc = s.generate_lightcurves(sne, lcmodel, fit=True) res = reso(lc) fig = pl.figure() # pl.plot(sne['z'], res['eColor'], marker='.', color='gray', ls='') p_first = (s.obslog.mjd.min() - sne['DayMax']) / (1. + sne['z']) p_last = (s.obslog.mjd.max() - sne['DayMax']) / (1. + sne['z']) idx = (p_first < -15.) & (p_last > 20.) print len(idx), idx.sum() pl.plot(sne['z'][idx], res['eColor'][idx], marker='.', color='b', ls='') pl.xlabel('$z$', fontsize=20) pl.ylabel('$\sigma_{\cal{C}}$', fontsize=20) pl.ylim((0., 0.15)) pl.axhline(0.03, color='r', ls='--') if label: pl.annotate(label, xy=(0.1, 0.8), xycoords='axes fraction', fontsize=18) pl.grid(1) if zlim: pl.axvline(zlim, ls='-.', color='gray', lw=2) if tofile: fig.savefig(tofile, bbox_inches='tight') pl.title('season=%d' % i_season) return s, sne, res, lc
def create_survey(survey_type, mjd_min=59884., color=True, n=1, CARD=None, zrange=(0.05, 1), graph=False, record=False): log = [ snsim.OpSimObsLog(create_log(survey_type, mjd_min)) for i in range(n) ] lcmodel = init_lcmodel(log[0].band) #r = log.split() lc = [] if CARD is None: CARD = CARDS[survey_type] for i in range(n): print('Creating %s survey (# %d over %d seasons) --- ' + time.ctime()) % (survey_type, i + 1, n) s = snsim.SnSurveyMC(obslog=log[i], filename='lsst_survey.conf') s.survey_area = CARD['field'] s.zrange = zrange sne = s.generate_sample(account_for_edges=True) sne.sort(order='z') # sne['X1'] = 0 if color is False: sne['Color'] = 0 lc += s.generate_lightcurves(sne, lcmodel, fit=1) if graph: plot_of_interest(lc, survey_type, record) return lc
def main(color=None): log = snsim.OpSimObsLog(NTuple.fromtxt('Observations_DD_290_LSSTPG.txt')) lcmodel = init_lcmodel(log.band) r = log.split() s = snsim.SnSurveyMC(obslog=r[2], filename='lsst_survey.conf') sne = s.generate_sample() sne.sort(order='z') sne['X1'] = 0 if color is not None: sne['Color'] = color lc = s.generate_lightcurves(sne, lcmodel, fit=1) return lc, log, lcmodel
def gen_simple_obslog( instrument, opsim_log=None, cadence=1., tmin=-20, tmax=60., excl_bands=['LSSTPG::u'], texp={ 'LSSTPG::g': 300., 'LSSTPG::r': 600., 'LSSTPG::i': 600., 'LSSTPG::z': 780., 'LSSTPG::y': 600. }): """ """ def select(data, excl): bands = data['band'] cut = np.in1d(bands, excl) return data[~cut] # if opsim_log is None: data = select(instrument.data, excl=excl_bands) else: data = update_instrument_summary_data_from_obslog( instrument, opsim_log) data = select(data, excl=excl_bands) seq = np.arange(tmin, tmax + cadence, cadence) nbands = len(data) n = len(seq) # band = np.repeat(data['band'], n) mjd = np.tile(seq, nbands) exptime = np.repeat([texp[b] for b in data['band']], n) seeing = np.repeat(data['iq'], n) moon_frac = np.zeros(len(band)) mag_sky = np.repeat(data['mag_sky'], n) flux_sky = instrument.mag_to_flux(mag_sky, band) kAtm = np.zeros(len(band)) airmass = np.ones(len(band)) m5sigmadepth = instrument.mag_lim(exptime, flux_sky, seeing, band, snr=5.0) Nexp = np.ones(len(band)) data = np.rec.array((band, mjd, exptime, seeing, moon_frac, mag_sky, kAtm, airmass, m5sigmadepth, Nexp), names=[ 'band', 'mjd', 'exptime', 'seeing', 'moon_frac', 'sky', 'kAtm', 'airmass', 'm5sigmadepth', 'Nexp' ]) return snsim.OpSimObsLog(data)
def reso_vs_lc_amplitude(): opsim = NTuple.fromtxt('Observations_DD_290_LSSTPG.txt') idx = opsim['band'] != 'LSSTPG::u' log = snsim.OpSimObsLog(opsim[idx]) r = log.split() lcmodel = init_lcmodel(log) s = snsim.SnSurveyMC(obslog=r[2], filename='lsst_survey.conf') sne = s.generate_sample() lc = s.generate_lightcurves(sne, lcmodel, fit=1) bands = np.unique(log.band) r = [] for l in lc: C = l.covmat() sa = [] for b in bands: sa.append(l.amplitude_snr(b)) r.append(np.sqrt(np.diag(C)).tolist() + sa) return sne, np.rec.fromrecords(r, names=['eX0', 'eX1', 'eColor', 'eDayMax'] + ['sig_' + b for b in bands])
def create_survey(survey_type, mjd_min=59884., color=True, n=1, record=False, zs=None): log = [snsim.OpSimObsLog(create_log(survey_type, mjd_min)) for i in range(n)] lcmodel = init_lcmodel(log[0].band) #r = log.split() lc = [] for i in range(n): print ('Creating %s survey (# %d over %d seasons) --- ' + time.ctime()) % (survey_type, i+1, n) s = snsim.SnSurveyMC(obslog=log[i], filename='lsst_survey.conf') s.survey_area = CARDS[survey_type]['field'] if survey_type[:4] == 'deep': s.zrange = 0.1, 0.9 elif survey_type[:4] == 'wide': s.zrange = 0.05, 0.35 sne = s.generate_sample(account_for_edges=True, z=zs) sne.sort(order='z') sne['X1'] = 0 if color is False: sne['Color'] = 0 lc += s.generate_lightcurves(sne, lcmodel, fit=1) plot_of_interest(lc, survey_type, record) return lc, log, lcmodel
def load_instruments(): # load instruments lsst = psf.ImagingInstrument('LSST') lsst.precompute(full=1) lsst_pg = psf.ImagingInstrument('LSSTPG') lsst_pg.precompute(full=1) lsst_pg_opsim = psf.ImagingInstrument('LSSTPG') log = snsim.OpSimObsLog(NTuple.fromtxt('Observations_DD_290_LSSTPG.txt')) d = update_instrument_summary_data_from_obslog(lsst_pg_opsim, log) lsst_pg_opsim.data[:] = d lsst_pg_opsim.precompute(full=1) # dump summary tables print "***** LSST [~LSE-40] ******" lsst.dump(exptime=30.) print "***** LSST [~SMTN-002 ] ******" lsst_pg.dump(exptime=30.) print "***** LSST [~SMTN-002 + OpSim default values ] ******" lsst_pg_opsim.dump(exptime=30.) return lsst, lsst_pg, lsst_pg_opsim
def main_depth_ddf( instr_name='LSSTPG', # bands=['r', 'i', 'z', 'y'], SNR=dict(zip(['LSSTPG::' + b for b in "grizy"], [25., 25., 60., 35., 20.])), target={ # 'LSSTPG::g': (26.91, 3.), # was 25.37 'LSSTPG::r': (26.43, 3.), # was 25.37 'LSSTPG::i': (26.16, 3.), # was 25.37 # could be 25.3 (400-s) 'LSSTPG::z': (25.56, 3.), # was 24.68 # could be 25.1 (1000-s) 'LSSTPG::y': (24.68, 3.) }): # was 24.72 bands = SNR.keys() instr = psf.find(instr_name) # DDF survey # logs = [snsim.OpSimObsLog(NTuple.fromtxt(fn)) for fn in glob.glob('OpSimLogs_LSST/*_DD_*.txt')] logs = [ snsim.OpSimObsLog(NTuple.fromtxt(fn)) for fn in glob.glob('OpSimLogs/*_DD_*.txt') ] m = np.hstack([log.median_values() for log in logs]) lims = f5_cadence_lims(zs=[0.6, 0.7, 0.8, 0.9, 1.0, 1.1], SNR=SNR) # bands=[instr_name + '::' + b for b in bands]) for bn in bands: f5_cadence_plot( instr, bn, # instr_name + '::' + bn, lims, target=target, mag_range=(23., 26.5), median_log_summary=m) pl.gcf().savefig('m5_cadence_limits_%s.png' % bn.split(':')[-1], bbox_inches='tight') pl.gcf().savefig('m5_cadence_limits_%s.pdf' % bn.split(':')[-1], bbox_inches='tight')
def plot_figure_3(): log = snsim.OpSimObsLog(NTuple.fromtxt('Observations_DD_290_LSSTPG.txt')) r = log.split() log = r[2] # Wide lsstpg = psf.find('LSSTPG') r = plot_sigc_vs_z(lsstpg, delta=4., exptimes={ 'LSSTPG::g': 30, 'LSSTPG::r': 30, 'LSSTPG::i': 30., 'LSSTPG::z': 30. }, zmax=0.5, sigc_filename='sigc_lsstpg_wide_30', snr_filename='snr_lsstpg_wide_30') r = plot_sigc_vs_z(lsstpg, delta=3., exptimes={ 'LSSTPG::g': 30, 'LSSTPG::r': 30, 'LSSTPG::i': 30., 'LSSTPG::z': 30. }, zmax=0.5, sigc_filename='sigc_lsstpg_wide_30_cad3', snr_filename='snr_lsstpg_wide_30_cad3') r = plot_sigc_vs_z(lsstpg, delta=4., exptimes={ 'LSSTPG::g': 30, 'LSSTPG::r': 30, 'LSSTPG::i': 30., 'LSSTPG::z': 30. }, zmax=0.5, sigc_filename='sigc_lsstpg_wide_30_minion', snr_filename='snr_lsstpg_wide_30_minion', reference_log=log) # DDF r = plot_sigc_vs_z(lsstpg, delta=4., exptimes={ 'LSSTPG::r': 600, 'LSSTPG::i': 600., 'LSSTPG::z': 780., 'LSSTPG::y': 600 }, zmax=1.1, sigc_filename='sigc_lsstpg_ddf_600', snr_filename='snr_lsstpg_ddf_600') r = plot_sigc_vs_z(lsstpg, delta=3., exptimes={ 'LSSTPG::r': 1200, 'LSSTPG::i': 1800., 'LSSTPG::z': 1800., 'LSSTPG::y': 1800 }, zmax=1.1, sigc_filename='sigc_lsstpg_ddf_1800_cad3', snr_filename='snr_lsstpg_ddf_1800_cad3') # r = plot_sigc_vs_z(lsstpg, delta=3., exptimes={'LSSTPG::r': 600, 'LSSTPG::i': 600., 'LSSTPG::z': 780., 'LSSTPG::y': 600}, # zmax=1.1, sigc_filename='sigc_lsstpg_ddf_1200_minion', snr_filename='snr_lsstpg_ddf_1200_minion', reference_log=log) # r = plot_sigc_vs_z(lsstpg, delta=3., exptimes={'LSSTPG::r': 1200, 'LSSTPG::i': 1200., 'LSSTPG::z': 1200., 'LSSTPG::y': 1200}, # zmax=1.1, sigc_filename='sigc_lsstpg_ddf_1200_cad2', snr_filename='snr_lsstpg_ddf_1200_cad2') lsst = psf.find('LSST') r = plot_sigc_vs_z(lsst, delta=4., exptimes={ 'LSST::r': 600., 'LSST::i': 600., 'LSST::z': 780., 'LSST::y4': 600 }, zmax=1.1, sigc_filename='sigc_lsst_ddf_600', snr_filename='snr_lsst_ddf_600') r = plot_sigc_vs_z(lsst, delta=3., exptimes={ 'LSST::r': 1200, 'LSST::i': 1800., 'LSST::z': 1800., 'LSST::y4': 1800 }, zmax=1.1, sigc_filename='sigc_lsst_ddf_1800_cad3', snr_filename='snr_lsst_ddf_1800_cad3')
def plot_sigc_vs_z(instrument, reference_log=None, fig=None, delta=4., zmax=1.1, sigc_filename=None, snr_filename=None, exptimes={ 'LSSTPG::r': 600., 'LSSTPG::i': 600., 'LSSTPG::z': 600., 'LSSTPG::y': 600. }): cad = regular_cadence(instrument, log=reference_log, delta=delta, exptimes=exptimes) bands = exptimes.keys() cad = snsim.OpSimObsLog(cad) lcmodel = init_lcmodel(cad.band) lcmodel.restframe_wavelength_range = (3600., 8000.) s = snsim.SnSurveyMC(obslog=cad, filename='lsst_survey.conf') s.survey_area = 20. z = np.linspace(0.005, zmax, 100) sne = s.generate_sample(z=z) sne.sort(order='z') sne_mean = sne.copy() sne_mean['X1'] = 0. sne_mean['Color'] = 0. sne_mean['DayMax'] = 0. lc_mean = s.generate_lightcurves(sne_mean, lcmodel, fit=1) magres_mean = reso(lc_mean, bands=bands) sne_red = sne.copy() sne_red['X1'] = -2. sne_red['Color'] = 0.2 sne_red['DayMax'] = 0. lc_red = s.generate_lightcurves(sne_red, lcmodel, fit=1) magres_red = reso(lc_red, bands=bands) sne_blue = sne.copy() sne_blue['X1'] = 2. sne_blue['Color'] = -0.2 sne_blue['DayMax'] = 0. lc_blue = s.generate_lightcurves(sne_blue, lcmodel, fit=1) magres_blue = reso(lc_blue, bands=bands) # plot with the if fig is None: fig = pl.figure() pl.fill_between(sne['z'], magres_red['eColor'], magres_blue['eColor'], color='blue', alpha=0.25) pl.plot(sne['z'], magres_mean['eColor'], color='k', ls='-') pl.plot(sne['z'], magres_blue['eColor'], color='b', ls='-', lw=1) pl.plot(sne['z'], magres_red['eColor'], color='r', ls='-', lw=1) pl.axhline(0.04, color='red', ls='--') pl.xlabel('$z$', fontsize=18) pl.ylabel('$\sigma_C$', fontsize=18) pl.xlim((0., zmax)) pl.ylim((0., 0.15)) pl.grid(1) if sigc_filename is not None: pl.gcf().savefig(sigc_filename + '.png', bbox_inches='tight') pl.gcf().savefig(sigc_filename + '.pdf', bbox_inches='tight') pl.figure() colors = psf.band_colors(exptimes.keys()) for bn in exptimes.keys(): bb = bn.split(':')[-1] idx = magres_red[bb + '_snr'] > 0. pl.plot(sne_red['z'][idx], magres_red[bb + '_snr'][idx], color=colors[bn], marker='.', label=bb) pl.xlabel('$z$', fontsize=18) pl.ylabel('amplitude SNR', fontsize=18) pl.ylim((0., 100.)) pl.legend(loc='best') pl.grid(1) pl.xlim((0., zmax)) if snr_filename is not None: pl.gcf().savefig(snr_filename + '.png', bbox_inches='tight') pl.gcf().savefig(snr_filename + '.pdf', bbox_inches='tight') return fig, sne, magres_red, magres_mean, magres_blue, lc_red
def plot_lc_snr(filename='Observations_DD_290_LSSTPG.txt', z=1.1, X1=0., Color=0., DayMax=0., bands=['LSSTPG::' + b for b in "rizy"], rest_frame_margins=(-15., 30.), snr_min=20., fig=None): """Return a metric from a log and a fiducial supernova. Args: z, X1, Color, DayMax: fiducial supernova """ lsstpg = psf.find('LSSTPG') colors = band_colors(lsstpg) mjd, shapes = get_pulse_shapes(bands, z=z, X1=X1, Color=Color) mjd_margins = rest_frame_margins[0] * (1. + z), rest_frame_margins[1] * (1. + z) log = snsim.OpSimObsLog(NTuple.fromtxt(filename)) r = log.split(delta=100.) # f5 = lsstpg.mag_to_flux(log.m5sigmadepth, log.band) flux_sky = lsstpg.mag_to_flux(log.mag_sky, log.band) f5 = lsstpg.flux_lim(log.exptime, flux_sky, log.seeing, log.band) # print lsstpg.mag_lim(log.exptime, flux_sky, log.seeing, log.band) # print lsstpg.mag_to_flux(lsstpg.mag_lim(log.exptime, flux_sky, log.seeing, log.band), log.band) if fig is None: fig = pl.figure(figsize=(12, 12)) ax = None mjd = np.arange(log.mjd.min(), log.mjd.max(), 1.) for i, bn in enumerate(bands): if ax is None: ax = pl.subplot(len(bands), 1, i + 1) pl.title('$SN[X1=%5.1f,C=%5.1f]\ at\ z=%4.2f$ [%s]' % (X1, Color, z, filename)) else: ax = pl.subplot(len(bands), 1, i + 1) # runs for rr in r: pl.axvspan(rr.mjd.min(), rr.mjd.max(), color='gray', alpha=0.25) pl.axvspan(rr.mjd.min() - rest_frame_margins[0], rr.mjd.max() - rest_frame_margins[1], color='gray', alpha=0.35) # plot the cadence metric idx = log.band == bn c = CadenceMetric(log.mjd[idx], f5[idx], log.band[idx], shapes[bn]) y = c(mjd) pl.plot(mjd, y, color=colors[bn], marker='.', ls=':') pl.ylabel('$SNR [%s]$' % bn.split(':')[-1], fontsize=16) # color=colors[bn]) pl.axhline(snr_min, ls='--', color='r') pl.ylim((0., max((y.max(), snr_min + 1)))) # plot the average number of observations averaged over a # window of ~ 21 days. c_sched = SimpleCadenceMetric(log.mjd[idx], 21.) print c_sched.sumw.min(), c_sched.sumw.max() y_sched = c_sched(mjd) ax = pl.gca().twinx() ax.plot(mjd, y_sched, color='gray', ls='-') pl.ylim((0., 0.28)) pl.ylabel("Cadence [day$^{-1}$]", color='black') cad = 1. / (4. * (1. + z)) pl.axhline(cad, ls=':', color='gray') if i < len(bands) - 1: ax.get_xaxis().set_ticklabels([]) pl.subplots_adjust(hspace=0.06) pl.xlabel('$MJD$ [days]', fontsize=16) return c