def plot_data(tempo_results, xkey, ykey, interactive=True, mark_peri=False, show_legend=True): subplot = 1 numsubplots = 2 global axes axes = [] global ax_types ax_types = [] global ax_phase_wraps ax_phase_wraps = [] global ax_jump_ranges ax_jump_ranges = [] handles = [] labels = [] for usepostfit in [False, True]: # Always use pre, then post TOAcount = 0 # All subplots are in a single column if subplot == 1: axes.append(plt.subplot(numsubplots, 1, subplot)) else: axes.append(plt.subplot(numsubplots, 1, subplot, sharex=axes[0])) if usepostfit: ax_types.append('post') else: ax_types.append('pre') ax_phase_wraps.append([]) ax_jump_ranges.append([]) # set tick formatter to not use scientific notation or an offset tick_formatter = matplotlib.ticker.ScalarFormatter(useOffset=False) tick_formatter.set_scientific(False) axes[-1].xaxis.set_major_formatter(tick_formatter) xmin, xmax = axes[0].get_xlim() for ii, (lo, hi) in enumerate(tempo_results.freqbands): freq_label = get_freq_label(lo, hi) resids = tempo_results.residuals[freq_label] xlabel, xdata = resids.get_xdata(xkey) ylabel, ydata, yerr = resids.get_ydata(ykey, usepostfit, tempo_results.phase_wraps) if len(xdata): # Plot the residuals handle = plt.errorbar(xdata, ydata, yerr=yerr, fmt='.', \ label=freq_label, picker=5, c=colors[len(tempo_results.freqbands)][ii]) if subplot == 1: handles.append(handle[0]) labels.append(freq_label) TOAcount += xdata.size # Plot phase wraps text_offset = offset_copy(axes[-1].transData, x=5, y=-10, units='dots') if usepostfit: pw = tempo_results.phase_wraps elif tempo_history.current_index > 0: pw = tempo_history.tempo_results[tempo_history.current_index - 1].phase_wraps else: pw = [] for wrap_index in pw: wrap_mjd_hi = tempo_results.ordered_MJDs[wrap_index] if wrap_index > 0: wrap_mjd_lo = tempo_results.ordered_MJDs[wrap_index - 1] else: wrap_mjd_lo = wrap_mjd_hi if xkey == 'mjd': wrap_x = 0.5 * (wrap_mjd_hi + wrap_mjd_lo) elif xkey == 'year': wrap_x = mjd_to_year(0.5 * (wrap_mjd_hi + wrap_mjd_lo)) elif xkey == 'numtoa': wrap_x = wrap_index - 0.5 else: break wrap_color = {'pre': 'pink', 'post': 'red'} wrp = plt.axvline(wrap_x, ls=':', label='_nolegend_', color=wrap_color[ax_types[-1]], lw=1.5) wrp_txt = plt.text(wrap_x, axes[-1].get_ylim()[1], "%+d" % pw[wrap_index], transform=text_offset, size='x-small', color=wrap_color[ax_types[-1]]) ax_phase_wraps[-1].append([wrp, wrp_txt]) # set up span selector for setting new jump ranges options.jump_spans[ax_types[-1]] = SpanSelector( axes[-1], select_jump_range, 'horizontal', useblit=True, rectprops=dict(alpha=0.5, facecolor='orange')) options.jump_spans[ax_types[-1]].visible = options.jump_mode if subplot > 1: axes[0].set_xlim((xmin, xmax)) # Finish off the plot plt.axhline(0, ls='--', label="_nolegend_", c='k', lw=0.5) axes[-1].ticklabel_format(style='plain', axis='x') if mark_peri and hasattr(tempo_results.outpar, 'BINARY'): # Be sure to check if pulsar is in a binary # Cannot mark passage of periastron if not a binary if usepostfit: binpsr = binary_psr.binary_psr(tempo_results.outpar.FILE) else: binpsr = binary_psr.binary_psr(tempo_results.inpar.FILE) xmin, xmax = axes[0].get_xlim() mjd_min = tempo_results.min_TOA mjd_max = tempo_results.max_TOA guess_mjds = np.arange(mjd_max + binpsr.par.PB, \ mjd_min - binpsr.par.PB, -binpsr.par.PB) for mjd in guess_mjds: peri_mjd = binpsr.most_recent_peri(float(mjd)) if xkey == 'mjd': plt.axvline(peri_mjd, ls=':', label='_nolegend_', c='k', lw=0.5) elif xkey == 'year': print "plotting peri passage" plt.axvline(mjd_to_year(peri_mjd), ls=':', label='_nolegend_', c='k', lw=0.5) axes[0].set_xlim((xmin, xmax)) plt.xlabel(xlabel) plt.ylabel(ylabel) subplot += 1 # Plot jump ranges for jstart, jend in tempo_results.jump_ranges: plot_jump_range((jstart, jend)) # axes[-1].set_ylim((ymin, ymax)) if numsubplots > 1: # Increase spacing between subplots. plt.subplots_adjust(hspace=0.25) # Write name of input files used for timing on figure if interactive: fntext = "Solution %d of %d, TOA file: %s, Parameter file: %s" % \ (tempo_history.current_index+1, tempo_history.get_nsolutions(), tempo_results.intimfn, tempo_results.inparfn) figure_text = plt.figtext(0.01, 0.01, fntext, verticalalignment='bottom', horizontalalignment='left') # Make the legend and set its visibility state leg = plt.figlegend(handles, labels, 'upper right') leg.set_visible(show_legend) leg.legendPatch.set_alpha(0.5) axes[0].xaxis.tick_top() plt.setp(axes[0].get_yticklabels()[0], visible=False) plt.setp(axes[1].get_yticklabels()[-1], visible=False) plt.setp(axes[0].get_yticklabels()[-1], visible=False) plt.setp(axes[1].get_yticklabels()[0], visible=False) plt.subplots_adjust(wspace=0.05, hspace=0.0, left=0.15, bottom=0.1, right=0.8, top=0.9) nms = [] fitmes = [] for b in tempo_history.get_parfile(): if tempo_history.get_parfile()[b].fit == None: tempo_history.get_parfile()[b].fit = 0 if not any(b in s for s in tempy_io.no_fit_pars): nms.append(b) fitmes.append(tempo_history.get_parfile()[b].fit) rax = plt.axes([0.85, 0.1, 0.1, 0.8]) rax.set_frame_on(False) options.fitcheck = CheckButtons(rax, nms, fitmes) options.fitcheck.on_clicked(update_fit_flag) redrawplot()
def plot_data(tempo_results, xkey, ykey, postfit=True, prefit=False, \ interactive=True, mark_peri=False, show_legend=True): # figure out what should be plotted # True means to plot postfit # False means to plot prefit if postfit and prefit: to_plot_postfit = [False, True] elif postfit and not prefit: to_plot_postfit = [True] elif not postfit and prefit: to_plot_postfit = [False] else: raise EmptyPlotValueError("At least one of prefit and postfit must be True.") subplot = 1 numsubplots = len(to_plot_postfit) global axes axes = [] handles = [] labels = [] for usepostfit in to_plot_postfit: TOAcount = 0 # All subplots are in a single column if subplot == 1: axes.append(plt.subplot(numsubplots, 1, subplot)) else: axes.append(plt.subplot(numsubplots, 1, subplot, sharex=axes[0])) # set tick formatter to not use scientific notation or an offset tick_formatter = matplotlib.ticker.ScalarFormatter(useOffset=False) tick_formatter.set_scientific(False) axes[-1].xaxis.set_major_formatter(tick_formatter) xmin, xmax = axes[0].get_xlim() for ii,(lo,hi) in enumerate(tempo_results.freqbands): freq_label = get_freq_label(lo, hi) resids = tempo_results.residuals[freq_label] xlabel, xdata = resids.get_xdata(xkey) ylabel, ydata, yerr = resids.get_ydata(ykey, usepostfit) if len(xdata): # Plot the residuals handle = plt.errorbar(xdata, ydata, yerr=yerr, fmt='.', \ label=freq_label, picker=5, c=colors[len(tempo_results.freqbands)][ii]) # Label isn't being set as expected. Use the following # as a kludgey work-around. handle[0].set_label(freq_label) if subplot == 1: handles.append(handle[0]) labels.append(freq_label) TOAcount += xdata.size if subplot > 1: axes[0].set_xlim((xmin, xmax)) # Finish off the plot plt.axhline(0, ls='--', label="_nolegend_", c='k', lw=0.5) axes[-1].ticklabel_format(style='plain', axis='x') if mark_peri and hasattr(tempo_results.outpar, 'BINARY'): # Be sure to check if pulsar is in a binary # Cannot mark passage of periastron if not a binary if usepostfit: binpsr = binary_psr.binary_psr(tempo_results.outpar.FILE) else: binpsr = binary_psr.binary_psr(tempo_results.inpar.FILE) xmin, xmax = axes[0].get_xlim() mjd_min = tempo_results.min_TOA mjd_max = tempo_results.max_TOA guess_mjds = np.arange(mjd_max + binpsr.par.PB, \ mjd_min - binpsr.par.PB, -binpsr.par.PB) for mjd in guess_mjds: peri_mjd = binpsr.most_recent_peri(float(mjd)) if xkey == 'mjd': plt.axvline(peri_mjd, ls=':', label='_nolegend_', c='k', lw=0.5) elif xkey == 'year': print "plotting peri passage" plt.axvline(mjd_to_year(peri_mjd), ls=':', label='_nolegend_', c='k', lw=0.5) axes[0].set_xlim((xmin, xmax)) plt.xlabel(xlabel) plt.ylabel(ylabel) if usepostfit: plt.title("Postfit Residuals (Number of TOAs: %d)" % TOAcount) else: plt.title("Prefit Residuals (Number of TOAs: %d)" % TOAcount) subplot += 1 if numsubplots > 1: # Increase spacing between subplots. plt.subplots_adjust(hspace=0.25) # Write name of input files used for timing on figure if interactive: fntext = "TOA file: %s, Parameter file: %s" % \ (tempo_results.intimfn, tempo_results.inparfn) figure_text = plt.figtext(0.01, 0.01, fntext, verticalalignment='bottom', \ horizontalalignment='left') # Make the legend and set its visibility state leg = plt.figlegend(handles, labels, 'upper right') leg.set_visible(show_legend) leg.legendPatch.set_alpha(0.5)
def plot_data(tempo_results, xkey, ykey, postfit=True, prefit=False, \ interactive=True, mark_peri=False, show_legend=True): # figure out what should be plotted # True means to plot postfit # False means to plot prefit if postfit and prefit: to_plot_postfit = [False, True] elif postfit and not prefit: to_plot_postfit = [True] elif not postfit and prefit: to_plot_postfit = [False] else: raise EmptyPlotValueError( "At least one of prefit and postfit must be True.") subplot = 1 numsubplots = len(to_plot_postfit) global axes axes = [] handles = [] labels = [] for usepostfit in to_plot_postfit: TOAcount = 0 # All subplots are in a single column if subplot == 1: axes.append(plt.subplot(numsubplots, 1, subplot)) else: axes.append(plt.subplot(numsubplots, 1, subplot, sharex=axes[0])) # set tick formatter to not use scientific notation or an offset tick_formatter = matplotlib.ticker.ScalarFormatter(useOffset=False) tick_formatter.set_scientific(False) axes[-1].xaxis.set_major_formatter(tick_formatter) xmin, xmax = axes[0].get_xlim() for ii, (lo, hi) in enumerate(tempo_results.freqbands): freq_label = get_freq_label(lo, hi) resids = tempo_results.residuals[freq_label] xlabel, xdata = resids.get_xdata(xkey) ylabel, ydata, yerr = resids.get_ydata(ykey, usepostfit) if len(xdata): # Plot the residuals handle = plt.errorbar(xdata, ydata, yerr=yerr, fmt='.', \ label=freq_label, picker=5, c=colors[len(tempo_results.freqbands)][ii]) # Label isn't being set as expected. Use the following # as a kludgey work-around. handle[0].set_label(freq_label) if subplot == 1: handles.append(handle[0]) labels.append(freq_label) TOAcount += xdata.size if subplot > 1: axes[0].set_xlim((xmin, xmax)) # Finish off the plot plt.axhline(0, ls='--', label="_nolegend_", c='k', lw=0.5) axes[-1].ticklabel_format(style='plain', axis='x') if mark_peri and hasattr(tempo_results.outpar, 'BINARY'): # Be sure to check if pulsar is in a binary # Cannot mark passage of periastron if not a binary if usepostfit: binpsr = binary_psr.binary_psr(tempo_results.outpar.FILE) else: binpsr = binary_psr.binary_psr(tempo_results.inpar.FILE) xmin, xmax = axes[0].get_xlim() mjd_min = tempo_results.min_TOA mjd_max = tempo_results.max_TOA guess_mjds = np.arange(mjd_max + binpsr.par.PB, \ mjd_min - binpsr.par.PB, -binpsr.par.PB) for mjd in guess_mjds: peri_mjd = binpsr.most_recent_peri(float(mjd)) if xkey == 'mjd': plt.axvline(peri_mjd, ls=':', label='_nolegend_', c='k', lw=0.5) elif xkey == 'year': print "plotting peri passage" plt.axvline(mjd_to_year(peri_mjd), ls=':', label='_nolegend_', c='k', lw=0.5) axes[0].set_xlim((xmin, xmax)) plt.xlabel(xlabel) plt.ylabel(ylabel) if usepostfit: plt.title("Postfit Residuals (Number of TOAs: %d)" % TOAcount) else: plt.title("Prefit Residuals (Number of TOAs: %d)" % TOAcount) subplot += 1 if numsubplots > 1: # Increase spacing between subplots. plt.subplots_adjust(hspace=0.25) # Write name of input files used for timing on figure if interactive: fntext = "TOA file: %s, Parameter file: %s" % \ (tempo_results.intimfn, tempo_results.inparfn) figure_text = plt.figtext(0.01, 0.01, fntext, verticalalignment='bottom', \ horizontalalignment='left') # Make the legend and set its visibility state leg = plt.figlegend(handles, labels, 'upper right') leg.set_visible(show_legend) leg.legendPatch.set_alpha(0.5)
sourcename = initvals['name'] mu_a = float(initvals['pmra']) mu_d = float(initvals['pmdec']) px = float(initvals['px']) Omega = float(initvals['Omega']) inc = float(initvals['inc']) ra = initvals['ra'] dec = initvals['dec'] posstring = ra + " " + dec except KeyError as e: print "Missing required key ", str(e), " in ", initsfile sys.exit() start_pos = coords.SkyCoord(posstring, unit=(u.hourangle, u.deg), frame='icrs') psr = bp.binary_psr(parfile) # Get the measurements and convert them to arrays of angles vlbiepoch, posns, ra_errs, dec_errs, baryMJDs = get_coords(pmparfile) # This is the Earth position in X, Y, Z (AU) in ICRS wrt SSB eposns = [solsys.solarsystem(mjd+2400000.5, 3, 0)[0] \ for mjd in baryMJDs] errs = np.concatenate((ra_errs.to(u.rad).value, dec_errs.to(u.rad).value)) # in radians ras = np.asarray([pos.ra.rad for pos in posns]) * u.rad decs = np.asarray([pos.dec.rad for pos in posns]) * u.rad meas = np.concatenate((ras, decs)) # in radians try:
# This is going for Figure 1 in Hulse & Taylor 1975 psr1 = presto.psrepoch("B1913+16", 42320.0) # unfortunatey, OMDOT is not in the binary part of the # database correctly. So we need to set that: psr1.orb.w = 179.0 psr1.orb.t = 0.0 Eo = presto.keplers_eqn(psr1.orb.t, psr1.orb.p, psr1.orb.e, 1e-15) Es = presto.dorbint(Eo, N, 2.0 * psr1.orb.p / N, psr1.orb) presto.E_to_v(Es, psr1.orb) plt.plot(ma, Es, 'b-') plt.xlabel("Orbital Phase") plt.ylabel("Pulsar Velocity (km/s)") plt.show() # This is going for Figure 1 in Champion et al 2008 bpsr = binary_psr.binary_psr("1903+0327.par") MJDs = bpsr.T0 + ma * bpsr.par.PB xs, ys = bpsr.position(MJDs) #cMJDs = bpsr.demodulate_TOAs(MJDs) #cxs, cys = bpsr.position(cMJDs) psr2 = presto.psrepoch("1903+0327.par", bpsr.T0) psr2.orb.t = 0.0 Eo = presto.keplers_eqn(psr2.orb.t, psr2.orb.p, psr2.orb.e, 1e-15) Es = presto.dorbint(Eo, N, 2.0 * psr2.orb.p / N, psr2.orb) # bt = Es.copy() presto.E_to_phib(Es, psr2.orb) # presto.E_to_phib_BT(bt, psr2.orb) plt.plot(ma, Es, 'b-') plt.plot(ma, -xs, 'r-')
def do_demodulate(merging, data_id, par_file, E_trunc, PI1, PI2): """ Using do_demodulate in binary_psr.py in Scott Ransom's PRESTO Python library to demodulate the time series for the merged event file! merging - True/False - whether to use merged data data_id - 10-digit ObsID or 6-digit ID for the merged event file par_file - orbital parameter file for input into binary_psr E_trunc - True/False - whether to do energy truncation PI1 - lower bound of PI (not energy in keV!) desired for the energy range PI2 - upper bound of PI (not energy in keV!) desired for the energy range """ TIMEZERO = -1 if type(data_id) != str: raise TypeError("data_id should be a string!") if len(data_id) != 6 and len(data_id) != 10: raise ValueError("data_id should have 6 or 10 digits in the string!") if E_trunc != True and E_trunc != False: raise ValueError( "E_trunc (energy truncation) should either be True or False!") if merging == True: print("Doing demodulation, merging is True!") all_merged_dir = Lv0_dirs.NICERSOFT_DATADIR + 'merged_events/' #directory for the merged events merged_dir = all_merged_dir + 'merged' + data_id + '/' if E_trunc == True: old_file = merged_dir + 'merged' + data_id + '_nicersoft_bary_E' + str( PI1).zfill(4) + '-' + str(PI2).zfill(4) + '.evt' else: old_file = merged_dir + 'merged' + data_id + '_nicersoft_bary.evt' else: print("Doing demodulation, merging is False!") if E_trunc == True: old_file = Lv0_dirs.NICERSOFT_DATADIR + data_id + '_pipe/ni' + data_id + '_nicersoft_bary_E' + str( PI1).zfill(4) + '-' + str(PI2).zfill(4) + '.evt' else: old_file = Lv0_dirs.NICERSOFT_DATADIR + data_id + '_pipe/ni' + data_id + '_nicersoft_bary.evt' new_file = old_file[:-4] + '_demod.evt' subprocess.check_call(['cp', old_file, new_file]) with fits.open(new_file, mode='update') as fitsfile_demod: MJDREFI = fitsfile_demod[1].header[ 'MJDREFI'] #integer for MJD reference MJDREFF = fitsfile_demod[1].header[ 'MJDREFF'] #float decimal for MJD reference times = fitsfile_demod[1].data['TIME'] #original time series gtis_start = fitsfile_demod[2].data['START'] #original GTI start times gtis_stop = fitsfile_demod[2].data['STOP'] #original GTI end times times_MJD = MJDREFI + MJDREFF + ( times + TIMEZERO) / 86400 #converting METs to MJD gtis_start_MJD = MJDREFI + MJDREFF + ( gtis_start + TIMEZERO) / 86400 #converting GTIs in METs to MJD gtis_stop_MJD = MJDREFI + MJDREFF + ( gtis_stop + TIMEZERO) / 86400 #converting GTIs in METs to MJD try: times_demod = binary_psr.binary_psr(par_file).demodulate_TOAs( times_MJD) #demodulated event times gtis_start_demod = binary_psr.binary_psr(par_file).demodulate_TOAs( gtis_start_MJD) #demodulated GTI start times gtis_stop_demod = binary_psr.binary_psr(par_file).demodulate_TOAs( gtis_stop_MJD) #demodulated GTI end times fitsfile_demod[1].data['TIME'] = ( times_demod - MJDREFI - MJDREFF) * 86400 #convert back to METs fitsfile_demod[2].data['START'] = ( gtis_start_demod - MJDREFI - MJDREFF) * 86400 #convert back to METs fitsfile_demod[2].data['STOP'] = ( gtis_stop_demod - MJDREFI - MJDREFF) * 86400 #convert back to METs fitsfile_demod.flush() except ValueError: pass return
def plot_data(tempo_results, xkey, ykey, interactive=True, mark_peri=False, show_legend=True): subplot = 1 numsubplots = 2 global axes axes = [] global ax_types ax_types = [] global ax_phase_wraps ax_phase_wraps = [] global ax_jump_ranges ax_jump_ranges = [] handles = [] labels = [] for usepostfit in [False, True]:# Always use pre, then post TOAcount = 0 # All subplots are in a single column if subplot == 1: axes.append(plt.subplot(numsubplots, 1, subplot)) else: axes.append(plt.subplot(numsubplots, 1, subplot, sharex=axes[0])) if usepostfit: ax_types.append('post') else: ax_types.append('pre') ax_phase_wraps.append([]) ax_jump_ranges.append([]) # set tick formatter to not use scientific notation or an offset tick_formatter = matplotlib.ticker.ScalarFormatter(useOffset=False) tick_formatter.set_scientific(False) axes[-1].xaxis.set_major_formatter(tick_formatter) xmin, xmax = axes[0].get_xlim() for ii,(lo,hi) in enumerate(tempo_results.freqbands): freq_label = get_freq_label(lo, hi) resids = tempo_results.residuals[freq_label] xlabel, xdata = resids.get_xdata(xkey) ylabel, ydata, yerr = resids.get_ydata(ykey, usepostfit, tempo_results.phase_wraps) if len(xdata): # Plot the residuals handle = plt.errorbar(xdata, ydata, yerr=yerr, fmt='.', \ label=freq_label, picker=5, c=colors[len(tempo_results.freqbands)][ii]) if subplot == 1: handles.append(handle[0]) labels.append(freq_label) TOAcount += xdata.size # Plot phase wraps text_offset = offset_copy(axes[-1].transData, x=5, y=-10, units='dots') if usepostfit: pw = tempo_results.phase_wraps elif tempo_history.current_index > 0: pw = tempo_history.tempo_results[tempo_history.current_index-1].phase_wraps else: pw = [] for wrap_index in pw: wrap_mjd_hi = tempo_results.ordered_MJDs[wrap_index] if wrap_index > 0: wrap_mjd_lo = tempo_results.ordered_MJDs[wrap_index-1] else: wrap_mjd_lo = wrap_mjd_hi if xkey == 'mjd': wrap_x = 0.5*(wrap_mjd_hi + wrap_mjd_lo) elif xkey == 'year': wrap_x = mjd_to_year(0.5*(wrap_mjd_hi + wrap_mjd_lo)) elif xkey == 'numtoa': wrap_x = wrap_index - 0.5 else: break wrap_color = {'pre':'pink', 'post':'red'} wrp = plt.axvline(wrap_x, ls=':', label='_nolegend_', color=wrap_color[ax_types[-1]], lw=1.5) wrp_txt = plt.text(wrap_x, axes[-1].get_ylim()[1], "%+d" % pw[wrap_index], transform=text_offset, size='x-small', color=wrap_color[ax_types[-1]]) ax_phase_wraps[-1].append([wrp, wrp_txt]) # set up span selector for setting new jump ranges options.jump_spans[ax_types[-1]] = SpanSelector(axes[-1], select_jump_range, 'horizontal', useblit=True, rectprops=dict(alpha=0.5, facecolor='orange')) options.jump_spans[ax_types[-1]].visible = options.jump_mode if subplot > 1: axes[0].set_xlim((xmin, xmax)) # Finish off the plot plt.axhline(0, ls='--', label="_nolegend_", c='k', lw=0.5) axes[-1].ticklabel_format(style='plain', axis='x') if mark_peri and hasattr(tempo_results.outpar, 'BINARY'): # Be sure to check if pulsar is in a binary # Cannot mark passage of periastron if not a binary if usepostfit: binpsr = binary_psr.binary_psr(tempo_results.outpar.FILE) else: binpsr = binary_psr.binary_psr(tempo_results.inpar.FILE) xmin, xmax = axes[0].get_xlim() mjd_min = tempo_results.min_TOA mjd_max = tempo_results.max_TOA guess_mjds = np.arange(mjd_max + binpsr.par.PB, \ mjd_min - binpsr.par.PB, -binpsr.par.PB) for mjd in guess_mjds: peri_mjd = binpsr.most_recent_peri(float(mjd)) if xkey == 'mjd': plt.axvline(peri_mjd, ls=':', label='_nolegend_', c='k', lw=0.5) elif xkey == 'year': print "plotting peri passage" plt.axvline(mjd_to_year(peri_mjd), ls=':', label='_nolegend_', c='k', lw=0.5) axes[0].set_xlim((xmin, xmax)) plt.xlabel(xlabel) plt.ylabel(ylabel) subplot += 1 # Plot jump ranges for jstart,jend in tempo_results.jump_ranges: plot_jump_range((jstart,jend)) # axes[-1].set_ylim((ymin, ymax)) if numsubplots > 1: # Increase spacing between subplots. plt.subplots_adjust(hspace=0.25) # Write name of input files used for timing on figure if interactive: fntext = "Solution %d of %d, TOA file: %s, Parameter file: %s" % \ (tempo_history.current_index+1, tempo_history.get_nsolutions(), tempo_results.intimfn, tempo_results.inparfn) figure_text = plt.figtext(0.01, 0.01, fntext, verticalalignment='bottom', horizontalalignment='left') # Make the legend and set its visibility state leg = plt.figlegend(handles, labels, 'upper right') leg.set_visible(show_legend) leg.legendPatch.set_alpha(0.5) axes[0].xaxis.tick_top() plt.setp(axes[0].get_yticklabels()[0], visible=False) plt.setp(axes[1].get_yticklabels()[-1], visible=False) plt.setp(axes[0].get_yticklabels()[-1], visible=False) plt.setp(axes[1].get_yticklabels()[0], visible=False) plt.subplots_adjust(wspace=0.05, hspace = 0.0, left=0.15, bottom=0.1, right=0.8, top=0.9) nms=[] fitmes=[] for b in tempo_history.get_parfile(): if tempo_history.get_parfile()[b].fit==None: tempo_history.get_parfile()[b].fit=0 if not any(b in s for s in tempy_io.no_fit_pars): nms.append(b) fitmes.append(tempo_history.get_parfile()[b].fit) rax = plt.axes([0.85, 0.1, 0.1, 0.8]) rax.set_frame_on(False) options.fitcheck = CheckButtons(rax, nms, fitmes) options.fitcheck.on_clicked(update_fit_flag) redrawplot()
# This is going for Figure 1 in Hulse & Taylor 1975 psr1 = presto.psrepoch("B1913+16", 42320.0) # unfortunatey, OMDOT is not in the binary part of the # database correctly. So we need to set that: psr1.orb.w = 179.0 psr1.orb.t = 0.0 Eo = presto.keplers_eqn(psr1.orb.t, psr1.orb.p, psr1.orb.e, 1e-15) Es = presto.dorbint(Eo, N, 2.0*psr1.orb.p/N, psr1.orb) presto.E_to_v(Es, psr1.orb) plt.plot(ma, Es, 'b-') plt.xlabel("Orbital Phase") plt.ylabel("Pulsar Velocity (km/s)") plt.show() # This is going for Figure 1 in Champion et al 2008 bpsr = binary_psr.binary_psr("1903+0327.par") MJDs = bpsr.T0 + ma * bpsr.par.PB xs, ys = bpsr.position(MJDs) #cMJDs = bpsr.demodulate_TOAs(MJDs) #cxs, cys = bpsr.position(cMJDs) psr2 = presto.psrepoch("1903+0327.par", bpsr.T0) psr2.orb.t = 0.0 Eo = presto.keplers_eqn(psr2.orb.t, psr2.orb.p, psr2.orb.e, 1e-15) Es = presto.dorbint(Eo, N, 2.0*psr2.orb.p/N, psr2.orb) # bt = Es.copy() presto.E_to_phib(Es, psr2.orb) # presto.E_to_phib_BT(bt, psr2.orb) plt.plot(ma, Es, 'b-') plt.plot(ma, -xs, 'r-')