### Find Example Data File Path Source: https://github.com/nanograv/pint/wiki/How-To Use `pint.config.examplefile()` to get the full path to example data files. This is useful for tutorials and testing. ```python import pint.config fullfilename = pint.config.examplefile(filename) ``` ```python import pint fullfilename = pint.config.examplefile("NGC6440E.par") ``` -------------------------------- ### Install PINT from Source Source: https://github.com/nanograv/pint/blob/master/docs/basic-installation.md Clone the PINT repository from GitHub and install it locally. This method provides access to the source code, example notebooks, and tests. Ensure all dependencies are available before installation. ```default $ git checkout https://github.com/nanograv/PINT.git $ cd PINT $ pip install . ``` -------------------------------- ### Setup Virtualenv Environment for Development Source: https://github.com/nanograv/pint/blob/master/CONTRIBUTING.rst Set up a development environment using virtualenv and install PINT and its dependencies. ```bash mkvirtualenv pint-devel cd PINT/ pip install -r requirements_dev.txt pip install -e . pre-commit install ``` -------------------------------- ### Access Example Data Files Source: https://github.com/nanograv/pint/blob/master/docs/working-with-notebooks.md Use `pint.config.examplefile()` to get the full path to data files stored in `src/pint/data/examples`. Ensure data files are placed in this directory and documented in `README.md`. ```python import pint.config fullfilename = pint.config.examplefile(filename) ``` -------------------------------- ### Setup Conda Environment for Development Source: https://github.com/nanograv/pint/blob/master/CONTRIBUTING.rst Create and activate a conda environment, then install PINT and its development dependencies. ```bash conda create -n pint-devel python=3.10 conda activate pint-devel cd PINT/ conda install -c conda-forge --file requirements_dev.txt conda install -c conda-forge --file requirements.txt pip install -e . pre-commit install ``` -------------------------------- ### Install PINT from Source Source: https://github.com/nanograv/pint/blob/master/README.rst Clone the PINT repository from GitHub and install the latest development version. Ensure all dependencies are available before installation. ```bash git clone https://github.com/nanograv/PINT.git cd PINT pip install . ``` -------------------------------- ### Install PINT from Source Source: https://github.com/nanograv/pint/blob/master/docs/installation.md Clone the PINT repository, create and activate a virtual environment, and install PINT in editable mode using pip. ```shell $ git clone https://github.com/nanograv/PINT.git $ cd PINT $ mkvirtualenv -p `which python3` pint (pint) $ pip install -e . (pint) $ python >>> import pint ``` -------------------------------- ### Install PINT via pip Source: https://github.com/nanograv/pint/blob/master/README.rst Use this command to install the latest released version of PINT from PyPI. Appending '--user' installs it for the current user only. A virtual environment is recommended. ```bash pip install pint-pulsar ``` -------------------------------- ### Install Pandoc on Linux Source: https://github.com/nanograv/pint/blob/master/docs/installation.md Installs the pandoc document converter on Linux systems using apt. This is required for building PINT documentation. ```shell apt install pandoc ``` -------------------------------- ### Install PINT Development Requirements Source: https://github.com/nanograv/pint/blob/master/docs/development-setup.md Installs all necessary packages for PINT development from a requirements file. Ensure you are in your development virtual environment before running this command. ```bash pip install -Ur requirements_dev.txt ``` -------------------------------- ### Install Development Requirements Source: https://github.com/nanograv/pint/blob/master/profiling/README.txt Install Python packages required for development, including those needed for `run_profile.py` such as graphviz, gprof2dot, and py-cpuinfo. ```bash pip install -r requirements_dev.txt ``` -------------------------------- ### Install Pandoc on MacPorts Source: https://github.com/nanograv/pint/blob/master/docs/installation.md Installs the pandoc document converter on macOS using MacPorts. This is required for building PINT documentation. ```shell sudo port install pandoc ``` -------------------------------- ### Install Pint-Pulsar with Pip Source: https://github.com/nanograv/pint/blob/master/docs/installation.md Use this command to install the latest released version of Pint-Pulsar via pip. Consider using the --user flag for user-specific installation or a virtual environment. ```shell $ pip install pint-pulsar ``` -------------------------------- ### Setup Logging in a Script with Loguru Source: https://github.com/nanograv/pint/blob/master/docs/user-questions.md Integrate PINT's logging into your script using `loguru`. Customize the sink, level, and colorization. The `pint.logging.setup()` function handles logger configuration and suppression of verbose messages. ```python import pint.logging from loguru import logger as log pint.logging.setup(sink=sys.stderr, level="WARNING", usecolors=True) ``` -------------------------------- ### Setup PINT Logging Source: https://github.com/nanograv/pint/blob/master/docs/controlling-logging.md Configure PINT's logging to a specific level, such as DEBUG. This is useful for detailed debugging. ```python import pint.logging pint.logging.setup(level="DEBUG") ``` -------------------------------- ### Import PINT Libraries and Setup Source: https://github.com/nanograv/pint/wiki/files/grid_parameters.ipynb Imports necessary libraries for PINT, including configuration, grid utilities, parameter handling, residual calculations, fitting, model building, TOA handling, plotting, and logging. Sets up matplotlib for inline plotting and configures PINT logging to WARNING level. ```python import astropy.units as u import numpy as np import copy import pint.config import pint.gridutils import pint.models.parameter as param import pint.residuals from pint.fitter import WLSFitter from pint.models.model_builder import get_model, get_model_and_toas from pint.toa import get_TOAs import matplotlib.pyplot as plt from astropy.visualization import quantity_support import pint.logging quantity_support() import scipy.stats %matplotlib inline pint.logging.setup(level='WARNING') ``` -------------------------------- ### Load Data and Initial Fit Source: https://github.com/nanograv/pint/wiki/files/Grid_J0740.ipynb Loads example par and tim files, constructs a WidebandDownhillFitter, and performs an initial fit to the TOAs. This sets up the base model for further analysis. ```python parfile = pint.config.examplefile("J0740+6620.FCP+21.wb.DMX3.0.par") timfile = pint.config.examplefile("J0740+6620.FCP+21.wb.tim") m, t = get_model_and_toas(parfile, timfile) f = pint.fitter.WidebandDownhillFitter(t, m) f.fit_toas() print( f"Computed best-fit chi2={f.resids.chi2} at {datetime.datetime.now().isoformat()}" ) ``` -------------------------------- ### Import necessary libraries for PINT timing comparison Source: https://github.com/nanograv/pint/blob/master/profiling/paper_timing_tables/timing_comparison.ipynb Imports required libraries for PINT, subprocess operations, timing, and data handling. Ensure TEMPO, Tempo2, and astropy are installed. ```python from pint import toa from pint import models from pint import fitter import subprocess import timeit from os import path from astropy.table import Table from astropy.io import ascii ``` -------------------------------- ### Control Logging Level with Argparse Source: https://github.com/nanograv/pint/blob/master/docs/user-questions.md Configure script logging levels dynamically using `argparse`. This example shows how to add a `--log-level` argument and pass the selected level to `pint.logging.setup()`. ```python parser.add_argument( "--log-level", type=str, choices=("TRACE", "DEBUG", "INFO", "WARNING", "ERROR"), default=pint.logging.script_level, help="Logging level", dest="loglevel", ) ... pint.logging.setup(level=args.loglevel, ...) ``` -------------------------------- ### Print PINT, TEMPO, and TEMPO2 versions Source: https://github.com/nanograv/pint/blob/master/docs/examples-rendered/paper_validation_example.ipynb Use this snippet to print the installed versions of PINT, TEMPO, and TEMPO2. It utilizes subprocess to call the version flags for TEMPO and TEMPO2. ```python print("PINT version: ", pint.__version__) tempo_v = subprocess.check_output(["tempo", "-v"]) print("TEMPO version: ", tempo_v.decode("utf-8")) # Not sure why tempo2_v = subprocess.check_output(["tempo2", "-v"]) does not work. process = subprocess.Popen(["tempo2", "-v"], stdout=subprocess.PIPE) tempo2_v = process.communicate()[0] print("TEMPO2 version: ", tempo2_v.decode("utf-8")) ``` -------------------------------- ### Capture Warnings with Logging Source: https://github.com/nanograv/pint/blob/master/docs/controlling-logging.md Configure PINT's logging setup to capture Python warnings and emit them through the logging module. This is the default behavior. ```python pint.logging.setup(capturewarnings=True) ``` -------------------------------- ### Load and Best-Fit Data Source: https://github.com/nanograv/pint/wiki/files/grid_parameters.ipynb Loads a pulsar timing dataset using example par and tim files. Initializes a WLSFitter with the loaded data and performs an initial best-fit to determine the initial chi-squared value. ```python # 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 ``` -------------------------------- ### Parallel Execution Setup Source: https://github.com/nanograv/pint/wiki/files/Grid_J0740.ipynb Configures the executor for parallel processing. This example shows how to use ProcessPoolExecutor, but comments indicate options for SLURM and MPI. ```python # may be needed for some executables # multiprocessing.freeze_support() # use this for SLURM # with cfut.SlurmExecutor(debug=True,keep_logs=False,additional_setup_lines=slurm_options) as executor: # use this for MPI # with MPIPoolExecutor() as executor: # default (could also just not supply any executor) with concurrent.futures.ProcessPoolExecutor() as executor: ``` -------------------------------- ### Get Observatory Instance in PINT Source: https://github.com/nanograv/pint/blob/master/docs/explanation.md Import the observatory module and retrieve an observatory instance by its name. This is a common starting point for accessing observatory-specific data. ```python import pint.observatory gbt = pint.observatory.get_observatory("gbt") ``` -------------------------------- ### Add a New Logger with Existing Logger Source: https://github.com/nanograv/pint/blob/master/docs/controlling-logging.md Add a new logger, for example, to a file, without removing prior loggers. This is achieved by setting `removeprior=False` in the `setup()` function. ```python pint.logging.setup(level="INFO", removeprior=False) ``` -------------------------------- ### Run PINT Tests and Documentation Build Source: https://github.com/nanograv/pint/blob/master/CONTRIBUTING.rst Execute the test suite and build the documentation to ensure changes are correct and well-formatted. ```bash make test tox make docs ``` -------------------------------- ### Build Documentation Locally Source: https://github.com/nanograv/pint/blob/master/docs/editing-documentation.md Use 'make docs' to build the documentation locally. Alternatively, 'tox -e docs' followed by opening the HTML file in a browser can be used. For faster builds that only regenerate changed files, use 'make -C docs/ html'. ```shell $ make docs ``` ```shell $ tox -e docs $ firefox docs/_build/index.html ``` ```shell $ make -C docs/ html ``` -------------------------------- ### Set up Pint-Pulsar Environment with Pixi Source: https://github.com/nanograv/pint/blob/master/docs/installation.md Initialize a new Pixi environment named 'PINT', add pint-pulsar to it, and activate the environment for use. This is useful for managing dependencies in a dedicated environment. ```shell $ pixi init PINT $ cd PINT $ pixi add pint-pulsar $ pixi shell ``` -------------------------------- ### Initialize PINT model from TEMPO2 parameter file Source: https://github.com/nanograv/pint/blob/master/docs/examples-rendered/paper_validation_example.ipynb Initializes a PINT model using a TEMPO2-style parameter file. This step is crucial for comparing PINT's analysis with TEMPO2's. ```python m_t2 = models.get_model(tempo2_par) ``` -------------------------------- ### Install PINT via Conda Source: https://github.com/nanograv/pint/blob/master/README.rst Install the latest released version of PINT from the conda-forge channel using Anaconda Python. ```bash conda install -c conda-forge pint-pulsar ``` -------------------------------- ### Install Specific PINT Version with conda Source: https://github.com/nanograv/pint/blob/master/docs/user-questions.md Install a specific version of the PINT package using conda by appending '=version' to the package name. ```shell conda install pint-pulsar=0.8.4 ``` -------------------------------- ### Run Timing Analysis with Pintempo Source: https://github.com/nanograv/pint/blob/master/docs/command-line.md Utilize pintempo for timing analysis, similar to tempo or tempo2. Requires a parfile and a tim file as arguments. ```bash pintempo --plot NGC6440E.par NGC6440E.tim ``` -------------------------------- ### Install Specific PINT Version with pip Source: https://github.com/nanograv/pint/blob/master/docs/user-questions.md Install a specific version of the PINT package using pip by appending '==version' to the package name. ```shell pip install -U pint-pulsar==0.8.4 ``` -------------------------------- ### Download Benchmark Data Source: https://github.com/nanograv/pint/blob/master/profiling/README.txt Download the necessary .tim file for benchmarking. This file is large and not included with PINT. ```bash curl -O https://data.nanograv.org/static/data/J0740+6620.cfr+19.tim ``` -------------------------------- ### Launch PINT GUI Source: https://github.com/nanograv/pint/blob/master/docs/command-line.md Use pintk to launch the graphical user interface for PINT, which offers similar functionality to Tempo2's plk plugin. ```bash pintk NGC6440E.par NGC6440E.tim ``` -------------------------------- ### Install Pint-Pulsar with Anaconda Source: https://github.com/nanograv/pint/blob/master/docs/installation.md Install Pint-Pulsar from the conda-forge channel using the conda package manager. This is suitable for users who manage their Python environments with Anaconda. ```shell $ conda install -c conda-forge pint-pulsar ``` -------------------------------- ### Run High-Level Benchmark Suite Source: https://github.com/nanograv/pint/blob/master/profiling/README.txt Execute the main script to run the entire suite of PINT benchmarks. ```bash python high_level_benchmark.py ``` -------------------------------- ### FDJUMPDM Parameter Examples Source: https://github.com/nanograv/pint/blob/master/docs/explanation.md Examples of frequency-dependent DM jump (FDJUMPDM) parameters used to model system-dependent corrections to DM delay in narrowband TOAs. These are applied per system. ```par FDJUMPDM -f 430_PUPPI 1e-4 1 1e-5 ``` ```par FDJUMPDM -f L-wide_PUPPI 1e-4 1 1e-5 ``` -------------------------------- ### PHOFF Parameter Example Source: https://github.com/nanograv/pint/blob/master/docs/explanation.md Example of an overall phase offset (PHOFF) parameter in a pulsar ephemeris file. This parameter accounts for arbitrary phase differences between measured TOAs and the TZR TOA. ```par PHOFF 0.1 1 0.001 ``` -------------------------------- ### DMJUMP Parameter Examples Source: https://github.com/nanograv/pint/blob/master/docs/explanation.md Examples of dispersion measure jump (DMJUMP) parameters for modeling system-dependent offsets in wideband DM values. These parameters can be specified per system, observatory, MJD range, or frequency range. ```par DMJUMP -f 430_PUPPI 1e-4 1 1e-5 ``` ```par DMJUMP tel ao 1e-4 1 1e-5 ``` ```par DMJUMP mjd 55000 55100 1e-4 1 1e-5 ``` ```par DMJUMP freq 1000 1400 1e-4 1 1e-5 ``` -------------------------------- ### JUMP Parameter Examples Source: https://github.com/nanograv/pint/blob/master/docs/explanation.md Examples of phase jump (JUMP) parameters used to model system-dependent delays between TOAs from different observatories or systems. These can be applied based on system, observatory, MJD range, or frequency range. ```par JUMP -f 430_PUPPI 0.01 1 1e-5 ``` ```par JUMP tel ao 0.01 1 1e-5 ``` ```par JUMP mjd 55000 55100 0.01 1 1e-5 ``` ```par JUMP freq 1000 1400 0.01 1 1e-5 ``` -------------------------------- ### Release PINT Package Source: https://github.com/nanograv/pint/blob/master/docs/development-setup.md Execute this command to build distribution packages and upload them to PyPI. Ensure your PyPI API token is configured in `~/.pypirc`. ```bash make release ``` -------------------------------- ### FDJUMP Parameter Examples Source: https://github.com/nanograv/pint/blob/master/docs/explanation.md Examples of frequency-dependent jump (FDJUMP) parameters for modeling frequency-dependent artefacts in narrowband timing residuals, applied separately for different systems. FD1JUMP and FD2JUMP represent different orders of the log-polynomial function. ```par FD1JUMP -f L-wide_PUPPI 1e-4 1 1e-5 ``` ```par FD2JUMP -f L-wide_PUPPI 1e-4 1 1e-5 ``` ```par FD1JUMP -f 430_PUPPI 1e-4 1 1e-5 ``` ```par FD2JUMP -f 430_PUPPI 1e-4 1 1e-5 ``` -------------------------------- ### Create a New Git Branch Source: https://github.com/nanograv/pint/blob/master/docs/development-setup.md Start a new feature branch from the master branch. ```git git checkout master git checkout -b a-thing ``` -------------------------------- ### Run and Time Simple Model Case Comparison Source: https://github.com/nanograv/pint/blob/master/profiling/paper_timing_tables/timing_comparison.ipynb Compares the execution time of PINT (with and without pickling) against TEMPO and Tempo2 for a simple timing model. The results are stored in a table for later output. ```python ptimes_nopickle = [] ptimes_pickle = [] ttimes = [] t2times = [] for tim in timfiles_simple: print("With " + tim + "...") print("Running PINT fitting w/o pickling...") # run PINT w/o pickling and average time over 5 runs pintrun(par_simple, tim, ptimes_nopickle, pickle=False, fitter="wls") print("Running PINT w/ pickling...") # run PINT with pickling and average time over 5 runs subprocess.check_call( ["pintempo", "--usepickle", par_simple, tim], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, ) # create pickle file pintrun(par_simple, tim, ptimes_pickle, pickle=True, fitter="wls") print("Running TEMPO...") temporun(par_simple, tim, ttimes, fitter="wls") print("Running Tempo2...") tempo2run(par_simple, tim, t2times) # create table 7 in PINT paper simple_comparison = Table( (ntoas_simple, ttimes, t2times, ptimes_nopickle, ptimes_pickle), names=( "Number of TOAs", "TEMPO (sec)", "Tempo2 (sec)", "PINT - No Pickle (sec)", "PINT - Pickle (sec)", ), ) print("Done") ``` ```python # Write out results ascii.write( simple_comparison, "simple_tables.tex", Writer=ascii.AASTex, formats={ "TEMPO (sec)": "%.3f", "Tempo2 (sec)": "%.3f", "PINT - No Pickle (sec)": "%.3f", "PINT - Pickle (sec)": "%.3f", }, overwrite=True, ) ``` -------------------------------- ### Check PYTHONPATH Environment Variable Source: https://github.com/nanograv/pint/blob/master/docs/installation.md Verify if the PYTHONPATH environment variable is set, which can interfere with virtual environment installations. ```shell $ printenv PYTHONPATH ``` -------------------------------- ### Build Custom PINT Model with BT Component Source: https://github.com/nanograv/pint/wiki/Code-Architecture Construct a custom PINT timing model using specific components, such as the BT binary model, and load parameters from a .par file. ```python from .bt import BT mb = model_builder("BT_model") mb.add_components(BT) psrJ1955 = mb.get_model_instance('J1955.par') ```