In [5]:
# This changes the current directory to the base saga directory - make sure to run this first!
# This is necessary to be able to import the py files and use the right directories,
# while keeping all the notebooks in their own directory.
import os
import sys
import numpy as np
if 'saga_base_dir' not in locals():
saga_base_dir = os.path.abspath('..')
if saga_base_dir not in sys.path:
os.chdir(saga_base_dir)
In [6]:
for module in ['hosts', 'targeting', 'mmthecto']:
if module in globals():
reload(globals()[module])
else:
globals()[module] = __import__(module)
g = targeting.get_gama() #re-caches the gama catalo
In [7]:
hostd=hosts.load_all_hosts()
In [16]:
tab = table.Table()
tab.add_column(table.Column(name='nsaid', data=[h.nsaid for h in hostd.values()]))
tab.add_column(table.Column(name='ra', data=[h.ra for h in hostd.values()]))
tab.add_column(table.Column(name='dec', data=[h.dec for h in hostd.values()]))
tab.add_column(table.Column(name='distmpcoh', data=[h.distmpc * .704 for h in hostd.values()]))
tab.add_column(table.Column(name='arcmin300kpc', data=[h.physical_to_projected(300) for h in hostd.values()]))
In [28]:
tab.write('hoststab.dat',format='ascii')
tab
Out[28]:
In [58]:
hids = np.array([h.nsaid for h in hostd.values()])
hds = np.array([h.distmpc for h in hostd.values()])
h300kpc = np.array([h.physical_to_projected(300) for h in hostd.values()])
hra = np.array([h.ra for h in hostd.values()])
hdec = np.array([h.dec for h in hostd.values()])
scatter(hra,hdec)
Out[58]:
In [77]:
from pyspherematch import spherematch
degtol = 3
losmpc = 8
i1,i2, dd = spherematch(hra,hdec,hra,hdec,nnearest=2)
dra = hra - hra[i2]
ddec = hdec - hdec[i2]
inmsk = (dd < degtol) & (np.abs(hds[i1] - hds[i2])<losmpc)
scatter(dra[inmsk],ddec[inmsk],c='b')
scatter(dra[~inmsk],ddec[~inmsk],c='r')
xlim(-30,30)
ylim(-30,30)
print sum(inmsk),'host pairs w/i',degtol,'deg and',losmpc,'Mpc LOS sep:\n',zip(hids[i1[inmsk]],hids[i2[inmsk]])
print 'Corresponding LOS distances:\n',zip(hds[i1[inmsk]],hds[i2[inmsk]])
print 'Corresponding proj distances:\n',dd[inmsk]
print 'Corresponding arcmin 300 kpc:\n',zip(h300kpc[i1[inmsk]],h300kpc[i2[inmsk]])
In [80]:
scatter(hra[inmsk]/15,hdec[inmsk])
Out[80]:
In [12]:
hostd = hosts.load_all_hosts(keyonname=True)
hcfhtl1 = hostd['NSA155005']
hcfhtl2 = hosts.NSAHost(53145)
In [16]:
targs1 = targeting.select_targets(hcfhtl1, outercutrad=300)
targs2 = targeting.select_targets(hcfhtl2, outercutrad=300)
In [23]:
targs1.write('NSA%i_targets.dat' % hcfhtl1.nsaid,format='ascii')
targs2.write('NSA%i_targets.dat' % hcfhtl2.nsaid,format='ascii')
In [44]:
import hosts
import targeting
In [72]:
h = hosts.aiw
In [36]:
h.sdss_image_cutout(scale=60*u.arcmin)
Out[36]:
In [74]:
h.sdss_image_cutout(scale=8*u.arcmin, targets=targeting.select_targets(h),imagesize=(1024, 1024),raoffset=3*u.arcmin)
Out[74]:
In [ ]:
In [2]:
import targeting
In [16]:
otargs = targeting.select_targets(hosts.odyssey, outercutrad=300, removegalsathighz=False)
otargs.write('odyssey_targets.csv', format='ascii', delimiter=',')
In [17]:
btargs = targeting.select_targets(hosts.beowulf, outercutrad=300, removegalsathighz=False)
otargs.write('beowulf_targets.csv', format='ascii', delimiter=',')
In [18]:
targeting.select_targets?
In [194]:
from astropy.io import ascii
from astropy import table
from astropy.coordinates import Angle
from astropy import units as u
In [220]:
ml = ascii.read('masterlist/masterlist.csv')
In [221]:
dm = 5*np.log10(ml['distance']) + 25
Mr = ml['r'] - dm
In [222]:
ml.add_column(table.MaskedColumn(name='r_abs', data=Mr))
In [223]:
rawrap = Angle(ml['RA'], u.deg).wrap_at(180*u.deg).value
rawrap = np.ma.masked_where(ml['RA'].mask, rawrap) # angle does not preserve the mask right now
In [224]:
def mpctodiam(dmpc, rvirkpc):
onempcdiam = ((2*rvirkpc/1000.)*u.radian).to(u.degree).value
return onempcdiam / dmpc
fovdiam = mpctodiam(ml['distance'], 300)
ml.add_column(table.MaskedColumn(name='FOVdiamforRv300kpc', data=fovdiam))
In [225]:
vmsk = ml['vhelio'] < 3000 # w/i 42 Mpc
magmsk = (-20.7< Mr ) & (Mr < -20.1) #~MW-like
In [226]:
#selects ~ 1 deg diameter FOV = 300 kpc Rvir
szmsk = (0.75 < fovdiam) & (fovdiam < 1.1)
In [227]:
#this selects stripe82
s82ramsk = (-50 < rawrap)&(rawrap < 59)
s82decmsk = (-1.25 < ml['Dec']) & (ml['Dec'] < +1.25)
#a stricter definition that accounts for the edges to ~ 20"
s82ramsk_edges = (-49.5 < rawrap)&(rawrap < 58.5)
s82decmsk_edges = (-0.92 < ml['Dec']) & (ml['Dec'] < +0.92)
ml.add_column(table.MaskedColumn(name='strictlyinsideS82', data=((s82ramsk_edges)&(s82decmsk_edges)).astype(int)))
In [229]:
msk = vmsk & s82ramsk & s82decmsk
print 'w/o mag cut', sum(msk)
print 'w mag cut', sum(msk & magmsk)
print 'w mag cut w szmsk', sum(msk & magmsk & szmsk)
print 'relaxed mag cut', sum(msk & (Mr < -18) & szmsk)
In [230]:
np.ma.masked_print_option.set_display('') # otherwise the empty entries have '--' instead of emptiness
mskml= ml[msk]
mskml.sort(['r_abs','FOVdiamforRv300kpc', 'strictlyinsideS82'])
mskml.write('s82masterlist.csv', format='ascii', delimiter=',')
In [231]:
mskml.show_in_browser()
Out[231]:
In [214]:
mski = ml['NSAID']== 132339
print msk[mski], vmsk[mski], s82ramsk[mski], s82decmsk[mski], szmsk[mski]
ml[mski].show_in_browser()
Out[214]:
In [8]:
from astropy.io import ascii
In [12]:
hs = hosts.get_saga_hosts_from_google(googleun, passwd)
In [13]:
mslst=ascii.read('newmasterlist.csv')
In [16]:
ks=[]
kes=[]
for h in hs:
msk=h.nsaid == mslst['NSAID']
mmsk = mslst[msk]
dm = -5*np.log10(mmsk['distance'])-25
ks.append((mmsk['K']+dm)[0])
kes.append(mmsk['K_err'][0])
hostnames = np.array([h.name for h in hs])
hostks = np.array(ks)
hostk_errs = np.array(kes)
nsatsdct = {'Odyssey':8,
'Iliad':-1,
'Alice':1,
'Beowulf':4,
'Gilgamesh':2,
'Hamlet':2,
'Aeneid':1,
'AnaK':5,
'Ulysses':-1,
'Sopranos':-1,
'Dune':-1}
nsats = np.array([nsatsdct[nm] for nm in hostnames])
In [17]:
compldct = {'Odyssey':.95,
'Iliad':-1,
'Alice':.1,
'Beowulf':.3,
'Gilgamesh':.96,
'Hamlet':.44,
'Aeneid':.62,
'AnaK':.72,
'Ulysses':-1,
'Sopranos':-1,
'Dune':-1}
compls = np.array([compldct[nm] for nm in hostnames])
In [18]:
plt.figure(figsize=(10,10))
plt.errorbar(hostks, nsats, None, hostk_errs,fmt='o')
plt.xlim(-24.6,-23.2)
plt.ylim(-1.2,8.2)
plt.axhline(0,color='k')
plt.xlabel('$M_K$',fontsize=24)
plt.ylabel('$N_{\\rm sats}$',fontsize=24)
plt.xlim(*plt.xlim()[::-1])
Out[18]:
In [34]:
plt.figure(figsize=(10,10))
msk = nsats>-1
plt.errorbar(hostks[msk], nsats[msk], nsats[msk]**0.5, hostk_errs[msk],fmt='o', ms=10)
plt.scatter(hostks[msk], nsats[msk]/compls[msk], facecolor='none',edgecolor='r',lw=2,s=70)
#plt.errorbar(hostks[msk], nsats[msk]/compls[msk], None, hostk_errs[msk],fmt='o')
plt.xlim(-24.6,-23.2)
plt.ylim(.1,12)
#plt.axhline(0,color='k')
plt.xlabel('$M_{\\rm K,Vega}$',fontsize=48)
plt.ylabel('$N_{\\rm sats}$',fontsize=48)
plt.xlim(*plt.xlim()[::-1])
plt.tight_layout()
plt.savefig('/Users/erik/Desktop/SAGAnums.pdf')
In [113]:
from astropy.coordinates import ICRS, Galactic
from astropy import units as u
from astropy.io import ascii
In [27]:
hs = hosts.get_saga_hosts_from_google(googleun, googlepw)
print [h.name for h in hs]
ras = [h.ra for h in hs]*u.deg
decs = [h.dec for h in hs]*u.deg
hcoo = ICRS(ras, decs)
In [251]:
hall = ascii.read('host_catalog_all.csv')
print hall.colnames
In [252]:
hallcoo = ICRS(np.array(hall['RA'])*u.deg, np.array(hall['Dec'])*u.deg)
In [253]:
g = hosts.get_gama()
g.dtype.names
Out[253]:
In [254]:
gcoo = ICRS(np.array(g['RA_J2000'])*u.deg, np.array(g['DEC_J2000'])*u.deg)
In [255]:
idx, d2d, d3d = hallcoo.match_to_catalog_sky(gcoo)
plt.figure(figsize=(10,6))
plt.subplot(1,2,1)
plt.hist(d2d.arcmin,bins=np.linspace(0,30,100))
plt.xlabel('arcmin')
plt.subplot(1,2,2)
plt.hist(d2d.arcsec,bins=np.linspace(0,10,100))
plt.xlabel('arcsec')
print '\n'.join([str(s) for s in hall[d2d<1*u.arcmin]['NSAID']])
In [256]:
plt.figure(figsize=(20,15))
ax=plt.axes(projection='hammer')
plt.scatter((gcoo.ra+180*u.deg).wrap_at(np.pi*u.rad).rad, gcoo.dec.rad, lw=0,s=3,alpha=1,color='k', label='GAMA')
plt.scatter((hallcoo.ra+180*u.deg).wrap_at(np.pi*u.rad).rad, hallcoo.dec.rad, lw=0,s=8,alpha=1, color='r', label='hosts_all')
gal0 = Galactic(l=np.roll(np.linspace(0,360,100),67)*u.deg, b=np.zeros(100)*u.deg)
plt.plot((gal0.icrs.ra+180*u.deg).wrap_at(180*u.deg).rad, gal0.icrs.dec.rad, label='$b_{\\rm Gal}=0$',c='b')
plt.legend(loc=0)
a=plt.xticks([-2*np.pi/3,-np.pi/3,0,np.pi/3,2*np.pi/3], [str(n)+u'\xb0' for n in (60, 120, 180, 240, 300)])
plt.tight_layout()
In [299]:
reload(targeting)
g = targeting.get_gama()
u = targeting.update_gama(None)
In [300]:
gamamsk = g['Z_SOURCE']==5
np.sum(g[gamamsk]['Z_HELIO']==-2)/np.sum(gamamsk)
Out[300]:
In [302]:
g.dtype.names
Out[302]:
In [303]:
u.dtype.names
Out[303]:
In [307]:
u['CATAID']
Out[307]:
In [308]:
np.array(g['GAMA_ID'])
Out[308]:
In [314]:
unfinishedids = np.array(g['GAMA_ID'][g['Z_HELIO']==-2])
In [324]:
np.sum(np.in1d(g['GAMA_ID'], u['CATAID']))/len(g)
Out[324]:
In [340]:
np.unique(u['SURVEY'])
Out[340]: