In [1]:
#a glance at current hubble catalog

In [1]:
%pylab inline
import matplotlib.gridspec as gridspec

from astropy.io import fits as pyfits
from astropy.table import Table
import numpy as np
import matplotlib.pyplot as plt
import requests
mpl.rcParams['text.usetex']=True
mpl.rcParams['axes.linewidth'] = 3
mpl.rcParams['xtick.labelsize'] = 18
mpl.rcParams['ytick.labelsize'] = 18


Populating the interactive namespace from numpy and matplotlib

In [2]:
def download_from_dropbox(url):
    
    local_filename = "../{:}".format(url.split("/")[-1].split("?")[0])
    r = requests.get(url, stream=True)
    with open(local_filename, 'wb') as f:
        for chunk in r.iter_content(chunk_size=1024): 
            if chunk: # filter out keep-alive new chunks
                f.write(chunk)
                f.flush()
            
    return local_filename

In [3]:
#load Hubble data 
hubble_name=download_from_dropbox('https://www.dropbox.com/s/axk7shxb4ikgc70/gz_hubble_catalog_3_8_2016.fits?dl=1')
data=Table.read(hubble_name)
#load ferengi data 
ferengi_filename = download_from_dropbox("https://www.dropbox.com/s/r88l9u5fcsbppui/ferengi_all_weighted_and_meta.fits?dl=1")
f_data = Table.read(ferengi_filename)


/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:315: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning

In [4]:
categories=list(set(data['Correctable_Category']))

In [9]:
#get table of categorization, divided by imaging
imaging_list=set(data['IMAGING'])

for survey in imaging_list:
    print ('%s: correctable = %i' %(survey, ((data['IMAGING'] == survey) & (data['Correctable_Category'] == 'correctable')).sum()))
    print ('%s: uncorrectable = %i'% (survey, ((data['IMAGING'] == survey) & (data['Correctable_Category'] == 'uncorrectable')).sum()))
    print ('%s: z < 0.3 = %i' %(survey, ((data['IMAGING'] == survey) & (data['Correctable_Category'] == 'z_lt_3')).sum()))
    print ('%s: NEI (due to not enough Ferengi galaxies in bin) = %i'%(survey,((data['IMAGING'] == survey) & (data['Correctable_Category'] == 'nei')).sum()))
    print ('%s: NEI galaxies (due to needing redshift measurements) = %i' %(survey,((data['IMAGING'] == survey) & (data['Correctable_Category'] == 'nei_needs_redshift')).sum()))
    print ('%s total: %i' %(survey,(data['IMAGING']==survey).sum()))
    
print ('total correctable: %i' %(data['Correctable_Category']=='correctable').sum())
print ('total uncorrectable: %i'%(data['Correctable_Category']=='uncorrectable').sum())
print ('total z less than .3: %i' %(data['Correctable_Category']=='z_lt_3').sum())
print ('total nei: %i' %(data['Correctable_Category']=='nei').sum())
print ('total nr: %i' %(data['Correctable_Category']=='nei_needs_redshift').sum())
print ('total: %i' %len(data))


GEMS: correctable = 1837
GEMS: uncorrectable = 2423
GEMS: z < 0.3 = 1175
GEMS: NEI (due to not enough Ferengi galaxies in bin) = 3308
GEMS: NEI galaxies (due to needing redshift measurements) = 561
GEMS total: 9304
GOODS-S: correctable = 514
GOODS-S: uncorrectable = 1143
GOODS-S: z < 0.3 = 267
GOODS-S: NEI (due to not enough Ferengi galaxies in bin) = 2670
GOODS-S: NEI galaxies (due to needing redshift measurements) = 319
GOODS-S total: 4913
GOODS-S-FULLDEPTH: correctable = 835
GOODS-S-FULLDEPTH: uncorrectable = 1282
GOODS-S-FULLDEPTH: z < 0.3 = 400
GOODS-S-FULLDEPTH: NEI (due to not enough Ferengi galaxies in bin) = 2523
GOODS-S-FULLDEPTH: NEI galaxies (due to needing redshift measurements) = 102
GOODS-S-FULLDEPTH total: 5142
GOODS-N-FULLDEPTH: correctable = 993
GOODS-N-FULLDEPTH: uncorrectable = 1385
GOODS-N-FULLDEPTH: z < 0.3 = 415
GOODS-N-FULLDEPTH: NEI (due to not enough Ferengi galaxies in bin) = 2535
GOODS-N-FULLDEPTH: NEI galaxies (due to needing redshift measurements) = 687
GOODS-N-FULLDEPTH total: 6015
GOODS-N: correctable = 748
GOODS-N: uncorrectable = 526
GOODS-N: z < 0.3 = 267
GOODS-N: NEI (due to not enough Ferengi galaxies in bin) = 851
GOODS-N: NEI galaxies (due to needing redshift measurements) = 159
GOODS-N total: 2551
AEGIS: correctable = 1654
AEGIS: uncorrectable = 1917
AEGIS: z < 0.3 = 955
AEGIS: NEI (due to not enough Ferengi galaxies in bin) = 2847
AEGIS: NEI galaxies (due to needing redshift measurements) = 1134
AEGIS total: 8507
COSMOS: correctable = 15170
COSMOS: uncorrectable = 26113
COSMOS: z < 0.3 = 11926
COSMOS: NEI (due to not enough Ferengi galaxies in bin) = 34511
COSMOS: NEI galaxies (due to needing redshift measurements) = 5088
COSMOS total: 92808
SDSS: correctable = 0
SDSS: uncorrectable = 0
SDSS: z < 0.3 = 37545
SDSS: NEI (due to not enough Ferengi galaxies in bin) = 0
SDSS: NEI galaxies (due to needing redshift measurements) = 14316
SDSS total: 51861
total correctable: 21751
total uncorrectable: 34789
total z less than .3: 52950
total nei: 49245
total nr: 22366
total: 181101

In [23]:
#plot 1D histograms of redshift, surface brightness and p_features of hubble catalog
categories=['correctable','uncorrectable','nei']
no_shallow = (data['IMAGING']!='GOODS-N') & (data['IMAGING']!='GOODS-S')
#categories=[row.strip() for row in categories]
f=plt.figure(figsize=(21,8))

gs=gridspec.GridSpec(1,3)
gs.update(wspace=0.1)
gs.update(hspace=0)
lws=[5,4,3]
alphas=[.5,.5,.2]
ax1 = plt.subplot(gs[0,0])
for i,c in enumerate(categories):
    cat = (data['Correctable_Category']==c)
    z_list=data[cat & no_shallow ]['Z_BEST']
    med = np.median(z_list)
    plt.hist(z_list,range=(.3,2.5),label='%s N=%i, median=%.2f'%(c,len(z_list),med),histtype='stepfilled',lw=lws[i],bins=30,alpha=alphas[i],normed=True)
plt.axvline(x=.3,c='k',ls='dashed')
plt.xlim(0,2.5)
plt.legend(prop={'size':15})
plt.ylabel(r'$\mathrm{Normalized~Count}$',fontsize=25)
plt.xlabel(r'$\mathrm{redshift}$',fontsize=25)
ax2 = plt.subplot(gs[0,1])
for i,c in enumerate(categories):
    cat = (data['Correctable_Category']==c)

    mu_list=data[cat  & no_shallow ]['MU_HI']
    med = np.median(mu_list)
    plt.hist(mu_list,label='%s N=%i, median=%.2f'%(c,len(mu_list),med),histtype='stepfilled',lw=lws[i],bins=30,alpha=alphas[i],normed=True)
plt.ylim(0,.7)
plt.xlim(15,30)
plt.legend(prop={'size':15})
plt.xlabel(r'$\mathrm{MU\textunderscore HI~(mag/arcsec^2)}$',fontsize=25)
ax3 = plt.subplot(gs[0,2])
for i,c in enumerate(categories):
    cat = (data['Correctable_Category']==c)

    p_list=data[cat  & no_shallow ]['t01_smooth_or_features_a02_features_or_disk_weighted_fraction']
    med = np.nanmedian(p_list)
    plt.hist(p_list,label='%s N=%i, median=%.2f'%(c,len(p_list),med),histtype='stepfilled',lw=lws[i],bins=30,alpha=alphas[i],normed=True,range=(0,1))
plt.xlabel(r'$\mathrm{p_{features,weighted}}$',fontsize=25)
plt.legend(prop={'size':15})
f.text(.135,.85,r'$z_0=0.3$',fontsize=20)
plt.savefig('../writeup/figures/hubble_z_mu_p_distributions.pdf')



In [25]:
#Plot the change in p_features for the 3 groups
f=plt.figure(figsize=(21,8))

gs=gridspec.GridSpec(1,3)
gs.update(wspace=0.1)
gs.update(hspace=0)

ax1 = plt.subplot(gs[0,0])
weighted_frac=data[data['Correctable_Category']=='correctable']['t01_smooth_or_features_a02_features_or_disk_weighted_fraction']
deb_frac=data[data['Correctable_Category']=='correctable']['t01_smooth_or_features_a02_features_or_disk_debiased_fraction']
hex1 = ax1.hexbin(weighted_frac,deb_frac, cmap=plt.cm.YlOrRd_r,gridsize=50,vmin =0,vmax=100)
plt.title(r'$\mathrm{Correctable}$',fontsize=25)
plt.xlabel(r'$\mathrm{p_{features}}$',fontsize=25)
plt.ylabel(r'$\mathrm{p_{features,debiased}}$',fontsize=25)
ax1.set_axis_bgcolor('#800000')
plt.ylim(0,1)
ax1.plot([0,1],[0,1],color='k',lw=2,ls='--')

ax2 = plt.subplot(gs[0,1])
weighted_frac=data[data['Correctable_Category']=='uncorrectable']['t01_smooth_or_features_a02_features_or_disk_weighted_fraction']
deb_frac=data[data['Correctable_Category']=='uncorrectable']['t01_smooth_or_features_a02_features_or_disk_debiased_fraction']
hex2 = ax2.hexbin(weighted_frac,deb_frac, cmap=plt.cm.YlOrRd_r,gridsize=50,vmin =0,vmax=100)
ax2.set_axis_bgcolor('#800000')
plt.title(r'$\mathrm{Uncorrectable}$',fontsize=25)
plt.xlabel(r'$\mathrm{p_{features}}$',fontsize=25)
ax2.plot([0,1],[0,1],color='k',lw=2,ls='--')

ax3 = plt.subplot(gs[0,2])
weighted_frac=data[data['Correctable_Category']=='nei']['t01_smooth_or_features_a02_features_or_disk_weighted_fraction']
deb_frac=data[data['Correctable_Category']=='nei']['t01_smooth_or_features_a02_features_or_disk_debiased_fraction']
hex3 = ax3.hexbin(weighted_frac,deb_frac, cmap=plt.cm.YlOrRd_r,gridsize=50,vmin =0,vmax=100)
ax3.set_axis_bgcolor('#800000')
plt.title(r'$\mathrm{nei}$',fontsize=25)
plt.xlabel(r'$\mathrm{p_{features}}$',fontsize=25)
ax3.plot([0,1],[0,1],color='k',lw=2,ls='--')

plt.savefig('../writeup/figures/debiased_corrections.pdf')



In [49]:
#purple/green plot for hubble:

yedges_ferengi=list(np.linspace(np.min(f_data['mu_max_i']),np.max(f_data['mu_max_i']),10))
xedges_ferengi=[.25,.35,.45,.55,.65,.75,.85,.95,1.05]
fx_width=xedges_ferengi[1]-xedges_ferengi[0]
fy_width=yedges_ferengi[1]-yedges_ferengi[0]

xedges=np.linspace(0.05,2.05,21)
yedges=[]
yedges.append(yedges_ferengi[0]-fy_width)
for i in range(0,17):
    yedges.append(yedges[-1]+fy_width)

extent=[xedges[0],xedges[-1],yedges[0],yedges[-1]]
galaxies = set(data['OBJNO'])

In [8]:
f=plt.figure(figsize=(20,15))
histy,xedges,yedges=np.histogram2d(data['Z'],data['MU_HI'],bins=(xedges,yedges))
plt.imshow(histy.T,origin='lower',interpolation='nearest',extent=extent,aspect='auto',cmap=cm.hot)
for y in yedges_ferengi:
    plt.plot([xedges_ferengi[0],xedges_ferengi[-1]],[y,y],c='w',lw=3)
for x in xedges_ferengi:
    plt.plot([x,x],[yedges_ferengi[0],yedges_ferengi[-1]],c='w',lw=3)
plt.xlim(xedges[0],xedges[-4])
plt.ylim(yedges[0],yedges[-6])
plt.colorbar()
plt.xlabel(r'$\mathrm{redshift}$',fontsize=30)
plt.ylabel(r'$\mathrm{MU\textunderscore HI~(mag/arcsec^2)}$',fontsize=30)
plt.tick_params(labelsize=30)
#plt.savefig('images/eye_of_sauron.pdf')
#plt.savefig('/home/mel/Documents/GZ_HUBBLE/ferengi_debias/gzhubble/writeup/figures/eye_of_sauron.pdf')



In [15]:
#len(data[data['Correctable_Category']==categories[0]])
correctable=(data['Correctable_Category']==categories[0])
uncorrectable=(data['Correctable_Category']==categories[1])
nei=(data['Correctable_Category']==categories[2])

Plotting debiased vs weighted p_features as a function of surface brightness and redshift:


In [68]:
scatter_dct={}
for z in xedges:
    for edge in yedges:
        scatter_dct[z,edge,'hi']=[]
        scatter_dct[z,edge,'lo']=[]
        scatter_dct[z,edge,'objid']=[]
        
scatter_dct_unc={}
for z in xedges:
    for edge in yedges:
        scatter_dct_unc[z,edge,'hi']=[]
        scatter_dct_unc[z,edge,'lo']=[]
        scatter_dct_unc[z,edge,'objid']=[]

In [69]:
Z='Z_BEST_COMBINED'

for x in range(0,len(xedges)-1):
    for y in range(0,len(yedges)-1):
        scatter_dct[xedges[x],yedges[y],'lo']=data[(data['Correctable_Category']==categories[0]) & (data[Z]>=xedges[x]) & (data[Z]<xedges[x+1]) & (data['MU_HI'] >=yedges[y]) & (data['MU_HI'] < yedges[y+1])]['t01_smooth_or_features_a02_features_or_disk_weighted_fraction']
        scatter_dct[xedges[x],yedges[y],'hi']=data[(data['Correctable_Category']==categories[0]) & (data[Z]>=xedges[x]) & (data[Z]<xedges[x+1]) & (data['MU_HI'] >=yedges[y]) & (data['MU_HI'] < yedges[y+1])]['t01_smooth_or_features_a02_features_or_disk_best_fraction']
for x in range(0,len(xedges)-1):
    for y in range(0,len(yedges)-1):
        scatter_dct_unc[xedges[x],yedges[y],'lo']=data[(data['Correctable_Category']==categories[1]) & (data[Z]>=xedges[x]) & (data[Z]<xedges[x+1]) & (data['MU_HI'] >=yedges[y]) & (data['MU_HI'] < yedges[y+1])]['t01_smooth_or_features_a02_features_or_disk_weighted_fraction']
        scatter_dct_unc[xedges[x],yedges[y],'hi']=data[(data['Correctable_Category']==categories[1]) & (data[Z]>=xedges[x]) & (data[Z]<xedges[x+1]) & (data['MU_HI'] >=yedges[y]) & (data['MU_HI'] < yedges[y+1])]['t01_smooth_or_features_a02_features_or_disk_best_fraction']

In [70]:
f=figure(figsize=(20,18))
gs=gridspec.GridSpec(9,10)
gs.update(wspace=0)
gs.update(hspace=0)
yedge_int=np.linspace(0,17,18)
yedge_int=yedge_int[::-1]
yedge_int=yedge_int[8:17]
yedge_int=[int(y) for y in yedge_int]
x_new = np.linspace(0,.95,40)

y_label=[]
facecolors=['#af8dc3','#999999','#7fbf7b']
for i in range(0,len(yedges)-1):
    y_label.append(round((yedges[i]+yedges[i+1])/2,2))
y_label=y_label[::-1]

for j,y in enumerate(yedge_int):
    for x in range(2,10):
        ax=plt.subplot(gs[j,x-2])
        xs=scatter_dct[xedges[x],yedges[y],'lo']
        ys=scatter_dct[xedges[x],yedges[y],'hi']
        xs_unc=scatter_dct_unc[xedges[x],yedges[y],'lo']
        ys_unc=scatter_dct_unc[xedges[x],yedges[y],'hi']

        plt.plot(x_new,x_new,c='k')
        plt.scatter(xs,ys,edgecolor='None',c='k')
        plt.scatter(xs_unc,ys_unc,c='r',edgecolor='None')

        plt.xlim(0,1)
            
        plt.tick_params(labelleft='off')
        plt.tick_params(top='off',right='off',labelbottom='off')

                
        if j==8:
            plt.xlabel('%s'%round((xedges[x]+xedges[x+1])/2,2),fontsize=16)
        if x==9:
            ax.yaxis.set_label_position("right")
            plt.ylabel('%s'%str(y_label[j+6]).rjust(500),fontsize=16,rotation=270,labelpad=20)

f.text(.78,.5,r'$\mathrm{MU~HI~(mag/arcsec^2)}$',rotation=270,fontsize=30,va='center')
f.text(.45,.91,r'$\mathrm{redshift}$',fontsize=30,ha='center')
f.text(.1,.5,r'$\mathrm{p_{features}~best}$',rotation=90,fontsize=30,va='center')
f.text(.45,.08,r'$\mathrm{p_{features}}$',fontsize=30,ha='center')
plt.savefig('/home/mel/Documents/GZ_HUBBLE/GZ_Hubble_Science/Red_Disk_Fraction/Images/best_features_hubble.png')



In [60]:
categories[0]


Out[60]:
'correctable             '

In [13]:
#isolate galaxies in red sequence
#plot fraction of disks in red sequence vs redshift
#p_features vs redshift?

In [32]:
contour_hist,xedges,yedges=np.histogram2d(data[correctable]['MAGI']-5*log10(3*10**10/70.*data[correctable]['Z']),data[correctable]['CFHT_U']-data[correctable]['CFHT_R'],range=((-25,-15),(.5,5)))
plt.imshow(contour_hist.T,origin='lower',aspect='auto',cmap=cm.Greys)

#plt.scatter(data[correctable]['MAGI']-5*log10(3*10**10/70.*data[correctable]['Z']),data[correctable]['MAGB']-data[correctable]['MAGI'])
#plt.ylim(-1,5)
#plt.xlim(-25,-15)


Out[32]:
<matplotlib.image.AxesImage at 0x7f1f651458d0>

In [17]:
red_sequence=(data['Correctable_Category']==categories[0]) & ((data['MAGB']-data['MAGI'])> 2) & ((data['MAGB']-data['MAGI']) < 6 )
blue_cloud=(data['Correctable_Category']==categories[0]) & ((data['MAGB']-data['MAGI'])> 0) & ((data['MAGB']-data['MAGI']) <= 2 )

red_sequence_disks=(data['Correctable_Category']==categories[0]) & ((data['MAGB']-data['MAGI'])> 2) & ((data['MAGB']-data['MAGI']) < 6) & (data['t01_smooth_or_features_a02_features_or_disk_debiased_fraction']>.5)
blue_cloud_disks=(data['Correctable_Category']==categories[0]) & ((data['MAGB']-data['MAGI'])> 0) & ((data['MAGB']-data['MAGI']) <= 2) & (data['t01_smooth_or_features_a02_features_or_disk_debiased_fraction']>.5)

In [18]:
f=plt.figure(figsize=(30,25))
bins=(7,7)
hist_all_red,xedges,yedges=np.histogram2d(data[red_sequence]['Z'],data[red_sequence]['MU_HI'],bins=bins)
hist_all_blue,x,y=np.histogram2d(data[blue_cloud]['Z'],data[blue_cloud]['MU_HI'],bins=(xedges,yedges))
hist_red_disks,x,y=np.histogram2d(data[red_sequence_disks]['Z'],data[red_sequence_disks]['MU_HI'],bins=(xedges,yedges))
hist_blue_disks,x,y=np.histogram2d(data[blue_cloud_disks]['Z'],data[blue_cloud_disks]['MU_HI'],bins=(xedges,yedges))


extent=[xedges[0],xedges[-1],yedges[0],yedges[-1]]


red_frac_hist=hist_red_disks/hist_all_red
where_are_NaNs = isnan(red_frac_hist)
red_frac_hist[where_are_NaNs] = 0
red_frac_hist = np.ma.array(red_frac_hist,mask=((hist_all_red)<10))

blue_frac_hist=hist_blue_disks/hist_all_blue
where_are_NaNs = isnan(blue_frac_hist)
blue_frac_hist[where_are_NaNs] = 0
blue_frac_hist = np.ma.array(blue_frac_hist,mask=((hist_all_blue)<10))

Redcm=cm.Reds
Redcm.set_bad('black')

Bluecm=cm.Blues
Bluecm.set_bad('black')


gs=gridspec.GridSpec(2,3)

axr=plt.subplot(gs[0,0])
plt.imshow(hist_all_red.T,origin='lower',interpolation='nearest',extent=extent,aspect='auto',cmap=Redcm,vmin=0,vmax=400)
plt.colorbar()
plt.ylabel('MU~HI',fontsize=35)
plt.title('all~red~($B-I>2$)~galaxies',fontsize=35)
#plt.xlim(.05,1.5)
#plt.ylim(17,25)

axb=plt.subplot(gs[0,1])
plt.imshow(hist_red_disks.T,origin='lower',interpolation='nearest',extent=extent,aspect='auto',cmap=Redcm,vmin=0,vmax=400)
plt.colorbar()
plt.title('red~disks~($p_{features}>0.5$)',fontsize=35)
#plt.xlim(.05,1.5)
#plt.ylim(17,25)

axb=plt.subplot(gs[0,2])
plt.imshow(red_frac_hist.T,origin='lower',interpolation='nearest',extent=extent,aspect='auto',cmap=Redcm,vmin=0,vmax=1)
plt.colorbar()
plt.title('red~disk~fraction',fontsize=35)
#plt.xlim(.05,1.5)
#plt.ylim(17,25)

