Libraries


In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

In [2]:
# %matplotlib notebook

Loading Dataset


In [3]:
my_data = np.loadtxt('../Catalogue/Match07_smalldoubleclean_emlines.csv', delimiter=',', dtype=str)

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]:
print my_data.shape
print my_data.size
print my_data[0,:]


(14332, 164)
2350448
['CATAID' 'OBJID_SDSSDR7' 'ALPHA_J2000' 'DELTA_J2000' 'KRON_RADIUS'
 'PETRO_RADIUS' 'MAG_PETRO_u' 'MAGERR_PETRO_u' 'FLAGS_u' 'MAG_PETRO_g'
 'MAGERR_PETRO_g' 'FLAGS_g' 'MAG_PETRO_r' 'MAGERR_PETRO_r' 'FLAGS_r'
 'MAG_PETRO_i' 'MAGERR_PETRO_i' 'FLAGS_i' 'MAG_PETRO_z' 'MAGERR_PETRO_z'
 'FLAGS_z' 'MAG_PETRO_X' 'MAGERR_PETRO_X' 'FLAGS_X' 'MAG_PETRO_Y'
 'MAGERR_PETRO_Y' 'FLAGS_Y' 'MAG_PETRO_J' 'MAGERR_PETRO_J' 'FLAGS_J'
 'MAG_PETRO_H' 'MAGERR_PETRO_H' 'FLAGS_H' 'MAG_PETRO_K' 'MAGERR_PETRO_K'
 'FLAGS_K' 'FLAGS' 'PSFMAG_R' 'FIBERMAG_R' 'FLAGS_R_SDSS' 'PETRORAD_R'
 'PETROR90_R' 'PETROR50_R' 'PETROMAG_R' 'MODELMAG_U' 'MODELMAG_G'
 'MODELMAG_R' 'MODELMAG_I' 'MODELMAG_Z' 'STATUS' 'BEST_MAG_NUV'
 'BEST_MAGERR_NUV' 'BEST_MAG_FUV' 'BEST_MAGERR_FUV' 'BEST_METHOD'
 'NMATCHUV' 'NMATCHOPT' 'NUVFLAG' 'FUVFLAG' 'NN_DIST' 'NN_NMATCH4'
 'NN_MANY2ONE' 'NN_SFLAGS_NUV' 'NN_SFLAGS_FUV' 'KCORR_FUV' 'KCORR_NUV'
 'KCORR_U' 'KCORR_G' 'KCORR_R' 'KCORR_I' 'KCORR_Z' 'KCORR_Y' 'KCORR_J'
 'KCORR_H' 'KCORR_K' 'CHI2' 'MASS' 'INTSFH' 'METS' 'B300' 'B1000'
 'SURVEY_CODE' 'SURVEY_CLASS' 'nbands' 'S2N' 'PPP' 'logmstar' 'dellogmstar'
 'logmoverl_i' 'dellogmoverl_i' 'logage' 'dellogage' 'logtau' 'dellogtau'
 'logmintsfh' 'dellogmintsfh' 'logmremnants' 'dellogmremnants' 'metal'
 'delmetal' 'extBV' 'delextBV' 'logLWage' 'dellogLWage' 'gminusi'
 'delgminusi' 'uminusr' 'deluminusr' 'gminusi_stars' 'uminusr_stars'
 'C_logM_ur' 'C_logM_gi' 'C_logM_eBV' 'SPECID' 'SURVEY_CODE_EMLINES' 'SN'
 'D4000N' 'D4000N_ERR' 'SURVEY' 'Z' 'NQ' 'PROB' 'HB_FLUX_COMP'
 'HB_FLUX_ERR_COMP' 'HB_EW_COMP' 'HB_EW_ERR_COMP' 'OIIIR_FLUX_COMP'
 'OIIIR_FLUX_ERR_COMP' 'OIIIR_EW_COMP' 'OIIIR_EW_ERR_COMP' 'HA_FLUX_COMP'
 'HA_FLUX_ERR_COMP' 'HA_EW_COMP' 'HA_EW_ERR_COMP' 'NIIR_FLUX_COMP'
 'NIIR_FLUX_ERR_COMP' 'NIIR_EW_COMP' 'NIIR_EW_ERR_COMP' 'MAG_AB_FUV'
 'MAG_AB_NUV' 'MAG_AB_U' 'MAG_AB_G' 'MAG_AB_R' 'MAG_AB_I' 'MAG_AB_Z'
 'MAG_AB_Y' 'MAG_AB_J' 'MAG_AB_H' 'MAG_AB_K' 'MAG_ABSOLUTE_FUV'
 'MAG_ABSOLUTE_NUV' 'MAG_ABSOLUTE_U' 'MAG_ABSOLUTE_G' 'MAG_ABSOLUTE_R'
 'MAG_ABSOLUTE_I' 'MAG_ABSOLUTE_Z' 'MAG_ABSOLUTE_Y' 'MAG_ABSOLUTE_J'
 'MAG_ABSOLUTE_H' 'MAG_ABSOLUTE_K' 'UV_CLASS_YI2011' 'TYPE' 'BPT_CLASS'
 'WHAN_CLASS']

In [6]:
redshift     = my_dictionary['Z'].astype(float)
cataid       = my_dictionary['CATAID'].astype(str)
z_prob       = my_dictionary['PROB'].astype(float)
z_quality    = my_dictionary['NQ'].astype(int)
fuv_band     = my_dictionary['MAG_AB_FUV'].astype(float)   
nuv_band     = my_dictionary['MAG_AB_NUV'].astype(float)
u_band       = my_dictionary['MAG_AB_U'].astype(float)
g_band       = my_dictionary['MAG_AB_G'].astype(float)
r_band       = my_dictionary['MAG_AB_R'].astype(float)
mag_abs_r    = my_dictionary['MAG_ABSOLUTE_R'].astype(float)
stellar_mass = my_dictionary['logmstar'].astype(float)   # stellar mass from sed fitting - log scale
stellar_age  = my_dictionary['logage'].astype(float)     # stellar age - log scale
stellar_met  = my_dictionary['metal'].astype(float)      # stellar metallicity
dn4000       = my_dictionary['D4000N'].astype(float)     
h_alpha_flux = my_dictionary['HA_FLUX_COMP'].astype(float)    
h_alpha_ew   = my_dictionary['HA_EW_COMP'].astype(float)      
h_beta_flux  = my_dictionary['HB_FLUX_COMP'].astype(float)    
h_beta_ew    = my_dictionary['HB_EW_COMP'].astype(float)      
nii_flux     = my_dictionary['NIIR_FLUX_COMP'].astype(float)  # R for red or 6583A -- see http://www.gama-survey.org/dr3/schema/dmu.php?id=8
oiii_flux    = my_dictionary['OIIIR_EW_COMP'].astype(float)   # R for red or 5007A -- see http://www.gama-survey.org/dr3/schema/dmu.php?id=8
uv_class     = my_dictionary['UV_CLASS_YI2011'].astype(str)
whan_class   = my_dictionary['WHAN_CLASS'].astype(str)

In [7]:
print np.unique(uv_class)
print np.unique(whan_class)


['RSF' 'UV_UPTURN' 'UV_WEAK']
['NA' 'Retired/Passive' 'SF' 'sAGN' 'wAGN']

In [8]:
print my_data[:,0].shape


(14332,)

In [9]:
idx_uvup   = np.where(uv_class=='UV_UPTURN')
idx_uvwk   = np.where(uv_class=='UV_WEAK')
idx_redseq = list(idx_uvup[0]) + list(idx_uvwk[0])

In [10]:
bins = np.arange(0, (redshift[idx_uvup]).max(), 0.05)
average_redshift = []
z_uvup_all = []
z_sf = []
z_sa = []
z_wa = []
z_rp = []
z_na = []
ratio_sf = []
ratio_wa = []
ratio_sa = []
ratio_rp = []
ratio_na = []
z_uvup = redshift[idx_uvup]
z_sf   = z_uvup[np.where(whan_class[idx_uvup]=='SF')]
z_sa   = z_uvup[np.where(whan_class[idx_uvup]=='sAGN')]
z_wa   = z_uvup[np.where(whan_class[idx_uvup]=='wAGN')]
z_rp   = z_uvup[np.where(whan_class[idx_uvup]=='Retired/Passive')]
z_na   = z_uvup[np.where(whan_class[idx_uvup]=='NA')]

In [11]:
for i in range(bins.size):
    if i==0:
        continue
    else:
        index_uvup_i = np.where((bins[i-1]<=z_uvup)*(z_uvup<=bins[i])) 
        index_sf_i   = np.where((bins[i-1]<=z_sf)*(z_sf<=bins[i]))
        index_sa_i   = np.where((bins[i-1]<=z_sa)*(z_sa<=bins[i]))
        index_wa_i   = np.where((bins[i-1]<=z_wa)*(z_wa<=bins[i]))
        index_rp_i   = np.where((bins[i-1]<=z_rp)*(z_rp<=bins[i]))
        index_na_i   = np.where((bins[i-1]<=z_na)*(z_na<=bins[i]))
        z_bin_uvup   = z_uvup[index_uvup_i]
        z_bin_sf     = z_sf[index_sf_i]
        z_bin_sa     = z_sa[index_sa_i]
        z_bin_wa     = z_wa[index_wa_i]
        z_bin_rp     = z_rp[index_rp_i]
        z_bin_na     = z_na[index_na_i]
        
        if (z_bin_uvup.size==0):
            ratio_sf_i = 0
            ratio_sa_i = 0
            ratio_wa_i = 0
            ratio_rp_i = 0
            ratio_na_i = 0
            print "There are no UV Upturn galaxies in this range of redshift: %.2f and %.2f" % (bins[i-1], bins[i])
        else:
            ratio_sf_i = (np.float(z_bin_sf.size)/np.float(z_bin_uvup.size))*100
            ratio_sa_i = (np.float(z_bin_sa.size)/np.float(z_bin_uvup.size))*100
            ratio_wa_i = (np.float(z_bin_wa.size)/np.float(z_bin_uvup.size))*100
            ratio_rp_i = (np.float(z_bin_rp.size)/np.float(z_bin_uvup.size))*100
            ratio_na_i = (np.float(z_bin_na.size)/np.float(z_bin_uvup.size))*100 
        ratio_sf.append(ratio_sf_i)
        ratio_sa.append(ratio_sa_i)
        ratio_wa.append(ratio_wa_i)
        ratio_rp.append(ratio_rp_i)
        ratio_na.append(ratio_na_i)
