Exemplo n.º 1
0
def test_broken_parameter_line_fit():
    broken_line1 = "\nPMELONG 3 SC 0.8"
    broken1 = base_par + broken_line1
    with pytest.raises(ValueError,
                       match="Unidentified string 'SC' in parfile "
                       "line PMELONG 3 SC 0.8"):
        get_model(StringIO(broken1))
Exemplo n.º 2
0
 def setUpClass(cls):
     os.chdir(datadir)
     # This uses ELONG and ELAT
     cls.m1 = mb.get_model("B1855+09_NANOGrav_9yv1.gls.par")
     # This uses RA and DEC
     cls.m2 = mb.get_model("B1855+09_NANOGrav_dfg+12_TAI_FB90.par")
     cls.t = 5000 * np.random.randn(100) + 49453.0
Exemplo n.º 3
0
 def setUpClass(self):
     os.chdir(datadir)
     # This uses ELONG and ELAT
     self.m1 = mb.get_model('B1855+09_NANOGrav_9yv1.gls.par')
     # This uses RA and DEC
     self.m2 = mb.get_model('B1855+09_NANOGrav_dfg+12_TAI_FB90.par')
     self.t = 5000 * np.random.randn(100) + 49453.0
Exemplo n.º 4
0
def test_valid_model(tmp_dir, name, expectation):
    """Check handling of bogus binary models.

    Note that ``get_model_new`` currently reports different errors
    from the old ``get_model``.

    """
    fn = join(tmp_dir, "file.par")
    with open(fn, "w") as f:
        f.write(par_template.format(name))
    with expectation:
        get_model(f.name)
Exemplo n.º 5
0
    def setUpClass(cls):
        # J0613 is in equatorial
        cls.parfileJ0613 = os.path.join(
            datadir, "J0613-0200_NANOGrav_dfg+12_TAI_FB90.par")
        cls.modelJ0613 = mb.get_model(cls.parfileJ0613)

        # B1855+09 is in ecliptic
        cls.parfileB1855 = os.path.join(datadir,
                                        "B1855+09_NANOGrav_9yv1.gls.par")
        cls.modelB1855 = mb.get_model(cls.parfileB1855)

        cls.log = logging.getLogger("TestGalactic")
Exemplo n.º 6
0
def test_get_model_roundtrip(tmp_dir, parfile):
    if basename(parfile) in bad_trouble:
        pytest.skip("This parfile is unclear")
    try:
        m_old = get_model(parfile)
    except (ValueError, IOError, MissingParameter) as e:
        pytest.skip("Existing code raised an exception {}".format(e))

    fn = join(tmp_dir, "file.par")
    with open(fn, "w") as f:
        f.write(m_old.as_parfile())
    m_roundtrip = get_model(fn)
    assert set(m_roundtrip.get_params_mapping().keys()) == set(
        m_old.get_params_mapping().keys())
    assert set(m_roundtrip.components.keys()) == set(m_old.components.keys())
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(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.º 9
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.º 10
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.º 11
0
def test_ECL_to_ICRS_uncertainties():
    # start with ECL model, fit with both models
    # compare parameter values and uncertainties
    model_ECL = get_model(io.StringIO(modelstring_ECL))

    toas = pint.simulation.make_fake_toas_uniform(MJDStart,
                                                  MJDStop,
                                                  NTOA,
                                                  model=model_ECL,
                                                  error=1 * u.us,
                                                  add_noise=True)
    fit_ECL = WLSFitter(toas, model_ECL)
    fit_ICRS = WLSFitter(toas, model_ECL.as_ICRS())
    fit_ECL.fit_toas()
    fit_ICRS.fit_toas()

    m1 = fit_ECL.model
    m2 = fit_ICRS.model.as_ECL()

    for p in ("ELONG", "ELAT", "PMELONG", "PMELAT"):
        assert np.isclose(m1.__getitem__(p).value, m2.__getitem__(p).value)
        # do a generous test here since the uncertainties could change
        assert np.isclose(m1.__getitem__(p).uncertainty,
                          m2.__getitem__(p).uncertainty,
                          rtol=0.5)
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_mix_alise():
    mixed_par = base_par + "\nEQUAD -fe 430 1\nT2EQUAD -fe guppi 2"
    m = get_model(StringIO(mixed_par), allow_name_mixing=True)
    assert hasattr(m, "EQUAD2")
    assert m.EQUAD2.value == 2
    assert m.EQUAD2.key == "-fe"
    assert m.EQUAD2.key_value == ["guppi"]
Exemplo n.º 14
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.º 15
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.º 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)
     self.out_parfile = 'test_parfile_write.par'
Exemplo n.º 17
0
def test_compare_get_model_new_and_old():
    m_new = get_model_new(parfile)
    m_old = get_model(parfile)

    assert set(m_new.get_params_mapping().keys()) == set(
        m_old.get_params_mapping().keys())
    assert set(m_new.components.keys()) == set(m_old.components.keys())
Exemplo n.º 18
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.º 19
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.º 20
0
 def test_write(self):
     # change parameter value
     for p in self.modelB1855.params:
         par = getattr(self.modelB1855, p)
         # Change value for 20%
         if isinstance(par.value, numbers.Number):
             ov = par.value
             if isinstance(par, mp.MJDParameter):
                 continue
             else:
                 par.value = ov * 0.8
     self.res = Residuals(self.toasB1855,
                          self.modelB1855,
                          use_weighted_mean=False).time_resids.to(u.s)
     f = open(self.out_parfile, "w")
     f.write(self.modelB1855.as_parfile())
     f.close()
     read_model = mb.get_model(self.out_parfile)
     read_res = Residuals(self.toasB1855,
                          read_model,
                          use_weighted_mean=False).time_resids.to(u.s)
     assert np.all(np.abs(read_res.value - self.res.value) < 1e-15
                   ), "Output parfile did not produce same residuals."
     for pp in self.modelB1855.params:
         par_ori = getattr(self.modelB1855, pp)
         par_read = getattr(read_model, pp)
         if par_ori.uncertainty_value is not None:
             unc_diff = par_ori.uncertainty_value - par_read.uncertainty_value
             assert np.abs(unc_diff) < 1e-15, (
                 pp + "uncertainty does not keep the precision. at" +
                 str(np.abs(unc_diff)))
Exemplo n.º 21
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.º 22
0
def test_multiple_freqs():
    # basic model, no EFAC or EQUAD
    model = get_model(
        io.StringIO(
            """
        PSRJ J1234+5678
        ELAT 0
        ELONG 0
        DM 10
        F0 1
        PEPOCH 58000
        """
        )
    )
    toas = pint.simulation.make_fake_toas_uniform(
        57001,
        58000,
        200,
        model=model,
        error=1 * u.us,
        add_noise=False,
        freq=np.array([1400, 400]) * u.MHz,
    )
    assert (toas.table["freq"][::2] == 1400 * u.MHz).all()
    assert (toas.table["freq"][1::2] == 400 * u.MHz).all()
Exemplo n.º 23
0
def check_tempo2_output(parf, timf, p, result_par):
    """Check out tempo2 output
    """
    res = subprocess.check_output('tempo2 -f ' + parf + ' ' + timf +
                                  ' -norescale -newpar',
                                  shell=True)
    mpre = re.search('RMS pre-fit residual =(.+?)(us)', res)
    mpost = re.search('RMS post-fit residual =(.+?)(us)', res)
    mchi = re.search('Chisqr/nfree =(.+?)/', res)
    m = mb.get_model(result_par)
    mpostn = re.findall(r'\d+\.\d+', mpost.group(1))
    try:
        pre_rms = float(mpre.group(1))
    except ValueError:
        pre_rms = mpre.group(1)
    try:
        post_rms = float(mpostn[0])
    except ValueError:
        post_rms = mpost.group(1)
    try:
        chi = float(mchi.group(1)) / len(t.table)
    except:
        chi = mchi.group(1)
    pv = getattr(m, p).value
    pu = getattr(m, p).uncertainty_value
    return pv, pu, post_rms, chi
Exemplo n.º 24
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.º 25
0
def test_ECL_to_allECL(ecl):
    model_ECL = get_model(io.StringIO(modelstring_ECL))
    model_ECL2 = model_ECL.as_ECL(ecl=ecl)
    coords_ECL2 = model_ECL2.get_psr_coords()
    assert model_ECL2.ECL.value == ecl
    # note that coord.separation() will transform between frames when needed
    assert np.isclose(
        model_ECL.get_psr_coords().separation(coords_ECL2).arcsec, 0)
Exemplo n.º 26
0
def test_infostring_in_parfile(setup_NGC6440E):
    parfile = setup_NGC6440E.m.as_parfile(comment="test parfile writing")
    f = io.StringIO(parfile)
    newmodel = mb.get_model(f)
    for p in setup_NGC6440E.m.params:
        assert (
            getattr(newmodel, p).value == getattr(setup_NGC6440E.m, p).value
        ), f"Value of {p} does not match in new par file: ({getattr(newmodel, p).value} vs. {getattr(setup_NGC6440E.m, p).value})"
Exemplo n.º 27
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.º 28
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.º 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(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.º 31
0
def test_if_stand_alone_binary_model_get_updated_from_PINT_model(parfile):
    if basename(parfile) in bad_trouble:
        pytest.skip("This parfile is unclear")
    try:
        m = get_model(parfile)
    except (ValueError, IOError, MissingParameter) as e:
        pytest.skip("Existing code raised an exception {}".format(e))
    verify_stand_alone_binary_parameter_updates(m)
Exemplo n.º 32
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.º 33
0
def test_stand_alone_model_params_updates():
    test_par_str = temp_par_str + "\n KIN  71.969  1  0.562"
    m = mb.get_model(StringIO(test_par_str))
    # Check if KIN exists in the pint facing object and stand alone binary
    # models.
    assert hasattr(m.binary_instance, "KIN")
    assert hasattr(m, "KIN")
    verify_stand_alone_binary_parameter_updates(m)
Exemplo n.º 34
0
def wb():
    m = get_model(join(datadir, "NGC6440E.par"))
    t = make_fake_toas(55000, 58000, 20, model=m, freq=1400 * u.MHz, dm=10 * pint.dmu)

    wb = WidebandTOAFitter(t, m)
    wb.fit_toas()

    return wb
Exemplo n.º 35
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.º 36
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.º 37
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.º 38
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.º 39
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.º 40
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.º 41
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 = Residuals(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.º 42
0
 def setUpClass(cls):
     os.chdir(datadir)
     cls.par = "NGC6440E.par"
     cls.tim = "NGC6440E.tim"
     cls.m = get_model(cls.par)
     cls.t = toa.get_TOAs(cls.tim, ephem="DE421")
     cls.wls = WLSFitter(cls.t, cls.m)
     cls.gls = GLSFitter(cls.t, cls.m)
     cls.gls_full = GLSFitter(cls.t, cls.m)
Exemplo n.º 43
0
 def setUpClass(cls):
     os.chdir(datadir)
     cls.parf = "B1855+09_NANOGrav_9yv1.gls.par"
     cls.timf = "B1855+09_NANOGrav_9yv1.tim"
     cls.toas = toa.get_TOAs(cls.timf, ephem="DE421", planets=False)
     cls.model = mb.get_model(cls.parf)
     cls.sort_toas = copy.deepcopy(cls.toas)
     cls.sort_toas.table.sort("mjd_float")
     cls.sort_toas.table["index"] = range(cls.sort_toas.ntoas)
Exemplo n.º 44
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.º 45
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.º 46
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.º 47
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.º 48
0
def check_tempo_output(parf, timf, result_par):
    """Check out tempo output
    """
    a = subprocess.check_output('tempo -f '+ parf + ' '+timf, shell=True)
    tempo_m = mb.get_model(result_par)
    info_idx = a.index('Weighted RMS residual: pre-fit')
    res = a[info_idx:-1]
    mpre = re.search('pre-fit(.+?)us', res)
    mpost = re.search('post-fit(.+?)us', res)
    mchi = re.search('=(.+?)pre/post', res)
    try:
        pre_rms = float(mpre.group(1))
        post_rms = float(mpost.group(1))
        chi = float(mchi.group(1))
    except ValueError:
        pre_rms = mpre.group(1)
        post_rms = mpost.group(1)
        chi  = mchi.group(1)
        if chi.startswith('**'):
            chi = 0.0
    return tempo_m, pre_rms, post_rms, chi
Exemplo n.º 49
0
 def test_write(self):
     # change parameter value
     for p in self.modelB1855.params:
         par = getattr(self.modelB1855, p)
         # Change value for 20%
         if isinstance(par.value, numbers.Number):
             ov = par.value
             if isinstance(par, mp.MJDParameter):
                 continue
             else:
                 par.value = ov * 0.8
     self.res = resids(self.toasB1855, self.modelB1855, False).time_resids.to(u.s)
     f = open(self.out_parfile, 'w')
     f.write(self.modelB1855.as_parfile())
     f.close()
     read_model = mb.get_model(self.out_parfile)
     read_res = resids(self.toasB1855, read_model, False).time_resids.to(u.s)
     assert np.all(np.abs(read_res.value - self.res.value) < 1e-15), 'Output parfile did not produce same residuals.'
     for pp in self.modelB1855.params:
         par_ori = getattr(self.modelB1855, pp)
         par_read = getattr(read_model, pp)
         if par_ori.uncertainty_value is not None:
             unc_diff = par_ori.uncertainty_value - par_read.uncertainty_value
             assert np.abs(unc_diff) < 1e-15, pp + 'uncertainty does not keep the precision. at' + str(np.abs(unc_diff)) 
Exemplo n.º 50
0
def check_tempo2_output(parf, timf, p, result_par):
    """Check out tempo2 output
    """
    res = subprocess.check_output('tempo2 -f '+ parf + ' '+timf+' -norescale -newpar', shell=True)
    mpre =  re.search('RMS pre-fit residual =(.+?)(us)', res)
    mpost = re.search('RMS post-fit residual =(.+?)(us)', res)
    mchi = re.search('Chisqr/nfree =(.+?)/', res)
    m = mb.get_model(result_par)
    mpostn = re.findall(r'\d+\.\d+',mpost.group(1))
    try:
        pre_rms = float(mpre.group(1))
    except ValueError:
        pre_rms = mpre.group(1)
    try:
        post_rms = float(mpostn[0])
    except ValueError:
        post_rms = mpost.group(1)
    try:
        chi = float(mchi.group(1))/len(t.table)
    except:
        chi  = mchi.group(1)
    pv = getattr(m, p).value
    pu = getattr(m, p).uncertainty_value
    return pv, pu, post_rms, chi
Exemplo n.º 51
0
def testdiff(model,dy,step):
    Pars = model.params
    dervs = {}
    for p in Pars:
        if p is 'EDOT':
            stepv = 1e-19
        elif p is 'PBDOT':
            stepv = 1e-7
        else:
            stepv = step
        print p
        c = test_diff(model,p,dy)
        pv = getattr(model,p).value
        numr = c.num_diff(stepv,pv)
        try:
            anlog = model.prtl_der(dy,p)
        except:
            if dy.startswith('delay'):
                anlog = getattr(model,'d_delay'+dy[5]+'_d_par')(p)
            else:
                raise ValueError('Wrong delay')
        print "Maximum error ", (numr.value - anlog.value).max()
        dervs[p+'_num'] = numr
        dervs[p+'_anlg'] = anlog
    return dervs
ddm = mb.get_model('B1855+09_NANOGrav_dfg+12_modified.par')
t = toa.get_TOAs("B1855+09_NANOGrav_dfg+12.tim",planets = True)
ddob = ddm.get_dd_object(t.table)
diff = testdiff(ddob,'delayInverse',1e-7)
Exemplo n.º 52
0
 def setUpClass(self):
     # This uses ELONG and ELAT
     self.m1 = mb.get_model('B1855+09_NANOGrav_9yv1.gls.par')
     # This uses RA and DEC
     self.m2 = mb.get_model('B1855+09_NANOGrav_dfg+12_TAI_FB90.par')
     self.t = 5000 * np.random.randn(100) + 49453.0
Exemplo n.º 53
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.º 54
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.º 55
0
 def setUpClass(self):
     self.m = mb.get_model('B1855+09_NANOGrav_dfg+12_modified.par')
     self.mp = mb.get_model('prefixtest.par')
Exemplo n.º 56
0
    def test_read_par_line(self):
        test_m = mb.get_model('test_par_read.par')
        self.assertEqual(test_m.F2.frozen, True)
        self.assertEqual(test_m.F3.frozen, True)
        self.assertTrue(
                numpy.isclose(test_m.F3.value, 0.0))
        self.assertTrue(
                numpy.isclose(test_m.F3.uncertainty_value, 0.0))
        self.assertEqual(test_m.F4.frozen, True)
        self.assertTrue(
                numpy.isclose(test_m.F4.value, 0.0))
        self.assertTrue(
                numpy.isclose(test_m.F4.uncertainty_value, 0.001))
        self.assertEqual(test_m.F5.frozen, True)
        self.assertTrue(
                numpy.isclose(test_m.F5.value, 0.0))
        self.assertTrue(
                numpy.isclose(test_m.F5.uncertainty_value, 0.001))
        self.assertEqual(test_m.F6.frozen, False)
        self.assertTrue(
                numpy.isclose(test_m.F6.value, 0.0))
        self.assertTrue(
                numpy.isclose(test_m.F6.uncertainty_value, 0.001))
        self.assertEqual(test_m.F7.frozen, True)
        self.assertTrue(
                numpy.isclose(test_m.F7.value, 0.0))
        self.assertTrue(
                numpy.isclose(test_m.F7.uncertainty_value, 3.0))
        self.assertEqual(test_m.F8.frozen, True)
        self.assertTrue(
                numpy.isclose(test_m.F8.value, 0.0))
        self.assertTrue(
                numpy.isclose(test_m.F8.uncertainty_value, 10))
        self.assertEqual(test_m.JUMP1.frozen, True)
        self.assertEqual(test_m.JUMP1.key, 'MJD')
        self.assertTrue(
                numpy.isclose(test_m.JUMP1.key_value[0].value, 52742.0, atol=1e-10))
        self.assertTrue(
                numpy.isclose(test_m.JUMP1.key_value[1].value, 52745.0, atol=1e-10))
        self.assertTrue(
                numpy.isclose(test_m.JUMP1.value, 0.2))

        self.assertEqual(test_m.JUMP2.frozen, True)
        self.assertTrue(
                numpy.isclose(test_m.JUMP2.value, 0.1))
        self.assertTrue(
                numpy.isclose(test_m.JUMP2.uncertainty_value, 0.0))
        self.assertTrue(
                numpy.isclose(test_m.JUMP7.value, 0.1))
        self.assertTrue(
                numpy.isclose(test_m.JUMP7.uncertainty_value, 10.5))
        self.assertTrue(
                numpy.isclose(test_m.JUMP6.value, 0.1))
        self.assertTrue(
                numpy.isclose(test_m.JUMP6.uncertainty_value, 10.0))
        self.assertEqual(test_m.JUMP12.key, '-testflag')
        self.assertEqual(test_m.JUMP12.frozen, False)
        self.assertEqual(test_m.JUMP12.key_value[0], 'flagvalue')
        self.assertTrue(
                numpy.isclose(test_m.JUMP12.value, 0.1))
        self.assertTrue(
                numpy.isclose(test_m.JUMP12.uncertainty_value, 2.0))
Exemplo n.º 57
0
    description="Reference epoch for phase = 0.0",
    parse_value=lambda x: time_from_mjd_string(x, scale="tdb"),
)
print "Before assigning paramMJD value."
print "paramMJD num value is ", longdouble2string(paramMJD.num_value)
print "paramMJD value is      ", paramMJD.value, "With type ", type(paramMJD.value)
print "paramMJD unit is       ", paramMJD.units
print "paramMJD num unit is  ", paramMJD.num_unit
paramMJD.set("54001.012345678901234")
print "After assigning paramMJD value."
print "paramMJD num value is ", longdouble2string(paramMJD.num_value)
print "paramMJD value is      ", paramMJD.value, "With type ", type(paramMJD.value)
print "paramMJD unit is       ", paramMJD.units
print "paramMJD num unit is  ", paramMJD.num_unit
# change num_value
paramMJD.num_value = data2longdouble("54001.012345678901234")
print "After assigning paramMJD num_value."
print "paramMJD num value is ", longdouble2string(paramMJD.num_value)
print "paramMJD value is      ", paramMJD.value, "With type ", type(paramMJD.value)
print "paramMJD unit is       ", paramMJD.units
print "paramMJD num unit is  ", paramMJD.num_unit

print "\n\n\n\n"
model = mb.get_model("J1744-1134.basic.par")

for pn in model.params:
    p = getattr(model, pn)
    print "Parameter name :", p.name
    print "Value is ", p.value, "num_value is ", p.num_value
    print "Unit is ", p.units, "num unit is ", p.num_unit
Exemplo n.º 58
0
#! /usr/bin/env python
import pint.toa
import pint.models
import pint.fitter
import pint.residuals
import pint.models.model_builder as mb
import matplotlib.pyplot as plt
import astropy.units as u
import os, sys

datadir = os.path.dirname(os.path.abspath(__file__))
parfile = os.path.join(datadir, 'NGC6440E.par')
timfile = os.path.join(datadir, 'NGC6440E.tim')

# Define the timing model
m = mb.get_model(parfile)

# Read in the TOAs
t = pint.toa.get_TOAs(timfile)

# These are pre-fit residuals
rs = pint.residuals.resids(t, m).phase_resids
xt = t.get_mjds()
plt.plot(xt, rs, 'x')
plt.title("%s Pre-Fit Timing Residuals" % m.PSR.value)
plt.xlabel('MJD')
plt.ylabel('Residual (phase)')
plt.grid()
plt.show()

# Now do the fit
Exemplo n.º 59
0
    def test_read_par_line(self):
        test_m = mb.get_model('test_par_read.par')
        self.assertEqual(test_m.F2.frozen, True)
        self.assertEqual(test_m.F3.frozen, True)
        self.assertTrue(
                numpy.isclose(test_m.F3.value, 0.0))
        self.assertTrue(
                numpy.isclose(test_m.F3.uncertainty_value, 0.0))
        self.assertEqual(test_m.F4.frozen, True)
        self.assertTrue(
                numpy.isclose(test_m.F4.value, 0.0))
        self.assertTrue(
                numpy.isclose(test_m.F4.uncertainty_value, 0.001))
        self.assertEqual(test_m.F5.frozen, True)
        self.assertTrue(
                numpy.isclose(test_m.F5.value, 0.0))
        self.assertTrue(
                numpy.isclose(test_m.F5.uncertainty_value, 0.001))
        self.assertEqual(test_m.F6.frozen, False)
        self.assertTrue(
                numpy.isclose(test_m.F6.value, 0.0))
        self.assertTrue(
                numpy.isclose(test_m.F6.uncertainty_value, 0.001))
        self.assertEqual(test_m.F7.frozen, True)
        self.assertTrue(
                numpy.isclose(test_m.F7.value, 0.0))
        self.assertTrue(
                numpy.isclose(test_m.F7.uncertainty_value, 3.0))
        self.assertEqual(test_m.F8.frozen, True)
        self.assertTrue(
                numpy.isclose(test_m.F8.value, 0.0))
        self.assertTrue(
                numpy.isclose(test_m.F8.uncertainty_value, 10))
        self.assertEqual(test_m.JUMP1.frozen, True)
        self.assertEqual(test_m.JUMP1.key, 'MJD')
        self.assertTrue(
                numpy.isclose(test_m.JUMP1.key_value[0], 52742.0, atol=1e-10))
        self.assertTrue(
                numpy.isclose(test_m.JUMP1.key_value[1], 52745.0, atol=1e-10))
        self.assertTrue(
                numpy.isclose(test_m.JUMP1.value, 0.2))

        self.assertEqual(test_m.JUMP2.frozen, True)
        self.assertTrue(
                numpy.isclose(test_m.JUMP2.value, 0.1))
        self.assertTrue(
                numpy.isclose(test_m.JUMP2.uncertainty_value, 0.0))
        self.assertTrue(
                numpy.isclose(test_m.JUMP7.value, 0.1))
        self.assertTrue(
                numpy.isclose(test_m.JUMP7.uncertainty_value, 10.5))
        self.assertTrue(
                numpy.isclose(test_m.JUMP6.value, 0.1))
        self.assertTrue(
                numpy.isclose(test_m.JUMP6.uncertainty_value, 10.0))
        self.assertEqual(test_m.JUMP12.key, '-testflag')
        self.assertEqual(test_m.JUMP12.frozen, False)
        self.assertEqual(test_m.JUMP12.key_value[0], 'flagvalue')
        self.assertTrue(
                numpy.isclose(test_m.JUMP12.value, 0.1))
        self.assertTrue(
                numpy.isclose(test_m.JUMP12.uncertainty_value, 2.0))
        self.assertTrue(
                numpy.isclose(test_m.RAJ.uncertainty_value, 476.94611148516092061223))

        self.assertTrue(
                numpy.isclose(test_m.DECJ.uncertainty_value, 190996312986311097848351.00000000000000000000))
        self.assertTrue(test_m.RAJ.uncertainty.unit, pint_units['hourangle_second'])
        self.assertTrue(test_m.RAJ.uncertainty.unit, u.arcsecond)
Exemplo n.º 60
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)