ax4=plt.subplot(gs[1,0])
plt.imshow(hist_all_blue.T,origin='lower',interpolation='nearest',extent=extent,aspect='auto',cmap=Bluecm,vmin=0,vmax=400)
plt.colorbar()
plt.xlabel('redshift',fontsize=35)
plt.ylabel('MU~HI',fontsize=35)
plt.title('all~blue~($B-I<2$)~galaxies',fontsize=35)

#plt.xlim(.05,1.5)
#plt.ylim(17,25)

ax5=plt.subplot(gs[1,1])
plt.imshow(hist_blue_disks.T,origin='lower',interpolation='nearest',extent=extent,aspect='auto',cmap=Bluecm,vmin=0,vmax=400)
plt.colorbar()
plt.title('blue~disks~($p_{features}<0.5$)',fontsize=35)
plt.xlabel('redshift',fontsize=35)

#plt.xlim(.05,1.5)
#plt.ylim(17,25)

ax6=plt.subplot(gs[1,2])
plt.imshow(blue_frac_hist.T,origin='lower',interpolation='nearest',extent=extent,aspect='auto',cmap=Bluecm,vmin=0,vmax=1)
plt.colorbar()
plt.xlabel('redshift',fontsize=35)
plt.title('blue~disk~fraction',fontsize=35)
mpl.rcParams['xtick.labelsize'] = 30
mpl.rcParams['ytick.labelsize'] = 30

#plt.xlim(.05,1.5)
#plt.ylim(17,25)


/usr/local/lib/python2.7/dist-packages/ipykernel/__main__.py:12: RuntimeWarning: invalid value encountered in divide
/usr/local/lib/python2.7/dist-packages/ipykernel/__main__.py:17: RuntimeWarning: invalid value encountered in divide

Comparison to ZEST


In [12]:
zest_early=(data['ZEST_type']==1) | (data['bulg']==0)
zest_disk=(data['ZEST_type']==2) & (data['bulg']!=0)

In [13]:
f=plt.figure(figsize=(20,10))

gs=gridspec.GridSpec(1,2)

alphas=[.8,.6]

axe=plt.subplot(gs[0,0])
plt.hist(data[zest_early]['t01_smooth_or_features_a02_features_or_disk_weighted_fraction'],range=(0,1),histtype='stepfilled',alpha=alphas[0],normed=True,label='ZEST~early~type')
plt.hist(data[zest_disk]['t01_smooth_or_features_a02_features_or_disk_weighted_fraction'],range=(0,1),histtype='stepfilled',alpha=alphas[1],normed=True,label='ZEST~disk')
plt.legend()
plt.title('$\mathrm{p_{features,weighted}}$',fontsize=40)

axd=plt.subplot(gs[0,1])
plt.hist(data[zest_early]['t01_smooth_or_features_a02_features_or_disk_debiased_fraction'],range=(0,1),histtype='stepfilled',alpha=alphas[0],normed=True)
plt.hist(data[zest_disk]['t01_smooth_or_features_a02_features_or_disk_debiased_fraction'],range=(0,1),histtype='stepfilled',alpha=alphas[1],normed=True)
plt.title('$\mathrm{p_{features,debiased}}$',fontsize=40)


Out[13]:
<matplotlib.text.Text at 0x7fad440c0610>

Well.. those aren't that great! Let's take a look at some images:


In [14]:
from PIL import Image
import urllib, cStringIO
cats=list(set(data['Correctable_Category']))
corr=cats[0]

In [25]:
#for getting images from HST cutouts 
import os,glob    
os.chdir('/home/mel/Documents/GZ_HUBBLE/get_hubble_cutouts/acs_mosaic_2.0')

def get_image_from_cutout(ra,dec):
    for f in glob.glob("*.jpg"):
        if ra == float(f.split('_')[1]) and dec == float(f.split('_')[2]):
            filename=f
            img=Image.open(filename)
    try:
        return img,filename
    except UnboundLocalError:
        return False,False

In [15]:
#get images from url (color composites )
def get_image_from_url(url):

    file = cStringIO.StringIO(urllib.urlopen(url).read())
    img = Image.open(file)
    return img

In [17]:
def galaxies_list(z_type,pl,ph):
    #get list of galaxies within certain ranges of z, mu and p_features 
    if z_type == 1: #zest ellipticals 
        these_data=((data['ZEST_type']==z_type) | (data['bulg']==0)) & (data['t01_smooth_or_features_a02_features_or_disk_debiased_fraction'] >=pl) & (data['t01_smooth_or_features_a02_features_or_disk_debiased_fraction'] < ph) & (data['Correctable_Category']==corr)
    if z_type == 2: #zest disks
        these_data=((data['ZEST_type']==z_type) & (data['bulg']!=0)) & (data['t01_smooth_or_features_a02_features_or_disk_debiased_fraction'] >=pl) & (data['t01_smooth_or_features_a02_features_or_disk_debiased_fraction'] < ph) & (data['Correctable_Category']==corr)
        
    return data[these_data]

In [78]:
corr


Out[78]:
'correctable             '

In [20]:
gs=gridspec.GridSpec(4,4)
gs.update(wspace=0.01)
gs.update(hspace=0.01)

#define upper and lower limits of z, mu, and p_features to look at:
z_type=1
pl = 0
ph = .2
 
these_data=galaxies_list(z_type,pl,ph)
if len(these_data) < 20:
    print 'try new values'

#shuffle which galaxies get displayed     
n_list=np.linspace(0,len(these_data)-1,len(these_data))
shuffle(n_list)

f=plt.figure(figsize=(30,30))
n=0
for i in range (0,4):
    for j in range(0,4):
        ax=plt.subplot(gs[i,j])
        while 'h' not in these_data[int(n_list[n])]['location']:
            n+=1
        gal = these_data[int(n_list[n])] # random galaxy from big list 
        plt.imshow(get_image_from_url(gal['location']))
        plt.tick_params(labelbottom='off',labelleft='off')
        ax.annotate('z: %s\n$\mu: %s$'%(round(gal['Z'],2),round(gal['MU_HI'],2)),fontsize=40,xy=(0,1),
            xycoords='axes fraction',verticalalignment='top',color='white')
        ax.annotate('%s'%gal['OBJNO'],fontsize=30,xy=(1,1),
            xycoords='axes fraction',verticalalignment='top',horizontalalignment='right',color='white')
        ax.annotate('$\mathrm{p_{features}: %s}$\n$\mathrm{p_{features,debiased}: %s}$'%(round(gal['t01_smooth_or_features_a02_features_or_disk_weighted_fraction'],2),round(gal['t01_smooth_or_features_a02_features_or_disk_debiased_fraction'],2)),fontsize=45,xy=(0,0),
            xycoords='axes fraction',color='white')
        n+=1
        

f.text(.5,.92,'$\mathrm{ZEST~ellipticals,~GZH~ellipticals}$\n$ZEST~type~=%s~or~2.0$\n$%s > p_{features} < %s$'%(z_type,pl,ph), fontsize=40,ha='center')


Out[20]:
<matplotlib.text.Text at 0x7fad443780d0>

In [21]:
gs=gridspec.GridSpec(4,4)
gs.update(wspace=0.01)
gs.update(hspace=0.01)

#define upper and lower limits of z, mu, and p_features to look at:
z_type=1
pl = .8
ph = 1
 
these_data=galaxies_list(z_type,pl,ph)
if len(these_data) < 20:
    print 'try new values'

#shuffle which galaxies get displayed     
n_list=np.linspace(0,len(these_data)-1,len(these_data))
shuffle(n_list)

f=plt.figure(figsize=(30,30))
n=0
for i in range (0,4):
    for j in range(0,4):
        ax=plt.subplot(gs[i,j])
        while 'h' not in these_data[int(n_list[n])]['location']:
            n+=1
        gal = these_data[int(n_list[n])] # random galaxy from big list 
        plt.imshow(get_image_from_url(gal['location']))
        plt.tick_params(labelbottom='off',labelleft='off')
        ax.annotate('z: %s\n$\mu: %s$'%(round(gal['Z'],2),round(gal['MU_HI'],2)),fontsize=40,xy=(0,1),
            xycoords='axes fraction',verticalalignment='top',color='white')
        ax.annotate('%s'%gal['OBJNO'],fontsize=30,xy=(1,1),
            xycoords='axes fraction',verticalalignment='top',horizontalalignment='right',color='white')
        ax.annotate('$\mathrm{p_{features}: %s}$\n$\mathrm{p_{features,debiased}: %s}$'%(round(gal['t01_smooth_or_features_a02_features_or_disk_weighted_fraction'],2),round(gal['t01_smooth_or_features_a02_features_or_disk_debiased_fraction'],2)),fontsize=45,xy=(0,0),
            xycoords='axes fraction',color='white')
        n+=1
        

f.text(.5,.92,'$\mathrm{ZEST~ellipticals,~GZH~disks}$\n$ZEST~type~=%s~or~2.0$\n$%s > p_{features} < %s$'%(z_type,pl,ph), fontsize=40,ha='center')


Out[21]:
<matplotlib.text.Text at 0x7fad54c4df90>

In [26]:
gs=gridspec.GridSpec(4,4)
gs.update(wspace=0.01)
gs.update(hspace=0.01)

#define upper and lower limits of z, mu, and p_features to look at:
z_type=2
pl = 0
ph = .2
 
these_data=galaxies_list(z_type,pl,ph)
if len(these_data) < 20:
    print 'try new values'

#shuffle which galaxies get displayed     
n_list=np.linspace(0,len(these_data)-1,len(these_data))
shuffle(n_list)

f=plt.figure(figsize=(30,30))
n=0
for i in range (0,4):
    for j in range(0,4):
        ax=plt.subplot(gs[i,j])
        while 'h' not in these_data[int(n_list[n])]['location']:
            n+=1
        gal = these_data[int(n_list[n])] # random galaxy from big list 
        plt.imshow(get_image_from_url(gal['location']))
        plt.tick_params(labelbottom='off',labelleft='off')
        ax.annotate('z: %s\n$\mu: %s$'%(round(gal['Z'],2),round(gal['MU_HI'],2)),fontsize=40,xy=(0,1),
            xycoords='axes fraction',verticalalignment='top',color='white')
        ax.annotate('%s'%gal['OBJNO'],fontsize=30,xy=(1,1),
            xycoords='axes fraction',verticalalignment='top',horizontalalignment='right',color='white')
        ax.annotate('$\mathrm{p_{features}: %s}$\n$\mathrm{p_{features,debiased}: %s}$'%(round(gal['t01_smooth_or_features_a02_features_or_disk_weighted_fraction'],2),round(gal['t01_smooth_or_features_a02_features_or_disk_debiased_fraction'],2)),fontsize=45,xy=(0,0),
            xycoords='axes fraction',color='white')
        n+=1
        

f.text(.5,.92,'$\mathrm{ZEST~disks,~GZH~ellipticals}$\n$ZEST~type~=%s$\n$%s > p_{features} < %s$'%(z_type,pl,ph), fontsize=40,ha='center')


Out[26]:
<matplotlib.text.Text at 0x7fad57710310>

In [23]:
gs=gridspec.GridSpec(4,4)
gs.update(wspace=0.01)
gs.update(hspace=0.01)

#define upper and lower limits of z, mu, and p_features to look at:
z_type=2
pl = .8
ph = 1
 
these_data=galaxies_list(z_type,pl,ph)
if len(these_data) < 20:
    print 'try new values'

#shuffle which galaxies get displayed     
n_list=np.linspace(0,len(these_data)-1,len(these_data))
shuffle(n_list)

f=plt.figure(figsize=(30,30))
n=0
for i in range (0,4):
    for j in range(0,4):
        ax=plt.subplot(gs[i,j])
        while 'h' not in these_data[int(n_list[n])]['location']:
            n+=1
        gal = these_data[int(n_list[n])] # random galaxy from big list 
        plt.imshow(get_image_from_url(gal['location']))
        plt.tick_params(labelbottom='off',labelleft='off')
        ax.annotate('z: %s\n$\mu: %s$'%(round(gal['Z'],2),round(gal['MU_HI'],2)),fontsize=40,xy=(0,1),
            xycoords='axes fraction',verticalalignment='top',color='white')
        ax.annotate('%s'%gal['OBJNO'],fontsize=30,xy=(1,1),
            xycoords='axes fraction',verticalalignment='top',horizontalalignment='right',color='white')
        ax.annotate('$\mathrm{p_{features}: %s}$\n$\mathrm{p_{features,debiased}: %s}$'%(round(gal['t01_smooth_or_features_a02_features_or_disk_weighted_fraction'],2),round(gal['t01_smooth_or_features_a02_features_or_disk_debiased_fraction'],2)),fontsize=45,xy=(0,0),
            xycoords='axes fraction',color='white')
        n+=1
        

f.text(.5,.92,'$\mathrm{ZEST~disks,~GZH~disks}$\n$ZEST~type~=%s$\n$%s > p_{features} < %s$'%(z_type,pl,ph), fontsize=40,ha='center')


Out[23]:
<matplotlib.text.Text at 0x7fad552fcc50>

Comparison using HST cutouts


In [38]:
gs=gridspec.GridSpec(4,4)
gs.update(wspace=0.01)
gs.update(hspace=0.01)

#define upper and lower limits of z, mu, and p_features to look at:
z_type=1
pl = 0
ph = .2
 
these_data=galaxies_list(z_type,pl,ph)
if len(these_data) < 20:
    print 'try new values'

#shuffle which galaxies get displayed     
n_list=np.linspace(0,len(these_data)-1,len(these_data))
shuffle(n_list)

f=plt.figure(figsize=(30,30))
n=0
for i in range (0,4):
    for j in range(0,4):
        ax=plt.subplot(gs[i,j])
        gal = these_data[int(n_list[n])] # random galaxy from big list 
        image,filename = get_image_from_cutout(gal['RA'],gal['DEC'])
        while image == False:
            n+=1
            gal = these_data[int(n_list[n])] # random galaxy from big list 
            image,filename = get_image_from_cutout(gal['RA'],gal['DEC'])

        plt.imshow(image)
        plt.tick_params(labelbottom='off',labelleft='off')
        ax.annotate('z: %s\n$\mu: %s$\ntype: %s\nbulg:%s'%(round(gal['Z'],2),round(gal['MU_HI'],2),gal['ZEST_type'],gal['bulg']),fontsize=30,xy=(0,1),
            xycoords='axes fraction',verticalalignment='top',color='black')
        ax.annotate('%s'%gal['OBJNO'],fontsize=30,xy=(1,1),
            xycoords='axes fraction',verticalalignment='top',horizontalalignment='right',color='black')
        ax.annotate('$\mathrm{p_{features}: %s}$\n$\mathrm{p_{features,debiased}: %s}$'%(round(gal['t01_smooth_or_features_a02_features_or_disk_weighted_fraction'],2),round(gal['t01_smooth_or_features_a02_features_or_disk_debiased_fraction'],2)),fontsize=45,xy=(0,0),
            xycoords='axes fraction',color='black')
        n+=1
        

f.text(.5,.92,'$\mathrm{ZEST~ellipticals,~GZH~ellipticals}$\n$ZEST~type~=%s~or~2.0$\n$%s > p_{features} < %s$'%(z_type,pl,ph), fontsize=40,ha='center')


Out[38]:
<matplotlib.text.Text at 0x7fad51ff9690>

In [39]:
gs=gridspec.GridSpec(4,4)
gs.update(wspace=0.01)
gs.update(hspace=0.01)

#define upper and lower limits of z, mu, and p_features to look at:
z_type=1
pl = .8
ph = 1
 
these_data=galaxies_list(z_type,pl,ph)
if len(these_data) < 20:
    print 'try new values'

#shuffle which galaxies get displayed     
n_list=np.linspace(0,len(these_data)-1,len(these_data))
shuffle(n_list)

f=plt.figure(figsize=(30,30))
n=0
for i in range (0,4):
    for j in range(0,4):
        ax=plt.subplot(gs[i,j])
        gal = these_data[int(n_list[n])] # random galaxy from big list 
        image,filename = get_image_from_cutout(gal['RA'],gal['DEC'])
        while image == False:
            n+=1
            gal = these_data[int(n_list[n])] # random galaxy from big list 
            image,filename = get_image_from_cutout(gal['RA'],gal['DEC'])

        plt.imshow(image)
        plt.tick_params(labelbottom='off',labelleft='off')
        ax.annotate('z: %s\n$\mu: %s$\ntype: %s\nbulg:%s'%(round(gal['Z'],2),round(gal['MU_HI'],2),gal['ZEST_type'],gal['bulg']),fontsize=30,xy=(0,1),
            xycoords='axes fraction',verticalalignment='top',color='black')
        ax.annotate('%s'%gal['OBJNO'],fontsize=30,xy=(1,1),
            xycoords='axes fraction',verticalalignment='top',horizontalalignment='right',color='black')
        ax.annotate('$\mathrm{p_{features}: %s}$\n$\mathrm{p_{features,debiased}: %s}$'%(round(gal['t01_smooth_or_features_a02_features_or_disk_weighted_fraction'],2),round(gal['t01_smooth_or_features_a02_features_or_disk_debiased_fraction'],2)),fontsize=45,xy=(0,0),
            xycoords='axes fraction',color='black')
        n+=1
        

