In [8]:
# 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 [9]:
%matplotlib inline
from matplotlib import pyplot as plt
from matplotlib import rcParams

rcParams['figure.figsize'] = (16, 10)
rcParams['image.interpolation'] = 'none'
rcParams['image.origin'] = 'lower'

In [53]:
from __future__ import print_function, division

from astropy import units as u
from astropy import table
from astropy.coordinates import *

import targeting

In [15]:
t = table.Table.read('allgoodspec_apr26_15.fits.gz')
smsk = (t['SATS']==1)&(t['REMOVE']==-1)
tsats = t[smsk]
tsats.colnames


Out[15]:
['objID',
 'ra',
 'dec',
 'phot_sg',
 'flags',
 'specObjID',
 'u',
 'g',
 'r',
 'i',
 'z',
 'u_err',
 'g_err',
 'r_err',
 'i_err',
 'z_err',
 'Au',
 'Ag',
 'Ar',
 'Ai',
 'Az',
 'fibermag_r',
 'fiber2mag_r',
 'expRad_r',
 'sb_exp_r',
 'petroR50_r',
 'petroR90_r',
 'petroMag_r',
 'sb_petro_r',
 'J',
 'Jerr',
 'H',
 'Herr',
 'K',
 'Kerr',
 'w1',
 'w1err',
 'w2',
 'w2err',
 'spec_z',
 'spec_z_err',
 'spec_z_warn',
 'photoz',
 'photoz_err',
 'HOST_RA',
 'HOST_DEC',
 'HOST_DIST',
 'HOST_VHOST',
 'HOST_MK',
 'HOST_NSAID',
 'RHOST_ARCM',
 'RHOST_KPC',
 'OBJ_NSAID',
 'SATS',
 'TELNAME',
 'MASKNAME',
 'ZQUALITY',
 'SPEC_REPEAT',
 'REMOVE']

In [30]:
def get_sats_and_names(hostdct, tsats):
    msk = np.array([hn in (hostdct.keys()) for hn in tsats['HOST_NSAID']])
    nms = []
    cntd = dict([(hn, 0) for hn in hostdct])
    for hn in tsats['HOST_NSAID'][msk]:
        cntd[hn] += 1
        nms.append(hostdct[hn] + str(cntd[hn]))
    return msk, np.array(nms)

In [31]:
evehost = {33446:'StarTrek',85746:'MobyDick',140594:'Alice', 165536:'Dune'}
evesats, evenms = get_sats_and_names(evehost, tsats)
evesc = SkyCoord(tsats['ra'][evesats], tsats['dec'][evesats], unit=u.deg)

In [32]:
mornhost = {61945:'AnaK',147100:'odyssey'}
mornsats, mornnms = get_sats_and_names(mornhost, tsats)
mornsc = SkyCoord(tsats['ra'][mornsats], tsats['dec'][mornsats], unit=u.deg)

In [33]:
targeting.sampled_imagelist(mornsc, None, names=mornnms)


Out[33]:
'name ra dec\nodyssey1 248.393225697 19.9461400824\nodyssey2 247.877387573 20.0936248407\nodyssey3 247.84002995 20.1840758135\nodyssey4 248.152079686 19.8102591366\nodyssey5 248.051339587 19.6957396993\nodyssey6 248.195368592 19.8670126788\nodyssey7 248.16342684 19.792207594\nodyssey8 248.58079685 19.7200349023\nAnaK1 354.350599991 0.390802769345\nAnaK2 354.195229736 0.62342377148'

In [34]:
targeting.sampled_imagelist(evesc, None, names=evenms)


Out[34]:
'name ra dec\nAlice1 180.29544216 -1.2976838319\nDune1 221.316115836 -0.159937082521\nStarTrek1 123.649897556 36.4343553979\nStarTrek2 123.243173206 36.198359966\nMobyDick1 149.687168865 32.7202654623'

In [85]:
#197+17.1        07 29 09.40 +20 54 45.90 2000.0
def make_starlist(fnout, tab, names):
    with open(fnout, 'w') as f:
        for e, nm in zip(tab, names):
            spaces = 16 - len(nm)
            if spaces >= 0:
                f.write(nm)
                f.write(' '*(spaces+1))
            else:
                f.write(nm[:16])
            f.write(SkyCoord(e['ra'], e['dec'], unit=u.deg).to_string('hmsdms', sep=' '))
            f.write(' 2000.0')
            f.write('\n')

In [86]:
make_starlist('/Users/erik/Desktop/evestarlist', tsats[evesats], evenms)
make_starlist('/Users/erik/Desktop/mornstarlist', tsats[mornsats], mornnms)

In [46]:
!cat /Users/erik/Desktop/evestarlist


Alice1           12 01 10.9061 -01 17 51.6618
Dune1            14 45 15.8678 -00 09 35.7735
StarTrek1        08 14 35.9754 +36 26 03.6794
StarTrek2        08 12 58.3616 +36 11 54.0959
MobyDick1        09 58 44.9205 +32 43 12.9557

In [47]:
!cat /Users/erik/Desktop/mornstarlist


odyssey1         16 33 34.3742 +19 56 46.1043
odyssey2         16 31 30.573 +20 05 37.0494
odyssey3         16 31 21.6072 +20 11 02.6729
odyssey4         16 32 36.4991 +19 48 36.9329
odyssey5         16 32 12.3215 +19 41 44.6629
odyssey6         16 32 46.8885 +19 52 01.2456
odyssey7         16 32 39.2224 +19 47 31.9473
odyssey8         16 34 19.3912 +19 43 12.1256
AnaK1            23 37 24.144 +00 23 26.89
AnaK2            23 36 46.8551 +00 37 24.3256

Offsets


In [76]:
def offset_info(fromsc, tosc, starlistname=False):
    dra = (tosc.ra-fromsc.ra)*np.cos((tosc.dec + fromsc.dec)/2)
    ddec = tosc.dec-fromsc.dec
    eorw = 'E' if dra>0 else 'W'
    nors = 'N' if ddec>0 else 'S'
    if starlistname:
        return '{0:16} {1} 2000.0 raoffset={2} decoffset={3}'.format(starlistname[:16], fromsc.to_string('hmsdms', sep=' '), dra.arcsec, ddec.arcsec)
    else:
        return '{0} {1} {2} {3}'.format(dra.arcsec, eorw, ddec.arcsec, nors)

In [77]:
#Target: #Alice1
star = SkyCoord(180.25811*u.deg, -1.33095*u.deg)
targ = SkyCoord(180.29501*u.deg, -1.29751*u.deg)

print('Target:', targ)
#print('PA12:', t1.position_angle(t2).deg, 'or', t1.position_angle(t2).deg-360)
#print('PA21:', t2.position_angle(t1).deg, 'or', t2.position_angle(t1).deg-360)
print('PA =',30.98)
print('Offsets:', offset_info(star, targ))
print('SLentry:', offset_info(star, targ, 'Alice1_star'))


Target: <SkyCoord (ICRS): (ra, dec) in deg
    (180.29501, -1.29751)>
PA = 30.98
Offsets: 132.805055622 E 120.384 N
SLentry: Alice1_star      12 01 01.9464 -01 19 51.42 2000.0 raoffset=132.805055622 decoffset=120.384

In [81]:
#Target: #Dune1
star = SkyCoord(221.41462*u.deg, -0.16425*u.deg)
targ = SkyCoord(221.31587*u.deg, -0.15953*u.deg)

print('Target:', targ)
#print('PA12:', t1.position_angle(t2).deg, 'or', t1.position_angle(t2).deg-360)
#print('PA21:', t2.position_angle(t1).deg, 'or', t2.position_angle(t1).deg-360)
print('PA =',140.2)
print('Offsets:', offset_info(star, targ))
print('SLentry:', offset_info(star, targ, 'Dune1_star'))


Target: <SkyCoord (ICRS): (ra, dec) in deg
    (221.31587, -0.15953)>
PA = 140.2
Offsets: -355.498580929 W 16.992 N
SLentry: Dune1_star       14 45 39.5088 -00 09 51.3 2000.0 raoffset=-355.498580929 decoffset=16.992

In [80]:
#Target: #ST1
star = SkyCoord(123.63623*u.deg, 36.44702*u.deg)
targ = SkyCoord(123.64988*u.deg, 36.43433*u.deg)

print('Target:', targ)
#print('PA12:', t1.position_angle(t2).deg, 'or', t1.position_angle(t2).deg-360)
#print('PA21:', t2.position_angle(t1).deg, 'or', t2.position_angle(t1).deg-360)
print('PA =',122.7)
print('Offsets:', offset_info(star, targ))
print('SLentry:', offset_info(star, targ, 'StarTrek1_star'))


Target: <SkyCoord (ICRS): (ra, dec) in deg
    (123.64988, 36.43433)>
PA = 122.7
Offsets: 39.5317697547 E -45.684 S
SLentry: StarTrek1_star   08 14 32.6952 +36 26 49.272 2000.0 raoffset=39.5317697547 decoffset=-45.684

In [82]:
#Target: #ST2
star = SkyCoord(123.19385*u.deg, 36.19421*u.deg)
targ = SkyCoord(123.24365*u.deg, 36.19831*u.deg)

print('Target:', targ)
#print('PA12:', t1.position_angle(t2).deg, 'or', t1.position_angle(t2).deg-360)
#print('PA21:', t2.position_angle(t1).deg, 'or', t2.position_angle(t1).deg-360)
print('PA =',79.8)
print('Offsets:', offset_info(star, targ))
print('SLentry:', offset_info(star, targ, 'StarTrek2_star'))


Target: <SkyCoord (ICRS): (ra, dec) in deg
    (123.19385, 36.19421)>
PA = 79.8
Offsets: -144.67875605 W -14.76 S
SLentry: StarTrek2_star   08 12 58.476 +36 11 53.916 2000.0 raoffset=-144.67875605 decoffset=-14.76

In [83]:
#Target: MobyDick1
star = SkyCoord(149.71499*u.deg, 32.73056*u.deg)
targ = SkyCoord(149.68717*u.deg, 32.72027*u.deg)

print('Target:', targ)
#print('PA12:', t1.position_angle(t2).deg, 'or', t1.position_angle(t2).deg-360)
#print('PA21:', t2.position_angle(t1).deg, 'or', t2.position_angle(t1).deg-360)
print('PA =',134.8)
print('Offsets:', offset_info(star, targ))
print('SLentry:', offset_info(star, targ, 'MobyDick1_star'))


Target: <SkyCoord (ICRS): (ra, dec) in deg
    (149.68717, 32.72027)>
PA = 134.8
Offsets: -84.2549793847 W -37.044 S
SLentry: MobyDick1_star   09 58 51.5976 +32 43 50.016 2000.0 raoffset=-84.2549793847 decoffset=-37.044

In [93]:
#Target: odyssey4
star = SkyCoord(248.17742*u.deg, 19.81614*u.deg)
targ = SkyCoord(248.15208*u.deg, 19.81026*u.deg)
pa = 154.0

print('Target:', targ)
#print('PA12:', t1.position_angle(t2).deg, 'or', t1.position_angle(t2).deg-360)
#print('PA21:', t2.position_angle(t1).deg, 'or', t2.position_angle(t1).deg-360)
print('PA =',pa)
print('Offsets:', offset_info(star, targ))
print('SLentry:', offset_info(star, targ, 'odyssey4_star'))


Target: <SkyCoord (ICRS): (ra, dec) in deg
    (248.15208, 19.81026)>
PA = 154.0
Offsets: -85.8237859035 W -21.168 S
SLentry: odyssey4_star    16 32 42.5808 +19 48 58.104 2000.0 raoffset=-85.8237859035 decoffset=-21.168

In [94]:
#Target: AnaK1
star = SkyCoord(354.31458*u.deg, 0.37003*u.deg)
targ = SkyCoord(354.35063*u.deg, 0.39077*u.deg)
pa = 140.7

print('Target:', targ)
#print('PA12:', t1.position_angle(t2).deg, 'or', t1.position_angle(t2).deg-360)
#print('PA21:', t2.position_angle(t1).deg, 'or', t2.position_angle(t1).deg-360)
print('PA =',pa)
print('Offsets:', offset_info(star, targ))
print('SLentry:', offset_info(star, targ, 'AnaK1_star'))


Target: <SkyCoord (ICRS): (ra, dec) in deg
    (354.35063, 0.39077)>
PA = 140.7
Offsets: 129.777139698 E 74.664 N
SLentry: AnaK1_star       23 37 15.4992 +00 22 12.108 2000.0 raoffset=129.777139698 decoffset=74.664

In [95]:
#Target: AnaK2
star = SkyCoord(354.15222*u.deg, 0.65171*u.deg)
targ = SkyCoord(354.19530*u.deg, 0.62340*u.deg)
pa = 129.3

print('Target:', targ)
#print('PA12:', t1.position_angle(t2).deg, 'or', t1.position_angle(t2).deg-360)
#print('PA21:', t2.position_angle(t1).deg, 'or', t2.position_angle(t1).deg-360)
print('PA =',pa)
print('Offsets:', offset_info(star, targ))
print('SLentry:', offset_info(star, targ, 'AnaK2_star'))


Target: <SkyCoord (ICRS): (ra, dec) in deg
    (354.1953, 0.6234)>
PA = 129.3
Offsets: 155.078398618 E -101.916 S
SLentry: AnaK2_star       23 36 36.5328 +00 39 06.156 2000.0 raoffset=155.078398618 decoffset=-101.916

In [96]:
#Target: Odyssey8
star = SkyCoord(248.56304*u.deg, 19.73387*u.deg)
targ = SkyCoord(248.58080*u.deg, 19.72003*u.deg) 
pa = 122.1

print('Target:', targ)
#print('PA12:', t1.position_angle(t2).deg, 'or', t1.position_angle(t2).deg-360)
#print('PA21:', t2.position_angle(t1).deg, 'or', t2.position_angle(t1).deg-360)
print('PA =',pa)
print('Offsets:', offset_info(star, targ))
print('SLentry:', offset_info(star, targ, 'odyssey8_star'))


Target: <SkyCoord (ICRS): (ra, dec) in deg
    (248.5808, 19.72003)>
PA = 122.1
Offsets: 60.1837165159 E -49.824 S
SLentry: odyssey8_star    16 34 15.1296 +19 44 01.932 2000.0 raoffset=60.1837165159 decoffset=-49.824