def generate_lightcurve(model, samples): t = Table() for key in samples.keys(): val = samples[key] t.add_column(Column(data=[val], name=key)) samples = t model_table = KNTable.model(model, samples) if len(model_table) == 0: return [], [], [] else: t, lbol, mag = model_table["t"][0], model_table["lbol"][ 0], model_table["mag"][0] return t, lbol, mag
def generate_spectra(model, samples): #kwargs = {'SaveModel':True,'LoadModel':False,'ModelPath':ModelPath} kwargs = {'SaveModel': False, 'LoadModel': True, 'ModelPath': ModelPath} kwargs["doAB"] = False kwargs["doSpec"] = True t = Table() for key, val in samples.iteritems(): t.add_column(Column(data=[val], name=key)) samples = t model_table = KNTable.model(model, samples, **kwargs) if len(model_table) == 0: return [], [], [] else: t, lambdas, spec = model_table["t"][0], model_table["lambda"][ 0], model_table["spec"][0] return t, lambdas, spec
def generate_lightcurve(model, samples): t = Table() for key in samples.keys(): val = samples[key] t.add_column(Column(data=[val], name=key)) samples = t if Global.n_coeff > 0: samples["n_coeff"] = Global.n_coeff try: samples["gptype"] = Global.gptype except: pass model_table = KNTable.model(model, samples) if len(model_table) == 0: return [], [], [] else: t, lbol, mag = model_table["t"][0], model_table["lbol"][ 0], model_table["mag"][0] return t, lbol, mag
samples['eth'] = eth samples['flgbct'] = flgbct samples['beta'] = beta samples['kappa_r'] = kappa_r samples['slope_r'] = slope_r samples['theta_r'] = theta_r samples['Ye'] = Ye kwargs = {'SaveModel': False, 'LoadModel': True, 'ModelPath': ModelPath} kwargs["doAB"] = True kwargs["doSpec"] = False # Create dict of tables for the various models, calculating mass ejecta velocity of ejecta and the lightcurve from the model model_tables = {} for model in models: model_tables[model] = KNTable.model(model, samples, **kwargs) # Now we need to do some interpolation for model in models: model_tables[model] = lightcurve_utils.calc_peak_mags(model_tables[model]) #model_tables[model] = lightcurve_utils.interpolate_mags_lbol(model_tables_lbol[model]) baseplotDir = opts.plotDir plotDir = os.path.join(baseplotDir, "_".join(models)) plotDir = os.path.join(plotDir, "event") plotDir = os.path.join(plotDir, opts.name) if opts.analysisType == "cbclist": plotDir = os.path.join(plotDir, opts.cbc_type) plotDir = os.path.join(plotDir, "%d_%d" % (opts.mindistance, opts.maxdistance))
if opts.doSaveModel: kwargs = {'SaveModel': True, 'LoadModel': False, 'ModelPath': ModelPath} else: kwargs = {'SaveModel': False, 'LoadModel': True, 'ModelPath': ModelPath} kwargs["doAB"] = opts.doAB kwargs["doSpec"] = opts.doSpec kwargs["phi"] = phi t = Table() for key in samples.keys(): val = samples[key] t.add_column(Column(data=[val], name=key)) samples = t if not opts.model in ["SN", "Afterglow"]: model_table = KNTable.model(opts.model, samples, **kwargs) if opts.doAB: t, lbol, mag = model_table["t"][0], model_table["lbol"][ 0], model_table["mag"][0] elif opts.doSpec: t, lambdas, spec = model_table["t"][0], model_table["lambda"][ 0], model_table["spec"][0] if opts.model == "KaKy2016": if opts.doEjecta: name = "KaKy2016_%sM%03dV%02d" % (opts.eos, opts.mej * 1000, opts.vej * 100) elif opts.doMasses: name = "%sQ%.0fa%.0f" % (opts.eos, opts.massratio, opts.chi_eff * 100) elif opts.model == "DiUj2017": if opts.doEjecta:
kwargs = {'SaveModel': False, 'LoadModel': True, 'ModelPath': ModelPath} kwargs["doAB"] = True kwargs["doSpec"] = False filts = ["u", "g", "r", "i", "z", "y", "J", "H", "K"] errorbudget = 0.0 tini, tmax, dt = 0.1, 14.0, 0.1 for grb in data_out.keys(): print('Generating lightcurves for %s' % grb) if "KN_samples" in data_out[grb]: samples = data_out[grb]["KN_samples"] samples['tini'] = tini samples['tmax'] = tmax samples['dt'] = dt data_out[grb]["KN_model"] = KNTable.model('Ka2017', samples, **kwargs) for ii, row in enumerate(data_out[grb]["KN_model"]): A = data_out[grb]["KN_model"][ii]["A"] dm = -2.5 * np.log10(A) data_out[grb]["KN_model"][ii][ "mag"] = data_out[grb]["KN_model"][ii]["mag"] + dm data_out[grb]["KN_model"][ii][ "lbol"] = data_out[grb]["KN_model"][ii]["lbol"] * A data_out[grb]["KN_med"] = lightcurve_utils.get_med( data_out[grb]["KN_model"], errorbudget=errorbudget) tt = np.arange(tini, tmax + dt, dt) #colors = ['coral','cornflowerblue','palegreen','goldenrod'] keys = data_out.keys() colors = cm.rainbow(np.linspace(0, 1, len(keys))) colors = ['coral', 'cornflowerblue', 'palegreen', 'goldenrod']
samples['tmax'] = tmax samples['dt'] = dt kwargs = {'SaveModel':False,'LoadModel':True,'ModelPath':ModelPath} kwargs["doAB"] = True kwargs["doSpec"] = False # Create dict of tables for the various models, calculating mass ejecta velocity of ejecta and the lightcurve from the model pcklFile = os.path.join(plotDir,"data.pkl") if os.path.isfile(pcklFile): f = open(pcklFile, 'r') (model_table) = pickle.load(f) f.close() else: if opts.model == "Ka2017_TrPi2018": model_table = KNTable.model("Ka2017", samples, **kwargs) elif opts.model == "Bu2019inc_TrPi2018": model_table = KNTable.model("Bu2019inc", samples, **kwargs) else: model_table = KNTable.model(opts.model, samples, **kwargs) f = open(pcklFile, 'wb') pickle.dump((model_table), f) f.close() if opts.model == "Ka2017_TrPi2018": samples_gw = KNTable.read_multinest_samples(opts.multinest_samples, "Ka2017") elif opts.model == "Bu2019inc_TrPi2018": samples_gw = KNTable.read_multinest_samples(opts.multinest_samples, "Bu2019inc") else: samples_gw = KNTable.read_multinest_samples(opts.multinest_samples, opts.model)
t['dt'] = dt t['vmin'] = vmin t['th'] = th t['ph'] = ph t['kappa'] = kappa t['eps'] = eps t['alp'] = alp t['eth'] = eth t['flgbct'] = flgbct t['beta'] = beta t['kappa_r'] = kappa_r t['slope_r'] = slope_r t['theta_r'] = theta_r t['Ye'] = Ye distance = 100 #Mpc t['dist'] = distance # Create dict of tables for the various models, calculating mass ejecta velocity of ejecta and the lightcurve from the model models = ["DiUj2017", "Me2017"] model_tables = {} for model in models: model_tables[model] = KNTable.model(model, t) # Now we need to do some interpolation for model in models: model_tables[model] = lightcurve_utils.calc_peak_mags(model_tables[model]) model_tables[model] = lightcurve_utils.interpolate_mags_lbol( model_tables[model]) plot = KNTable.plot_mag_panels(model_tables, distance=distance) plt.savefig("test.png")
def calc_lightcurve(self, model_KN): self.samples = self.samples.downsample(Nsamples=1000) #add default values from above to table self.samples['tini'] = tini self.samples['tmax'] = tmax self.samples['dt'] = dt self.samples['vmin'] = vmin self.samples['th'] = th self.samples['ph'] = ph self.samples['kappa'] = kappa self.samples['eps'] = eps self.samples['alp'] = alp self.samples['eth'] = eth self.samples['flgbct'] = flgbct self.samples['beta'] = beta self.samples['kappa_r'] = kappa_r self.samples['slope_r'] = slope_r self.samples['theta_r'] = theta_r self.samples['Ye'] = Ye kwargs = { 'SaveModel': False, 'LoadModel': True, 'ModelPath': ModelPath } kwargs["doAB"] = True kwargs["doSpec"] = False model_tables = {} models = model_KN.split(",") for model in models: model_tables[model] = KNTable.model(model, self.samples, **kwargs) if (model_KN == "Bu2019inc"): idx = np.where(model_tables[model]['mej'] <= 1e-6)[0] model_tables[model]['mag'][idx] = 10. model_tables[model]['lbol'][idx] = 1e30 elif (model_KN == "Ka2017"): idx = np.where(model_tables[model]['mej'] <= 1e-3)[0] model_tables[model]['mag'][idx] = 10. model_tables[model]['lbol'][idx] = 1e30 for model in models: model_tables[model] = lightcurve_utils.calc_peak_mags( model_tables[model]) mag_all = {} app_mag_all_mbta = {} lbol_all = {} for model in models: mag_all[model] = {} app_mag_all_mbta[model] = {} lbol_all[model] = {} lbol_all[model] = np.empty((0, len(tt)), float) for filt, magidx in zip(filts, magidxs): mag_all[model][filt] = np.empty((0, len(tt))) app_mag_all_mbta[model][filt] = np.empty((0, len(tt))) peak_mags_all = {} for model in models: model_tables[model] = lightcurve_utils.calc_peak_mags( model_tables[model]) for row in model_tables[model]: t, lbol, mag = row["t"], row["lbol"], row["mag"] dist_mbta = row['dist_mbta'] if np.sum(lbol) == 0.0: #print "No luminosity..." continue allfilts = True for filt, magidx in zip(filts, magidxs): idx = np.where(~np.isnan(mag[magidx]))[0] if len(idx) == 0: allfilts = False break if not allfilts: continue for filt, magidx in zip(filts, magidxs): idx = np.where(~np.isnan(mag[magidx]))[0] f = interp.interp1d(t[idx], mag[magidx][idx], fill_value='extrapolate') maginterp = f(tt) app_maginterp_mbta = maginterp + 5 * (np.log10( (dist_mbta) * 1e6) - 1) mag_all[model][filt] = np.append(mag_all[model][filt], [maginterp], axis=0) app_mag_all_mbta[model][filt] = np.append( app_mag_all_mbta[model][filt], [app_maginterp_mbta], axis=0) idx = np.where((~np.isnan(np.log10(lbol))) & ~(lbol == 0))[0] f = interp.interp1d(t[idx], np.log10(lbol[idx]), fill_value='extrapolate') lbolinterp = 10**f(tt) lbol_all[model] = np.append(lbol_all[model], [lbolinterp], axis=0) return (mag_all, app_mag_all_mbta, lbol_all)