Exemplo n.º 1
0
def plot_wise(cat_path):

    for catfile in find_files(cat_path, "*merged+wise.csv"):

        print("\nreading catalog: {}".format(catfile))
        df = pd.read_csv(catfile)

        # convert to magnitudes
        nbadflux = (df.flux <= 0).sum()
        try:
            assert nbadflux == 0
        except:
            print("warning: {} negative flux source(s)".format(nbadflux))
        ch = catfile.split('/')[-1].split('_')[1]
        mags = spz_jy_to_mags(df.flux * 1e-3, float(ch))
        if ch == '1':
            plt.scatter(df.W1mag, mags)
            plt.xlabel('W1 [mag]')
            plt.ylabel('I1 [mag]')
        elif ch == '2':
            plt.scatter(df.W2mag, mags)
            plt.xlabel('W2 [mag]')
            plt.ylabel('I2 [mag]')
        ax = plt.gca()
        xlim, ylim = ax.get_xlim(), ax.get_ylim()
        plt.plot([-5, ylim[1] * 2], [-5, ylim[1] * 2], 'r-')
        ax.set_xlim(xlim)
        ax.set_ylim(ylim)
        reg = catfile.split('/')[-1].split('_')[0]
        name = '{}_{}_IRAC_vs_WISE.png'.format(reg, ch)
        outpath = '/'.join(catfile.split('/')[:-1] + [name])
        plt.savefig(outpath, dpi=120)
        plt.close()
Exemplo n.º 2
0
def plot_wise(cat_path):

	for catfile in find_files(cat_path, "*merged+wise.csv"):

		print("\nreading catalog: {}".format(catfile))
		df = pd.read_csv(catfile)

		# convert to magnitudes
		nbadflux = (df.flux <= 0).sum()
		try:
			assert nbadflux == 0
		except:
			print("warning: {} negative flux source(s)".format(nbadflux))
		ch = catfile.split('/')[-1].split('_')[1]
		mags = spz_jy_to_mags(df.flux*1e-3, float(ch))
		if ch == '1':
			plt.scatter(df.W1mag, mags)
			plt.xlabel('W1 [mag]')
			plt.ylabel('I1 [mag]')
		elif ch == '2':
			plt.scatter(df.W2mag, mags)
			plt.xlabel('W2 [mag]')
			plt.ylabel('I2 [mag]')
		ax = plt.gca()
		xlim, ylim = ax.get_xlim(), ax.get_ylim()
		plt.plot([-5, ylim[1]*2], [-5, ylim[1]*2], 'r-')
		ax.set_xlim(xlim) ; ax.set_ylim(ylim)
		reg = catfile.split('/')[-1].split('_')[0]
		name = '{}_{}_IRAC_vs_WISE.png'.format(reg, ch)
		outpath = '/'.join(catfile.split('/')[:-1]+[name])
		plt.savefig(outpath, dpi=120)
		plt.close()
