-
Notifications
You must be signed in to change notification settings - Fork 54
/
orbit_plots.py
769 lines (631 loc) · 30.2 KB
/
orbit_plots.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
import numpy as np
import pandas as pd
from matplotlib import rcParams, gridspec
from matplotlib import pyplot as pl
from matplotlib.ticker import MaxNLocator
from astropy.time import Time
import radvel
from radvel import plot
from radvel.plot import mcmc_plots
from radvel.utils import t_to_phase, fastbin, sigfig
class MultipanelPlot(object):
"""
Class to handle the creation of RV multipanel plots.
Args:
post (radvel.Posterior): radvel.Posterior object. The model
plotted will be generated from `post.params`
epoch (int, optional): epoch to subtract off of all time measurements
yscale_auto (bool, optional): Use matplotlib auto y-axis
scaling (default: False)
yscale_sigma (float, optional): Scale y-axis limits for all panels to be +/-
yscale_sigma*(RMS of data plotted) if yscale_auto==False
phase_nrows (int, optional): number of columns in the phase
folded plots. Default is nplanets.
phase_ncols (int, optional): number of columns in the phase
folded plots. Default is 1.
uparams (dict, optional): parameter uncertainties, must
contain 'per', 'k', and 'e' keys.
telfmts (dict, optional): dictionary of dictionaries mapping
instrument suffix to plotting format code. Example:
telfmts = {
'hires': dict(fmt='o',label='HIRES'),
'harps-n' dict(fmt='s')
}
legend (bool, optional): include legend on plot? Default: True.
phase_limits (list, optional): two element list specifying
pyplot.xlim bounds for phase-folded plots. Useful for
partial orbits.
nobin (bool, optional): If True do not show binned data on
phase plots. Will default to True if total number of
measurements is less then 20.
phasetext_size (string, optional): fontsize for text in phase plots.
Choice of {'xx-small', 'x-small', 'small', 'medium', 'large',
'x-large', 'xx-large'}. Default: 'x-small'.
rv_phase_space (float, optional): amount of space to leave between orbit/residual plot
and phase plots.
figwidth (float, optional): width of the figures to be produced.
Default: 7.5 (spans a page with 0.5 in margins)
fit_linewidth (float, optional): linewidth to use for orbit model lines in phase-folded
plots and residuals plots.
set_xlim (list of float): limits to use for x-axes of the timeseries and residuals plots, in
JD - `epoch`. Ex: [7000., 70005.]
text_size (int): set matplotlib.rcParams['font.size'] (default: 9)
highlight_last (bool): make the most recent measurement much larger in all panels
show_rms (bool): show RMS of the residuals by instrument in the legend
legend_kwargs (dict): dict of options to pass to legend (plotted in top panel)
status (ConfigParser): (optional) result of radvel.driver.load_status on the .stat status file
"""
def __init__(self, post, saveplot=None, epoch=2450000, yscale_auto=False, yscale_sigma=3.0,
phase_nrows=None, phase_ncols=None, uparams=None, telfmts={}, legend=True,
phase_limits=[], nobin=False, phasetext_size='large', rv_phase_space=0.08,
figwidth=7.5, fit_linewidth=2.0, set_xlim=None, text_size=9, highlight_last=False,
show_rms=False, legend_kwargs=dict(loc='best'), status=None):
self.post = post
self.saveplot = saveplot
self.epoch = epoch
self.yscale_auto = yscale_auto
self.yscale_sigma = yscale_sigma
if phase_ncols is None:
self.phase_ncols = 1
if phase_nrows is None:
self.phase_nrows = self.post.likelihood.model.num_planets
self.uparams = uparams
self.rv_phase_space = rv_phase_space
self.telfmts = telfmts
self.legend = legend
self.phase_limits = phase_limits
self.nobin = nobin
self.phasetext_size = phasetext_size
self.figwidth = figwidth
self.fit_linewidth = fit_linewidth
self.set_xlim = set_xlim
self.highlight_last = highlight_last
self.show_rms = show_rms
self.legend_kwargs = legend_kwargs
rcParams['font.size'] = text_size
if status is not None:
self.status = status
if isinstance(self.post.likelihood, radvel.likelihood.CompositeLikelihood):
self.like_list = self.post.likelihood.like_list
else:
self.like_list = [self.post.likelihood]
# FIGURE PROVISIONING
self.ax_rv_height = self.figwidth * 0.6
self.ax_phase_height = self.ax_rv_height / 1.4
# convert params to synth basis
synthparams = self.post.params.basis.to_synth(self.post.params)
self.post.params.update(synthparams)
self.model = self.post.likelihood.model
self.rvtimes = self.post.likelihood.x
self.rverr = self.post.likelihood.errorbars()
self.num_planets = self.model.num_planets
self.rawresid = self.post.likelihood.residuals()
self.resid = (
self.rawresid + self.post.params['dvdt'].value*(self.rvtimes-self.model.time_base)
+ self.post.params['curv'].value*(self.rvtimes-self.model.time_base)**2
)
if self.saveplot is not None:
resolution = 10000
else:
resolution = 2000
periods = []
for i in range(self.num_planets):
periods.append(synthparams['per%d' % (i+1)].value)
if len(periods) > 0:
longp = max(periods)
else:
longp = max(self.post.likelihood.x) - min(self.post.likelihood.x)
self.dt = max(self.rvtimes) - min(self.rvtimes)
self.rvmodt = np.linspace(
min(self.rvtimes) - 0.05 * self.dt, max(self.rvtimes) + 0.05 * self.dt + longp,
int(resolution)
)
self.orbit_model = self.model(self.rvmodt)
self.rvmod = self.model(self.rvtimes)
if ((self.rvtimes - self.epoch) < -2.4e6).any():
self.plttimes = self.rvtimes
self.mplttimes = self.rvmodt
elif self.epoch == 0:
self.epoch = 2450000
self.plttimes = self.rvtimes - self.epoch
self.mplttimes = self.rvmodt - self.epoch
else:
self.plttimes = self.rvtimes - self.epoch
self.mplttimes = self.rvmodt - self.epoch
self.slope = (
self.post.params['dvdt'].value * (self.rvmodt-self.model.time_base)
+ self.post.params['curv'].value * (self.rvmodt-self.model.time_base)**2
)
self.slope_low = (
self.post.params['dvdt'].value * (self.rvtimes-self.model.time_base)
+ self.post.params['curv'].value * (self.rvtimes-self.model.time_base)**2
)
# list for Axes objects
self.ax_list = []
def plot_timeseries(self):
"""
Make a plot of the RV data and model in the current Axes.
"""
ax = pl.gca()
ax.axhline(0, color='0.5', linestyle='--')
if self.show_rms:
rms_values = dict()
for like in self.like_list:
inst = like.suffix
rms = np.std(like.residuals())
rms_values[inst] = rms
else:
rms_values = False
# plot orbit model
ax.plot(self.mplttimes, self.orbit_model, 'b-', rasterized=False, lw=self.fit_linewidth)
# plot data
vels = self.rawresid+self.rvmod
plot.mtelplot(
# data = residuals + model
self.plttimes, vels, self.rverr, self.post.likelihood.telvec, ax, telfmts=self.telfmts,
rms_values=rms_values
)
if self.set_xlim is not None:
ax.set_xlim(self.set_xlim)
else:
ax.set_xlim(min(self.plttimes)-0.01*self.dt, max(self.plttimes)+0.01*self.dt)
pl.setp(ax.get_xticklabels(), visible=False)
if self.highlight_last:
ind = np.argmax(self.plttimes)
pl.plot(self.plttimes[ind], vels[ind], **plot.highlight_format)
# legend
if self.legend:
ax.legend(numpoints=1, **self.legend_kwargs)
# years on upper axis
axyrs = ax.twiny()
xl = np.array(list(ax.get_xlim())) + self.epoch
decimalyear = Time(xl, format='jd', scale='utc').decimalyear
# axyrs.plot(decimalyear, decimalyear)
axyrs.get_xaxis().get_major_formatter().set_useOffset(False)
axyrs.set_xlim(*decimalyear)
axyrs.set_xlabel('Year', fontweight='bold')
pl.locator_params(axis='x', nbins=5)
if not self.yscale_auto:
scale = np.std(self.rawresid+self.rvmod)
ax.set_ylim(-self.yscale_sigma * scale, self.yscale_sigma * scale)
ax.set_ylabel('RV [{ms:}]'.format(**plot.latex), weight='bold')
ticks = ax.yaxis.get_majorticklocs()
ax.yaxis.set_ticks(ticks[1:])
def plot_residuals(self):
"""
Make a plot of residuals and RV trend in the current Axes.
"""
ax = pl.gca()
ax.plot(self.mplttimes, self.slope, 'b-', lw=self.fit_linewidth)
plot.mtelplot(self.plttimes, self.resid, self.rverr, self.post.likelihood.telvec, ax, telfmts=self.telfmts)
if not self.yscale_auto:
scale = np.std(self.resid)
ax.set_ylim(-self.yscale_sigma * scale, self.yscale_sigma * scale)
if self.highlight_last:
ind = np.argmax(self.plttimes)
pl.plot(self.plttimes[ind], self.resid[ind], **plot.highlight_format)
if self.set_xlim is not None:
ax.set_xlim(self.set_xlim)
else:
ax.set_xlim(min(self.plttimes)-0.01*self.dt, max(self.plttimes)+0.01*self.dt)
ticks = ax.yaxis.get_majorticklocs()
ax.yaxis.set_ticks([ticks[0], 0.0, ticks[-1]])
pl.xlabel('JD - {:d}'.format(int(np.round(self.epoch))), weight='bold')
ax.set_ylabel('Residuals', weight='bold')
ax.yaxis.set_major_locator(MaxNLocator(5, prune='both'))
def plot_phasefold(self, pltletter, pnum):
"""
Plot phased orbit plots for each planet in the fit.
Args:
pltletter (int): integer representation of
letter to be printed in the corner of the first
phase plot.
Ex: ord("a") gives 97, so the input should be 97.
pnum (int): the number of the planet to be plotted. Must be
the same as the number used to define a planet's
Parameter objects (e.g. 'per1' is for planet #1)
"""
ax = pl.gca()
if len(self.post.likelihood.x) < 20:
self.nobin = True
bin_fac = 1.75
bin_markersize = bin_fac * rcParams['lines.markersize']
bin_markeredgewidth = bin_fac * rcParams['lines.markeredgewidth']
rvmod2 = self.model(self.rvmodt, planet_num=pnum) - self.slope
modph = t_to_phase(self.post.params, self.rvmodt, pnum, cat=True) - 1
rvdat = self.rawresid + self.model(self.rvtimes, planet_num=pnum) - self.slope_low
phase = t_to_phase(self.post.params, self.rvtimes, pnum, cat=True) - 1
rvdatcat = np.concatenate((rvdat, rvdat))
rverrcat = np.concatenate((self.rverr, self.rverr))
rvmod2cat = np.concatenate((rvmod2, rvmod2))
bint, bindat, binerr = fastbin(phase+1, rvdatcat, nbins=25)
bint -= 1.0
ax.axhline(0, color='0.5', linestyle='--', )
ax.plot(sorted(modph), rvmod2cat[np.argsort(modph)], 'b-', linewidth=self.fit_linewidth)
plot.labelfig(pltletter)
telcat = np.concatenate((self.post.likelihood.telvec, self.post.likelihood.telvec))
if self.highlight_last:
ind = np.argmax(self.rvtimes)
hphase = t_to_phase(self.post.params, self.rvtimes[ind], pnum, cat=False)
if hphase > 0.5:
hphase -= 1
pl.plot(hphase, rvdatcat[ind], **plot.highlight_format)
plot.mtelplot(phase, rvdatcat, rverrcat, telcat, ax, telfmts=self.telfmts)
if not self.nobin and len(rvdat) > 10:
ax.errorbar(
bint, bindat, yerr=binerr, fmt='ro', mec='w', ms=bin_markersize,
mew=bin_markeredgewidth
)
if self.phase_limits:
ax.set_xlim(self.phase_limits[0], self.phase_limits[1])
else:
ax.set_xlim(-0.5, 0.5)
if not self.yscale_auto:
scale = np.std(rvdatcat)
ax.set_ylim(-self.yscale_sigma*scale, self.yscale_sigma*scale)
keys = [p+str(pnum) for p in ['per', 'k', 'e']]
labels = [self.post.params.tex_labels().get(k, k) for k in keys]
if pnum < self.num_planets:
ticks = ax.yaxis.get_majorticklocs()
ax.yaxis.set_ticks(ticks[1:-1])
ax.set_ylabel('RV [{ms:}]'.format(**plot.latex), weight='bold')
ax.set_xlabel('Phase', weight='bold')
print_params = ['per', 'k', 'e']
units = {'per': 'days', 'k': plot.latex['ms'], 'e': ''}
anotext = []
for l, p in enumerate(print_params):
val = self.post.params["%s%d" % (print_params[l], pnum)].value
if self.uparams is None:
_anotext = r'$\mathregular{%s}$ = %4.2f %s' % (labels[l].replace("$", ""), val, units[p])
else:
if hasattr(self.post, 'medparams'):
val = self.post.medparams["%s%d" % (print_params[l], pnum)]
else:
print("WARNING: medparams attribute not found in " +
"posterior object will annotate with " +
"max-likelihood values and reported uncertainties " +
"may not be appropriate.")
err = self.uparams["%s%d" % (print_params[l], pnum)]
if err > 1e-15:
val, err, errlow = sigfig(val, err)
_anotext = r'$\mathregular{%s}$ = %s $\mathregular{\pm}$ %s %s' \
% (labels[l].replace("$", ""), val, err, units[p])
else:
_anotext = r'$\mathregular{%s}$ = %4.2f %s' % (labels[l].replace("$", ""), val, units[p])
anotext += [_anotext]
if hasattr(self.post, 'derived'):
chains = pd.read_csv(self.status['derive']['chainfile'])
self.post.nplanets = self.num_planets
dp = mcmc_plots.DerivedPlot(chains, self.post)
labels = dp.labels
texlabels = dp.texlabels
units = dp.units
if units == "M$_{\\rm Jup}$":
conversion_fac = 0.00315
elif units == "M$_{\\odot}$":
conversion_fac = 0.000954265748
else:
conversion_fac = 1
derived_params = ['mpsini']
for l, par in enumerate(derived_params):
par_label = par + str(pnum)
if par_label in self.post.derived.columns:
val = self.post.derived["%s%d" % (derived_params[l], pnum)].loc[0.500]
low = self.post.derived["%s%d" % (derived_params[l], pnum)].loc[0.159]
high = self.post.derived["%s%d" % (derived_params[l], pnum)].loc[0.841]
err_low = val - low
err_high = high - val
err = np.mean([err_low, err_high])
err = radvel.utils.round_sig(err)
index = np.where(np.array(labels) == par_label)[0][0]
if err > 1e-15:
val, err, errlow = sigfig(val, err)
_anotext = r'$\mathregular{%s}$ = %s $\mathregular{\pm}$ %s %s' \
% (texlabels[index].replace("$", ""), val*conversion_fac, err*conversion_fac, units[index])
else:
_anotext = r'$\mathregular{%s}$ = %4.2f %s' % (texlabels[index].replace("$", ""), val*conversion_fac, units[index])
anotext += [_anotext]
anotext = '\n'.join(anotext)
plot.add_anchored(
anotext, loc=1, frameon=True, prop=dict(size=self.phasetext_size, weight='bold'),
bbox=dict(ec='none', fc='w', alpha=0.8)
)
def plot_multipanel(self, nophase=False, letter_labels=True):
"""
Provision and plot an RV multipanel plot
Args:
nophase (bool, optional): if True, don't
include phase plots. Default: False.
letter_labels (bool, optional): if True, include
letter labels on orbit and residual plots.
Default: True.
Returns:
tuple containing:
- current matplotlib Figure object
- list of Axes objects
"""
if nophase:
scalefactor = 1
else:
scalefactor = self.phase_nrows
figheight = self.ax_rv_height + self.ax_phase_height * scalefactor
# provision figure
fig = pl.figure(figsize=(self.figwidth, figheight))
fig.subplots_adjust(left=0.12, right=0.95)
gs_rv = gridspec.GridSpec(2, 1, height_ratios=[1., 0.5])
divide = 1 - self.ax_rv_height / figheight
gs_rv.update(left=0.12, right=0.93, top=0.93,
bottom=divide+self.rv_phase_space*0.5, hspace=0.)
# orbit plot
ax_rv = pl.subplot(gs_rv[0, 0])
self.ax_list += [ax_rv]
pl.sca(ax_rv)
self.plot_timeseries()
if letter_labels:
pltletter = ord('a')
plot.labelfig(pltletter)
pltletter += 1
# residuals
ax_resid = pl.subplot(gs_rv[1, 0])
self.ax_list += [ax_resid]
pl.sca(ax_resid)
self.plot_residuals()
if letter_labels:
plot.labelfig(pltletter)
pltletter += 1
# phase-folded plots
if not nophase:
gs_phase = gridspec.GridSpec(self.phase_nrows, self.phase_ncols)
if self.phase_ncols == 1:
gs_phase.update(left=0.12, right=0.93,
top=divide - self.rv_phase_space * 0.5,
bottom=0.07, hspace=0.003)
else:
gs_phase.update(left=0.12, right=0.93,
top=divide - self.rv_phase_space * 0.5,
bottom=0.07, hspace=0.25, wspace=0.25)
for i in range(self.num_planets):
i_row = int(i / self.phase_ncols)
i_col = int(i - i_row * self.phase_ncols)
ax_phase = pl.subplot(gs_phase[i_row, i_col])
self.ax_list += [ax_phase]
pl.sca(ax_phase)
self.plot_phasefold(pltletter, i+1)
pltletter += 1
if self.saveplot is not None:
pl.savefig(self.saveplot, dpi=150)
print("RV multi-panel plot saved to %s" % self.saveplot)
return fig, self.ax_list
class GPMultipanelPlot(MultipanelPlot):
"""
Class to handle the creation of RV multipanel plots for posteriors fitted
using Gaussian Processes.
Takes the same args as MultipanelPlot, with a few additional bells and whistles...
Args:
subtract_gp_mean_model (bool, optional): if True, subtract the Gaussian
process mean max likelihood model from the data and the
model when plotting the results. Default: False.
plot_likelihoods_separately (bool, optional): if True, plot a separate
panel for each Likelihood object. Default: False
subtract_orbit_model (bool, optional): if True, subtract the best-fit
orbit model from the data and the model when plotting
the results. Useful for seeing the structure of correlated
noise in the data. Default: False.
status (ConfigParser): (optional) result of radvel.driver.load_status on the .stat status file
"""
def __init__(self, post, saveplot=None, epoch=2450000, yscale_auto=False, yscale_sigma=3.0,
phase_nrows=None, phase_ncols=None, uparams=None, rv_phase_space=0.08, telfmts={},
legend=True,
phase_limits=[], nobin=False, phasetext_size='large', figwidth=7.5, fit_linewidth=2.0,
set_xlim=None, text_size=9, legend_kwargs=dict(loc='best'), subtract_gp_mean_model=False,
plot_likelihoods_separately=False, subtract_orbit_model=False, status=None):
super(GPMultipanelPlot, self).__init__(
post, saveplot=saveplot, epoch=epoch, yscale_auto=yscale_auto,
yscale_sigma=yscale_sigma, phase_nrows=phase_nrows, phase_ncols=phase_ncols,
uparams=uparams, rv_phase_space=rv_phase_space, telfmts=telfmts, legend=legend,
phase_limits=phase_limits, nobin=nobin, phasetext_size=phasetext_size,
figwidth=figwidth, fit_linewidth=fit_linewidth, set_xlim=set_xlim, text_size=text_size,
legend_kwargs=legend_kwargs
)
self.subtract_gp_mean_model = subtract_gp_mean_model
self.plot_likelihoods_separately = plot_likelihoods_separately
self.subtract_orbit_model = subtract_orbit_model
if status is not None:
self.status = status
is_gp = False
for like in self.like_list:
if isinstance(like, radvel.likelihood.GPLikelihood):
is_gp = True
break
else:
pass
assert is_gp, "This class requires at least one GPLikelihood object in the Posterior."
def plot_gp_like(self, like, orbit_model4data, ci):
"""
Plot a single Gaussian Process Likleihood object in the current Axes,
including Gaussian Process uncertainty bands.
Args:
like (radvel.GPLikelihood): radvel.GPLikelihood object. The model
plotted will be generated from `like.params`.
orbit_model4data (numpy array):
ci (int): index to use when choosing a color to plot from
radvel.plot.default_colors. This is only used if the
Likelihood object being plotted is not in the list of defaults.
Increments by 1 if it is used.
Returns: current (possibly changed) value of the input `ci`
"""
ax = pl.gca()
if isinstance(like, radvel.likelihood.GPLikelihood):
xpred = np.linspace(np.min(like.x), np.max(like.x), num=int(3e3))
gpmu, stddev = like.predict(xpred)
if self.subtract_orbit_model:
gp_orbit_model = np.zeros(xpred.shape)
else:
gp_orbit_model = self.model(xpred)
if ((xpred - self.epoch) < -2.4e6).any():
pass
elif self.epoch == 0:
self.epoch = 2450000
xpred = xpred - self.epoch
else:
xpred = xpred - self.epoch
if self.subtract_gp_mean_model:
gpmu = 0.
else:
gp_mean4data, _ = like.predict(like.x)
indx = np.where(self.post.likelihood.telvec == like.suffix)
orbit_model4data[indx] += gp_mean4data
if like.suffix not in self.telfmts and like.suffix in plot.telfmts_default:
color = plot.telfmts_default[like.suffix]['color']
if like.suffix in self.telfmts:
color = self.telfmts[like.suffix]['color']
if like.suffix not in self.telfmts and like.suffix not in plot.telfmts_default:
color = plot.default_colors[ci]
ci += 1
ax.fill_between(xpred, gpmu+gp_orbit_model-stddev, gpmu+gp_orbit_model+stddev,
color=color, alpha=0.5, lw=0
)
ax.plot(xpred, gpmu+gp_orbit_model, 'b-', rasterized=False, lw=0.1)
else:
# plot orbit model
ax.plot(self.mplttimes, self.orbit_model, 'b-', rasterized=False, lw=0.1)
if not self.yscale_auto:
scale = np.std(self.rawresid+self.rvmod)
ax.set_ylim(-self.yscale_sigma * scale, self.yscale_sigma * scale)
ax.set_ylabel('RV [{ms:}]'.format(**plot.latex), weight='bold')
ticks = ax.yaxis.get_majorticklocs()
ax.yaxis.set_ticks(ticks[1:])
return ci
def plot_timeseries(self):
"""
Make a plot of the RV data and Gaussian Process + orbit model in the current Axes.
"""
ax = pl.gca()
ax.axhline(0, color='0.5', linestyle='--')
if self.subtract_orbit_model:
orbit_model4data = np.zeros(self.rvmod.shape)
else:
orbit_model4data = self.rvmod
ci = 0
for like in self.like_list:
ci = self.plot_gp_like(like, orbit_model4data, ci)
# plot data
plot.mtelplot(
# data = residuals + model
self.plttimes, self.rawresid+orbit_model4data, self.rverr,
self.post.likelihood.telvec, ax, telfmts=self.telfmts
)
if self.set_xlim is not None:
ax.set_xlim(self.set_xlim)
else:
ax.set_xlim(min(self.plttimes)-0.01*self.dt, max(self.plttimes)+0.01*self.dt)
pl.setp(ax.get_xticklabels(), visible=False)
# legend
if self.legend:
ax.legend(numpoints=1, **self.legend_kwargs)
# years on upper axis
axyrs = ax.twiny()
xl = np.array(list(ax.get_xlim())) + self.epoch
decimalyear = Time(xl, format='jd', scale='utc').decimalyear
axyrs.plot(decimalyear, decimalyear)
axyrs.get_xaxis().get_major_formatter().set_useOffset(False)
axyrs.set_xlim(*decimalyear)
pl.locator_params(axis='x', nbins=5)
axyrs.set_xlabel('Year', fontweight='bold')
def plot_multipanel(self, nophase=False):
"""
Provision and plot an RV multipanel plot for a Posterior object containing
one or more Gaussian Process Likelihood objects.
Args:
nophase (bool, optional): if True, don't
include phase plots. Default: False.
Returns:
tuple containing:
- current matplotlib Figure object
- list of Axes objects
"""
if not self.plot_likelihoods_separately:
super(GPMultipanelPlot, self).plot_multipanel()
else:
if nophase:
scalefactor = 1
else:
scalefactor = self.phase_nrows
n_likes = len(self.like_list)
figheight = self.ax_rv_height*(n_likes+0.5) + self.ax_phase_height * scalefactor
# provision figure
fig = pl.figure(figsize=(self.figwidth, figheight))
fig.subplots_adjust(left=0.12, right=0.95)
hrs = np.zeros(n_likes+1) + 1.
hrs[-1] = 0.5
gs_rv = gridspec.GridSpec(n_likes+1, 1, height_ratios=hrs)
divide = 1 - self.ax_rv_height*len(self.like_list) / figheight
gs_rv.update(left=0.12, right=0.93, top=0.93,
bottom=divide+self.rv_phase_space*0.5, hspace=0.0)
# orbit plot for each likelihood
pltletter = ord('a')
i = 0
ci = 0
for like in self.like_list:
ax = pl.subplot(gs_rv[i, 0])
i += 1
self.ax_list += [ax]
pl.sca(ax)
ax.axhline(0, color='0.5', linestyle='--')
if self.subtract_orbit_model:
orbit_model4data = np.zeros(self.rvmod.shape)
else:
orbit_model4data = self.rvmod
self.plot_gp_like(like, orbit_model4data, ci)
# plot data
plot.mtelplot(
# data = residuals + model
self.plttimes, self.rawresid+orbit_model4data, self.rverr,
self.post.likelihood.telvec, ax, telfmts=self.telfmts
)
ax.set_xlim(min(self.plttimes)-0.01*self.dt, max(self.plttimes)+0.01*self.dt)
pl.setp(ax.get_xticklabels(), visible=False)
# legend
if self.legend and i == 1:
ax.legend(numpoints=1, **self.legend_kwargs)
# years on upper axis
if i == 1:
axyrs = ax.twiny()
xl = np.array(list(ax.get_xlim())) + self.epoch
decimalyear = Time(xl, format='jd', scale='utc').decimalyear
axyrs.plot(decimalyear, decimalyear)
axyrs.get_xaxis().get_major_formatter().set_useOffset(False)
axyrs.set_xlim(*decimalyear)
axyrs.set_xlabel('Year', fontweight='bold')
plot.labelfig(pltletter)
pltletter += 1
# residuals
ax_resid = pl.subplot(gs_rv[-1, 0])
self.ax_list += [ax_resid]
pl.sca(ax_resid)
self.plot_residuals()
plot.labelfig(pltletter)
pltletter += 1
# phase-folded plots
if not nophase:
gs_phase = gridspec.GridSpec(self.phase_nrows, self.phase_ncols)
if self.phase_ncols == 1:
gs_phase.update(left=0.12, right=0.93,
top=divide - self.rv_phase_space * 0.5,
bottom=0.07, hspace=0.003)
else:
gs_phase.update(left=0.12, right=0.93,
top=divide - self.rv_phase_space * 0.5,
bottom=0.07, hspace=0.25, wspace=0.25)
for i in range(self.num_planets):
i_row = int(i / self.phase_ncols)
i_col = int(i - i_row * self.phase_ncols)
ax_phase = pl.subplot(gs_phase[i_row, i_col])
self.ax_list += [ax_phase]
pl.sca(ax_phase)
self.plot_phasefold(pltletter, i+1)
pltletter += 1
if self.saveplot is not None:
pl.savefig(self.saveplot, dpi=150)
print("RV multi-panel plot saved to %s" % self.saveplot)
return fig, self.ax_list