pint.gridutils.tuple_chisq

pint.gridutils.tuple_chisq(ftr, parnames, parvalues, extraparnames=[], executor=None, ncpu=None, chunksize=1, printprogress=True, **fitargs)[source]

Compute chisq over a list of parameter tuples

Parameters:
Returns:

  • np.ndarray (array of chisq values)

  • extraout (dict of np.ndarray) – Parameter values computed at each point for extraparnames

Example

>>> import astropy.units as u
>>> import numpy as np
>>> import pint.config
>>> import pint.gridutils
>>> from pint.fitter import WLSFitter
>>> from pint.models.model_builder import get_model, get_model_and_toas
# Load in a basic dataset
>>> parfile = pint.config.examplefile("NGC6440E.par")
>>> timfile = pint.config.examplefile("NGC6440E.tim")
>>> m, t = get_model_and_toas(parfile, timfile)
>>> f = WLSFitter(t, m)
# find the best-fit
>>> f.fit_toas()
>>> bestfit = f.resids.chi2
# We'll do something like 3-sigma around the best-fit values of  F0
>>> F0 = np.linspace(f.model.F0.quantity - 3 * f.model.F0.uncertainty,f.model.F0.quantity + 3 * f.model.F0.uncertainty,25)
>>> F1 = np.ones(len(F0))*f.model.F1.quantity
>>> chi2_F0,extra = pint.gridutils.tuple_chisq(f, ("F0","F1",), parvalues, extraparnames=("DM",))

Notes

By default, it will create ProcessPoolExecutor with max_workers equal to the desired number of cpus. However, if you are running this as a script you may need something like:

import multiprocessing

if __name__ == "__main__":
    multiprocessing.freeze_support()
    ...
    tuple_chisq(...)

If an instantiated Executor is passed instead, it will be used as-is.

The behavior for different combinations of executor and ncpu is: +—————–+——–+————————+ | executor | ncpu | result | +=================+========+========================+ | existing object | any | uses existing executor | +—————–+——–+————————+ | None | 1 | uses single-processor | +—————–+——–+————————+ | None | None | creates default | | | | executor with | | | | cpu_count workers | +—————–+——–+————————+ | None | >1 | creates default | | | | executor with desired | | | | number of workers | +—————–+——–+————————+

Other Executors can be found for different computing environments: * [1] for MPI * [2] for SLURM or Condor