def make_2ch_catalogs(cat_tuple, tol=2 / 3600.0): ch1, ch2 = cat_tuple reg1 = ch1.split("/")[-1].split("_")[0] reg2 = ch2.split("/")[-1].split("_")[0] assert reg1 == reg2 df1 = pd.read_csv(ch1, sep=" ") df2 = pd.read_csv(ch2, sep=" ") idx1, idx2 = match_cats(df1, df2, tol=tol) matched1 = df1.loc[idx1] matched2 = df2.loc[idx2] ch1_cols = [i + "_1" for i in df1.columns.tolist()] ch2_cols = [i + "_2" for i in df2.columns.tolist()] matched1.columns = ch1_cols matched2.columns = ch2_cols # matched = np.concatenate([matched1.values, matched2.values], 1) # df_matched = pd.DataFrame(matched, columns=ch1_cols+ch2_cols) # df_matched[['n_obs_1', 'n_obs_2']] = df_matched[['n_obs_1', 'n_obs_2']].astype(int) matched1.index = pd.Index(np.arange(matched1.shape[0])) matched2.index = pd.Index(np.arange(matched2.shape[0])) df_matched = pd.concat([matched1, matched2], 1) out_path = "/".join(ch1.split("/")[:-2]) + "/{}_2ch_matched.csv".format(reg1) df_matched.to_csv(out_path, index=False, float_format="%.8f") print("created file: " + out_path)
def plot_spz_vs_wise_sdss_class(cat_path, plot_style='scatter'): ch1 = list(find_files(cat_path, "*merged+sdss+wise.csv"))[::2] ch2 = list(find_files(cat_path, "*merged+sdss+wise.csv"))[1::2] for ch1, ch2 in zip(ch1, ch2): reg1 = ch1.split('/')[-1].split('_')[0] reg2 = ch2.split('/')[-1].split('_')[0] assert reg1 == reg2 print("\nreading catalog: {}".format(ch1)) print("reading catalog: {}".format(ch2)) df1 = pd.read_csv(ch1) df2 = pd.read_csv(ch2) # convert to magnitudes mags1 = spz_jy_to_mags(df1.flux * 1e-3, 1) mags2 = spz_jy_to_mags(df2.flux * 1e-3, 2) # match ch1 / ch2 idx1, idx2 = match_cats(df1, df2, tol=2 / 3600.) # save matched catalogs matched1 = df1.loc[idx1] matched2 = df2.loc[idx2] ch1_cols = [i + '_1' for i in df1.columns.tolist()] ch2_cols = [i + '_2' for i in df2.columns.tolist()] # matched1.columns = ch1_cols # matched2.columns = ch2_cols # matched = pd.concat([matched1, matched2], 1, ignore_index=True) # weird error matched = np.concatenate([matched1.values, matched2.values], 1) df_matched = pd.DataFrame(matched, columns=ch1_cols + ch2_cols) df_matched['I1'] = mags1[idx1].values df_matched['I2'] = mags2[idx2].values outpath = '/'.join( ch1.split('/')[:-1]) + '/{}_2ch_matched+sdss.csv'.format(reg1) df_matched.to_csv(outpath, index=False, float_format='%.8f') print("created file: {}".format(outpath)) # identify SDSS galaxies and stars galaxies = (df1.cl[idx1].values == 3) & (df2.cl[idx2].values == 3) stars = (df1.cl[idx1].values == 6) & (df2.cl[idx2].values == 6) # plot I1-I2 vs. W1-W2 color1 = df1.W1mag[idx1].values - df2.W2mag[idx2].values color2 = mags1[idx1].values - mags2[idx2].values # galaxies name = '{}_I1-I2_vs_W1-W2_galaxies_plot_style.png'.format(reg1) name = name.replace('plot_style', plot_style) outpath = '/'.join(ch1.split('/')[:-1] + [name]) plot(color1[galaxies], color2[galaxies], outpath, 'W1-W2 [mag]', 'I1-I2 [mag]', plot_style=plot_style, plot_type='color-color') # stars outpath = '/'.join(ch1.split('/')[:-1] + [name]).replace( 'galaxies', 'stars') plot(color1[stars], color2[stars], outpath, 'W1-W2 [mag]', 'I1-I2 [mag]', plot_style=plot_style, plot_type='color-color') # plot I1-W1 vs. I2-W2 color1 = mags1[idx1].values - df1.W1mag[idx1].values color2 = mags2[idx2].values - df2.W2mag[idx2].values # galaxies name = '{}_I1-W1_vs_I2-W2_galaxies_plot_style.png'.format(reg1) name = name.replace('plot_style', plot_style) outpath = '/'.join(ch1.split('/')[:-1] + [name]) plot(color1[galaxies], color2[galaxies], outpath, 'I1-W1 [mag]', 'I2-W2 [mag]', plot_style=plot_style, plot_type='color-color') # stars outpath = '/'.join(ch1.split('/')[:-1] + [name]).replace( 'galaxies', 'stars') plot(color1[stars], color2[stars], outpath, 'I1-W1 [mag]', 'I2-W2 [mag]', plot_style=plot_style, plot_type='color-color') # plot spz color-magnitude diagrams color = mags1[idx1].values - mags2[idx2].values mags = mags1[idx1].values # galaxies name = '{}_I1_vs_I1-I2_galaxies_plot_style.png'.format(reg1) name = name.replace('plot_style', plot_style) outpath = '/'.join(ch1.split('/')[:-1] + [name]) plot(mags[galaxies], color[galaxies], outpath, 'I1 [mag]', 'I1-I2 [mag]', plot_style=plot_style, plot_type='color-mag') # stars outpath = '/'.join(ch1.split('/')[:-1] + [name]).replace( 'galaxies', 'stars') plot(mags[stars], color[stars], outpath, 'I1 [mag]', 'I1-I2 [mag]', plot_style=plot_style, plot_type='color-mag') # plot wise color-magnitude diagrams color = df1.W1mag[idx1].values - df2.W2mag[idx2].values mags = df1.W1mag[idx1].values # galaxies name = '{}_W1_vs_W1-W2_galaxies_plot_style.png'.format(reg1) name = name.replace('plot_style', plot_style) outpath = '/'.join(ch1.split('/')[:-1] + [name]) plot(mags[galaxies], color[galaxies], outpath, 'W1 [mag]', 'W1-W2 [mag]', plot_style=plot_style, plot_type='color-mag') # stars outpath = '/'.join(ch1.split('/')[:-1] + [name]).replace( 'galaxies', 'stars') plot(mags[stars], color[stars], outpath, 'W1 [mag]', 'W1-W2 [mag]', plot_style=plot_style, plot_type='color-mag') # plot I1 vs I2 mags1_matched = mags1[idx1].values mags2_matched = mags2[idx2].values # galaxies name = '{}_I1_vs_I2_galaxies_plot_style.png'.format(reg1) name = name.replace('plot_style', plot_style) outpath = '/'.join(ch1.split('/')[:-1] + [name]) plot(mags1_matched[galaxies], mags2_matched[galaxies], outpath, 'I1 [mag]', 'I2 [mag]', plot_style=plot_style, plot_type='mag-mag') # stars outpath = '/'.join(ch1.split('/')[:-1] + [name]).replace( 'galaxies', 'stars') plot(mags1_matched[stars], mags2_matched[stars], outpath, 'I1 [mag]', 'I2 [mag]', plot_style=plot_style, plot_type='mag-mag')
def plot_spz_vs_wise_sdss_class(cat_path, plot_style='scatter'): ch1 = list(find_files(cat_path, "*merged+sdss+wise.csv"))[::2] ch2 = list(find_files(cat_path, "*merged+sdss+wise.csv"))[1::2] for ch1, ch2 in zip(ch1, ch2): reg1 = ch1.split('/')[-1].split('_')[0] reg2 = ch2.split('/')[-1].split('_')[0] assert reg1 == reg2 print("\nreading catalog: {}".format(ch1)) print("reading catalog: {}".format(ch2)) df1 = pd.read_csv(ch1) df2 = pd.read_csv(ch2) # convert to magnitudes mags1 = spz_jy_to_mags(df1.flux*1e-3, 1) mags2 = spz_jy_to_mags(df2.flux*1e-3, 2) # match ch1 / ch2 idx1, idx2 = match_cats(df1, df2, tol=2/3600.) # save matched catalogs matched1 = df1.loc[idx1] matched2 = df2.loc[idx2] ch1_cols = [i+'_1' for i in df1.columns.tolist()] ch2_cols = [i+'_2' for i in df2.columns.tolist()] # matched1.columns = ch1_cols # matched2.columns = ch2_cols # matched = pd.concat([matched1, matched2], 1, ignore_index=True) # weird error matched = np.concatenate([matched1.values, matched2.values], 1) df_matched = pd.DataFrame(matched, columns=ch1_cols+ch2_cols) df_matched['I1'] = mags1[idx1].values df_matched['I2'] = mags2[idx2].values outpath = '/'.join(ch1.split('/')[:-1])+'/{}_2ch_matched+sdss.csv'.format(reg1) df_matched.to_csv(outpath, index=False, float_format='%.8f') print("created file: {}".format(outpath)) # identify SDSS galaxies and stars galaxies = (df1.cl[idx1].values == 3) & (df2.cl[idx2].values == 3) stars = (df1.cl[idx1].values == 6) & (df2.cl[idx2].values == 6) # plot I1-I2 vs. W1-W2 color1 = df1.W1mag[idx1].values - df2.W2mag[idx2].values color2 = mags1[idx1].values - mags2[idx2].values # galaxies name = '{}_I1-I2_vs_W1-W2_galaxies_plot_style.png'.format(reg1) name = name.replace('plot_style', plot_style) outpath = '/'.join(ch1.split('/')[:-1]+[name]) plot(color1[galaxies], color2[galaxies], outpath, 'W1-W2 [mag]', 'I1-I2 [mag]', plot_style=plot_style, plot_type='color-color') # stars outpath = '/'.join(ch1.split('/')[:-1]+[name]).replace('galaxies', 'stars') plot(color1[stars], color2[stars], outpath, 'W1-W2 [mag]', 'I1-I2 [mag]', plot_style=plot_style, plot_type='color-color') # plot I1-W1 vs. I2-W2 color1 = mags1[idx1].values - df1.W1mag[idx1].values color2 = mags2[idx2].values - df2.W2mag[idx2].values # galaxies name = '{}_I1-W1_vs_I2-W2_galaxies_plot_style.png'.format(reg1) name = name.replace('plot_style', plot_style) outpath = '/'.join(ch1.split('/')[:-1]+[name]) plot(color1[galaxies], color2[galaxies], outpath, 'I1-W1 [mag]', 'I2-W2 [mag]', plot_style=plot_style, plot_type='color-color') # stars outpath = '/'.join(ch1.split('/')[:-1]+[name]).replace('galaxies', 'stars') plot(color1[stars], color2[stars], outpath, 'I1-W1 [mag]', 'I2-W2 [mag]', plot_style=plot_style, plot_type='color-color') # plot spz color-magnitude diagrams color = mags1[idx1].values - mags2[idx2].values mags = mags1[idx1].values # galaxies name = '{}_I1_vs_I1-I2_galaxies_plot_style.png'.format(reg1) name = name.replace('plot_style', plot_style) outpath = '/'.join(ch1.split('/')[:-1]+[name]) plot(mags[galaxies], color[galaxies], outpath, 'I1 [mag]', 'I1-I2 [mag]', plot_style=plot_style, plot_type='color-mag') # stars outpath = '/'.join(ch1.split('/')[:-1]+[name]).replace('galaxies', 'stars') plot(mags[stars], color[stars], outpath, 'I1 [mag]', 'I1-I2 [mag]', plot_style=plot_style, plot_type='color-mag') # plot wise color-magnitude diagrams color = df1.W1mag[idx1].values - df2.W2mag[idx2].values mags = df1.W1mag[idx1].values # galaxies name = '{}_W1_vs_W1-W2_galaxies_plot_style.png'.format(reg1) name = name.replace('plot_style', plot_style) outpath = '/'.join(ch1.split('/')[:-1]+[name]) plot(mags[galaxies], color[galaxies], outpath, 'W1 [mag]', 'W1-W2 [mag]', plot_style=plot_style, plot_type='color-mag') # stars outpath = '/'.join(ch1.split('/')[:-1]+[name]).replace('galaxies', 'stars') plot(mags[stars], color[stars], outpath, 'W1 [mag]', 'W1-W2 [mag]', plot_style=plot_style, plot_type='color-mag') # plot I1 vs I2 mags1_matched = mags1[idx1].values mags2_matched = mags2[idx2].values # galaxies name = '{}_I1_vs_I2_galaxies_plot_style.png'.format(reg1) name = name.replace('plot_style', plot_style) outpath = '/'.join(ch1.split('/')[:-1]+[name]) plot(mags1_matched[galaxies], mags2_matched[galaxies], outpath, 'I1 [mag]', 'I2 [mag]', plot_style=plot_style, plot_type='mag-mag') # stars outpath = '/'.join(ch1.split('/')[:-1]+[name]).replace('galaxies', 'stars') plot(mags1_matched[stars], mags2_matched[stars], outpath, 'I1 [mag]', 'I2 [mag]', plot_style=plot_style, plot_type='mag-mag')