Exemplo n.º 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)
Exemplo n.º 2
0
 def setUp(self):
     os.chdir(datadir)
     # 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)
Exemplo n.º 3
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
     }
Exemplo n.º 4
0
def test_model_override1():
    parstr = StringIO(simplepar)
    m = get_model(parstr)
    y = toa.get_TOAs("test1.tim", model=m)
    assert y.ephem == "DE436"
    assert y.planets is True
    assert y.clock_corr_info["bipm_version"] == "BIPM2017"
Exemplo n.º 5
0
def test_get_TOAs(high_precision):
    toas = get_TOAs(StringIO(tim), ephem="de421")
    m = toas.get_mjds(high_precision=high_precision)
    assert isinstance(m, np.ndarray)
    assert not np.all(
        np.diff(m) > 0), "returned values should be grouped by observatory"
    assert len(m) == n_tim
Exemplo n.º 6
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)
Exemplo n.º 7
0
 def setUpClass(cls):
     os.chdir(datadir)
     cls.par = "B1855+09_NANOGrav_dfg+12_TAI_FB90.par"
     cls.tim = "B1855+09_NANOGrav_dfg+12.tim"
     cls.m = get_model(cls.par)
     cls.t = toa.get_TOAs(cls.tim, ephem="DE405")
     cls.f = WLSFitter(cls.t, cls.m)
     # set perturb parameter step
     cls.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,
     }
Exemplo n.º 8
0
 def setUpClass(cls):
     os.chdir(datadir)
     cls.tim = "B1855+09_NANOGrav_dfg+12.tim"
     cls.toas = toa.get_TOAs(cls.tim,
                             ephem="DE405",
                             planets=False,
                             include_bipm=False)
Exemplo n.º 9
0
 def setUpClass(self):
     os.chdir(datadir)
     self.tim = 'B1855+09_NANOGrav_dfg+12.tim'
     self.toas = toa.get_TOAs(self.tim,
                              ephem="DE405",
                              planets=False,
                              include_bipm=False)
Exemplo n.º 10
0
def test_ecorr_average():
    par = os.path.join(datadir, "J0023+0923_NANOGrav_11yv0.gls.par")
    tim = os.path.join(datadir, "J0023+0923_NANOGrav_11yv0.tim")
    m = mb.get_model(par)
    t = toa.get_TOAs(tim, ephem="DE436")
    f = GLSFitter(t, m)
    # Get comparison resids and uncertainties
    mjd, freq, res, err, ophase, chi2, info = np.genfromtxt(par + ".resavg",
                                                            unpack=True)
    resavg_mjd = mjd * u.d
    # resavg_freq = freq * u.MHz
    resavg_res = res * u.us
    resavg_err = err * u.us
    # resavg_chi2 = chi2

    f.fit_toas()
    avg = f.resids.ecorr_average()
    # The comparison data always come out time-sorted
    # so we need to sort here.
    ii = np.argsort(avg["mjds"])
    mjd_diff = avg["mjds"][ii] - resavg_mjd
    res_diff = avg["time_resids"][ii] - resavg_res
    err_ratio = avg["errors"][ii] / resavg_err
    assert np.abs(mjd_diff).max() < 1e-9 * u.d
    assert np.abs(res_diff).max() < 7 * u.ns
    assert np.abs(err_ratio - 1.0).max() < 5e-4
Exemplo n.º 11
0
def test_many_timfile_jumps():
    m = get_model(io.StringIO(par_base))
    pairs = 15
    toas_per_jump = 3
    t = make_fake_toas_uniform(56000, 57000, 5 + toas_per_jump * pairs, model=m)
    # The following lets us write the fake TOAs to a string as a timfile
    f = io.StringIO()
    with redirect_stdout(f):
        t.write_TOA_file(sys.stdout)
    s = f.getvalue().splitlines()
    toalist = ["\n".join(s[:11]) + "\n"]
    lo = 12
    for _ in range(pairs):
        toalist.append("\n".join(["JUMP"] + s[lo : lo + toas_per_jump] + ["JUMP\n"]))
        lo += toas_per_jump
    # read the TOAs
    tt = get_TOAs(io.StringIO("".join(toalist)))
    # convert the timfile JUMPs to params
    m.jump_flags_to_params(tt)
    assert "PhaseJump" in m.components
    assert len(m.components["PhaseJump"].jumps) == pairs
    assert "JUMP1" in m.components["PhaseJump"].jumps
    assert "JUMP2" in m.components["PhaseJump"].jumps
    assert "JUMP10" in m.components["PhaseJump"].jumps
    assert "JUMP15" in m.components["PhaseJump"].jumps
Exemplo n.º 12
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)
Exemplo n.º 13
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."
Exemplo n.º 14
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'
Exemplo n.º 15
0
 def __init__(self, par, tim):
     self.par = par
     self.tim = tim
     self.m = mb.get_model(self.par)
     self.t = toa.get_TOAs(
         self.tim, ephem="DE405", planets=False, include_bipm=False
     )
Exemplo n.º 16
0
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
Exemplo n.º 17
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')
Exemplo n.º 18
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()
Exemplo n.º 19
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

        with warnings.catch_warnings():
            warnings.simplefilter("ignore", category=UserWarning)
            correction_sec, correction_mjd, model = \
                get_orbital_correction_from_ephemeris_file(mjdstart, mjdstop,
                                                           parfile, ntimes=1000,
                                                           return_pint_model=True)

        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)
Exemplo n.º 20
0
 def test_toa_noise_designmatrix(self):
     toas = get_TOAs("B1855+09_NANOGrav_9yv1.tim")
     model = get_model("B1855+09_NANOGrav_9yv1.gls.par")
     noise_designmatrix = self.noise_designmatrix_maker(toas, model)
     assert noise_designmatrix.shape[0] == toas.ntoas
     assert noise_designmatrix.derivative_quantity == ["toa"]
     assert noise_designmatrix.derivative_params == ["toa_noise_params"]
Exemplo n.º 21
0
    def test_combine_designmatrix_all(self):
        toas = get_TOAs("B1855+09_NANOGrav_12yv3.wb.tim")
        model = get_model("B1855+09_NANOGrav_12yv3.wb.gls.par")
        noise_designmatrix = self.noise_designmatrix_maker(toas, model)

        toa_designmatrix = self.toa_designmatrix_maker(
            toas, model, self.test_param_lite
        )
        dm_designmatrix = self.dm_designmatrix_maker(
            toas, model, self.test_param_lite, offset=True, offset_padding=0.0
        )
        combined_quantity = combine_design_matrices_by_quantity(
            [toa_designmatrix, dm_designmatrix,]
        )
        combined_param = combine_design_matrices_by_param(
            combined_quantity, noise_designmatrix
        )

        assert combined_param.shape == (
            toa_designmatrix.shape[0] + dm_designmatrix.shape[0],
            toa_designmatrix.shape[1] + noise_designmatrix.shape[1],
        )

        assert np.all(
            combined_param.matrix[
                toas.ntoas : toas.ntoas * 2, toa_designmatrix.shape[1] : :
            ]
            == 0.0
        )
Exemplo n.º 22
0
def _gen_data(par, tim):
    t = toa.get_TOAs(tim, ephem="DE436")
    m = mb.get_model(par)
    gls = GLSFitter(t, m)
    gls.fit_toas()

    mjds = t.get_mjds().to(u.d).value
    freqs = t.get_freqs().to(u.MHz).value
    res = gls.resids.time_resids.to(u.us).value
    err = m.scaled_sigma(t).to(u.us).value
    info = t.get_flag_value("f")

    fout = open(par + ".resids", "w")
    iout = open(par + ".info", "w")
    for i in range(t.ntoas):
        line = "%.10f %.4f %+.8e %.3e 0.0 %s" % (
            mjds[i],
            freqs[i],
            res[i],
            err[i],
            info[i],
        )
        fout.write(line + "\n")
        iout.write(info[i] + "\n")
    fout.close()
    iout.close()

    # Requires res_avg in path
    cmd = "cat %s.resids | res_avg -r -t0.0001 -E%s -i%s.info > %s.resavg" % (
        par,
        par,
        par,
        par,
    )
    print(cmd)
Exemplo n.º 23
0
def test_ftest_wb():
    """Test for wideband fitter class F-test."""
    wb_m = tm.get_model(
        os.path.join(datadir, "J1614-2230_NANOGrav_12yv3.wb.gls.par"))
    wb_t = toa.get_TOAs(
        os.path.join(datadir, "J1614-2230_NANOGrav_12yv3.wb.tim"))
    wb_f = fitter.WidebandTOAFitter(wb_t, wb_m)
    wb_f.fit_toas()
    # Parallax
    PX = param.floatParameter(parameter_type="float",
                              name="PX",
                              value=0.0,
                              units=u.mas,
                              frozen=False)
    PX_Component = "AstrometryEcliptic"
    # A1DOT
    A1DOT = param.floatParameter(
        parameter_type="float",
        name="A1DOT",
        value=0.0,
        units=ls / u.second,
        frozen=False,
    )
    A1DOT_Component = "BinaryELL1"
    # Test adding A1DOT
    Ftest_dict = wb_f.ftest(A1DOT,
                            A1DOT_Component,
                            remove=False,
                            full_output=True)
    assert isinstance(Ftest_dict["ft"], float) or isinstance(
        Ftest_dict["ft"], bool)
    # Test removing parallax
    Ftest_dict = wb_f.ftest(PX, PX_Component, remove=True, full_output=True)
    assert isinstance(Ftest_dict["ft"], float) or isinstance(
        Ftest_dict["ft"], bool)
Exemplo n.º 24
0
def test_ftest_nb():
    """Test for narrowband fitter class F-test."""
    m = tm.get_model(os.path.join(datadir, "B1855+09_NANOGrav_9yv1.gls.par"))
    t = toa.get_TOAs(os.path.join(datadir, "B1855+09_NANOGrav_9yv1.tim"))
    f = fitter.WLSFitter(toas=t, model=m)
    f.fit_toas()
    # Test adding parameters
    FD4 = param.prefixParameter(parameter_type="float",
                                name="FD4",
                                value=0.0,
                                units=u.s,
                                frozen=False)
    ft = f.ftest(FD4, "FD", remove=False)
    assert isinstance(ft["ft"], float) or isinstance(ft["ft"], bool)
    # Test return the full output
    Ftest_dict = f.ftest(FD4, "FD", remove=False, full_output=True)
    assert isinstance(Ftest_dict["ft"], float) or isinstance(
        Ftest_dict["ft"], bool)
    # Test removing parameter
    FD3 = param.prefixParameter(parameter_type="float",
                                name="FD3",
                                value=0.0,
                                units=u.s,
                                frozen=False)
    ft = f.ftest(FD3, "FD", remove=True)
    assert isinstance(ft["ft"], float) or isinstance(ft["ft"], bool)
    Ftest_dict = f.ftest(FD3, "FD", remove=True, full_output=True)
    assert isinstance(Ftest_dict["ft"], float) or isinstance(
        Ftest_dict["ft"], bool)
Exemplo n.º 25
0
    def __init__(self, parfile=None, timfile=None, ephem=None, fitter="GLSFitter"):
        super(Pulsar, self).__init__()

        log.info(f"Loading pulsar parfile: {str(parfile)}")

        if parfile is None or timfile is None:
            raise ValueError("No valid pulsar model and/or TOAs to load")

        self.parfile = parfile
        self.timfile = timfile
        self.prefit_model = pint.models.get_model(self.parfile)

        if ephem is not None:
            log.info(
                f"Overriding model ephemeris {self.prefit_model.EPHEM.value} with {ephem}"
            )
            self.prefit_model.EPHEM.value = ephem
        self.all_toas = get_TOAs(self.timfile, model=self.prefit_model, usepickle=True)
        # Make sure that if we used a model, that any phase jumps from
        # the parfile have their flags updated in the TOA table
        if "PhaseJump" in self.prefit_model.components:
            self.prefit_model.jump_params_to_flags(self.all_toas)
        # turns pre-existing jump flags in toas.table['flags'] into parameters in parfile
        self.prefit_model.jump_flags_to_params(self.all_toas)
        self.selected_toas = copy.deepcopy(self.all_toas)
        print("The prefit model as a parfile:")
        print(self.prefit_model.as_parfile())
        # adds extra prefix params for fitting
        self.add_model_params()

        self.all_toas.print_summary()

        self.prefit_resids = Residuals(self.all_toas, self.prefit_model)
        self.selected_prefit_resids = self.prefit_resids
        print(
            "RMS pre-fit PINT residuals are %.3f us\n"
            % self.prefit_resids.rms_weighted().to(u.us).value
        )
        # Set of indices from original list that are deleted
        # We use indices because of the grouping of TOAs by observatory
        self.deleted = set([])
        if fitter == "auto":
            self.fit_method = self.getDefaultFitter(downhill=False)
            log.info(
                f"Since wideband={self.all_toas.wideband} and correlated={self.prefit_model.has_correlated_errors}, selecting fitter={self.fit_method}"
            )
        elif fitter == "downhill":
            self.fit_method = self.getDefaultFitter(downhill=True)
            log.info(
                f"Since wideband={self.all_toas.wideband} and correlated={self.prefit_model.has_correlated_errors}, selecting Downhill fitter={self.fit_method}"
            )
        else:
            self.fit_method = fitter
        self.fitter = None
        self.fitted = False
        self.stashed = None  # for temporarily stashing some TOAs
        self.faketoas1 = None  # for random models
        self.faketoas = None  # for random models
        self.use_pulse_numbers = False
Exemplo n.º 26
0
def get_model_and_toas(
    parfile,
    timfile,
    ephem=None,
    include_bipm=None,
    bipm_version=None,
    include_gps=None,
    planets=None,
    usepickle=False,
    tdb_method="default",
    picklefilename=None,
):
    """Load a timing model and a related TOAs, using model commands as needed

    Parameters
    ----------
    parfile : str
        The parfile name, or a file-like object to read the parfile contents from
    timfile : str
        The timfile name, or a file-like object to read the timfile contents from
    include_bipm : bool or None
        Whether to apply the BIPM clock correction. Defaults to True.
    bipm_version : string or None
        Which version of the BIPM tables to use for the clock correction.
        The format must be 'BIPMXXXX' where XXXX is a year.
    include_gps : bool or None
        Whether to include the GPS clock correction. Defaults to True.
    planets : bool or None
        Whether to apply Shapiro delays based on planet positions. Note that a
        long-standing TEMPO2 bug in this feature went unnoticed for years.
        Defaults to False.
    usepickle : bool
        Whether to try to use pickle-based caching of loaded clock-corrected TOAs objects.
    tdb_method : str
        Which method to use for the clock correction to TDB. See
        :func:`pint.observatory.Observatory.get_TDBs` for details.
    picklefilename : str or None
        Filename to use for caching loaded file. Defaults to adding ``.pickle.gz`` to the
        filename of the timfile, if there is one and only one. If no filename is available,
        or multiple filenames are provided, a specific filename must be provided.

    Returns
    -------
    A tuple with (model instance, TOAs instance)
    """
    mm = get_model(parfile)
    tt = get_TOAs(
        timfile,
        model=mm,
        ephem=ephem,
        include_bipm=include_bipm,
        bipm_version=bipm_version,
        include_gps=include_gps,
        planets=planets,
        usepickle=usepickle,
        tdb_method=tdb_method,
        picklefilename=picklefilename,
    )
    return mm, tt
Exemplo n.º 27
0
def test_pickle_invalidated_time(temp_tim, monkeypatch):
    tt, tp = temp_tim
    toa.get_TOAs(tt, usepickle=True)

    rpf = toa.TOAs.read_pickle_file

    def change(self, *args, **kwargs):
        rpf(self, *args, **kwargs)
        self.was_pickled = True

    monkeypatch.setattr(toa.TOAs, "read_pickle_file", change)
    assert toa.get_TOAs(tt, usepickle=True).was_pickled

    time.sleep(1)
    with open(tt, "at") as f:
        f.write("\n")
    assert not hasattr(toa.get_TOAs(tt, usepickle=True), "was_pickled")
Exemplo n.º 28
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')
Exemplo n.º 29
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)
Exemplo n.º 30
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, include_bipm=False)
     # libstempo result
     self.ltres, self.ltbindelay = np.genfromtxt(self.parf + '.tempo_test',
                                                 unpack=True)
Exemplo n.º 31
0
def test_toas_read_list():
    x = toa.get_TOAs("test1.tim")
    toas, commands = toa.read_toa_file("test1.tim")
    y = toa.get_TOAs_list(toas,
                          commands=commands,
                          filename=x.filename,
                          hashes=x.hashes)
    assert x == y
Exemplo n.º 32
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)
Exemplo n.º 33
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)
Exemplo n.º 34
0
 def test_toa_read(self):
     toas = toa.get_TOAs(self.tim,
                         ephem="DE436",
                         planets=False,
                         include_bipm=True)
     assert toas.ntoas == 848, "CHIME TOAs did not read correctly."
     assert list(set(toas.get_obss())) == ['chime'], \
         "CHIME did not recognized by observatory module."
Exemplo n.º 35
0
def test_flags(s):
    f = StringIO("\n".join([
        basic_tim_header,
        f"""some_barycentered 999999.999 56400.000000000000000   1.000  @{s}""",
        basic_tim,
    ]))
    toas = get_TOAs(f)
    do_roundtrip(toas)
Exemplo n.º 36
0
def wls():
    m = get_model(join(datadir, "NGC6440E.par"))
    t = get_TOAs(join(datadir, "NGC6440E.tim"), ephem="DE421")

    wls = WLSFitter(t, m)
    wls.fit_toas()

    return wls
Exemplo n.º 37
0
def test_barycenter(k):
    f = StringIO(basic_tim_header + """
some_barycentered 999999.999 56400.000000000000000   1.000  @  -some argument -another argument
some_barycentered 999999.999 56401.000000000000000   1.000  @  -some argument -another argument
some_barycentered 999999.999 56402.000000000000000   1.000  @  -some argument -another argument
some_barycentered 999999.999 56403.000000000000000   1.000  @  -some argument -another argument
""" + basic_tim)
    do_roundtrip(get_TOAs(f, **k), **k)
Exemplo n.º 38
0
    def test_copy_toa_object(self):
        toa = get_TOAs("J1614-2230_NANOGrav_12yv3.wb.tim")
        toa_copy = copy.deepcopy(toa)

        assert sys.getsizeof(toa) == sys.getsizeof(toa_copy)
        assert id(toa) != id(toa_copy)
        assert toa.ntoas == toa_copy.ntoas
        assert all(toa.table["mjd"] == toa_copy.table["mjd"])
Exemplo n.º 39
0
 def setUpClass(cls):
     os.chdir(datadir)
     cls.parf = "test_FD.par"
     cls.timf = "test_FD.simulate.pint_corrected"
     cls.FDm = mb.get_model(cls.parf)
     cls.toas = toa.get_TOAs(cls.timf, include_bipm=False)
     # libstempo result
     cls.ltres, cls.ltbindelay = np.genfromtxt(cls.parf + ".tempo_test", unpack=True)
Exemplo n.º 40
0
def test_toa_check_hashes(tmpdir):
    tf = os.path.join(tmpdir, "file.tim")
    shutil.copy("NGC6440E.tim", tf)
    t = toa.get_TOAs(tf)
    assert t.check_hashes()
    with open(tf, "at") as f:
        f.write("\n")
    assert not t.check_hashes()
Exemplo n.º 41
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)
Exemplo n.º 42
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)
Exemplo n.º 43
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)
Exemplo n.º 44
0
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()
Exemplo n.º 45
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)
Exemplo n.º 46
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)
Exemplo n.º 47
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}
Exemplo n.º 48
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))
Exemplo n.º 49
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)
Exemplo n.º 50
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"
Exemplo n.º 51
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)
Exemplo n.º 52
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)
Exemplo n.º 53
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()
Exemplo n.º 54
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))
Exemplo n.º 55
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)
Exemplo n.º 56
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))
Exemplo n.º 57
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:
Exemplo n.º 58
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)
Exemplo n.º 59
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)