How to use the pint.toa.get_TOAs function in Pint

To help you get started, we’ve selected a few Pint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nanograv / PINT / tests / test_fitter.py View on Github external
def test_ftest():
    """Test for 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, float) or isinstance(ft, bool)
    # Test return the full output
    ft, r_rms, chi2, dof = f.ftest(FD4, "FD", remove=False, full_output=True)
    # 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, float) or isinstance(ft, bool)
github nanograv / PINT / tests / test_model.py View on Github external
# log.setLevel('INFO')
    os.chdir(datadir)

    parfile = "J1744-1134.basic.par"
    t1_parfile = "J1744-1134.t1.par"
    timfile = "J1744-1134.Rcvr1_2.GASP.8y.x.tim"

    m = tm.get_model(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, include_bipm=False, 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 = Residuals(t, m, use_weighted_mean=False).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:
    log.info("RMS PINT residuals are %.3f us" % resids_us.std().value)
github nanograv / PINT / tests / test_dd.py View on Github external
def setUpClass(cls):
        os.chdir(datadir)
        cls.parfileB1855 = "B1855+09_NANOGrav_dfg+12_modified_DD.par"
        cls.timB1855 = "B1855+09_NANOGrav_dfg+12.tim"
        cls.toasB1855 = toa.get_TOAs(
            cls.timB1855, ephem="DE405", planets=False, include_bipm=False
        )
        cls.modelB1855 = mb.get_model(cls.parfileB1855)
        # libstempo result
        cls.ltres, cls.ltbindelay = np.genfromtxt(
            cls.parfileB1855 + ".tempo_test", unpack=True
        )
github nanograv / PINT / tests / test_B1855_9yrs.py View on Github external
def setUpClass(cls):
        os.chdir(datadir)
        cls.parfileB1855 = "B1855+09_NANOGrav_9yv1.gls.par"
        cls.timB1855 = "B1855+09_NANOGrav_9yv1.tim"
        cls.toasB1855 = toa.get_TOAs(
            cls.timB1855, ephem="DE421", planets=False, include_bipm=False
        )
        cls.modelB1855 = mb.get_model(cls.parfileB1855)
        # tempo result
        cls.ltres = np.genfromtxt(
            cls.parfileB1855 + ".tempo2_test", skip_header=1, unpack=True
        )
github nanograv / PINT / tests / test_toa_writer.py View on Github external
def test_roundtrip_topo_toa_TEMPOformat(self):
        # Create a barycentric TOA
        t1time = Time(58534.0, 0.0928602471130208, format="mjd", scale="utc")
        t1 = toa.TOA(t1time, obs="gbt", freq=0.0)
        ts = toa.get_TOAs_list([t1], ephem="DE421")
        ts.write_TOA_file("testtopot1.tim", format="TEMPO")
        ts2 = toa.get_TOAs("testtopot1.tim")
        print(ts.table, ts2.table)
        assert np.abs(ts.table["mjd"][0] - ts2.table["mjd"][0]) < 1.0e-15 * u.d
        assert np.abs(ts.table["tdb"][0] - ts2.table["tdb"][0]) < 1.0e-15 * u.d

        # Comment out because TEMPO2 distro doesn't include gmrt2gps.clk so far
        # def test_roundtrip_gmrt_toa_Tempo2format(self):
        #     if os.getenv("TEMPO2") is None:
        #         pytest.skip("TEMPO2 evnironment variable is not set, can't run this test")
        #     # Create a barycentric TOA
        #     t1time = Time(58534.0, 0.0928602471130208, format="mjd", scale="utc")
        #     t1 = toa.TOA(t1time, obs="gmrt", freq=0.0)
        #     ts = toa.get_TOAs_list([t1], ephem="DE421")
        #     ts.write_TOA_file("testgmrt.tim", format="Tempo2")
        #     ts2 = toa.get_TOAs("testgmrt.tim")
        #     print(ts.table, ts2.table)
        assert np.abs(ts.table["mjd"][0] - ts2.table["mjd"][0]) < 1.0e-15 * u.d
github nanograv / PINT / src / pint / pintk / timedit.py View on Github external
def applyChanges(self):
        tfilename = tempfile.mkstemp()[1]
        tfile = open(tfilename, 'w')
        tfile.write(self.editor.get('1.0', 'end-1c'))
        tfile.close()
        self.psr.selected_toas = pint.toa.get_TOAs(tfilename)
        os.remove(tfilename)
        self.call_updates()
github nanograv / PINT / profiling / bench_chisq_grid.py View on Github external
#!/usr/bin/env python

import pint.toa
import pint.models
import pint.fitter
from pint.gridutils import grid_chisq
import numpy as np
import astropy.units as u

# Get .tim file and par file from here:
# curl -O https://data.nanograv.org/static/data/J0740+6620.cfr+19.tim
# curl -O https://data.nanograv.org/static/data/J0740+6620.par

# This will load the TOAs, compute the positions of the Earth and planets, and apply clock corrections and build the table.
thanktoas = pint.toa.get_TOAs(
    "J0740+6620.cfr+19.tim",
    ephem="DE436",
    planets=True,
    usepickle=False,
    include_gps=True,
    bipm_version="BIPM2017",
    include_bipm=True,
)

# Load model
thankmod = pint.models.get_model("J0740+6620.par")

# Fit one time
thankftr = pint.fitter.GLSFitter(toas=thanktoas, model=thankmod)
chisq = thankftr.fit_toas()
github nanograv / PINT / pint / fit_NGC6440E_orig.py View on Github external
import matplotlib.pyplot as plt

import astropy.units as u
import os

redge = 3
ledge = 0.5
datadir = os.path.dirname(os.path.abspath(str(__file__)))
parfile = os.path.join(datadir, 'NGC6440E.par.orig')
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)
t0 = pint.toa.get_TOAs(timfile)

print(t.table['groups'])
t.get_highest_density_range(70)
# Examples of how to select some subsets of TOAs
# These can be un-done using t.unselect()
#
# Use every other TOA
# t.select(np.where(np.arange(t.ntoas) % 2))

# Use only TOAs with errors < 30 us
# t.select(t.get_errors() < 30 * u.us)

# Use only TOAs from the GBT (although this is all of them for this example)
# t.select(t.get_obss() == 'gbt')
github nanograv / PINT / profiling / bench_chisq_grid_WLSFitter.py View on Github external
#!/usr/bin/env python

import pint.toa
import pint.models
import pint.fitter
from pint.gridutils import grid_chisq
import numpy as np
import astropy.units as u

# Get .tim file and par file from here:
# curl -O https://data.nanograv.org/static/data/J0740+6620.cfr+19.tim
# curl -O https://data.nanograv.org/static/data/J0740+6620.par

thanktoas = pint.toa.get_TOAs(
    "J0740+6620.cfr+19.tim",
    ephem="DE436",
    planets=True,
    usepickle=False,
    include_gps=False,
    bipm_version="BIPM2015",
    include_bipm=False,
)

# Load model
thankmod = pint.models.get_model("J0740+6620.par")

# Fit one time
thankftr = pint.fitter.WLSFitter(toas=thanktoas, model=thankmod)
chisq = thankftr.fit_toas()