In [1]:
    
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
    
In [2]:
    
my_data = np.loadtxt('myGAMA_ALL_AB_ABSOL_MAGS_clean.csv', delimiter=',', dtype=str)
    
In [3]:
    
print my_data.shape
    
    
In [4]:
    
my_dictionary = {}
for i in range(len(my_data[0, :])):                                         # Converting numpy array into dictionary
    my_dictionary[my_data[0, i]] = np.array(my_data[0 + 1:, i], dtype=str)
    
In [5]:
    
redshift     = my_dictionary['Z_HELIO'].astype(float)
fuv_band     = my_dictionary['MAG_AB_FUV'].astype(float)   
nuv_band     = my_dictionary['MAG_AB_NUV'].astype(float)
r_band       = my_dictionary['MAG_AB_R'].astype(float)
stellar_mass = my_dictionary['MASS_k0'].astype(float)
sex_index_r  = my_dictionary['SEX_INDEX_R'].astype(float)  #SEx Sérsic Index
sex_index_h  = my_dictionary['SEX_INDEX_H'].astype(float)  #SEx Sérsic Index
gal_index_r  = my_dictionary['GAL_INDEX_R'].astype(float)  #Galfit Sérsic Index
gal_index_h  = my_dictionary['GAL_INDEX_H'].astype(float)  #Galfit Sérsic Index
    
In [6]:
    
print sex_index_h.size
print sex_index_r
    
    
In [7]:
    
indexes = np.arange(redshift.size)
index_clean = indexes[(redshift>0.015)*(r_band>0)*(nuv_band>0)*(fuv_band>0)*((fuv_band-nuv_band)<50)*((fuv_band-nuv_band)>(-20))]
    
In [8]:
    
index_uvup        = np.where(((redshift>0.015)*(r_band>0)*(nuv_band>0)*(fuv_band>0)*(nuv_band - r_band) > 5.4)*(fuv_band-nuv_band<0.9)*(fuv_band - r_band<6.6)*(fuv_band-nuv_band<50)*(fuv_band-nuv_band>-20))
index_rsf         = np.where(((redshift>0.015)*(r_band>0)*(nuv_band>0)*(fuv_band>0)*(nuv_band - r_band) < 5.4)*(fuv_band-nuv_band<50)*(fuv_band-nuv_band>-20))
index_uvweak      = np.where(((redshift>0.015)*(r_band>0)*(nuv_band>0)*(fuv_band>0)*(nuv_band - r_band) > 5.4)*((fuv_band - r_band)>6.6)*(fuv_band-nuv_band<50)*(fuv_band-nuv_band>-20))
index_redsequence = np.where(((redshift>0.015)*(r_band>0)*(nuv_band>0)*(fuv_band>0)*(nuv_band - r_band) > 5.4)*(fuv_band-nuv_band<50)*(fuv_band-nuv_band>-20))
    
In [9]:
    
print fuv_band[index_uvup].size
print fuv_band[index_rsf].size
print fuv_band[index_uvweak].size
print (fuv_band.size)
    
    
In [10]:
    
print redshift[index_clean].min(), redshift[index_clean].max()
    
    
In [11]:
    
idx_si = indexes[(redshift>0.015)*(r_band>0)*(nuv_band>0)*(fuv_band>0)*((fuv_band-nuv_band)<50)*((fuv_band-nuv_band)>(-20))*(gal_index_r>0)*(gal_index_h>0)]
plt.subplots(1,1, figsize=(10,7))
plt.plot(gal_index_r[idx_si], gal_index_h[idx_si], 'o', color = '#fdae6b', alpha=0.7)
plt.xlabel("Sersic Index r band", fontsize=15)
plt.ylabel("Sersic Index H band", fontsize=15)
plt.ylim(0,20)
plt.xlim(0,20)
plt.tick_params('both', labelsize='15')
plt.savefig('./Figs/sex_indexes_galfit.png', dpi=100)
plt.show()
    
    
In [12]:
    
idx_si = indexes[(redshift>0.015)*(r_band>0)*(nuv_band>0)*(fuv_band>0)*((fuv_band-nuv_band)<50)*((fuv_band-nuv_band)>(-20))*(sex_index_r>0)*(sex_index_h>0)]
plt.subplots(1,1, figsize=(10,7))
plt.plot(sex_index_r[idx_si], sex_index_h[idx_si], 'o', color = '#fdae6b', alpha=0.7)
plt.xlabel("Sersic Index r band", fontsize=15)
plt.ylabel("Sersic Index H band", fontsize=15)
plt.ylim(0,20)
plt.xlim(0,20)
plt.tick_params('both', labelsize='15')
plt.savefig('./Figs/sex_indexes_sextractor.png', dpi=100)
plt.show()
    
    
In [13]:
    
sns.set_style("whitegrid")
plt.subplots(1,1, figsize=(10,7))
plt.plot((nuv_band - r_band)[index_clean], (fuv_band - nuv_band)[index_clean], 'o', color = '#fdae6b', alpha=0.7)
plt.plot((nuv_band - r_band)[index_uvup], (fuv_band - nuv_band)[index_uvup], 'o', color = '#e6550d', alpha=0.7)
plt.text(-5, 8, r"RSF", fontsize=15)
plt.text(-5, -3, r"RSF", fontsize=15)
plt.text(7, 8, r"UV Weak", fontsize=15)
plt.text(7, -3, r"UV upturn", fontsize=15)
plt.axvline(x=5.4, color='black', linewidth=2.)
plt.axhline(y=0.9, color='black', linewidth=2.)
plt.xlabel("NUV-r", fontsize=15)
plt.ylabel("FUV-NUV", fontsize=15)
plt.tick_params('both', labelsize='15')
#plt.savefig('./Figs/uvupturn_nospurious.png', dpi=100)
plt.show()
    
    
In [14]:
    
sns.set_style("whitegrid")
plt.subplots(1,1, figsize=(10,7))
plt.plot((nuv_band - r_band)[index_clean], (fuv_band - nuv_band)[index_clean], 'o', color = '#fec44f', alpha=0.7)
plt.plot((nuv_band - r_band)[index_redsequence], (fuv_band - nuv_band)[index_redsequence], 'o', color = '#feb24c', alpha=0.7)
plt.plot((nuv_band - r_band)[index_uvup], (fuv_band - nuv_band)[index_uvup], 'o', color = '#f03b20', alpha=0.7)
plt.text(-5, 8, r"RSF", fontsize=20)
plt.text(-5, -3, r"RSF", fontsize=20)
plt.text(7, 8, r"UV Weak", fontsize=20)
plt.text(7, -3, r"UV upturn", fontsize=20)
plt.axvline(x=5.4, color='black', linewidth=2.)
plt.axhline(y=0.9, color='black', linewidth=2.)
plt.xlabel("NUV-r", fontsize=20)
plt.ylabel("FUV-NUV", fontsize=20)
plt.tick_params('both', labelsize='20')
plt.grid(alpha=0.40)
plt.savefig('./Figs/yi_diagram.pdf')
plt.savefig('./Figs/yi_diagram.png')
plt.show()
    
    
In [15]:
    
print (nuv_band - r_band)[index_clean].size
    
    
In [16]:
    
sns.set_style("whitegrid")
plt.subplots(1,1, figsize=(10,7))
plt.semilogy(redshift[index_clean], stellar_mass[index_clean], 'o', alpha=0.7, color='#1b9e77', label='All Galaxies')
plt.semilogy(redshift[index_redsequence], stellar_mass[index_redsequence], 'o', alpha=0.7, color='#7570b3', label='Red Sequence (UV weak+upturn)')
plt.semilogy(redshift[index_uvup], stellar_mass[index_uvup], 'o', alpha=0.7, color='#d95f02', label='UV Upturn')
plt.xlabel("Redshift", fontsize=15)
plt.ylabel("Stellar Mass", fontsize=15)
plt.legend(loc='best', numpoints=1, fontsize=20, frameon=False)
# plt.axhline(y=5E9, color='black', linewidth=1.)
# plt.axvline(x=0.35, color='black', linewidth=1.)
# plt.axvline(x=0.015, color='black', linewidth=1.)
plt.tick_params('both', labelsize='15')
plt.xlim(0, 0.6)
plt.grid(alpha=0.40)
plt.savefig('./Figs/mass_z_uvcategories.pdf')
plt.savefig('./Figs/mass_z_uvcategories.png')
plt.show()
    
    
In [17]:
    
bins = np.arange(0, (redshift[index_clean]).max(), 0.05)
ratio_uvup_redseq = []
average_redshift = []
redshift_uvup = redshift[index_uvup]
z_uv = []
z_rs = []
for i in range(bins.size):
    if i==0:
        continue
    else:
        index_redseq_i = np.where((bins[i-1] <= redshift[index_redsequence]) * (redshift[index_redsequence] <= bins[i]))
        index_uvup_i = np.where((bins[i-1] <= redshift_uvup) * (redshift_uvup <= bins[i]))
        redshift_bin_redseq = redshift[index_redseq_i]
        redshift_bin_uvup   = redshift_uvup[index_uvup_i]
        if (redshift_bin_redseq.size==0):
            ratio_uvup_i = 0
            print "There are no UV Upturn galaxies in this range of redshift: %.2f and %.2f" % (bins[i-1], bins[i])
        else:
            ratio_uvup_i = (np.float(redshift_bin_uvup.size) / np.float(redshift_bin_redseq.size)) *100
            average_redshift_i = np.average((bins[i], bins[i-1]))
        z_uv.append(redshift_bin_uvup.size)
        z_rs.append(redshift_bin_redseq.size)
        ratio_uvup_redseq.append(ratio_uvup_i)
        average_redshift.append(average_redshift_i)
ratio_uvup_redseq = np.array(ratio_uvup_redseq)
z_uv = np.array(z_uv)
z_rs = np.array(z_rs)
average_redshift  = np.array(average_redshift)
print ratio_uvup_redseq
print average_redshift
print z_uv
print z_rs
    
    
In [18]:
    
n_groups = bins.size
index = np.arange(1,n_groups,1)
sns.set_style('white')
plt.subplots(1,1, figsize=(10,7))
plt.bar(index, ratio_uvup_redseq, width=1., alpha=0.7, color='#e6550d', edgecolor='#e6550d')
for i in range(9):
    plt.text(index[i]-.4, ratio_uvup_redseq[i]+1, r"%d/%d" % (z_uv[i], z_rs[i]))
plt.xticks(index, bins)
plt.ylabel("% of UV Upturn Galaxies", fontsize=15)
plt.xlabel("Redshift Ranges", fontsize=15)
plt.tick_params('both', labelsize='15')
plt.xlim(0, 10)
plt.ylim(0, 65)
# plt.grid(alpha=0.40)
plt.savefig('./Figs/percentageuvup_redseq.pdf')
plt.savefig('./Figs/percentageuvup_redseq.png')
plt.show()
    
    
In [19]:
    
n_groups = bins.size
# index = np.arange(1,n_groups,1)
sns.set_style('white')
plt.subplots(1,1, figsize=(10,7))
plt.hist(redshift[index_rsf], bins=bins, log=True,  color='#fec44f', alpha=0.6, label='RSF Objects')
plt.hist(redshift[index_redsequence],  bins=bins,log=True,  color='#feb24c', alpha=0.9, label='Red Sequence objects')
plt.hist(redshift[index_uvup], bins=bins, log=True, color='#f03b20', alpha=0.8,  label='UV Upturn')
# plt.xticks(index, bins)
plt.ylabel("Frequency", fontsize=20)
plt.xlabel("Redshift Ranges", fontsize=20)
plt.tick_params('both', labelsize='15')
plt.xlim(0, 0.6)
plt.legend(loc='best', numpoints=1, fontsize=20, frameon=False)
# plt.grid(alpha=0.40)
plt.savefig('./Figs/gal_dist.pdf')
plt.savefig('./Figs/gal_dist.png')
plt.show()
    
    
In [20]:
    
plt.subplots(1,1, figsize=(10,7))
plt.plot(average_redshift, ratio_uvup_redseq, 'o')
plt.ylabel("% of UV Upturn Galaxies", fontsize=15)
plt.xlabel("Redshift Ranges", fontsize=15)
plt.tick_params('both', labelsize='15')
plt.xlim(0.,0.4)
plt.savefig('./Figs/uv_trend.pdf')
plt.savefig('./Figs/uv_trend.png')
plt.show()
    
    
In [21]:
    
mag_abs_r = my_dictionary['MAG_ABSOLUTE_R'].astype(float)
g_band = my_dictionary['MAG_AB_G'].astype(float)
    
In [22]:
    
with plt.style.context("seaborn-whitegrid"):
    plt.rcParams["axes.edgecolor"] = "0.15"
    plt.rcParams["axes.linewidth"]  = 1.25
    
    plt.subplots(1,1, figsize=(10,7))
    plt.plot(mag_abs_r[index_clean], (nuv_band[index_clean]- r_band[index_clean]), 'o', color='gray', alpha=0.05, label='All galaxies')
    plt.plot(mag_abs_r[index_uvup], (nuv_band[index_uvup] - r_band[index_uvup]), 'o', color='#e6550d', alpha=0.2, label='UV Upturn')
    sns.kdeplot(mag_abs_r[index_clean], (nuv_band[index_clean] - r_band[index_clean]), n_levels=50, shade=False, 
                cmap="Purples_d", cbar=True)
    plt.xlabel("M$_r$", fontsize=15)
    plt.ylabel("NUV-r", fontsize=15)
    plt.tick_params('both', labelsize='15')
#     plt.xlim(-23, -16.5)
    plt.ylim(-2, 10)
    plt.legend(loc='best', numpoints=100, fontsize=20, frameon=False)
      
    plt.savefig('./Figs/color_mag01.pdf')
    plt.savefig('./Figs/color_mag01.png')
    plt.show()
    
    
In [23]:
    
with plt.style.context("seaborn-whitegrid"):
    plt.rcParams["axes.edgecolor"] = "0.15"
    plt.rcParams["axes.linewidth"]  = 1.25
    
    plt.subplots(1,1, figsize=(10,7))    
    index01 = np.where(((g_band - r_band) <1) * ((nuv_band - r_band) > 5.4) * ((fuv_band - nuv_band) < 0.9) * ((fuv_band - r_band) < 6.6))
    plt.plot(mag_abs_r[index_clean], (g_band - r_band)[index_clean], 'o', color='gray', alpha=0.05, label='All galaxies')
    plt.plot(mag_abs_r[index_uvup], (g_band - r_band)[index_uvup], 'o', color='#e6550d', alpha=0.2, label='UV Upturn')
    sns.kdeplot(mag_abs_r[index_clean], (g_band - r_band)[index_clean], n_levels=50, shade=False, 
                        cmap="Purples_d", cbar=True)
    plt.ylim(-1., 4.)
    plt.xlim()
    plt.xlabel("M$_r$", fontsize=15)
    plt.ylabel("g-r", fontsize=15)
    plt.tick_params('both', labelsize='15')
    plt.legend(loc='best', numpoints=100, fontsize=20, frameon=False)
    plt.savefig('./Figs/color_mag02.pdf')
    plt.savefig('./Figs/color_mag02.png')
    plt.show()
    
    
In [24]:
    
print my_data[0,:]
    
    
In [25]:
    
header = my_data[0,:]
    
In [26]:
    
print my_data[1:,0].size
print my_data[0,:].size
    
    
In [27]:
    
my_data_clean = my_data[1:,:][index_clean]
    
In [28]:
    
print my_data[1:,:].shape
print my_data_clean.shape
print header
    
    
In [29]:
    
my_data_clean_df = pd.DataFrame(my_data_clean)
    
In [30]:
    
my_data_clean_df.to_csv('./myGAMA_ALL_AB_ABSOL_MAGS_clean_postprocess.csv', sep=',', header=header, index=False)
    
In [31]:
    
sex_clean = sex_index_r[index_clean][[(sex_index_r[index_clean]!=-9999.)*(gal_index_r[index_clean]!=-9999.)*(sex_index_r[index_clean]<=15)*(gal_index_r[index_clean]<=15)]]
gal_clean = gal_index_r[index_clean][[(sex_index_r[index_clean]!=-9999.)*(gal_index_r[index_clean]!=-9999.)*(sex_index_r[index_clean]<=15)*(gal_index_r[index_clean]<=15)]]
    
In [32]:
    
plt.hist(sex_clean, bins=50)
# plt.gca().set_yscale("log")
plt.show()
    
    
In [33]:
    
plt.hist(gal_clean, bins=50)
# plt.gca().set_yscale("log")
plt.show()
    
    
In [34]:
    
bins_sersic = np.arange(0, gal_clean.max(), 0.5)
    
In [35]:
    
sns.set_style("white")
plt.subplots(1,1, figsize=(10,7))
plt.hist(gal_index_r[index_rsf][[gal_index_r[index_rsf]<=10]], color='#fec44f', alpha=0.4, bins=bins_sersic, log=True, label='RSF Objects')
plt.hist(gal_index_r[index_redsequence][[gal_index_r[index_redsequence]<=10]], color='#feb24c', alpha=0.8, bins=bins_sersic, log=True, label='Red Sequence objects')
plt.hist(gal_index_r[index_uvup][[gal_index_r[index_uvup]<=10]], color='#f03b20', alpha=0.8, bins=bins_sersic, log=True, label='UV Upturn')
plt.xlabel("Sersic Index (SDSS r band)", fontsize=20)
plt.ylabel("Frequency", fontsize=20)
plt.tick_params('both', labelsize='15')
plt.xlim(0,11)
plt.legend(loc='best', numpoints=1, fontsize=20, frameon=False)
plt.savefig('./Figs/sersic_dist.pdf')
plt.show()
    
    
In [ ]: