-
Notifications
You must be signed in to change notification settings - Fork 40
/
markGaia.py
96 lines (73 loc) · 3.69 KB
/
markGaia.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import numpy as np
import matplotlib.pyplot as plt
from lightkurve import KeplerTargetPixelFile as ktpf
from ellie import find_sources as ctpf
from astropy.io import fits
from astropy.wcs import WCS
from oneSource import files_in_dir
import mplcursors
from astroquery.mast import Catalogs
def find_center(header):
""" Finds the true center of the TPF """
# Finds center (RA,Dec) and (x,y) of TPF
return (header['CEN_RA'], header['CEN_DEC']), (header['CEN_X'], header['CEN_Y'])
def cone_search_sources(cen_ra, cen_dec):#gaia_id):
""" Completes a cone search for sources """
pos = [cen_ra, cen_dec]
# Finds Gaia sources around associated Gaia ID
newlocate = ctpf(pos=pos)
sources = newlocate.cone_search(0.05, 'Mast.Catalogs.GaiaDR2.Cone')
return sources['ra'], sources['dec'], sources['source_id'], sources['phot_g_mean_mag']
def pointingCorr(xy, camera, chip):
""" Corrects (x,y) coordinates based on pointing model """
shift = np.loadtxt('pointingModel_{}-{}.txt'.format(camera, chip), skiprows=1, usecols=(1,2,3))[0]
shift[0] = np.radians(shift[0])
x = xy[0]*np.cos(shift[0]) - xy[1]*np.sin(shift[0]) - shift[1]
y = xy[0]*np.sin(shift[0]) + xy[1]*np.cos(shift[0]) - shift[2]
return np.array([x,y])
def in_tpf(xy, gaiaXY, gaiaID, gaiaMAG):
""" Pushes the Gaia sources to the appropriate place in the TPF """
gaiaX, gaiaY = gaiaXY[0]-xy[0]+4, gaiaXY[1]-xy[1]+5
inds = np.where( (gaiaX > -0.5) & (gaiaX < 8.5) &
(gaiaY > -0.5) & (gaiaY < 8.5) )
return [gaiaX[inds], gaiaY[inds]], gaiaID[inds], gaiaMAG[inds]
def plot_with_hover(tpf, gaiaXY, gaiaID, gaiaMAG, ticID, tmag):
fig, ax = plt.subplots()
ax.imshow(tpf.flux[0], origin='lower')
sc = ax.scatter(gaiaXY[0], gaiaXY[1], c='k', s=10)
plt.xlim([-0.5,8.5])
plt.ylim([-0.5,8.5])
mplcursors.cursor(sc).connect(
"add", lambda sel: sel.annotation.set_text("TIC ID = {}\nTmag = {}\nGaia ID = {}\nGmag = {}".format(ticID[sel.target.index],
tmag[sel.target.index],
gaiaID[sel.target.index],
gaiaMAG[sel.target.index])))
plt.show()
def main(id, camera, chip):
""" Temporary main function """
# file = './figures/TIC{}_tpf.fits'.format(id)
file = 'hlsp_ellie_tess_ffi_284969084_v1_lc.fits'
# dir = './2019/2019_1_{}-{}/ffis/'.format(camera, chip)
# fns = files_in_dir(dir)
hdu = fits.open(file)
tpf = hdu[0].data
post, post_header = fits.getdata(hdu[0].header['COMMENT'][6], header=True)
# flux, header = fits.getdata(fns[0], header=True)
pos, xy = find_center(post_header)
print(post_header)
gaiaRA, gaiaDEC, gaiaID, gaiaMAG = cone_search_sources(pos[0], pos[1])#hdu1['GAIA_ID'])
gaiaXY = WCS(post_header).all_world2pix(gaiaRA, gaiaDEC, 1)
gaiaXY = pointingCorr(gaiaXY, camera, chip)
gaiaXY, gaiaID, gaiaMAG = in_tpf(xy, gaiaXY, gaiaID, gaiaMAG)
crossmatch = ctpf()
crossTable = crossmatch.crossmatch_multi_to_tic(list=gaiaID.data)
ticLabel, tmagLabel = np.zeros(len(gaiaID.data)), np.zeros(len(gaiaID.data))
for i in range(len(gaiaID.data)):
row = crossTable[i]
# print(row['separation'])
if row['separation'] <= 1.0 and row['Gmag'] <= 16.5:
ticLabel[i] = row['TIC_ID']
tmagLabel[i] = row['Tmag']
tpf = ktpf.from_fits(file)
plot_with_hover(tpf, gaiaXY, gaiaID, gaiaMAG, ticLabel, tmagLabel)
main(198593129, 3, 3)