ratio_sf = np.array(ratio_sf)
ratio_sa = np.array(ratio_sa)
ratio_wa = np.array(ratio_wa)
ratio_rp = np.array(ratio_rp)
ratio_na = np.array(ratio_na)


There are no UV Upturn galaxies in this range of redshift: 0.00 and 0.05

In [12]:
%matplotlib notebook

In [13]:
palette = ['#018571', '#80cdc1', '#dfc27d', '#a6611a', 'gray']
alphas  = float(0.85)

In [14]:
n_groups = bins.size
index    = np.arange(1, n_groups, 1)

index2 = np.arange(0, index.max()+4, 2)
bins2  = np.arange(0., bins.max(), 0.1)

sns.set_style('white')
plt.rcParams["axes.edgecolor"] = "0.15"
plt.rcParams["axes.linewidth"] = 1.
plt.rcParams['mathtext.fontset'] = u'stixsans'
ylims = [0.0, 55.]
xlims = [0.05, 0.35]
plt.subplots(1,1, figsize=(10,3))

ax1=plt.subplot(1,5,1)
plt.bar(index, ratio_sf, width=1., alpha=alphas, color=palette[0], edgecolor=palette[0], linewidth=2., 
        label='WHAN\'s SF')
plt.ylabel("% of Galaxies", fontsize=15)
plt.title('WHAN\'s SF')
plt.ylim(ylims)
plt.xlim(xlims)
plt.xticks(index2, bins2)
plt.yticks(list(np.arange(ylims[0], ylims[1], 10)))
plt.tick_params('both', labelsize='13')

ax2=plt.subplot(1,5,2)
plt.bar(index, ratio_sa, width=1., alpha=alphas, color=palette[1], edgecolor=palette[1], linewidth=2.,
        label='WHAN\'s sAGN')
plt.title('WHAN\'s sAGN')
ax2.yaxis.set_visible(False)
plt.ylim(ylims)
plt.xlim(xlims)
plt.xticks(index2, bins2)
plt.tick_params('both', labelsize='13')

ax3=plt.subplot(1,5,3)
plt.bar(index, ratio_wa, width=1., alpha=alphas, color=palette[2], edgecolor=palette[2], linewidth=2.,
        label='WHAN\'s wAGN')
plt.title('WHAN\'s wAGN')
ax3.yaxis.set_visible(False)
plt.ylim(ylims)
plt.xlim(xlims)
plt.xticks(index2, bins2)
plt.tick_params('both', labelsize='13')
plt.xlabel("Redshift", fontsize=14)

ax4=plt.subplot(1,5,4)
plt.bar(index, ratio_rp, width=1., alpha=alphas, color=palette[3], edgecolor=palette[3], linewidth=2.,
        label='WHAN\'s R/P')
plt.title('WHAN\'s R/P')
ax4.yaxis.set_visible(False)
plt.ylim(ylims)
plt.xlim(xlims)
plt.xticks(index2, bins2)
plt.tick_params('both', labelsize='13')

ax5=plt.subplot(1,5,5)
plt.bar(index, ratio_na, width=1., alpha=alphas, color=palette[4], edgecolor=palette[4], linewidth=2.,
        label='Not classified')
plt.title('Not classified')
ax5.yaxis.set_visible(False)
plt.ylim(ylims)
plt.xlim(xlims)
plt.xticks(index2, bins2)
plt.tick_params('both', labelsize='13')
plt.tight_layout(w_pad=0.5)
plt.savefig('./../Figs/g2_barplot_propuv.png')
plt.savefig('./../Figs/g2_barplot_propuv.pdf')
plt.show()



In [15]:
print index
print bins


[1 2 3 4 5 6]
[ 0.    0.05  0.1   0.15  0.2   0.25  0.3 ]

In [16]:
index2 = np.arange(0, index.max()+2, 2)
bins2  = np.arange(0, bins.max()+0.2, 0.1)

In [17]:
print index2
print bins2


[0 2 4 6]
[ 0.   0.1  0.2  0.3  0.4]

In [18]:
list(np.arange(ylims[0], ylims[1], 10))


Out[18]:
[0.0, 10.0, 20.0, 30.0, 40.0, 50.0]

In [ ]: