How to use the pint.residuals.Residuals 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_residuals.py View on Github external
def test_combined_residuals(self):
        phase_res = Residuals(toas=self.toa, model=self.model)
        dm_res = Residuals(toas=self.toa, model=self.model, residual_type="dm")
        cb_residuals = CombinedResiduals([phase_res, dm_res])
        cb_chi2 = cb_residuals.chi2

        assert len(cb_residuals.resids) == 2 * self.toa.ntoas
        assert cb_residuals.unit == [u.s, u.pc / u.cm ** 3]
        assert cb_chi2 == phase_res.chi2 + dm_res.chi2
github nanograv / PINT / tests / test_parfile_writing.py View on Github external
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:
github nanograv / PINT / tests / test_model_ifunc.py View on Github external
# test a fit
        f = pint.fitter.WLSFitter(self.t, self.m)
        f.fit_toas()
        rs = f.resids
        rms = rs.time_resids.to(u.us).std()
        chi2 = rs.get_reduced_chi2()
        emsg = "RMS of " + str(rms.value) + " is too big."
        assert rms < 2700.0 * u.us, emsg
        emsg = "reduced chi^2 of " + str(chi2.value) + " is too big."
        assert chi2.value < 1.1, emsg

        # the residuals are actually terrible when using linear interpolation,
        # so this test just makes sure there are no access errors
        print("Test RMS of a PSR J0007+7303 ephemeris with IFUNCs(0).")
        self.m.SIFUNC.quantity = 0
        rs = pint.residuals.Residuals(self.t, self.m)
github nanograv / PINT / tests / test_ddk.py View on Github external
def test_J1713(self):
        log = logging.getLogger("TestJ1713.test_J1713")
        pint_resids_us = Residuals(
            self.toasJ1713, self.modelJ1713, use_weighted_mean=False
        ).time_resids.to(u.s)
        diff = pint_resids_us.value - self.ltres
        log.debug("Max diff %lf" % np.abs(diff - diff.mean()).max())
        assert np.all(np.abs(diff - diff.mean()) < 5e-7), "DDK J1713 TEST FAILED"
github nanograv / PINT / tests / test_fbx.py View on Github external
def test_J0023(self):
        pint_resids_us = Residuals(
            self.toasJ0023, self.modelJ0023, use_weighted_mean=False
        ).time_resids.to(u.s)
        assert np.all(
            np.abs(pint_resids_us.value - self.ltres) < 1e-8
        ), "J0023 residuals test failed."
github nanograv / PINT / tests / test_early_chime_data.py View on Github external
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)
        # Comment out the following test for now, since the new residual
github nanograv / PINT / src / pint / pintk / pulsar.py View on Github external
def update_resids(self):
        # update the pre and post fit residuals using all_toas
        self.prefit_resids = Residuals(self.all_toas, self.prefit_model)
        if self.fitted:
            self.postfit_resids = Residuals(self.all_toas, self.postfit_model)
github nanograv / PINT / docs / examples / fit_NGC6440E_MCMC.py View on Github external
print(parfile)
print(timfile)
nwalkers = 50
nsteps = 2000

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

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

# Print a summary of the TOAs that we have
t.print_summary()

# These are pre-fit residuals
rs = pint.residuals.Residuals(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
print("Fitting...")
sampler = pint.sampler.EmceeSampler(nwalkers)
f = pint.mcmc_fitter.MCMCFitter(
    t,
    m,
    sampler,
    resids=True,
github nanograv / PINT / src / pint / fitter.py View on Github external
def __init__(self, toas, model, residuals=None):
        self.toas = toas
        self.model_init = model
        if residuals is None:
            self.resids_init = Residuals(toas=toas, model=model)
            self.reset_model()
        else:
            # residuals were provided, we're just going to use them
            # probably using GLSFitter to compute a chi-squared
            self.model = copy.deepcopy(self.model_init)
            self.resids = residuals
            self.fitresult = []
        self.method = None