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:

  • 1: calib/std stars
  • 2: g-r < 1.0 & r-i < 0.5
  • 3: g-r < 1.3 & r-i < 0.7

Odyssey


In [3]:
host = hosts.odyssey

In [4]:
host.sdss_environs_query(True)


File catalogs/Odyssey_sdss.dat exists - not downloading anything.

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)


Removing 179 objects at high z, keeping 4 (total of 43128 objects)
Out[5]:
1324

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]:
({0: 0, 1: 0, 2: 812, 3: 512}, {0: 0, 1: 0, 2: 422, 3: 261})

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))


Including 681 targets
Found 109 Flux stars
Found 172 guide stars

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);

Gilgamesh


In [110]:
host = hosts.gilgamesh

In [111]:
print host.environskpc, host.environsarcmin


300.0 37.1882521443

In [112]:
host.sdss_environs_query(True)


File catalogs/Gilgamesh_sdss.dat exists - not downloading anything.

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)


Removing 180 objects at high z, keeping 7 (total of 37151 objects)
Out[113]:
2159

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]:
{0: 0, 1: 0, 2: 1260, 3: 899}

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))


Inlcuding 2150 targets
Found 95 Flux stars
Found 163 guide stars

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);

Hamlet


In [117]:
host = hosts.hamlet

In [118]:
print host.environskpc, host.environsarcmin


300.0 28.1804560295

In [119]:
host.sdss_environs_query(True)


File catalogs/Hamlet_sdss.dat exists - not downloading anything.

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)


Removing 147 objects at high z, keeping 4 (total of 17650 objects)
Out[120]:
1550

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]:
{0: 0, 1: 0, 2: 1012, 3: 538}

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))


Inlcuding 1533 targets
Found 42 Flux stars
Found 72 guide stars

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);

Checks on flux stars


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)


nflx 129
nflx 109

In [154]:
plot_all_cmd_flx(hosts.gilgamesh)



In [159]:
plot_all_cmd_flx(hosts.hamlet)


Odyssey Completeness tests


In [4]:
hosts.odyssey.sdss_environs_query(True)


File catalogs/Odyssey_sdss.dat exists - not downloading anything.

Tests for completeness in parallel w/ Marla


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]:
1384

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)


Removing 179 objects at high z, keeping 4 (total of 43128 objects)
Out[13]:
1343

In [14]:
targs_fibcut = targs[targs['fibermag_r']<23]
len(targs_fibcut)


Out[14]:
1334

In [7]:
odat = fits.getdata('catalogs/saga_Odyssey_data_May62014.fits')
odat = odat[odat['ZQUALITY']>=3]
odat.dtype.names


Out[7]:
('SDSS_OBJID',
 'TELNAME',
 'MASKFILE',
 'SPECID',
 'RA',
 'DEC',
 'Z',
 'ZQUALITY',
 'SDSS_R',
 'SDSS_G',
 'SDSS_I',
 'SDSS_SG',
 'SDSS_PZ',
 'SDSS_PZ_ERR',
 'SATS')

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)


Already have spectrum: 641 Don't yet: 693

Miscellaneous stuff


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]:
'name ra dec\n0 248.496013256 19.90141787\n1 248.345656954 20.1965399784\n2 247.597593722 19.7474149015\n3 248.028767964 20.2754527742\n4 248.076609812 19.3809762261\n5 247.734553677 20.1056276903\n6 248.131620149 19.9158142121\n7 248.422185553 19.5655789723\n8 248.305031928 19.4227908756\n9 248.068663185 19.7882256128\n10 247.785208152 19.7394331318\n11 247.982173298 19.9880787942\n12 247.883426904 19.364739638\n13 248.008403717 20.1322001027\n14 248.465328474 19.7983988477\n15 247.982037129 20.0707476194\n16 248.447831865 19.6284242029\n17 248.156967504 19.7636294824\n18 248.071477363 19.3687028298\n19 248.366159651 19.5110282823\n20 247.697559549 19.9092944887\n21 248.509721206 19.6240089587\n22 247.640552598 19.9394333183\n23 247.940453037 19.8244304414\n24 248.240390293 19.6367797531\n25 248.429561223 19.5882309004\n26 248.202673252 19.7881508306\n27 248.51599889 19.828908653'

In [24]:
lowfib=targs[(23<targs['fibermag_r'])]
targeting.sampled_imagelist(lowfib['ra'],lowfib['dec'],10000)


Out[24]:
'name ra dec\n0 248.21331629 19.6466085749\n1 248.36901766 20.0947691805\n2 248.435280907 19.4729136623\n3 248.367245317 20.2258262213\n4 248.384844607 19.5723579938\n5 248.550444057 19.6382907907\n6 248.36015449 20.139737498\n7 248.129670872 19.6539752286\n8 248.135975343 19.88599774'

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')

Checking designed configs


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]:
<open file '<fdopen>', mode 'w+b' at 0x125d1de40>

In [53]:
print np.sum(realtargs[nomatch]['rank']=='2'),np.sum(realtargs[nomatch]['rank']=='3')
targeting.sampled_imagelist(realtargs[nomatch],None,None)


16 27
Out[53]:
'name ra dec\n0 248.295913696 20.2879734039\n1 248.5806427 19.7208023071\n2 248.074996948 19.3281059265\n3 248.361419678 19.5155906677\n4 248.421173096 19.4428520203\n5 248.516540527 19.5393600464\n6 248.572738647 19.6643428802\n7 248.1769104 19.6133155823\n8 248.562561035 20.0378341675\n9 248.605773926 19.7115306854\n10 248.386474609 19.4891204834\n11 248.611068726 19.9338302612\n12 248.464355469 19.4706192017\n13 247.871459961 20.002576828\n14 247.902297974 19.584821701\n15 248.004623413 19.8682022095\n16 247.8175354 20.0309944153\n17 248.313705444 20.2810249329\n18 248.594268799 19.7795124054\n19 248.320922852 19.3816413879\n20 248.518753052 19.5534915924\n21 248.548202515 20.0831985474\n22 247.76524353 19.7425785065\n23 247.731048584 19.6835975647\n24 248.425521851 19.481136322\n25 248.418823242 19.432844162\n26 248.092529297 19.7699718475\n27 247.896652222 19.6066246033\n28 248.071380615 19.3258342743\n29 247.65385437 20.0425930023\n30 248.503234863 19.5388622284\n31 248.408691406 19.4779472351\n32 247.805557251 19.3986530304\n33 247.94581604 19.5686378479\n34 248.411392212 19.5050945282\n35 247.804534912 20.0590076447\n36 248.503265381 19.5954685211\n37 247.872528076 19.4073791504\n38 248.202316284 19.6686706543\n39 248.613555908 19.8483543396\n40 248.173233032 19.6185932159\n41 247.883422852 19.3647403717\n42 248.521240234 19.6281681061'

In [63]:



File catalogs/Hamlet_sdss.dat exists - not downloading anything.

Redo of Hamlet with wider area for guide/flux stars


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')


File catalogs/Hamlet_sdss.dat exists, overwriting with new download.
File catalogs/Hamlet_sdss.dat exists, overwriting with new download.
Downloading NSA ID166035 to catalogs/Hamlet_sdss.dat
Unknown Size
11159 kB downloaded

In [102]:
host = hosts.hamlet

In [82]:
print host.environskpc, host.environsarcmin
host.physical_to_projected(300*u.kpc).to(u.arcmin).value


372.598654507 35
Out[82]:
28.18045602951767

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)


Removing 219 objects at high z, keeping 4 (total of 27492 objects)
Out[83]:
1551

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]:
{0: 0, 1: 0, 2: 1012, 3: 539}

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))


Including 1534 targets
Found 60 Flux stars
Found 110 guide stars

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 [ ]: