-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtessplotter.py
94 lines (74 loc) · 2.7 KB
/
tessplotter.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
import numpy as np
import lightkurve as lk
import matplotlib.pyplot as plt
import matplotlib as mpl
import pandas as pd
import scipy.signal as sps
import astropy.timeseries as ts
from astropy.io import fits
import os, sys, time, argparse
from spinneret import *
parser = argparse.ArgumentParser(description='Process a Kepler quarter and TESSified sector using spinneret')
# parser.add_argument('-f', '--filename', required=True, type=str, help='FITS file name')
parser.add_argument('-c', '--case', required=False, type=str, default='misc', help='Systematics test case')
parser.add_argument('-t', '--tic', required=True, type=int, help='TESS ID')
parser.add_argument('-s', '--sector', required=True, type=int, help='TESS sector')
parser.add_argument('-p', '--gtp', required=False, type=float, default=0, help='Ground truth period')
params = parser.parse_args()
# fn = params.filename
case = params.case
tid = params.tic
sec = params.sector
gtp = params.gtp
id_prepend = 'tic'
file_append = 'tess'
cadence = 1/24/30 # 2min
printsec = ''
if sec < 10:
printsec = f'0{sec}'
else:
printsec = str(sec)
ticstr = ''
if len(str(tid)) == 7:
ticstr = f'00{tid}'
elif len(str(tid)) == 8:
ticstr = f'0{tid}'
else:
ticstr = str(tid)
fn = None
for roots, dirs, files in os.walk('/shared_data/vanir/TESS/LightCurves/sector{printsec}/'):
for f in files:
if str(tic) in f:
fn = f
else:
pass
filename = f'/shared_data/vanir/TESS/LightCurves/sector{printsec}/{fn}'
directorymaker(case)
# dir_name = f'sector{printsec}'
# directorymaker(dir_name)
try:
hdu = fits.open(filename)
except FileNotFoundError:
print(f'NO DATA: {tid}')
sys.exit()
table = hdu[1].data
time = table['TIME']
flux = table['PDCSAP_FLUX']
hdu.close()
time, flux = nancleaner2d(time, flux)
time, flux = clip(time, flux, 3) #3 sigma clip
flux = lk.LightCurve(time=time, flux=flux).normalize().flux.value - 1
# minfreq = 1/(time[-1] - time[0])
# p_grid = np.linspace(0.001, time[-1], 5000)
# freq = 1/p_grid
target = Spinner(time, flux, teff=teff, logg=logg, crowding=cr, tmag=tmag)
freq, ps = ts.LombScargle(time, flux).autopower(method='fastchi2', maximum_frequency=200, samples_per_peak=20)
target.ls_one_term(freq, ps)
freq, ps = ts.LombScargle(time, flux, nterms=2).autopower(method='fastchi2', maximum_frequency=200, samples_per_peak=20)
target.ls_two_term(freq, ps)
lags_raw, acf_raw, lags, acf, _x, _y = simple_acf(time, flux, cadence, width=16)
target.acf(lags, acf)
fig1 = target.diagnostic_plot(heading=f'TIC {tid}')
figsaver(fig1, f'TIC{tid}_{file_append}.png', filepath=f'./figs{printsec}')
# filemaker(target, tid, 0, filename=f'{id_prepend}{tid}_{file_append}.csv', filepath=f'./{dir_name}')
print(f'{tid} done')