Exemplo n.º 3
0
def plot_sdss(cat_path):
    for catfile in find_files(cat_path, "*merged+sdss.txt"):

        # for now ignore the channel 2 files
        if catfile.split('/')[-1].split('_')[1] != '1':
            continue

        print("\nreading catalog: {}".format(catfile))
        df = pd.read_table(catfile, sep=' ')

        # get rid of negative flux sources, if any
        df = df[df.flux > 0]

        # convert to magnitudes
        mags = spz_jy_to_mags(df.flux * 1e-3, 1)

        # print counts per magnitude bin
        for i in range(10, 15):
            sc = ((df.cl == 3) & (mags > i) & (mags < i + 1)).sum()
            xc = ((df.xsc == 1) & (mags > i) & (mags < i + 1)).sum()
            msg = "{}th to {}th mag: {} SDSS galaxy sources, {} 2MASS XSC sources"
            print(msg.format(i, i + 1, sc, xc))

        # print number of sources agreed upon
        agree = ((df.xsc == 1) & (df.cl == 3)).sum()
        disagree = ((df.xsc == 1) & (df.cl == 6)).sum()
        na = ((df.xsc == 1) & (df.cl == 0)).sum()
        msg = "{} 2MASS XSC sources classified as galaxies by SDSS"
        print(msg.format(agree))
        msg = "{} 2MASS XSC sources classified as stars by SDSS"
        print(msg.format(disagree))
        msg = "{} 2MASS XSC sources not matched to SDSS"
        print(msg.format(na))

        # plot normed histograms of 2MASS XSC and SDSS galaxy magnitudes
        xsc_gals = (mags > 10) & (mags < 15) & (df.xsc == 1)
        sdss_gals = (mags > 10) & (mags < 15) & (df.cl == 3)
        # mags[xsc_gals].hist(label='2MASS XSC', normed=True)
        # mags[sdss_gals].hist(label='SDSS galaxies', normed=True)
        plt.hist([mags[xsc_gals].values, mags[sdss_gals].values],
                 bins=5,
                 label=['2MASS', 'SDSS'])
        plt.xlabel('IRAC1 [mag]')
        plt.ylabel('Number Count')
        reg = catfile.split('/')[-1].split('_')[0]
        plt.title('{} Extended Sources / Galaxies'.format(reg))
        plt.legend(loc=2)
        name = '{}_2mass_xsc_vs_sdss_hist.png'.format(reg)
        outpath = '/'.join(catfile.split('/')[:-1] + [name])
        plt.savefig(outpath, dpi=100)
        plt.close()
        print("created file: {}".format(outpath))
Exemplo n.º 4
0
def plot_sdss(cat_path):
	for catfile in find_files(cat_path, "*merged+sdss.txt"):

		# for now ignore the channel 2 files
		if catfile.split('/')[-1].split('_')[1] != '1':
			continue

		print("\nreading catalog: {}".format(catfile))
		df = pd.read_table(catfile, sep=' ')

		# get rid of negative flux sources, if any
		df = df[df.flux > 0]

		# convert to magnitudes
		mags = spz_jy_to_mags(df.flux*1e-3, 1)

		# print counts per magnitude bin
		for i in range(10,15):
			sc = ((df.cl == 3) & (mags > i) & (mags < i+1)).sum()
			xc = ((df.xsc == 1) & (mags > i) & (mags < i+1)).sum() 
			msg = "{}th to {}th mag: {} SDSS galaxy sources, {} 2MASS XSC sources"
			print(msg.format(i, i+1, sc, xc))

		# print number of sources agreed upon
		agree = ((df.xsc == 1) & (df.cl == 3)).sum()
		disagree = ((df.xsc == 1) & (df.cl == 6)).sum()
		na = ((df.xsc == 1) & (df.cl == 0)).sum()
		msg = "{} 2MASS XSC sources classified as galaxies by SDSS"
		print(msg.format(agree))
		msg = "{} 2MASS XSC sources classified as stars by SDSS"
		print(msg.format(disagree))
		msg = "{} 2MASS XSC sources not matched to SDSS"
		print(msg.format(na))

		# plot normed histograms of 2MASS XSC and SDSS galaxy magnitudes
		xsc_gals = (mags > 10) & (mags < 15) & (df.xsc == 1)
		sdss_gals = (mags > 10) & (mags < 15) & (df.cl == 3)
		# mags[xsc_gals].hist(label='2MASS XSC', normed=True)
		# mags[sdss_gals].hist(label='SDSS galaxies', normed=True)
		plt.hist([mags[xsc_gals].values, mags[sdss_gals].values],
			bins=5, label=['2MASS', 'SDSS'])
		plt.xlabel('IRAC1 [mag]')
		plt.ylabel('Number Count')
		reg = catfile.split('/')[-1].split('_')[0]
		plt.title('{} Extended Sources / Galaxies'.format(reg))
		plt.legend(loc=2)
		name = '{}_2mass_xsc_vs_sdss_hist.png'.format(reg)
		outpath = '/'.join(catfile.split('/')[:-1]+[name])
		plt.savefig(outpath, dpi=100)
		plt.close()
		print("created file: {}".format(outpath))
Exemplo n.º 5
0
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')
Exemplo n.º 6
0
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')