f.text(.5,.92,'$\mathrm{ZEST~ellipticals,~GZH~disks}$\n$ZEST~type~=%s~or~2.0$\n$%s > p_{features} < %s$'%(z_type,pl,ph), fontsize=40,ha='center')


Out[39]:
<matplotlib.text.Text at 0x7fad50d9b250>

In [44]:
gs=gridspec.GridSpec(4,4)
gs.update(wspace=0.01)
gs.update(hspace=0.01)

#define upper and lower limits of z, mu, and p_features to look at:
z_type=2
pl = 0
ph = .2
 
these_data=galaxies_list(z_type,pl,ph)
if len(these_data) < 20:
    print 'try new values'

#shuffle which galaxies get displayed     
n_list=np.linspace(0,len(these_data)-1,len(these_data))
shuffle(n_list)

f=plt.figure(figsize=(30,30))
n=0
for i in range (0,4):
    for j in range(0,4):
        ax=plt.subplot(gs[i,j])
        gal = these_data[int(n_list[n])] # random galaxy from big list 
        image,filename = get_image_from_cutout(gal['RA'],gal['DEC'])
        while image == False:
            n+=1
            gal = these_data[int(n_list[n])] # random galaxy from big list 
            image,filename = get_image_from_cutout(gal['RA'],gal['DEC'])

        plt.imshow(image)
        plt.tick_params(labelbottom='off',labelleft='off')
        ax.annotate('z: %s\n$\mu: %s$\ntype: %s\nbulg:%s'%(round(gal['Z'],2),round(gal['MU_HI'],2),gal['ZEST_type'],gal['bulg']),fontsize=30,xy=(0,1),
            xycoords='axes fraction',verticalalignment='top',color='black')
        ax.annotate('%s'%gal['OBJNO'],fontsize=30,xy=(1,1),
            xycoords='axes fraction',verticalalignment='top',horizontalalignment='right',color='black')
        ax.annotate('$\mathrm{p_{features}: %s}$\n$\mathrm{p_{features,debiased}: %s}$'%(round(gal['t01_smooth_or_features_a02_features_or_disk_weighted_fraction'],2),round(gal['t01_smooth_or_features_a02_features_or_disk_debiased_fraction'],2)),fontsize=45,xy=(0,0),
            xycoords='axes fraction',color='black')
        n+=1
        

f.text(.5,.92,'$\mathrm{ZEST~disks,~GZH~ellipticals}$\n$ZEST~type~=%s~(not~2.0)$\n$%s > p_{features} < %s$'%(z_type,pl,ph), fontsize=40,ha='center')


Out[44]:
<matplotlib.text.Text at 0x7fad518be450>

In [41]:
gs=gridspec.GridSpec(4,4)
gs.update(wspace=0.01)
gs.update(hspace=0.01)

#define upper and lower limits of z, mu, and p_features to look at:
z_type=2
pl = .8
ph = 1
 
these_data=galaxies_list(z_type,pl,ph)
if len(these_data) < 20:
    print 'try new values'

#shuffle which galaxies get displayed     
n_list=np.linspace(0,len(these_data)-1,len(these_data))
shuffle(n_list)

f=plt.figure(figsize=(30,30))
n=0
for i in range (0,4):
    for j in range(0,4):
        ax=plt.subplot(gs[i,j])
        gal = these_data[int(n_list[n])] # random galaxy from big list 
        image,filename = get_image_from_cutout(gal['RA'],gal['DEC'])
        while image == False:
            n+=1
            gal = these_data[int(n_list[n])] # random galaxy from big list 
            image,filename = get_image_from_cutout(gal['RA'],gal['DEC'])

        plt.imshow(image)
        plt.tick_params(labelbottom='off',labelleft='off')
        ax.annotate('z: %s\n$\mu: %s$\ntype: %s\nbulg:%s'%(round(gal['Z'],2),round(gal['MU_HI'],2),gal['ZEST_type'],gal['bulg']),fontsize=30,xy=(0,1),
            xycoords='axes fraction',verticalalignment='top',color='black')
        ax.annotate('%s'%gal['OBJNO'],fontsize=30,xy=(1,1),
            xycoords='axes fraction',verticalalignment='top',horizontalalignment='right',color='black')
        ax.annotate('$\mathrm{p_{features}: %s}$\n$\mathrm{p_{features,debiased}: %s}$'%(round(gal['t01_smooth_or_features_a02_features_or_disk_weighted_fraction'],2),round(gal['t01_smooth_or_features_a02_features_or_disk_debiased_fraction'],2)),fontsize=45,xy=(0,0),
            xycoords='axes fraction',color='black')
        n+=1
        

f.text(.5,.92,'$\mathrm{ZEST~disks,~GZH~disks}$\n$ZEST~type~=%s~(not~2.0)$\n$%s > p_{features} < %s$'%(z_type,pl,ph), fontsize=40,ha='center')


Out[41]:
<matplotlib.text.Text at 0x7fad518be510>

In [16]:
20489+33120+52416+45724+21888


Out[16]:
173637

In [ ]: