def fig_rv(): plt.rcParams['lines.markersize'] = 3 post = ktwo19.keplerian.max_a_posteriori() plotter = orbit_plots.GPMultipanelPlot( post, subtract_orbit_model=False, nobin=True, phase_nrows=None, phase_ncols=3, ) fig = plt.figure(figsize=(8, 5.5)) ax1 = plt.subplot2grid((2, 3), (0, 0), colspan=3) ax2 = plt.subplot2grid( (2, 3), (1, 0), ) ax3 = plt.subplot2grid( (2, 3), (1, 1), ) ax4 = plt.subplot2grid( (2, 3), (1, 2), ) axL = [ax1, ax2, ax3, ax4] plt.rc('font', size=9) plotter.nobin = True plotter.legend = False plotter.epoch = 2454833 plotter.phasetext_size = 'small' plt.sca(ax1) plotter.plot_timeseries() radvel.plot.labelfig(97) plt.sca(ax2) plotter.plot_phasefold(98, 1) plt.sca(ax3) plotter.plot_phasefold(99, 2) plt.sca(ax4) plotter.plot_phasefold(100, 3) plt.setp(axL[2:], ylabel='') _ = plt.setp(axL[1:], ylim=(-23, 23), yticks=[-20, -15, -10, -5, 0, 5, 10, 15, 20]) _ = plt.setp(axL[0], ylim=(-38, 38), xlim=(2200, 3300)) plt.tight_layout(True) plt.subplots_adjust(wspace=0.2)
def plots(args): """ Generate plots Args: args (ArgumentParser): command line arguments """ config_file = args.setupfn conf_base = os.path.basename(config_file).split('.')[0] statfile = os.path.join( args.outputdir, "{}_radvel.stat".format(conf_base) ) status = load_status(statfile) P, post = radvel.utils.initialize_posterior(config_file, decorr=args.decorr) assert status.getboolean('fit', 'run'), \ "Must perform max-liklihood fit before plotting" post = radvel.posterior.load(status.get('fit', 'postfile')) for ptype in args.type: print("Creating {} plot for {}".format(ptype, conf_base)) if ptype == 'rv': args.plotkw['uparams'] = post.uparams args.plotkw['status'] = status if 'saveplot' not in args.plotkw: saveto = os.path.join( args.outputdir, conf_base+'_rv_multipanel.pdf' ) else: saveto = args.plotkw['saveplot'] args.plotkw.pop('saveplot') P, _ = radvel.utils.initialize_posterior(config_file) if hasattr(P, 'bjd0'): args.plotkw['epoch'] = P.bjd0 if args.gp: GPPlot = orbit_plots.GPMultipanelPlot( post, saveplot=saveto, **args.plotkw ) GPPlot.plot_multipanel() else: RVPlot = orbit_plots.MultipanelPlot( post, saveplot=saveto, **args.plotkw ) RVPlot.plot_multipanel() # check to make sure that Posterior is not GP, print warning if it is if isinstance(post.likelihood, radvel.likelihood.CompositeLikelihood): like_list = post.likelihood.like_list else: like_list = [post.likelihood] for like in like_list: if isinstance(like, radvel.likelihood.GPLikelihood): print("WARNING: GP Likelihood(s) detected. \ You may want to use the '--gp' flag when making these plots.") break if ptype == 'corner' or ptype == 'auto' or ptype == 'trend': assert status.getboolean('mcmc', 'run'), \ "Must run MCMC before making corner, auto, or trend plots" chains = pd.read_csv(status.get('mcmc', 'chainfile')) autocorr = pd.read_csv(status.get('mcmc', 'autocorrfile')) if ptype == 'auto': saveto = os.path.join(args.outputdir, conf_base+'_auto.pdf') Auto = mcmc_plots.AutoPlot(autocorr, saveplot=saveto) Auto.plot() if ptype == 'corner': saveto = os.path.join(args.outputdir, conf_base+'_corner.pdf') Corner = mcmc_plots.CornerPlot(post, chains, saveplot=saveto) Corner.plot() if ptype == 'trend': nwalkers = status.getint('mcmc', 'nwalkers') nensembles = status.getint('mcmc', 'nensembles') saveto = os.path.join(args.outputdir, conf_base+'_trends.pdf') Trend = mcmc_plots.TrendPlot(post, chains, nwalkers, nensembles, saveto) Trend.plot() if ptype == 'derived': assert status.has_section('derive'), \ "Must run `radvel derive` before plotting derived parameters" P, _ = radvel.utils.initialize_posterior(config_file) chains = pd.read_csv(status.get('derive', 'chainfile')) saveto = os.path.join( args.outputdir, conf_base+'_corner_derived_pars.pdf' ) Derived = mcmc_plots.DerivedPlot(chains, P, saveplot=saveto) Derived.plot() savestate = {'{}_plot'.format(ptype): os.path.relpath(saveto)} save_status(statfile, 'plot', savestate)