def get_tempo2_result(parfile, timfile, general2=None): """This function is to get the results from tempo and write them to a file. Parameter --------- parfile : str The file to read parameters. timfile : str The file to read toas. general2 : list/ None The values required from tempo2 general2 plugin. Return ---------- A file named as parfile name ends with '.tempo2_test' stored residuals in the first column, binary delay in the second column and general2 results if general2 are provided. """ if not has_tempo2_utils: raise ImportError( "To get tempo2 general2 results, tempo2_utils are" " required. See page" " https://github.com/demorest/tempo_utils" ) residuals = t2u.general2(parfile, timfile, ["pre"])["pre"] outfile = parfile + ".tempo2_test" f = open(outfile, "w") outstr = "residuals " if general2 is not None and general2 != []: tempo2_vals = t2u.general2(parfile, timfile, general2) for keys in general2: outstr += keys + " " outstr += "\n" f.write(outstr) for ii in range(len(residuals)): outstr = longdouble2str(residuals[ii]) + " " if general2 is not None: for keys in general2: outstr += longdouble2str(tempo2_vals[keys][ii]) + " " outstr += "\n" f.write(outstr) f.close()
def get_tempo2_result(parfile, timfile, general2=None): """This function is to get the results from tempo and write them to a file. Parameter --------- parfile : str The file to read parameters. timfile : str The file to read toas. general2 : list/ None The values required from tempo2 general2 plugin. Return ---------- A file named as parfile name ends with '.tempo2_test' stored residuals in the first column, binary delay in the second column and general2 results if general2 are provided. """ if not has_tempo2_utils: raise ImportError("To get tempo2 general2 results, tempo2_utils are" " required. See page" " https://github.com/demorest/tempo_utils") residuals = t2u.general2(parfile, timfile, ['pre'])['pre'] outfile = parfile + '.tempo2_test' f = open(outfile, 'w') outstr = 'residuals ' if general2 is not None and general2 != []: tempo2_vals = t2u.general2(parfile, timfile, general2) for keys in general2: outstr += keys+' ' outstr += '\n' f.write(outstr) for ii in range(len(residuals)): outstr = longdouble2string(residuals[ii]) +' ' if general2 is not None: for keys in general2: outstr += longdouble2string(tempo2_vals[keys][ii])+' ' outstr += '\n' f.write(outstr) f.close()
def get_tempo2_result(parfile, timfile, general2=None): """This function is to get the results from tempo and write them to a file. Parameter --------- parfile : str The file to read parameters. timfile : str The file to read toas. general2 : list/ None The values required from tempo2 general2 plugin. Return ---------- A file named as parfile name ends with '.tempo2_test' stored residuals in the first column, binary delay in the second column and general2 results if general2 are provided. """ psr = lt.tempopulsar(parfile, timfile) residuals = psr.residuals() binary_delay = psr.binarydelay() outfile = parfile + '.tempo2_test' f = open(outfile, 'w') outstr = 'residuals BinaryDelay ' if general2 is not None and general2 != []: if not has_tempo2_utils: raise ImportError("To get tempo2 general2 results, tempo2_utils are" " required. See page" " https://github.com/demorest/tempo_utils") else: tempo2_vals = t2u.general2(parfile, timfile, general2) for keys in general2: outstr += keys+' ' outstr += '\n' f.write(outstr) for ii in range(len(residuals)): outstr = longdouble2string(residuals[ii]) + ' ' +longdouble2string(binary_delay[ii]) +' ' if general2 is not None: for keys in general2: outstr += longdouble2string(tempo2_vals[keys][ii])+' ' outstr += '\n' f.write(outstr) f.close()
import matplotlib.pyplot as plt import tempo2_utils import astropy.units as u from pint.residuals import resids import numpy as np import os, unittest import tempo2_utils # Using Nanograv data B1855 datadir = '../tests/datafile' parfile = os.path.join(datadir, 'B1855+09_NANOGrav_dfg+12_TAI_FB90.par') timfile = os.path.join(datadir, 'B1855+09_NANOGrav_dfg+12.tim') # libstempo calculation print "tempo2 calculation" tempo2_vals = tempo2_utils.general2(parfile, timfile, ['pre']) # Build PINT model print "PINT calculation" mdd = mb.get_model(parfile) # Get toas to pint toas = toa.get_TOAs(timfile, planets=False, ephem='DE405') tt = toas.table # Get residuals t2_resids = tempo2_vals['pre'] presids_us = resids(toas, mdd).time_resids # Plot residuals plt.errorbar(toas.get_mjds(high_precision=False), presids_us.value, toas.get_errors(), fmt='x') plt.title("%s Pre-Fit Timing Residuals" % mdd.PSR.value)
try: import tempo2_utils except ImportError: log.error( "This example requires tempo_utils, download from: https://github.com/demorest/tempo_utils and 'pip install .'" ) raise # Using Nanograv data J0623-0200 datadir = "../../tests/datafile" parfile = os.path.join(datadir, "J0613-0200_NANOGrav_dfg+12_TAI_FB90.par") timfile = os.path.join(datadir, "J0613-0200_NANOGrav_dfg+12.tim") # libstempo calculation print("tempo2 calculation") tempo2_vals = tempo2_utils.general2(parfile, timfile, ["pre"]) # Build PINT model print("PINT calculation") m = mb.get_model(parfile) # Get toas to pint toas = toa.get_TOAs(timfile, planets=False, ephem="DE405", include_bipm=False) t2_resids = tempo2_vals["pre"] presids_us = resids(toas, m).time_resids.to(u.us) # Plot residuals plt.errorbar(toas.get_mjds().value, presids_us.value, toas.get_errors().value, fmt="x") plt.title("%s Pre-Fit Timing Residuals" % m.PSR.value) plt.xlabel("MJD")
for ii, tt in enumerate(t.table): p = m.phase(tt) resids[ii] = p.frac ss_roemer[ii] = m.solar_system_geometric_delay(tt) ss_shapiro[ii] = m.solar_system_shapiro_delay(tt) time_phase = time.time() - t0 sys.stderr.write("Computed phases in %.3f sec\n" % time_phase) # resids in (approximate) us: resids_us = resids / float(m.F0.value) * 1e6 sys.stderr.write("RMS PINT residuals are %.3f us\n" % resids_us.std()) # Get some general2 stuff tempo2_vals = tempo2_utils.general2(parfile, timfile, ['tt2tb', 'roemer', 'post_phase', 'shapiro', 'shapiroJ']) t2_resids = tempo2_vals['post_phase'] / float(m.F0.value) * 1e6 diff_t2 = resids_us - t2_resids diff_t2 -= diff_t2.mean() # run tempo1 also, if the tempo_utils module is available try: import tempo_utils t1_toas = tempo_utils.read_toa_file(timfile) tempo_utils.run_tempo(t1_toas, t1_parfile) t1_resids = t1_toas.get_resids(units='phase') / float(m.F0.value) * 1e6 diff_t1 = resids_us - t1_resids diff_t1 -= diff_t1.mean() diff_t2_t1 = t2_resids - t1_resids
import matplotlib.pyplot as plt import tempo2_utils import astropy.units as u from pint.residuals import resids import numpy as np import os, unittest import tempo2_utils # Using Nanograv data B1855 datadir = '../tests/datafile' parfile = os.path.join(datadir, 'B1855+09_NANOGrav_dfg+12_TAI_FB90.par') timfile = os.path.join(datadir, 'B1855+09_NANOGrav_dfg+12.tim') # libstempo calculation print "tempo2 calculation" tempo2_vals = tempo2_utils.general2(parfile, timfile,['pre']) # Build PINT model print "PINT calculation" mdd = mb.get_model(parfile) # Get toas to pint toas = toa.get_TOAs(timfile, planets=False, ephem='DE405') tt = toas.table # Get residuals t2_resids = tempo2_vals['pre'] presids_us = resids(toas, mdd).time_resids # Plot residuals plt.errorbar(toas.get_mjds(high_precision=False), presids_us.value, toas.get_errors(), fmt='x') plt.title("%s Pre-Fit Timing Residuals" % mdd.PSR.value) plt.xlabel('MJD') plt.ylabel('Residual (us)')
datapath = os.path.join(os.environ['PINT'],'tests','datafile') # Using Nanograv data B1855 parfile = os.path.join(datapath, 'B1855+09_NANOGrav_dfg+12_modified.par') timfile = os.path.join(datapath, 'B1855+09_NANOGrav_dfg+12.tim') # libstempo calculation print "libstempo calculation" psr = lt.tempopulsar(parfile, timfile) # Build PINT model print "PINT calculation" mdd = mb.get_model(parfile) # Get toas to pint toas = toa.get_TOAs(timfile, planets=True) tt = toas.table # Run tempo2 general2 pluging tempo2_vals = tempo2_utils.general2(parfile, timfile, ['tt2tb', 'roemer', 'post_phase', 'shapiro', 'shapiroJ','bat','clock0', 'clock1','clock2','clock3','clock4','sat', 'tropo']) # compute residules t2_resids = tempo2_vals['post_phase'] / float(mdd.F0.value) * 1e6 * u.us presids_us = resids(toas, mdd).time_resids.to(u.us) toas = psr.toas() toas.sort() plt.plot(toas,presids_us-t2_resids) plt.xlabel('Mjd (DAY)') plt.ylabel('residule (us)') plt.title('Residule difference between PINT and tempo2') plt.show()
for ii, tt in enumerate(t.table): p = m.phase(tt) resids[ii] = p.frac ss_roemer[ii] = m.solar_system_geometric_delay(tt) ss_shapiro[ii] = m.solar_system_shapiro_delay(tt) time_phase = time.time() - t0 sys.stderr.write("Computed phases in %.3f sec\n" % time_phase) # resids in (approximate) us: resids_us = resids / float(m.F0.value) * 1e6 sys.stderr.write("RMS PINT residuals are %.3f us\n" % resids_us.std()) # Get some general2 stuff tempo2_vals = tempo2_utils.general2( parfile, timfile, ['tt2tb', 'roemer', 'post_phase', 'shapiro', 'shapiroJ']) t2_resids = tempo2_vals['post_phase'] / float(m.F0.value) * 1e6 diff_t2 = resids_us - t2_resids diff_t2 -= diff_t2.mean() # run tempo1 also, if the tempo_utils module is available try: import tempo_utils t1_toas = tempo_utils.read_toa_file(timfile) tempo_utils.run_tempo(t1_toas, t1_parfile) t1_resids = t1_toas.get_resids(units='phase') / float(m.F0.value) * 1e6 diff_t1 = resids_us - t1_resids diff_t1 -= diff_t1.mean() diff_t2_t1 = t2_resids - t1_resids