In [ ]:
# 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 [158]:
import wiyn
import mmthecto
import magellan
import targeting
import hosts
from astropy import coordinates as coords
from astropy import units as u
from astropy.io import ascii
In [267]:
reload(targeting)
reload(hosts)
reload(wiyn)
reload(mmthecto)
reload(magellan)
Out[267]:
In [4]:
#collect all the SDSS objids of the targets that were *observed* based on Ben's *_cat files
fns = !ls mmthecto/configs_observed/NSA147100_*_cat
cats = [ascii.read(fn,names='idx,ra,dec,mag,fiber?,code,name'.split(',')) for fn in fns]
#now pick just pull in all the IDs
observedids = []
for i, cat in enumerate(cats):
for nm in cat['name']:
nm0 = nm.split('_')[0]
if nm0 in ('sky', 'parked'):
pass#observedids.append(-1)
else:
observedids.append(int(nm0))
In [5]:
fullcat = hosts.odyssey.get_sdss_catalog()
In [23]:
#load the catalog of all the *targets* for hectospec and determine which are already observed
mmtcat = ascii.read('mmthecto/NSA147100.cat', data_start=2) # remove the '---' lines
mmttargs = mmtcat[mmtcat['type'] == 'TARGET']
mmtids = np.array([-1 if nm.startswith('NSA') else int(nm.split('_')[0]) for nm in mmttargs['object']])
mmtidsobserved = np.array([False if id_ is '' else id_ in observedids for id_ in mmtids])
In [31]:
#There are more in `mmtidsobserved` than `observedids` because many of the observed things are sky/guide stars
print sum(mmtidsobserved)
print len(observedids)
print len(np.unique(observedids))
In [26]:
#mmttargs goes up to 22 but fullcat only goes to 21.5
np.max(fullcat['r']), np.max(mmttargs['mag'])
In [30]:
#but there's an ID in fullcat for every mmt object with r<21.5, so this scheme is self-consistent
np.all([(i in fullcat['objID']) for i in mmtids[(mmttargs['mag']<21.5) & mmtidsobserved]])
Out[30]:
In [49]:
#get the USNO-B catalog
hosts.odyssey.usnob_environs_query(True)
In [56]:
#so we use the *unobserved* mmt objects' rows from fullcat to build a new catalog
catmsk = np.in1d(fullcat['objID'], mmtids[~mmtidsobserved])
unobservedcat = fullcat[catmsk]
print 'Base catalog faintest r:', np.max(unobservedcat['r']) # it cuts off at 21.5, *not* 22
In [296]:
#and use that catalog to output a WIYN-appropriate master catalog for The Odyssey
mastercat = 'hydra_targets/Odyssey2.cat'
#!rm $mastercat
wiyn.construct_master_catalog(hosts.odyssey, mastercat, unobservedcat, faintlimit=20)
In [298]:
#need to go through and identify the FOPS that are actually galaxies/dbl stars/etc. Then the next cell removes them
wiyn.imagelist_from_master(mastercat, 'fop');
In [297]:
#identified by eye from above cell
invalidfops= ['USNO1099-0254783', 'USNO1094-0250228', 'USNO1094-0250370', 'USNO1101-0267099', 'USNO1098-0253607', 'USNO1102-0276584',
'USNO1100-0256856', 'USNO1098-0253620', 'USNO1094-0250722', 'USNO1103-0282084', 'USNO1102-0276672', 'USNO1098-0253619',
'USNO1096-0252506', 'USNO1100-0256855','USNO1095-0252418', 'USNO1096-0252914', 'USNO1095-0252413', 'USNO1103-0281809',
'USNO1099-0254637']
wiyn.clean_master_catalog(mastercat, invalidfops)
In [254]:
#this is iterated 3 times to generate new ast files that get sent to the department linux machines for running whydra
#note that for these the do_whydra parameters were relaxed because there's not much left in the core:
#./do_whydra -R 1.5 -C 2.0 -c 9
wiyn.generate_ast_file(mastercat, 21,texp=1, faintmagcut=19.5, scpname='turtle')
In [258]:
#the remainder should have mostly fainter objects
wiyn.generate_ast_file(mastercat, 21,texp=1, faintmagcut=20, scpname='michigan')
In [286]:
#look at the AST files and plot the targets to see why there's only 12 fibers in the last one
def plot_inner_ones(fn, circleoffsets=(0,0)):
ast = ascii.read(fn ,data_start=8)
ras = ast['col3']
decs = ast['col4']
ra = np.array([coords.Angle(rai, 'hr').degrees for rai in ras])
dec = np.array([coords.Angle(deci, 'deg').degrees for deci in decs])
cen = coords.ICRSCoordinates('16:32:20.952', '+19:49:35.15', unit=('hr','deg'))
dra = (ra - cen.ra.degrees) * 60
ddec = (dec - cen.dec.degrees) * 60
scatter(dra, ddec)
t = linspace(0,2*pi,100)
plot(sin(t)*30+circleoffsets[0],cos(t)*30+circleoffsets[1], c='r')
return sum(hypot(dra,ddec) < 60)
res1 = plot_inner_ones('hydra_targets/Odyssey2_1.ast')
title('Odyssey2_1.ast')
figure()
res2 = plot_inner_ones('hydra_targets/Odyssey2_6.ast')
title('Odyssey2_7.ast')
print res1, res2
In [265]:
#download USNOB catalog if necessary
hosts.iliad.usnob_environs_query(True)
In [218]:
ilcat = hosts.iliad.get_sdss_catalog()
In [171]:
observedids = []
observedids.extend(magellan.get_smf_entries('imacs_targets/N7393_1.SMF', inclholes=False)[0])
observedids.extend(magellan.get_smf_entries('imacs_targets/N7393_2.SMF', inclholes=False)[0])
observedids = np.array(observedids, dtype=int)
#all are accounted for in the catalog
np.in1d(observedids,ilcat['objID']).all()
Out[171]:
In [173]:
ilobsmsk = np.in1d(ilcat['objID'], observedids)
ilunobscat = ilcat[~ilobsmsk]
In [260]:
#explore effects of fiber mag cuts
#this is for the one-degree field - want larger so there's some space later
targs = targeting.select_targets(hosts.iliad, faintlimit=20, outercutrad=-30)
print len(targs)
#HYDRA-red has 2" fibers, so fiber2mag is the way to go
fibermagcut20 = targs['fiber2mag_r'] < 20
fibermagcut21 = targs['fiber2mag_r'] < 21
fibermagcut22 = targs['fiber2mag_r'] < 22
fibermagcut225 = targs['fiber2mag_r'] < 22.5
fibermagcut23 = targs['fiber2mag_r'] < 23
print fibermagcut20.sum(), fibermagcut21.sum(), fibermagcut22.sum(), fibermagcut225.sum(), fibermagcut23.sum()
figure(figsize=(10,6))
plt.scatter(ilcat['r'], ilcat['fiber2mag_r'], color='k',lw=0,s=2,alpha=.5)
plt.scatter(ilcat['r'][ilcat['phot_sg']=='STAR'], ilcat['fiber2mag_r'][ilcat['phot_sg']=='STAR'], color='r',lw=0,s=2,alpha=.5)
plt.scatter(targs['r'], targs['fiber2mag_r'], color='b',lw=0,s=3,alpha=1)
plt.axhline(20, color='g', lw=1)
plt.axhline(21, color='g', lw=1)
plt.axhline(22, color='g', lw=1)
plt.axhline(22.5, color='g', lw=1)
plt.axhline(23, color='g', lw=1)
plt.xlabel('$r$')
plt.ylabel('$r$ (2 arcsec fiber)')
plt.xlim(12,21.5)
plt.ylim(12,25);
In [300]:
#generate WIYN master catalog, and then based on the above plot, but on fiber2mag < 22.5
!rm hydra_targets/Iliad.cat
wiyn.construct_master_catalog(hosts.iliad, targetcat=dict(faintlimit=20, outercutrad=-40), fibermaglimit=22.5)
In [302]:
wiyn.imagelist_from_master('hydra_targets/Iliad.cat', 'fop');
In [303]:
#identified by eye from above cell
invalidfops="""USNO0842-0645669
USNO0848-0637474
USNO0846-0642169
USNO0847-0628459
USNO0840-0646181
USNO0848-0637640
USNO0839-0663718
USNO0845-0640286
USNO0843-0651469
USNO0844-0645131
USNO0841-0655504
USNO0841-0655559
USNO0844-0644955
USNO0848-0637546
USNO0842-0646243
USNO0844-0644868
USNO0848-0637878
USNO0849-0620415
USNO0844-0644801
USNO0847-0628943
USNO0843-0652186
USNO0844-0644757
USNO0839-0663529
USNO0840-0646113
""".split()
wiyn.clean_master_catalog('hydra_targets/Iliad.cat', invalidfops)
In [361]:
#first a set of 4 bright masks
wiyn.generate_ast_file('hydra_targets/Iliad.cat', lst=23,texp=1, faintmagcut=19, finame='Iliad_%i-bright')
In [387]:
#now go fainter
#for the last 4, use more generous do_whydra:
#./do_whydra -R 1.5 -C 2.0 -c 9
wiyn.generate_ast_file('hydra_targets/Iliad.cat', lst=23,texp=1, faintmagcut=20, finame='Iliad_%i')
In [324]:
#download usnob catalog if necessary
hosts.lotr.usnob_environs_query(True)
In [326]:
lotrcat = hosts.lotr.get_sdss_catalog()
In [360]:
#explore effects of fiber mag cuts
#this is for the one-degree field - want larger so there's some space later
targs = targeting.select_targets(hosts.lotr,faintlimit=20, outercutrad=-30, photflags=True,colorcuts=None)
targscc = targeting.select_targets(hosts.lotr,faintlimit=20, outercutrad=-30, photflags=True,colorcuts=targeting.bossanova_color_cuts)
print len(targs),len(targscc)
#HYDRA-red has 2" fibers, so fiber2mag is the way to go
fibermagcut20 = targscc['fiber2mag_r'] < 20
fibermagcut21 = targscc['fiber2mag_r'] < 21
fibermagcut22 = targscc['fiber2mag_r'] < 22
fibermagcut225 = targscc['fiber2mag_r'] < 22.5
fibermagcut23 = targscc['fiber2mag_r'] < 23
print fibermagcut20.sum(), fibermagcut21.sum(), fibermagcut22.sum(), fibermagcut225.sum(), fibermagcut23.sum()
figure(figsize=(10,6))
plt.scatter(lotrcat['r'][lotrcat['phot_sg']=='STAR'], lotrcat['fiber2mag_r'][lotrcat['phot_sg']=='STAR'], color='r',lw=0,s=2,alpha=.5)
plt.scatter(lotrcat['r'][lotrcat['phot_sg']=='GALAXY'], lotrcat['fiber2mag_r'][lotrcat['phot_sg']=='GALAXY'], color='k',lw=0,s=2,alpha=.5)
plt.scatter(targs['r'], targs['fiber2mag_r'], color='b',lw=0,s=3,alpha=1)
plt.scatter(targscc['r'], targscc['fiber2mag_r'], color='g',lw=0,s=3,alpha=1)
plt.axhline(20, color='g', lw=1)
plt.axhline(21, color='g', lw=1)
plt.axhline(22, color='g', lw=1)
plt.axhline(22.5, color='g', lw=1)
plt.axhline(23, color='g', lw=1)
plt.xlabel('$r$')
plt.ylabel('$r$ (2 arcsec fiber)')
plt.xlim(12,21.5)
plt.ylim(12,25);
In [357]:
#weird ones with rfib ~ 19 and r>17.5 in targs but not targscc:
galmsk = targs['phot_sg'] == 'GALAXY'
magmsk = targs['r'] > 17.5
fmagmsk = targs['fiber2mag_r'] < 19
tmpcat = targs[galmsk&magmsk&fmagmsk]
targeting.sampled_imagelist(tmpcat['ra'],tmpcat['dec'],None);
#turns out they're a satellite track in only r-band
In [370]:
#make master catalog
#!rm hydra_targets/LordoftheRings.cat
wiyn.construct_master_catalog(hosts.lotr, 'hydra_targets/LOTR.cat', targetcat=dict(faintlimit=20.5, outercutrad=-40, colorcuts=targeting.bossanova_color_cuts), fibermaglimit=22.5)
In [378]:
wiyn.imagelist_from_master('hydra_targets/LOTR.cat', 'fop');
In [380]:
#identified by eye from above cell
invalidfops="""
USNO0845-0022221
USNO0845-0022354
USNO0840-0022140
USNO0839-0022512
USNO0844-0021768
USNO0841-0022780
USNO0845-0022087
USNO0846-0021793
USNO0845-0022261
USNO0844-0022117
USNO0842-0021983
USNO0840-0022323
USNO0842-0022135
USNO0849-0021659
USNO0843-0022470
USNO0841-0022840
USNO0844-0022100
USNO0845-0022204
USNO0845-0022624
USNO0841-0022963
USNO0844-0022473
USNO0842-0021863
USNO0849-0022026
""".split()
wiyn.clean_master_catalog('hydra_targets/LOTR.cat', invalidfops)
In [394]:
#first a set of 2 bright masks
wiyn.generate_ast_file('hydra_targets/LOTR.cat', lst=0.5,texp=1, faintmagcut=19, finame='LOTR_%i-bright', scpname=None)
In [399]:
#now a few fainter ones
wiyn.generate_ast_file('hydra_targets/LOTR.cat', lst=0.5,texp=1, faintmagcut=20, finame='LOTR_%i', scpname=None)
In [404]:
#finally, make the cache
wiyn.generate_wiyn_cache('hydra_targets/aug13.cachelist')
In [ ]: