How to use the pint.models.get_model 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 / pint / scripts / htest_optimize.py View on Github external
def main(argv=None):

    if len(argv)==3:
        eventfile, parfile, weightcol = sys.argv[1:]
    elif len(argv)==2:
        eventfile, parfile = sys.argv[1:]
        weightcol=None
    else:
        print("usage: htest_optimize eventfile parfile [weightcol]")
        sys.exit()

    # Read in initial model
    modelin = pint.models.get_model(parfile)
    # Remove the dispersion delay as it is unnecessary
    modelin.delay_funcs['L1'].remove(modelin.dispersion_delay)
    # Set the target coords for automatic weighting if necessary
    if 'ELONG' in modelin.params:
        tc = SkyCoord(modelin.ELONG.quantity,modelin.ELAT.quantity,
            frame='barycentrictrueecliptic')
    else:
        tc = SkyCoord(modelin.RAJ.quantity,modelin.DECJ.quantity,frame='icrs')

    target = tc if weightcol=='CALC' else None

    # TODO: make this properly handle long double
    if not (os.path.isfile(eventfile+".pickle") or
        os.path.isfile(eventfile+".pickle.gz")):
        # Read event file and return list of TOA objects
        tl = fermi.load_Fermi_TOAs(eventfile, weightcolumn=weightcol,
github nanograv / PINT / src / pint / scripts / htest_optimize.py View on Github external
def main(argv=None):

    if len(argv) == 3:
        eventfile, parfile, weightcol = sys.argv[1:]
    elif len(argv) == 2:
        eventfile, parfile = sys.argv[1:]
        weightcol = None
    else:
        print("usage: htest_optimize eventfile parfile [weightcol]")
        sys.exit()

    # Read in initial model
    modelin = pint.models.get_model(parfile)
    # Remove the dispersion delay as it is unnecessary
    modelin.delay_funcs.remove(modelin.dispersion_delay)
    # Set the target coords for automatic weighting if necessary
    if "ELONG" in modelin.params:
        tc = SkyCoord(
            modelin.ELONG.quantity,
            modelin.ELAT.quantity,
            frame="barycentrictrueecliptic",
        )
    else:
        tc = SkyCoord(modelin.RAJ.quantity, modelin.DECJ.quantity, frame="icrs")

    target = tc if weightcol == "CALC" else None

    # TODO: make this properly handle long double
    if not (
github nanograv / PINT / tests / test_absphase.py View on Github external
def test_phase_zero(self):
        # Check that model phase is 0.0 for a TOA at exactly the TZRMJD
        model = pint.models.get_model(parfile)
        toas = pint.toa.get_TOAs(timfile)

        ph = model.phase(toas,abs_phase=True)
        # Check that integer and fractional phase values are very close to 0.0
        self.assertAlmostEqual(ph[0].value,0.0)
        self.assertAlmostEqual(ph[1].value,0.0)
github nanograv / PINT / tests / test_priors.py View on Github external
def setUpClass(cls):
        os.chdir(datadir)
        cls.m = pint.models.get_model("B1855+09_NANOGrav_dfg+12_modified.par")
github nanograv / PINT / tests / test_change_epoch.py View on Github external
def model(request):
    parfile = os.path.join(datadir, request.param)
    return models.get_model(parfile)
github nanograv / PINT / examples / testfermi.py View on Github external
# Read event file and return list of TOA objects
    tl  = load_Fermi_TOAs(eventfile,weightcolumn=weightcol)

    # Now convert to TOAs object and compute TDBs and posvels
    ts = toa.TOAs(toalist=tl)
    ts.filename = eventfile
    ts.compute_TDBs()
    ts.compute_posvels(ephem=ephem,planets=planets)

    print(ts.get_summary())

    #print(ts.table)

    # Read in initial model
    modelin = pint.models.get_model(parfile)

    # Remove the dispersion delay as it is unnecessary
    modelin.delay_funcs.remove(modelin.dispersion_delay)

    # Compute model phase for each TOA
    phss = modelin.phase(ts.table)[1]
    # ensure all postive
    phases = np.where(phss < 0.0, phss + 1.0, phss)
    mjds = ts.get_mjds()
    weights = np.array([w['weight'] for w in ts.table['flags']])
    phaseogram(mjds,phases,weights)
github nanograv / PINT / src / pint / scripts / event_optimize_MCMCFitter.py View on Github external
burnin = args.burnin
    nsteps = args.nsteps
    if burnin >= nsteps:
        log.error("burnin must be < nsteps")
        sys.exit(1)
    nbins = 256  # For likelihood calculation based on gaussians file
    outprof_nbins = 256  # in the text file, for pygaussfit.py, for instance
    minMJD = args.minMJD
    maxMJD = args.maxMJD  # Usually set by coverage of IERS file

    minWeight = args.minWeight
    do_opt_first = args.doOpt
    wgtexp = args.wgtexp

    # Read in initial model
    modelin = pint.models.get_model(parfile)

    # The custom_timing version below is to manually construct the TimingModel
    # class, which allows it to be pickled. This is needed for parallelizing
    # the emcee call over a number of threads.  So far, it isn't quite working
    # so it is disabled.  The code above constructs the TimingModel class
    # dynamically, as usual.
    # modelin = custom_timing(parfile)

    # Remove the dispersion delay as it is unnecessary
    # modelin.delay_funcs['L1'].remove(modelin.dispersion_delay)
    # Set the target coords for automatic weighting if necessary
    if "ELONG" in modelin.params:
        tc = SkyCoord(
            modelin.ELONG.quantity,
            modelin.ELAT.quantity,
            frame="barycentrictrueecliptic",
github nanograv / PINT / src / pint / scripts / event_optimize_multiple.py View on Github external
nwalkers = args.nwalkers
    burnin = args.burnin
    nsteps = args.nsteps
    if burnin >= nsteps:
        log.error("burnin must be < nsteps")
        sys.exit(1)
    nbins = 256  # For likelihood calculation based on gaussians file
    outprof_nbins = 256  # in the text file, for pygaussfit.py, for instance
    minMJD = args.minMJD
    maxMJD = args.maxMJD  # Usually set by coverage of IERS file

    minWeight = args.minWeight
    wgtexp = args.wgtexp

    # Read in initial model
    modelin = pint.models.get_model(parfile)

    # Set the target coords for automatic weighting if necessary
    if "ELONG" in modelin.params:
        tc = SkyCoord(
            modelin.ELONG.quantity,
            modelin.ELAT.quantity,
            frame="barycentrictrueecliptic",
        )
    else:
        tc = SkyCoord(modelin.RAJ.quantity, modelin.DECJ.quantity, frame="icrs")

    eventinfo = load_eventfiles(
        args.eventfiles, tcoords=tc, minweight=minWeight, minMJD=minMJD, maxMJD=maxMJD
    )

    nsets = len(eventinfo["toas"])
github nanograv / PINT / profiling / bench_chisq_grid_WLSFitter.py View on Github external
# 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()

# Fit 3 x 3 grid of chisq values
n = 3
sini_grid = np.sin(np.linspace(86.25 * u.deg, 88.5 * u.deg, n))
m2_grid = np.linspace(0.2 * u.solMass, 0.30 * u.solMass, n)
thankftr_chi2grid = grid_chisq(thankftr, "M2", m2_grid, "SINI", sini_grid)

print()
print("Number of TOAs: " + str(thanktoas.ntoas))
print("Grid size of parameters: " + str(n) + "x" + str(n))
print("Number of fits: 1")
print()
github nanograv / PINT / pint / ltinterface.py View on Github external
def loadparfile(self, parfile):
        """
        Load a parfile with pint

        :param parfile:
            Name of the parfile
        """

        self.model = pm.get_model(parfile)
        log.info("model.as_parfile():\n%s"%self.model.as_parfile())

        try:
            self.planets = self.model.PLANET_SHAPIRO.value
        except AttributeError:
            self.planets = False

        self._readparams()