Beispiel #1
0
 def setUp(self):
     # First, read the TOAs from the tim file.
     # This should also create the pickle file.
     try:
         os.remove('test1.tim.pickle.gz')
         os.remove('test1.tim.pickle')
     except OSError:
         pass
     tt = toa.get_TOAs("test1.tim",usepickle=False, include_bipm=False)
     self.numtoas = tt.ntoas
     del tt
     # Now read them from the pickle
     self.t = toa.get_TOAs("test1.tim",usepickle=True, include_bipm=False)
def get_toas(evtfile, flags, tcoords=None, minweight=0, minMJD=0, maxMJD=100000):
    if evtfile[:-3] == 'tim':
        usepickle = False
        if 'usepickle' in flags:
            usepickle = flags['usepickle']
        ts = toa.get_TOAs(evtfile, usepickle=False)
        #Prune out of range MJDs
        mask = np.logical_or(ts.get_mjds() < minMJD * u.day,
                             ts.get_mjds() > maxMJD * u.day)
        ts.table.remove_rows(mask)
        ts.table = ts.table.group_by('obs')
    else:
        if 'usepickle' in flags and flags['usepickle']:
            try:
                picklefile = toa._check_pickle(evtfile)
                if not picklefile:
                    picklefile = evtfile
                ts = toa.TOAs(picklefile)
                return ts
            except:
                pass
        weightcol = flags['weightcol'] if 'weightcol' in flags else None
        target = tcoords if weightcol == 'CALC' else None
        tl = fermi.load_Fermi_TOAs(evtfile, weightcolumn=weightcol,
                                   targetcoord=target, minweight=minweight)
        tl = filter(lambda t: (t.mjd.value > minMJD) and (t.mjd.value < maxMJD), tl)
        ts = toa.TOAs(toalist=tl)
        ts.filename = evtfile
        ts.compute_TDBs()
        ts.compute_posvels(ephem="DE421", planets=False)
        ts.pickle()
    log.info("There are %d events we will use" % len(ts.table))
    return ts
Beispiel #3
0
 def setUpClass(self):
     self.parfileB1855 = 'B1855+09_NANOGrav_dfg+12_modified.par'
     self.timB1855 = 'B1855+09_NANOGrav_dfg+12.tim'
     self.toasB1855 = toa.get_TOAs(self.timB1855, ephem="DE405", planets=False)
     self.modelB1855 = mb.get_model(self.parfileB1855)
     self.psrB1855 = lt.tempopulsar(self.parfileB1855, self.timB1855)
     self.ltres = self.psrB1855.residuals()
Beispiel #4
0
 def setUpClass(self):
     self.parfileB1855 = 'B1855+09_NANOGrav_dfg+12_modified_DD.par'
     self.timB1855 = 'B1855+09_NANOGrav_dfg+12.tim'
     self.toasB1855 = toa.get_TOAs(self.timB1855, ephem="DE405", planets=False)
     self.modelB1855 = mb.get_model(self.parfileB1855)
     # libstempo result
     self.ltres, self.ltbindelay = np.genfromtxt(self.parfileB1855 + '.tempo_test', unpack=True)
Beispiel #5
0
 def setUpClass(self):
     self.parf = 'test_FD.par'
     self.timf = 'test_FD.simulate.pint_corrected'
     self.FDm = mb.get_model(self.parf)
     self.toas = toa.get_TOAs(self.timf)
     # libstempo result
     self.ltres, self.ltbindelay = np.genfromtxt(self.parf + '.tempo_test', unpack=True)
Beispiel #6
0
 def test_residuals(self):
     model = mb.get_model(self.parfile)
     toas = toa.get_TOAs(self.tim, ephem="DE436", planets=False,
                         include_bipm=True)
     r = resids(toas, model)
     assert np.all(np.abs(r.time_resids.to(u.us)) < 800 * u.us), \
         "Residuals did not computed correctly for early CHIME data."
Beispiel #7
0
 def setUpClass(self):
     self.parfileB1855 = 'B1855+09_NANOGrav_9yv1.gls.par'
     self.timB1855 = 'B1855+09_NANOGrav_9yv1.tim'
     self.toasB1855 = toa.get_TOAs(self.timB1855, ephem="DE421",
                                   planets=False, include_bipm=False)
     self.modelB1855 = mb.get_model(self.parfileB1855)
     self.out_parfile = 'test_parfile_write.par'
Beispiel #8
0
 def setUpClass(self):
     self.parf = 'B1855+09_NANOGrav_dfg+12_TAI.par'
     self.timf = 'B1855+09_NANOGrav_dfg+12.tim'
     self.JUMPm = mb.get_model(self.parf)
     self.toas = toa.get_TOAs(self.timf, ephem="DE405", planets=False)
     # libstempo calculation
     self.ltres = np.genfromtxt(self.parf + '.tempo_test', unpack=True, names=True, dtype='float128')
Beispiel #9
0
 def setUpClass(self):
     self.parfileB1855 = 'B1855+09_polycos.par'
     self.timB1855 = 'B1855_polyco.tim'
     self.toasB1855 = toa.get_TOAs(self.timB1855, ephem="DE405", planets=False)
     self.modelB1855 = mb.get_model(self.parfileB1855)
     # Read tempo style polycos.
     self.plc = Polycos()
     self.plc.read_polyco_file('B1855_polyco.dat', 'tempo')
Beispiel #10
0
 def setUpClass(self):
     self.parfileJ1713 = 'J1713+0747_NANOGrav_11yv0.gls.par'
     self.timJ1713 = 'J1713+0747_NANOGrav_11yv0_short.tim'
     self.toasJ1713 = toa.get_TOAs(self.timJ1713, ephem="DE421", planets=False)
     self.toasJ1713.table.sort('index')
     self.modelJ1713 = mb.get_model(self.parfileJ1713)
     # libstempo result
     self.ltres, self.ltbindelay = np.genfromtxt(self.parfileJ1713 + '.tempo_test', unpack=True)
Beispiel #11
0
 def setUpClass(self):
     self.parf= 'B1855+09_NANOGrav_9yv1.gls.par'
     self.timf = 'B1855+09_NANOGrav_9yv1.tim'
     self.toas = toa.get_TOAs(self.timf, ephem="DE421", planets=False)
     self.model = mb.get_model(self.parf)
     self.sort_toas = copy.deepcopy(self.toas)
     self.sort_toas.table.sort('mjd_float')
     self.sort_toas.table['index'] = range(self.sort_toas.ntoas)
Beispiel #12
0
 def setUpClass(self):
     self.par = 'B1855+09_NANOGrav_9yv1.gls.par'
     self.tim = 'B1855+09_NANOGrav_9yv1.tim'
     self.m = mb.get_model(self.par)
     self.t = toa.get_TOAs(self.tim, ephem='DE436')
     self.f = GLSFitter(self.t, self.m)
     # get tempo2 parameter dict
     with open('B1855+09_tempo2_gls_pars.json', 'r') as fp:
         self.t2d = json.load(fp)
Beispiel #13
0
 def setUpClass(self):
     self.parfileJ0023 = 'J0023+0923_NANOGrav_11yv0.gls.par'
     self.timJ0023 = 'J0023+0923_NANOGrav_11yv0.tim'
     self.toasJ0023 = toa.get_TOAs(self.timJ0023, ephem="DE436",
                                   planets=False)
     self.modelJ0023 = mb.get_model(self.parfileJ0023)
     # tempo result
     self.ltres, self.ltbindelay = np.genfromtxt(self.parfileJ0023 + \
                               '.tempo2_test',skip_header=1, unpack=True)
