forked from mkenworthy/exorings
/
plot_disk_fit.py
102 lines (76 loc) · 3.29 KB
/
plot_disk_fit.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
96
97
98
99
100
101
import sys, getopt
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import exorings
from astropy.io import ascii
# set sensible imshow defaults
mpl.rc('image', interpolation='nearest', origin='lower', cmap='gray')
mpl.rc('axes.formatter', limits=(-7, 7))
def plot_gradient_fit(t, f, fn, xt, yt, p):
# f = gradient of fit at points of measurement
p.plot(xt, yt, lw=3.0, color='black', zorder=1)
p.scatter(t, f, facecolor='1.0', s=60, color='black', zorder=2, lw=1)
p.scatter(t, f, facecolor='None', s=60, color='black', zorder=3, lw=1)
p.scatter(t, fn, facecolor='0.0', s=60, zorder=4, lw=1)
p.vlines(t, f, fn, zorder=1, lw=2, color='0.5', linestyles='dotted')
p.set_xlabel('HJD - 2450000 [Days]')
p.set_ylabel('Light curve gradient [$L_\star/day$]')
################################################################################
# BEGIN main program
################################################################################
def helpme():
print 'plot_disk_fit.py -d <disk input FITS> -o <output plot file>'
print 'Example: '
print ' plot_disk_fit.py -d 54220.65.try3.fits -o disk_fit.pdf'
sys.exit()
# parse command line options
try:
opts, args = getopt.getopt(sys.argv[1:], "hd:o:", ["dfile=", "ofile="])
except getopt.GetoptError:
helpme()
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
help()
elif opt in ("-d", "--dfile"):
fitsin_disk = arg
read_in_disk_parameters = True
elif opt in ("-o", "--ofile"):
plotfileout = arg
# get light curve gradients
grad = ascii.read("gradients.txt")
grad_time = grad['col1'] + 54222.
grad_mag = np.abs(grad['col2'])
# read in or create the ring system tau and radii
print 'Reading in disk parameters from %s' % fitsin_disk
(res, taun_ringsxx, rad_ringsxx, dstar) = exorings.read_ring_fits(fitsin_disk)
# make the radius and projected gradient for the measured gradient points
(ring_disk_fit, grad_disk_fit) = \
exorings.make_ring_grad_line(grad_time, res[0], res[1], res[2], res[3])
# produce fine grained gradient and ring values
samp_t = np.arange(-100, 100, 0.001) + 54222.
(samp_r, samp_g) = exorings.make_ring_grad_line(samp_t, res[0], res[1], res[2], res[3])
hjd_minr = samp_t[np.argmin(samp_g)]
exorings.print_disk_parameters(res, hjd_minr, samp_r)
# plotting fit of gradients from ellipse curve to J1407 gradients
plt.rc('font', **{'family':'sans-serif', 'sans-serif':['Helvetica']})
plt.rc('text', usetex=True)
figfit = plt.figure(figsize=(10, 6))
f2 = figfit.add_subplot(111)
f2.set_ylim([0, 1.1*np.max(grad_mag)])
f2.set_xlim([np.min(samp_t), np.max(samp_t)])
plot_gradient_fit(grad_time, grad_disk_fit * np.max(grad_mag), grad_mag, \
samp_t, samp_g*np.max(grad_mag), f2)
# make ticks thicker
for ax in figfit.axes: # go over all the subplots in the figure fig
for i in ax.spines.itervalues(): # ... and go over all the axes too...
i.set_linewidth(2)
ax.minorticks_on() # switch on the minor ticks
# set the tick lengths and tick widths
ax.tick_params('both', length=15, width=2, which='major')
ax.tick_params('both', length=6, width=1, which='minor')
# adjust text size on the axes
f2.tick_params(axis='both', which='major', labelsize=14)
print 'writing plot out to file %s' % plotfileout
plt.savefig(plotfileout)