-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoc_plotter
More file actions
64 lines (49 loc) · 1.79 KB
/
oc_plotter
File metadata and controls
64 lines (49 loc) · 1.79 KB
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
import numpy as np
import matplotlib.pyplot as plt
import astropy.units as u
from astropy.table import Table
from scipy import optimize
import pandas as pd
import sys
sys.path.insert(0, '/local/php24aly/')
from functions import SDSStoCSS_changer
### INPUTS ###
object = 'SDSS_J1005+2249'
##############
#check for CSS name for etimes file, and change if needed
object = SDSStoCSS_changer(object, etimes=False)
#read the data
data = Table.read('/local/php24aly/o-c/{}_etimes.txt'.format(object), format='ascii') #input the etimes data
#read T0 and period from the systems.csv file
systems = pd.read_csv('/local/php24aly/o-c/systems.csv', sep=',')
row = systems.loc[systems['Data_path']==(object + '_etimes.txt')]
T0 = row['T0'].to_string(index=False)
period = row['Porb'].to_string(index=False)
#define functions
def ephemeris(cycle, t0, per):
mjd = t0 + (cycle * per)
return mjd
def chisq(pars, x, obs, err):
t0, per = pars
e = ephemeris(x, t0, per)
resid = ((obs - e)**2) / (err**2)
return np.sum(resid)
#find the new fitted ephemeris
guess = (T0, period) #input initial ephemeris values
res = optimize.minimize(chisq, guess, args=(data['Cycle'], data['MJD(BTDB)'], data['err']), method='Nelder-Mead')
print('T0 =', res.x[0])
print('period =', res.x[1])
#O-C using given ephemeris
cycle_num = data['Cycle']
obs_t = data['MJD(BTDB)']
calc_t = []
calc_t.append(res.x[0] + (cycle_num * res.x[1]))
yax = obs_t - calc_t
yax = np.reshape(yax, (len(cycle_num),))
plt.plot(cycle_num, yax, '.', color='black', zorder=1)
plt.errorbar(cycle_num, yax, data['err'], fmt='.', color='black', ecolor='black', alpha=0.65, zorder=2)
plt.gca().ticklabel_format(axis='y', style='sci', scilimits=(0,0))
plt.ylabel('O-C')
plt.xlabel('Cycle Number')
plt.savefig('/local/php24aly/o-c/{}_plot'.format(object))
plt.show()