pint.models.model_builder.ModelBuilder

class pint.models.model_builder.ModelBuilder[source]

Bases: object

Class for building a TimingModel object from a parameter file.

The ModelBuilder class helps building a TimingModel from a parameter file (i.e., pulsar ephemeris or ‘.par’ file). It first maps the provided parameter names to the PINT defined parameter names, if they are in the PINT parameter aliases list. Then, the ModelBuilder selects model components based on the following rules:

  • The components in the default_components list will be selected.

  • When a component get mapped uniquely by the given parameters.

  • The pulsar binary component will be selected by the ‘BINARY’ parameter.

Methods

choose_binary_model(param_inpar[, ...])

Choose the BINARY model based on the parfile.

choose_model(param_inpar[, ...])

Choose the model components based on the parfile.

__call__(parfile, allow_name_mixing=False, allow_tcb=False, allow_T2=False, force_binary_model=None, toas_for_tzr=None, **kwargs)[source]

Callable object for making a timing model from .par file.

Parameters:
  • parfile (str or file-like object) – Input .par file name or string contents

  • allow_name_mixing (bool, optional) – Flag for allowing the input to have mixing aliases names for the same parameter. For example, if this flag is true, one can have T2EFAC and EFAC, both of them maps to PINT parameter EFAC, present in the parfile at the same time.

  • allow_tcb (True, False, or "raw", optional) – Whether to read TCB par files. Default is False, and will throw an error upon encountering TCB par files. If True, the par file will be converted to TDB upon read. If “raw”, an unconverted malformed TCB TimingModel object will be returned.

  • allow_T2 (bool, optional) – Whether to convert a T2 binary model to an appropriate underlying binary model. Default is False, and will throw an error upon encountering the T2 binary model. If True, the binary model will be converted to the most appropriate PINT-compatible binary model.

  • force_binary_model (str, optional) – When set to some binary model, like force_binary_model=”DD”, this will override the binary model set in the parfile. Defaults to None

  • toas_for_tzr (TOAs or None, optional) – If this is not None, a TZR TOA (AbsPhase) will be created using the given TOAs object.

  • kwargs (dict) – Any additional parameter/value pairs that will add to or override those in the parfile.

Returns:

The result timing model based on the input .parfile or file object.

Return type:

pint.models.timing_model.TimingModel

choose_model(param_inpar, force_binary_model=None, allow_T2=False)[source]

Choose the model components based on the parfile.

Parameters:
  • param_inpar (dict) – Dictionary of the unique parameters in .par file with the key is the parfile line. parse_parfile() returns this dictionary.

  • allow_T2 (bool, optional) – Whether to convert a T2 binary model to an appropriate underlying binary model. Default is False, and will throw an error upon encountering the T2 binary model. If True, the binary model will be converted to the most appropriate PINT-compatible binary model.

  • force_binary_model (str, optional) – When set to some binary model, like force_binary_model=”DD”, this will override the binary model set in the parfile. Defaults to None

Returns:

  • list – List of selected components.

  • dict – Conflict components dictionary, where the key the component name, the value is a list of component names that are conflicted with the components in the key.

  • list – A list of parameters that are in the .parfile but not in the PINT defined parameters.

Note

The selection algorithm:
  1. Look at the BINARY in the par file and cache the indicated binary model

  2. Translate para file parameters to the pint parameter name

  3. Go over the parameter-component map and pick up the components based on the parameters in parfile.

    1. Select the components that have its unique parameters in the parfile. In other words, select the components that have one parameter to on component mapping.

    2. Log the conflict components, one parameter to multiple components mapping.

choose_binary_model(param_inpar, force_binary_model=None, allow_T2=False)[source]

Choose the BINARY model based on the parfile.

Parameters:
  • param_inpar (dict) – Dictionary of the unique parameters in .par file with the key is the parfile line. parse_parfile() returns this dictionary.

  • force_binary_model (str, optional) – When set to some binary model, like force_binary_model=”DD”, this will override the binary model set in the parfile. Defaults to None

  • allow_T2 (bool, optional) – Whether to convert a T2 binary model to an appropriate underlying binary model. Default is False, and will throw an error upon encountering the T2 binary model. If True, the binary model will be converted to the most appropriate PINT-compatible binary model.

Returns:

Name of the binary component

Return type:

str

Note

If the binary model does not have a PINT model (e.g. the T2 model), an error is thrown with the suggested model that could replace it. If allow_T2 is set to True, the most appropriate binary model is guessed and used. If an appropriate model cannot be found, no suggestion is given and an error is thrown.