コード例 #1
0
ファイル: test_fitter.py プロジェクト: cdeil/PINT
#! /usr/bin/env python
import time, sys, os
import pint.models as tm
from pint.phase import Phase
from pint import toa
from pint import fitter
import matplotlib.pyplot as plt
import numpy

from pinttestdata import testdir, datadir

# Get model
m = tm.StandardTimingModel()
m.read_parfile(os.path.join(datadir,'NGC6440E.par'))

# Get TOAs
t = toa.TOAs(os.path.join(datadir,'NGC6440E.tim'))
t.apply_clock_corrections()
t.compute_TDBs()
try:
    planet_ephems = m.PLANET_SHAPIRO.value
except AttributeError:
    planet_ephems = False
t.compute_posvels(planets=planet_ephems)

f=fitter.fitter(toas=t,model=m)

# Print initial chi2
print('chi^2 is initially %0.2f' % f.resids.chi2)

# Plot initial residuals
コード例 #2
0
    def __init__(self, parfile=None, timfile=None, testpulsar=False):
        """
        Initialize the pulsar object

        @param parfile:     Filename of par file
        @param timfile:     Filename of tim file
        @param testpulsar:  If true, load J1744 test pulsar
        """

        # Create a timing-model
        self._interface = "pint"
        m = tm.StandardTimingModel()

        if testpulsar:
            # Write a test-pulsar, and open that for testing
            parfilename = tempfile.mktemp()
            timfilename = tempfile.mktemp()
            parfile = open(parfilename, 'w')
            timfile = open(timfilename, 'w')
            parfile.write(J1744_parfile_basic)
            timfile.write(J1744_timfile)
            parfile.close()
            timfile.close()
        elif parfile is not None and timfile is not None:
            pass
        else:
            raise ValueError("No valid pulsar to load")

        # We have a par/tim file. Read them in!
        m.read_parfile(parfilename)

        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(timfilename)
        time_toa = time.time() - t0
        t.print_summary()

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

        self._mjds = t.get_mjds()
        #d_tdbs = np.array([x.tdb.delta_tdb_tt for x in t.table['mjd']])
        self._toaerrs = t.get_errors()
        resids = np.zeros_like(self._mjds)
        #ss_roemer = np.zeros_like(self._mjds)
        #ss_shapiro = np.zeros_like(self._mjds)

        sys.stderr.write("Computing residuals...\n")
        t0 = time.time()
        phases = m.phase(t.table)
        resids = phases.frac

        #for ii, tt in enumerate(t.table):
        #    p = m.phase(tt)
        #    resids[ii] = p.frac
        #    ss_roemer[ii] = m.solar_system_geometric_delay(tt)
        #    ss_shapiro[ii] = m.solar_system_shapiro_delay(tt)

        time_phase = time.time() - t0
        sys.stderr.write("Computed phases in %.3f sec\n" % time_phase)

        # resids in (approximate) us:
        self._resids_us = resids / float(m.F0.value) * 1e6
        sys.stderr.write("RMS PINT residuals are %.3f us\n" %
                         self._resids_us.std())

        # Create a dictionary of the fitting parameters
        self.pardict = OrderedDict()
        self.pardict['START'] = tempopar('START')
        self.pardict['FINISH'] = tempopar('FINISH')
        self.pardict['RAJ'] = tempopar('RAJ')
        self.pardict['DECJ'] = tempopar('DECJ')
        self.pardict['PMRA'] = tempopar('PMRA')
        self.pardict['PMDEC'] = tempopar('PMDEC')
        self.pardict['F0'] = tempopar('F0')
        self.pardict['F1'] = tempopar('F1')

        if testpulsar:
            os.remove(parfilename)
            os.remove(timfilename)