In [58]:
# 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
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 [59]:
import hosts
import targeting
import mmthecto
from astropy import units as u
This run assigns the ranks to targets like so:
In [3]:
host = hosts.odyssey
In [4]:
host.sdss_environs_query(True)
In [5]:
targs = targeting.select_targets(host, outercutrad=300*u.kpc, innercutrad=20,
colorcuts=targeting.bossanova_color_cuts,
galvsallcutoff=21, removegalsathighz=True,
fibermagcut=('r', 22.5))
len(targs)
Out[5]:
In [6]:
# Odyssey already has existing observations, so *don't* do those
odat = fits.getdata('catalogs/saga_Odyssey_data_May62014.fits') #already has ZQUALITY>=3
c = coo.ICRS(np.array(targs['ra'])*u.deg,np.array(targs['dec'])*u.deg)
coodat = coo.ICRS(odat['RA']*u.deg, odat['DEC']*u.deg)
idx, d2d, d3d= coodat.match_to_catalog_sky(c)
got_spectra = np.zeros(len(targs), dtype=bool)
got_spectra[idx[d2d < 1*u.arcsec]] = True
In [7]:
targranks = np.ones(len(targs), dtype=int) * 2
#now down-rank those that are *not* in the tighter color cuts
targranks[~mmthecto.colorcut_mask(targs, targeting.tighter_color_cuts)] +=1
dict(enumerate(np.bincount(targranks))), dict(enumerate(np.bincount(targranks[~got_spectra])))
Out[7]:
In [8]:
#from Marla
toremove_odyssey="""
J163347.65+192831.0
J163128.51+194534.0
"""[1:-1].split('\n')
toremove_odyssey_msk = np.zeros(len(targs), dtype=bool)
idx, sep = targeting.sdss_IAU_id_to_ra_dec(toremove_odyssey, targs)
toremove_odyssey_msk[idx] = True
In [9]:
toremove_odyssey_msk = toremove_odyssey_msk | got_spectra
In [10]:
tab = mmthecto.generate_catalog(host, targs[~toremove_odyssey_msk], targranks[~toremove_odyssey_msk],
fluxrank=1, repeatflux=10)#,
#fnout='mmthecto/{0}_may2014.cat'.format(host.name),
#fluxfnout='mmthecto/{0}_may2014.fluxstars'.format(host.name))
In [138]:
#check out the guide stars (opens a browser window)
targeting.sampled_imagelist(tab[tab['rank']==''], None);
In [139]:
#check out the calib stars (opens a browser window)
targeting.sampled_imagelist(tab[tab['rank']=='1'], None);
In [115]:
#check out the primary targets (opens a browser window)
targeting.sampled_imagelist(tab[tab['rank']=='2'], None);
In [114]:
#check out the secondary targets (opens a browser window)
targeting.sampled_imagelist(tab[tab['rank']=='3'], None);
In [110]:
host = hosts.gilgamesh
In [111]:
print host.environskpc, host.environsarcmin
In [112]:
host.sdss_environs_query(True)
In [113]:
targs = targeting.select_targets(host, outercutrad=300*u.kpc, innercutrad=20,
colorcuts=targeting.bossanova_color_cuts,
galvsallcutoff=21, removegalsathighz=True,
fibermagcut=('r', 22.5))
len(targs)
Out[113]:
In [114]:
targranks = np.ones(len(targs), dtype=int) * 2
#now down-rank those that are *not* in the tighter color cuts
targranks[~mmthecto.colorcut_mask(targs, targeting.tighter_color_cuts)] +=1
dict(enumerate(np.bincount(targranks)))
Out[114]:
In [115]:
#from Marla
toremove_gilgamesh="""
J153601.8+164556.7
J153509.15+163310.4
J153511.65+163254.4
J153717.76+160357.1
J153657.12+160343.7
J153512.32+163302.7
J153511.79+163249.8
J153509.31+163322.2
J153740.28+161035.7
"""[1:-1].split('\n')
toremove_gilgamesh_msk = np.zeros(len(targs),dtype=bool)
idx, sep = targeting.sdss_IAU_id_to_ra_dec(toremove_gilgamesh, targs)
toremove_gilgamesh_msk[idx] = True
In [55]:
tab = mmthecto.generate_catalog(host,
targs[~toremove_gilgamesh_msk], targranks[~toremove_gilgamesh_msk],
fluxrank=1, repeatflux=10,
fnout='mmthecto/{0}_may2014.cat'.format(host.name),
fluxfnout='mmthecto/{0}_may2014.fluxstars'.format(host.name))
In [488]:
#check out the guide stars (opens a browser window)
targeting.sampled_imagelist(tab[tab['rank']==''], None);
In [489]:
#check out the calib stars (opens a browser window)
targeting.sampled_imagelist(tab[tab['rank']=='1'], None,1000);
In [260]:
#check out the primary targets (opens a browser window)
targeting.sampled_imagelist(tab[tab['rank']=='2'], None);
In [114]:
#check out the secondary targets (opens a browser window)
targeting.sampled_imagelist(tab[tab['rank']=='3'], None);
In [117]:
host = hosts.hamlet
In [118]:
print host.environskpc, host.environsarcmin
In [119]:
host.sdss_environs_query(True)
In [120]:
targs = targeting.select_targets(host, outercutrad=300*u.kpc, innercutrad=20,
colorcuts=targeting.bossanova_color_cuts,
galvsallcutoff=21, removegalsathighz=True,
fibermagcut=('r', 22.5))
len(targs)
Out[120]:
In [121]:
targranks = np.ones(len(targs), dtype=int) * 2
#now down-rank those that are *not* in the tighter color cuts
targranks[~mmthecto.colorcut_mask(targs, targeting.tighter_color_cuts)] +=1
dict(enumerate(np.bincount(targranks)))
Out[121]:
In [85]:
#these were found by Erik visually-inspecting the outputs of the `sampled_imagelist` calls below
toremove_hamlet= ['J151503.37+421253.9',
'J151328.66+421950',
'J151329.65+421932.7',
'J151359.68+421331.8',
'J151328.51+422007.3',
'J151256.31+421745.1',
'J151335.92+415734.3',
'J151259.28+415038.9',
'J151609.23+421918.7',
'J151502.99+421256.1',
'J151503.20+421254.8',
'J151506.78+421234.9',
'J151333.48+415715.7',
#'J151506.13+421233.6', #big one? pg36
'J151329.94+421949.3',
'J151236.39+420520', #after this rank 3
'J151443.50+420236.4',
'J151502.29+421303.5']
In [122]:
toremove_hamlet_msk = np.zeros(len(targs),dtype=bool)
idx, sep = targeting.sdss_IAU_id_to_ra_dec(toremove_hamlet, targs)
toremove_hamlet_msk[idx] = True
In [89]:
#slightly relaxed flux stars b/c it's at high galactic lat
tab = mmthecto.generate_catalog(host,
targs[~toremove_hamlet_msk], targranks[~toremove_hamlet_msk],
fluxrank=1, repeatflux=10, fluxrng=(16.8,18),
fnout='mmthecto/{0}_may2014.cat'.format(host.name),
fluxfnout='mmthecto/{0}_may2014.fluxstars'.format(host.name))
In [246]:
#check out the guide stars (opens a browser window)
targeting.sampled_imagelist(tab[tab['rank']==''], None, None);
In [88]:
#check out the calib stars (opens a browser window)
targeting.sampled_imagelist(tab[tab['rank']=='1'], None, None);
In [548]:
#check out the primary targets (opens a browser window)
targeting.sampled_imagelist(tab[tab['rank']=='2'], None, None);
In [536]:
#check out the secondary targets (opens a browser window)
targeting.sampled_imagelist(tab[tab['rank']=='3'], None, None);
In [305]:
def plot_all_cmd_flx(host, extcorr=False):
allsdss = host.get_sdss_catalog()
flx = mmthecto.select_flux_stars(allsdss, extcorr=extcorr)
print 'nflx', len(flx)
samp = allsdss[allsdss['psf_r']<23]
u,g,r = samp['psf_u'],samp['psf_g'],samp['psf_r']
uf,gf,rf = flx['psf_u'],flx['psf_g'],flx['psf_r']
if extcorr:
u = u - samp['Au']
g = g - samp['Ag']
r = r - samp['Ar']
uf = uf - flx['Au']
gf = gf - flx['Ag']
rf = rf - flx['Ar']
plt.scatter(g-r, u-g, c=r, lw=0, alpha=.5, s=5,vmin=13)
plt.scatter(gf-rf, uf-gf, c=rf, lw=1, alpha=.5, s=5,vmin=13)
plt.colorbar().set_label('r')
plt.xlabel('g-r')
plt.xlim(-0.5,2.5)
plt.ylim(-1,3.5)
plt.ylabel('u-g')
plt.tight_layout()
In [306]:
plt.figure(figsize=(10,10))
plt.subplot(1,2,1)
plot_all_cmd_flx(hosts.odyssey,True)
plt.subplot(1,2,2)
plot_all_cmd_flx(hosts.odyssey,False)
In [154]:
plot_all_cmd_flx(hosts.gilgamesh)
In [159]:
plot_all_cmd_flx(hosts.hamlet)
In [4]:
hosts.odyssey.sdss_environs_query(True)
In [4]:
#no gal removal
targs = targeting.select_targets(hosts.odyssey, outercutrad=300*u.kpc, innercutrad=20,
colorcuts=targeting.bossanova_color_cuts,
galvsallcutoff=21, removegalsathighz=False)
len(targs)
Out[4]:
In [13]:
targs = targeting.select_targets(hosts.odyssey, outercutrad=300*u.kpc, innercutrad=20,
colorcuts=targeting.bossanova_color_cuts,
galvsallcutoff=21, removegalsathighz=True)
len(targs)
Out[13]:
In [14]:
targs_fibcut = targs[targs['fibermag_r']<23]
len(targs_fibcut)
Out[14]:
In [7]:
odat = fits.getdata('catalogs/saga_Odyssey_data_May62014.fits')
odat = odat[odat['ZQUALITY']>=3]
odat.dtype.names
Out[7]:
In [8]:
c = coo.ICRS(np.array(targs_fibcut['ra'])*u.deg,np.array(targs_fibcut['dec'])*u.deg)
coodat = coo.ICRS(odat['RA']*u.deg, odat['DEC']*u.deg)
idx, d2d, d3d= coodat.match_to_catalog_sky(c)
hist(d2d.to(u.arcsec).value, bins=100,histtype='step',range=(0,10), log=True);
In [9]:
got_spectra = np.zeros(len(targs_fibcut), dtype=bool)
got_spectra[idx[d2d < 1*u.arcsec]] = True
print 'Already have spectrum:',sum(got_spectra),'Don\'t yet:', sum(~got_spectra)
In [58]:
midfib=targs[(22<targs['fibermag_r'])&(targs['fibermag_r']<23)]
targeting.sampled_imagelist(midfib['ra'],midfib['dec'],10000)
In [63]:
midfib2=targs[(22<targs['fibermag_r'])&(targs['fibermag_r']<22.5)]
targeting.sampled_imagelist(midfib2['ra'],midfib2['dec'],10000)
Out[63]:
In [24]:
lowfib=targs[(23<targs['fibermag_r'])]
targeting.sampled_imagelist(lowfib['ra'],lowfib['dec'],10000)
Out[24]:
In [53]:
figure(figsize=(12,8))
plot(targs['fibermag_r'],targs['r'],'.r',alpha=.8,ms=1);
plt.xlabel('fibermag_r')
plt.ylabel('r')
plt.xlim(18,23.5)
plt.ylim(15,21.1);
In [518]:
#for marla's visual vetting - need to run after one of the calls above where `tab` and `host` are defined
writetargs=tab[(tab['rank']=='2') | (tab['rank']=='3')]
with open('/Users/erik/Desktop/{0}_for_marla.cat'.format(host.name), 'w') as f:
f.write('ra dec\n')
for a,b,c in zip(writetargs['ra'],writetargs['dec'],writetargs['object']):
f.write('{0:.6f}'.format(a))
f.write(' ')
f.write('{0:.6f}'.format(b))
#f.write(' ')
#f.write(str(c))
f.write('\n')
In [131]:
#For writing out the removed stars list - must be after one of the `hosts` and `targs` is defined appropriately
with open('{0}_removed_objects.dat'.format(host.name), 'w') as f:
f.write('objid ra dec\n')
for t in targs[locals()['toremove_{0}_msk'.format(host.name.lower())]]:
f.write('{0}'.format(t['objID']))
f.write(' ')
f.write('{0:.6f}'.format(t['ra']))
f.write(' ')
f.write('{0:.6f}'.format(t['dec']))
f.write('\n')
In [27]:
coordscfg, targetscfg, rankscfg, fieldscfg = mmthecto.parse_cfg_file('mmthecto/Odyssey_may2014.cfg')
coordscfg = coo.ICRS([ci.ra.degree for ci in coordscfg]*u.deg, [ci.dec.degree for ci in coordscfg]*u.deg)
In [52]:
realtargs = tab[(tab['rank']=='2') | (tab['rank']=='3')]
cootargs = coo.ICRS(np.array(realtargs['ra'])*u.deg, np.array(realtargs['dec'])*u.deg)
idx, d2d, d3d = cootargs.match_to_catalog_sky(coordscfg)
nomatch = d2d>1*u.arcsec
realtargs[nomatch].show_in_browser()
Out[52]:
In [53]:
print np.sum(realtargs[nomatch]['rank']=='2'),np.sum(realtargs[nomatch]['rank']=='3')
targeting.sampled_imagelist(realtargs[nomatch],None,None)
Out[53]:
In [63]:
In [77]:
reload(hosts)
hosts.hamlet.environsarcmin = 35 # default is 300 kpc, but that's not big enough for MMT to get guide stars
hosts.hamlet.sdss_environs_query('overwrite')
In [102]:
host = hosts.hamlet
In [82]:
print host.environskpc, host.environsarcmin
host.physical_to_projected(300*u.kpc).to(u.arcmin).value
Out[82]:
In [83]:
targs = targeting.select_targets(host, outercutrad=300*u.kpc, innercutrad=20,
colorcuts=targeting.bossanova_color_cuts,
galvsallcutoff=21, removegalsathighz=True,
fibermagcut=('r', 22.5))
len(targs)
Out[83]:
In [84]:
targranks = np.ones(len(targs), dtype=int) * 2
#now down-rank those that are *not* in the tighter color cuts
targranks[~mmthecto.colorcut_mask(targs, targeting.tighter_color_cuts)] +=1
dict(enumerate(np.bincount(targranks)))
Out[84]:
In [86]:
#use the toremove_hamlet list from above
toremove_hamlet_msk = np.zeros(len(targs),dtype=bool)
idx, sep = targeting.sdss_IAU_id_to_ra_dec(toremove_hamlet, targs)
toremove_hamlet_msk[idx] = True
In [89]:
#slightly relaxed flux stars b/c it's at high galactic lat
tab = mmthecto.generate_catalog(host,
targs[~toremove_hamlet_msk], targranks[~toremove_hamlet_msk],
fluxrank=1, repeatflux=10, fluxrng=(16.8,18),
fnout='mmthecto/{0}_may2014_2.cat'.format(host.name),
fluxfnout='mmthecto/{0}_may2014_2.fluxstars'.format(host.name))
In [101]:
plt.figure(figsize=(12,10))
plt.scatter(tab['ra'],tab['dec'], c=[float(i if i!='' else -1) for i in tab['rank']],lw=0,s=5)
plt.colorbar();
In [ ]: