def get_iPTF14gqr(colorplt=False): """ De+18, Table S1, already corrected for extinction """ z = 0.063 # ebv = 0.082 D = cosmo.luminosity_distance([z])[0].value * 1e+6 # in pc dis_mod = 5 * np.log10(D / 10) t_exp = 56943.74 # t_max = 56950.26 # g band max light + 3 tb = Table(fits.open('../data/otherSN/De2018/tables1.fit')[1].data) tb.rename_column('MJD', 'mjd') tb['texp_rf'] = (tb['mjd'] - t_exp) / (1 + z) tb['tmax_rf'] = (tb['mjd'] - t_max) / (1 + z) # tb = tb[tb["Filt"]=="g "] tb = tb[~np.isnan(tb['e_mag'])] tb.rename_column('Filt', 'filter') tb.rename_column('e_mag', 'emag') tb.rename_column('mag', 'mag0') ixg = tb['filter'] == "g " ixB = tb['filter'] == "B " ixV = tb['filter'] == "V " ixr = tb['filter'] == "r " ixi = tb['filter'] == "i " ixUVW1 = tb['filter'] == "UVW1" ixUVW2 = tb['filter'] == "UVW2" tb['wave'] = np.zeros(len(tb)) tb['wave'][ixUVW2] = 2079 tb['wave'][ixUVW1] = 2614 tb['wave'][ixB] = 4359 tb['wave'][ixg] = 4814 tb['wave'][ixV] = 5430 tb['wave'][ixr] = 6422 tb['wave'][ixi] = 7883 tb['mag0_abs'] = tb['mag0'] - dis_mod tb = tb.to_pandas() tb["texp_rf"] = tb["Phase"] tb = tb.drop(columns=["recno", "Phase", "l_mag"]) """ ix = np.any([tb['Tel'].values=="P60 ", tb["filter"].values=='g '], axis=0) tb = tb[ix] """ tb = add_datecol(tb) tb = add_physcol(tb) tt = tb["tmax_rf"].values epochs = [" " for x in range(len(tt))] epochs = np.array(epochs) """ ix = (tt>-5.6)&(tt<-5.55) epochs[ix] = "epoch 01" """ ix = (tt > -5.55) & (tt < -5.50) epochs[ix] = "epoch 02" ix = (tt > -5.50) & (tt < -5.45) epochs[ix] = "epoch 03" ix = (tt > -5.2) & (tt < -5.0) epochs[ix] = "epoch 04" ix = (tt > -5.0) & (tt < -4.7) epochs[ix] = "epoch 05" ix = (tt > -4.7) & (tt < -4.5) epochs[ix] = "epoch 06" ix = (tt > -4.5) & (tt < -3.5) epochs[ix] = "epoch 07" ix = (tt > -3.5) & (tt < -2.5) epochs[ix] = "epoch 08" ix = (tt > -1.5) & (tt < -1) epochs[ix] = "epoch 09" ix = (tt > -1) & (tt < -0.82) epochs[ix] = "epoch 10" ix = (tt > -0.82) & (tt < -0.6) epochs[ix] = "epoch 11" ix = (tt > -0.5) & (tt < 0.5) epochs[ix] = "epoch 12" ix = (tt > 0.5) & (tt < 1.5) epochs[ix] = "epoch 13" ix = (tt > 1.5) & (tt < 2.5) epochs[ix] = "epoch 14" ix = (tt > 3.5) & (tt < 4.5) epochs[ix] = "epoch 15" ix = (tt > 4.5) & (tt < 5) epochs[ix] = "epoch 16" ix = (tt > 5) & (tt < 5.6) epochs[ix] = "epoch 17" ix = (tt > 5.6) & (tt < 5.8) epochs[ix] = "epoch 18" ix = (tt > 6) & (tt < 7) epochs[ix] = "epoch 19" ix = (tt > 7) & (tt < 8) epochs[ix] = "epoch 20" ix = (tt > 8) & (tt < 9) epochs[ix] = "epoch 21" tb["epoch"] = epochs if colorplt == False: return tb else: tb = add_datecol(tb) ix = np.in1d(tb["filter"].values, np.array(['g ', 'r ', 'i '])) tb = tb[ix] dates = get_date_span(tb) datesave = [] for i in range(len(dates)): x = dates[i] ix = tb["date"].values == x tbsub = tb[ix] if len(tbsub) != 0: flts = tbsub['filter'].values if "r " in flts and np.sum(np.unique(flts)) != 1: datesave.append(x) datesave = np.array(datesave) mcolor = [] mcolor_unc = [] mjds = [] colorname = [] for i in range(len(datesave)): x = datesave[i] ix = tb["date"].values == x tbsub = tb[ix] gtb = tbsub[tbsub["filter"].values == "g "] rtb = tbsub[tbsub["filter"].values == "r "] itb = tbsub[tbsub["filter"].values == "i "] if len(gtb) != 0: gmjds = gtb["mjd"].values gmags = gtb["mag0"].values gemags = gtb["emag"].values gwtgs = 1 / gemags**2 gmag = np.sum(gmags * gwtgs) / np.sum(gwtgs) gmjd = np.sum(gmjds * gwtgs) / np.sum(gwtgs) gemag = 1 / np.sqrt(np.sum(gwtgs)) if len(rtb) != 0: rmjds = rtb["mjd"].values rmags = rtb["mag0"].values remags = rtb["emag"].values rwtgs = 1 / remags**2 rmag = np.sum(rmags * rwtgs) / np.sum(rwtgs) rmjd = np.sum(rmjds * rwtgs) / np.sum(rwtgs) remag = 1 / np.sqrt(np.sum(rwtgs)) if len(itb) != 0: imjds = itb["mjd"].values imags = itb["mag0"].values iemags = itb["emag"].values iwtgs = 1 / iemags**2 imag = np.sum(imags * iwtgs) / np.sum(iwtgs) imjd = np.sum(imjds * iwtgs) / np.sum(iwtgs) iemag = 1 / np.sqrt(np.sum(iwtgs)) if len(gtb) != 0 and len(rtb) != 0: mcolor.append(gmag - rmag) mjds.append(0.5 * (gmjd + rmjd)) mcolor_unc.append(np.sqrt(gemag**2 + remag**2)) colorname.append("gmr") if len(rtb) != 0 and len(itb) != 0: mcolor.append(rmag - imag) mjds.append(0.5 * (rmjd + imjd)) mcolor_unc.append(np.sqrt(remag**2 + iemag**2)) colorname.append("rmi") ctb = Table(data=[mjds, mcolor, mcolor_unc, colorname], names=["mjd", "c", "ec", "cname"]) ctb['tmax_rf'] = (ctb['mjd'] - t_max) / (1 + z) ctb = ctb.to_pandas() return ctb
output = Lambda(lambda x: K.mean(x, axis=1))(output) output = Dense(len(classes), activation='softmax', kernel_initializer='normal', kernel_regularizer=regularizers.l2(l=0.01), bias_regularizer=regularizers.l2(l=0.01), use_bias=True)(output) model = Model(inputs=input, outputs=output) return model t = fits.open('table1.fits', memmap=True) train = Table(t[1].data).to_pandas() train = shuffle(train) classes = train['class'].to_frame() train = train.drop(['class', 'Name'], axis=1) metadata = pd.read_csv('metadata.csv') print('Read training set and metadata...') num_columns = len(train.columns) X_train = np.array([train.values]) train = train.reset_index() class_map = dict() for i, val in enumerate(list(classes['class'].values)): class_map[i] = val targets = classes target_map = np.zeros((targets.shape[0], )) target_map = np.array( [class_map[i] for i, val in enumerate(list(classes['class'].values))]) Y = to_categorical(target_map)
def fitting(directory, groupid, sky_coord, ja200_coord, cutoff=None): results_table = Table({ 'MJD': [], 'Filter': [], 'Mag': [], 'Error': [], 'ZP': [], 'SUB': [] }) for filename in os.listdir(directory): if filename != '.DS_Store': MJD, mg, zp, err, filter_, sub = CP.Return( directory + '/' + filename, groupid, sky_coord, (ja200_coord[0], ja200_coord[1]), cutoff) if isinstance(mg, float) and mg != 0.0: pass else: continue results_table.add_row([MJD, filter_, mg, err, zp, sub]) results_table = results_table.group_by(['MJD', 'Filter', 'SUB']) results_table = results_table.groups.aggregate(np.mean) df = results_table.to_pandas() indices = (df[df['ZP'] == 0].index.to_numpy()) for i in indices: zp = np.array(df.loc[(df['MJD'] == df['MJD'][i]) & (df['Filter'] == df['Filter'][i]) & (df['ZP'] != 0)]['ZP']) zp_idx = (df[(df['MJD'] == df['MJD'][i]) & (df['Filter'] == df['Filter'][i]) & (df['ZP'] != 0)].index) if len(zp_idx) == 0: df = df.drop([i]) else: df = df.drop([zp_idx[0]]) df['ZP'][i] = zp if cutoff is not '': df = df[(df['MJD'] < int(cutoff)) | (df['SUB'] == 1)] df['Mag'] = df['ZP'] - df['Mag'] results_table = df results_table = results_table.drop(columns=['SUB']) results_table.to_excel("Photometry_data.xlsx", sheet_name='Sheet_name_1') plt.figure() B = results_table[results_table['Filter'] == 1] plt.errorbar(B['MJD'], B['Mag'], yerr=B['Error'], fmt='o') scatter = plt.scatter(B['MJD'], B['Mag'], label='B') V = results_table[results_table['Filter'] == 2] plt.errorbar(V['MJD'], V['Mag'], yerr=V['Error'], fmt='o') plt.scatter(V['MJD'], V['Mag'], label='V') gp = results_table[results_table['Filter'] == 3] plt.errorbar(gp['MJD'], gp['Mag'], yerr=gp['Error'], fmt='o') plt.scatter(gp['MJD'], gp['Mag'], label='gp') ip = results_table[results_table['Filter'] == 4] plt.errorbar(ip['MJD'], ip['Mag'], yerr=ip['Error'], fmt='o') plt.scatter(ip['MJD'], ip['Mag'], label='ip') rp = results_table[results_table['Filter'] == 5] plt.errorbar(rp['MJD'], rp['Mag'], yerr=rp['Error'], fmt='o') plt.scatter(rp['MJD'], rp['Mag'], label='rp') I = results_table[results_table['Filter'] == 6] plt.errorbar(I['MJD'], I['Mag'], yerr=I['Error'], fmt='o') plt.scatter(I['MJD'], I['Mag'], label='SDSS-I') R = results_table[results_table['Filter'] == 7] plt.errorbar(R['MJD'], R['Mag'], yerr=R['Error'], fmt='o') plt.scatter(R['MJD'], R['Mag'], label='SDSS-R') Z = results_table[results_table['Filter'] == 8] plt.errorbar(Z['MJD'], Z['Mag'], yerr=Z['Error'], fmt='o') plt.scatter(Z['MJD'], Z['Mag'], label='SDSS-Z') G = results_table[results_table['Filter'] == 9] plt.errorbar(G['MJD'], G['Mag'], yerr=G['Error'], fmt='o') plt.scatter(G['MJD'], G['Mag'], label='SDSS-G') ax = scatter.axes ax.invert_yaxis() plt.legend() plt.savefig('Light_curve.png') plt.show()