Beispiel #14
0
 def setUpClass(self):
     self.parfileB1953 = 'B1953+29_NANOGrav_dfg+12_TAI_FB90.par'
     self.timB1953 = 'B1953+29_NANOGrav_dfg+12.tim'
     self.toasB1953 = toa.get_TOAs(self.timB1953, ephem="DE405", planets=False)
     self.modelB1953 = mb.get_model(self.parfileB1953)
     # tempo result
     self.ltres, self.ltbindelay = np.genfromtxt(self.parfileB1953 + \
                                  '.tempo2_test',skip_header=1, unpack=True)
     print(self.ltres)
def produce_libstempo_delays():
    """Use simulated data of J1955 with TEMPO2 and test if reproducible"""

    parfile = 'tests/J1955.par'
    timfile = 'tests/J1955.tim'

    toas = toa.get_TOAs(timfile, planets=False, usepickle=False)

    SECS_PER_DAY = 86400

    toasld = toas.table['tdbld']
    t0 = toasld[0]
    toaslds = (toasld - t0) * SECS_PER_DAY

    newmodel = bt.BT()

    newmodel.read_parfile(parfile)

    phases = newmodel.phase(toas.table)

    #t0 = time.time()
    delays = newmodel.delay(toas.table)

    psr = lt.tempopulsar(parfile, timfile)
    t2resids = psr.residuals()
    btdelay = psr.binarydelay()
    bttoasld = psr.toas()
    btt0 = bttoasld[0]
    bttoaslds = (bttoasld - btt0) * SECS_PER_DAY

    # HACK (paulr): Flip sign of btdelay to match what PINT uses.  Not sure why this is necessary. Should be figured out.
    btdelay *= -1.0

    with open('tests/J1955_ltdelays.dat', 'w') as fobj:
        for i in range(len(delays)):
            print("{:.20} {:.20}".format(toaslds[i], btdelay[i]), file=fobj)

    plt.figure("Delays")
    plt.plot(toaslds, delays, label='PINT')
    plt.scatter(toaslds, delays)

    plt.plot(bttoaslds, btdelay, label='T2')
    plt.scatter(bttoaslds, btdelay)

    plt.legend()
    plt.xlabel('Time (d)')
    plt.ylabel('Delay (s)')

    plt.figure("Diff")

    plt.plot(toaslds, delays - btdelay)
    plt.scatter(toaslds, delays - btdelay)

    plt.legend()
    plt.xlabel('Time (d)')
    plt.ylabel('Diff (s)')
    plt.show()
Beispiel #16
0
 def setUpClass(self):
     self.parfileB1855 = 'B1855+09_NANOGrav_9yv1.gls.par'
     self.timB1855 = 'B1855+09_NANOGrav_9yv1.tim'
     self.toasB1855 = toa.get_TOAs(self.timB1855, ephem="DE421",
                                   planets=False, include_bipm=False)
     self.modelB1855 = mb.get_model(self.parfileB1855)
     # tempo result
     self.ltres= np.genfromtxt(self.parfileB1855 + \
                               '.tempo2_test',skip_header=1, unpack=True)
Beispiel #17
0
 def setUpClass(self):
     self.parfileJ0613 = 'J0613-0200_NANOGrav_dfg+12_TAI_FB90.par'
     self.timJ0613 = 'J0613-0200_NANOGrav_dfg+12.tim'
     self.toasJ0613 = toa.get_TOAs(self.timJ0613, ephem="DE405",
                                   planets=False, include_bipm=False)
     self.modelJ0613 = mb.get_model(self.parfileJ0613)
     # tempo result
     self.ltres, self.ltbindelay = np.genfromtxt(self.parfileJ0613 + \
                                  '.tempo2_test',skip_header=1, unpack=True)
     print(self.ltres)
Beispiel #18
0
 def setUpClass(self):
     self.par = 'B1855+09_NANOGrav_dfg+12_TAI_FB90.par'
     self.tim = 'B1855+09_NANOGrav_dfg+12.tim'
     self.m = mb.get_model(self.par)
     self.t = toa.get_TOAs(self.tim, ephem='DE405')
     self.f = WlsFitter(self.t, self.m)
     # set perturb parameter step
     self.per_param = {'A1': 1e-05, 'DECJ': 1e-06, 'DMX_0003': 120, 'ECC': 0.2,
                       'F0': 1e-12, 'F1': 0.001, 'JUMP3': 10.0, 'M2': 10.0,
                       'OM': 1e-06, 'PB': 1e-08, 'PMDEC': 0.1, 'PMRA': 0.1,
                       'PX': 100, 'RAJ': 1e-08, 'SINI': -0.004075, 'T0': 1e-10}
Beispiel #19
0
def test_wave():
    parfile = 'J1513-5908_PKS_alldata_white.par'
    timfile = 'J1744-1134.Rcvr1_2.GASP.8y.x.tim'
    t = toa.get_TOAs(timfile, usepickle=False)

    m = tm.get_model(parfile)
    log.info("model.as_parfile():\n%s"%m.as_parfile())

    print(m.as_parfile())
    print(m)
    print(m.delay(t))
Beispiel #20
0
 def setUpClass(self):
     self.parfileB1855 = 'B1855+09_NANOGrav_dfg+12_TAI_FB90.par'
     self.timB1855 = 'B1855+09_NANOGrav_dfg+12.tim'
     self.toasB1855 = toa.get_TOAs(self.timB1855, ephem="DE405",
                                   planets=False, include_bipm=False)
     self.modelB1855 = mb.get_model(self.parfileB1855)
     from astropy import log as l
     l.warning('%s' % self.modelB1855.components)
     l.warning('%s' % self.modelB1855.params)
     # tempo result
     self.ltres= np.genfromtxt(self.parfileB1855 + \
                               '.tempo2_test',skip_header=1, unpack=True)
Beispiel #21
0
    def test_1955(self):
        """Compare delays from the BT model with libstempo and PINT"""

        parfile = "tests/J1955.par"
        timfile = "tests/J1955.tim"

        # Calculate delays with PINT
        toas = toa.get_TOAs(timfile, planets=False)
        newmodel = bt.BT()
        newmodel.read_parfile(parfile)
        pint_delays = newmodel.delay(toas.table)

        # Load delays calculated with libstempo
        _, lt_delays = np.genfromtxt("tests/J1955_ltdelays.dat", unpack=True)

        assert np.all(np.abs(pint_delays - lt_delays) < 1e-11), "BT TEST FAILED"
Beispiel #22
0
    def test_pint_installed_correctly(self):
        import pint.toa as toa
        from pint.residuals import resids
        import pint.models.model_builder as mb
        import astropy.units as u
        parfile = os.path.join(self.datadir, 'example_pint.par')
        timfile = os.path.join(self.datadir, 'example_pint.tim')

        toas = toa.get_TOAs(timfile, ephem="DE405",
                            planets=False, include_bipm=False)
        model = mb.get_model(parfile)

        pint_resids_us = resids(toas, model, False).time_resids.to(u.s)

        # Due to the gps2utc clock correction. We are at 3e-8 seconds level.
        assert np.all(np.abs(pint_resids_us.value) < 3e-6)
Beispiel #23
0
    def test_orbit_from_parfile(self):
        import pint.toa as toa
        parfile = os.path.join(self.datadir, 'example_pint.par')
        timfile = os.path.join(self.datadir, 'example_pint.tim')

        toas = toa.get_TOAs(timfile, ephem="DE405",
                            planets=False, include_bipm=False)
        mjds = np.array([m.value for m in toas.get_mjds(high_precision=True)])

        mjdstart, mjdstop = mjds[0] - 1, mjds[-1] + 1

        correction_sec, correction_mjd = \
            get_orbital_correction_from_ephemeris_file(mjdstart, mjdstop,
                                                       parfile, ntimes=1000)

        mjdref = 50000
        toa_sec = (mjds - mjdref) * 86400
        corr = correction_mjd(mjds)
        corr_s = correction_sec (toa_sec, mjdref)
        assert np.allclose(corr, corr_s / 86400 + mjdref)
Beispiel #24
0
    def loadtimfile(self, timfile):
        """
        Load a pulsar with pint

        :param parfile:
            Name of the parfile

        :param timfile:
            Name of the timfile, if we want to load it
        """

        t0 = time.time()
        self.t = pt.get_TOAs(timfile, planets=self.planets,usepickle=False)
        time_toa = time.time() - t0
        log.info("Read/corrected TOAs in %.3f sec" % time_toa)

        if log.level < 25:
            self.t.print_summary()

        self.deleted = np.zeros(self.t.ntoas, dtype=np.bool)
        self._readflags()
Beispiel #25
0
from pint.utils import PosVel
from astropy import log
import os

from pinttestdata import testdir, datadir

log.setLevel('ERROR')
# for nice output info, set the following instead
#log.setLevel('INFO')

observatories = obsmod.read_observatories()

ls = u.def_unit('ls', const.c * 1.0 * u.s)

log.info("Reading TOAs into PINT")
ts = toa.get_TOAs(datadir + "/testtimes.tim",usepickle=False)
if log.level < 25:
    ts.print_summary()
ts.table.sort('index')

log.info("Calling TEMPO2")
#cmd = 'tempo2 -output general2 -f tests/testtimes.par tests/testtimes.tim -s "XXX {clock0} {clock1} {clock2} {clock3} {tt} {t2tb} {telSSB} {telVel} {Ttt}\n"'
cmd = 'tempo2 -output general2 -f ' + datadir+'/testtimes.par ' + datadir + \
      '/testtimes.tim -s "XXX {clock0} {clock1} {clock2} {clock3} {tt} {t2tb} {earth_ssb1} {earth_ssb2} {earth_ssb3} {earth_ssb4} {earth_ssb5} {earth_ssb6} {telEpos} {telEVel} {Ttt}\n"'
args = shlex.split(cmd)

tout = subprocess.check_output(args)
goodlines = [x for x in tout.split("\n") if x.startswith("XXX")]

assert(len(goodlines)==len(ts.table))
Beispiel #26
0
 def setUpClass(self):
     self.parf = os.path.join(datadir, 'B1855+09_NANOGrav_dfg+12_DMX.par')
     self.timf = os.path.join(datadir, 'B1855+09_NANOGrav_dfg+12.tim')
     self.DMXm = mb.get_model(self.parf)
     self.toas = toa.get_TOAs(self.timf, ephem='DE405', include_bipm=False)
Beispiel #27
0
    t1_parfile = 'tests/J1744-1134.t1.par'
    timfile = 'tests/J1744-1134.Rcvr1_2.GASP.8y.x.tim'

    m = tm.StandardTimingModel()
    m.read_parfile(parfile)

    print "model.as_parfile():"
    print m.as_parfile()

    try:
        planet_ephems = m.PLANET_SHAPIRO.value
    except AttributeError:
        planet_ephems = False

    t0 = time.time()
    t = toa.get_TOAs(timfile)
    time_toa = time.time() - t0

    sys.stderr.write("Read/corrected TOAs in %.3f sec\n" % time_toa)

    mjds = t.get_mjds()
    d_tdbs = numpy.array([x.tdb.delta_tdb_tt for x in t.table['mjd']])
    errs = t.get_errors()
    resids = numpy.zeros_like(mjds)
    ss_roemer = numpy.zeros_like(mjds)
    ss_shapiro = numpy.zeros_like(mjds)

    sys.stderr.write("Computing residuals...\n")
    t0 = time.time()
    for ii, tt in enumerate(t.table):
        p = m.phase(tt)
Beispiel #28
0
 def setUpClass(self):
     self.parf = os.path.join(datapath,
                              'B1855+09_NANOGrav_dfg+12_modified.par')
     self.timf = os.path.join(datapath, 'J1923+2515_NANOGrav_9yv1.tim')
     self.DMXm = mb.get_model(self.parf)
     self.toas = toa.get_TOAs(self.timf)
Beispiel #29
0
def Pulsar(*args, **kwargs):

    ephem = kwargs.get('ephem', None)
    planets = kwargs.get('planets', True)
    sort = kwargs.get('sort', True)
    drop_t2pulsar = kwargs.get('drop_t2pulsar', True)
    timing_package = kwargs.get('timing_package', 'tempo2')

    if pint:
        toas = list(filter(lambda x: isinstance(x, toa.TOAs), args))
        model = list(filter(lambda x: isinstance(x, TimingModel), args))

    t2pulsar = list(filter(lambda x: isinstance(x, t2.tempopulsar), args))

    parfile = list(filter(lambda x: isinstance(x, str) and
                          x.split('.')[-1] == 'par', args))
    timfile = list(filter(lambda x: isinstance(x, str) and
                          x.split('.')[-1] in ['tim', 'toa'], args))

    if pint and toas and model:
        return PintPulsar(toas[0], model[0], sort=sort, planets=planets)
    elif t2pulsar:
        return Tempo2Pulsar(t2pulsar, sort=sort, drop_t2pulsar=drop_t2pulsar,
                            planets=planets)
    elif parfile and timfile:
        # Check whether the two files exist
        if not os.path.isfile(parfile[0]) or not os.path.isfile(timfile[0]):
            msg = 'Cannot find parfile {0} or timfile {1}!'.format(
                parfile[0], timfile[0])
            raise IOError(msg)

        # Obtain the directory name of the timfile, and change to it
        timfiletup = os.path.split(timfile[0])
        dirname = timfiletup[0] or './'
        reltimfile = timfiletup[-1]
        relparfile = os.path.relpath(parfile[0], dirname)

        # get current directory
        cwd = os.getcwd()

        # Change directory to the base directory of the tim-file to deal with
        # INCLUDE statements in the tim-file
        os.chdir(dirname)

        if timing_package.lower() == 'pint':
            if ephem is None:
                ephem = 'DE421'
            toas = toa.get_TOAs(reltimfile, ephem=ephem, planets=planets)
            model = mb.get_model(relparfile)
            os.chdir(cwd)
            return PintPulsar(toas, model, sort=sort, planets=planets)

        elif timing_package.lower() == 'tempo2':

            # hack to set maxobs
            maxobs = get_maxobs(reltimfile) + 100
            t2pulsar = t2.tempopulsar(relparfile, reltimfile,
                                      maxobs=maxobs, ephem=ephem)
            os.chdir(cwd)
            return Tempo2Pulsar(t2pulsar, sort=sort,
                                drop_t2pulsar=drop_t2pulsar,
                                planets=planets)
    else:
        print('Unknown arguments {}'.format(args))
Beispiel #30
0
parfile = 'J1744-1134.basic.par'
t1_parfile = 'J1744-1134.t1.par'
timfile = 'J1744-1134.Rcvr1_2.GASP.8y.x.tim'

m = tm.StandardTimingModel()
m.read_parfile(parfile)
log.info("model.as_parfile():\n%s"%m.as_parfile())

try:
    planets = m.PLANET_SHAPIRO.value
except AttributeError:
    planets = False

t0 = time.time()
t = toa.get_TOAs(timfile, planets=planets,usepickle=False)
time_toa = time.time() - t0
if log.level < 25:
    t.print_summary()
log.info("Read/corrected TOAs in %.3f sec" % time_toa)

mjds = t.get_mjds()
errs = t.get_errors()

log.info("Computing residuals...")
t0 = time.time()
resids_us = resids(t, m).time_resids.to(u.us)
time_phase = time.time() - t0
log.info("Computed phases and residuals in %.3f sec" % time_phase)

# resids in (approximate) us: