GetDist

repository·master·Indexed 41 days ago

https://github.com/cmbant/getdist

A Python package for analyzing and plotting Monte Carlo samples, specifically from Markov Chain Monte Carlo (MCMC) processes. It provides tools for 1D, 2D, and 3D plotting, triangle plots, convergence diagnostics, and a GUI for interactive analysis. GetDist includes integration with ArviZ InferenceData, PyMC, and emcee, and offers both a traditional Qt-based GUI and a Streamlit-based web interface.

Tokens
36.4K
Snippets
129
Records
178
Agent score
51%

What's inside GetDist

  1. Overview of GetDist functionality

    master
    GetDist is a Python package designed for analyzing and plotting Monte Carlo (or other) samples. It provides high-level modules for sample analysis and visualization, as well as lower-level modules for handling specific statistical and data structures.
  2. Handle burn-in in GetDist

    master

    To remove burn-in samples when using GetDist, you can either remove them from your arrays before passing them to GetDist, or use the settings argument to ignore a fraction of the start of each chain.

    Example: To ignore the first 33% of samples:

    # If using Cobaya samples directly
    getdist_samples = mcmc.samples(combined=True, skip_samples=0.33, to_getdist=True)
  3. Understand the loglikes convention in GetDist

    master
    In GetDist, the loglikes parameter and related variables represent -log(posterior), rather than -log(likelihood). Because the posterior is the product of the likelihood and the prior, the loglikes value includes the negative logarithm of both the likelihood and any prior contributions.
  4. Understand the plain text samples file format

    master

    GetDist can read parameter sample/chain files in a specific plain text format. A set of chains is identified by a root name xxx, requiring the following files in the same directory:

    1. xxx_1.txt, xxx_2.txt, etc.: The actual chain files. Each row follows the format: weight like param1 param2 param3 ...
      • weight: Number of samples or importance weight.
      • like: -log(posterior).
      • paramN: Parameter values.
    2. xxx.paramnames: A file listing parameter names (one per line).
      • Supports LaTeX labels: x1 x_1.
      • Derived parameters are indicated by a trailing asterisk: xy* x_1+y_1.
    3. xxx.ranges: Defines hard bounds for parameters: param_name lower_limit upper_limit. Use N for unbounded limits (e.g., x2 0 N).
    4. xxx.properties.ini (Optional): Allows setting burn_removed=T or ignore_rows=x (where x is a fraction 0 < x < 1 or a fixed number of rows if x > 1).
  5. Configure analysis settings via .ini files or dictionaries

    master

    GetDist uses analysis settings to process samples. You can specify these settings in two ways:

    1. Using a .ini file: Define your settings in an initialization file.
    2. Using a dictionary: Override settings programmatically by passing a dictionary to the analysis functions.

    By default, GetDist uses the settings defined in analysis_defaults.ini.

  6. Configure GetDist dependencies

    master

    GetDist requires the following dependencies:

    • Core: Python 3.10+, matplotlib, scipy
    • Optional (for GUI):
      • PySide6: Required for the Qt-based desktop GUI (getdist-gui).
      • Streamlit: Required for the web-based GUI (getdist-streamlit).
    • Optional (for Plotting/Tables): A working LaTeX installation is recommended for certain high-quality plotting and LaTeX table functions.
  7. Use the GetDist GUI to plot and analyze chains

    master

    The GUI allows you to visualize cosmological parameter chains and grids (including paramgrid and Cobaya grids).

    Workflow

    1. Open Directory: Open a folder containing chain files. If you downloaded a grid from the Planck Legacy Archive, unzip it and open the main directory.
    2. Select Chains: Select the chain root names you want to plot. They will appear in a list box. You can drag and drop them to change the plotting order.
    3. Select Parameters: Use the checkboxes to select parameter names (these correspond to names available in the first selected chain).
    4. Plotting Types: The GUI supports 1D, 2D (line and filled), 3D (using 'color by' for a second parameter), triangle, and rectangle plots.

    Exporting Plots

    • Quick Export: Use the File menu to export a plot as-is to PDF or other image formats.
    • High Quality/Customization: Use the Script Preview tab to view the Python script generated for the current plot. You can export this script, edit it (e.g., to add custom legend text), and run it separately for fine control and better resolution.
  8. Create a plotter instance with get_single_plotter or get_subplot_plotter

    master

    To generate plots from samples, you must first create a plotter instance using either get_single_plotter or get_subplot_plotter. Once the instance is created, you can use its methods to generate and export specific plots.

    Plotter functions accept a roots argument, which can be:

    • A root name for chain files.
    • An in-memory MCSamples instance.
    • A list of either of the above (used for making comparison plots).

    Parameters are referenced by their names (as defined in the .paramnames file or the MCSamples instance). For functions requiring lists of parameters, you can provide lists of names or use glob patterns to match subsets (e.g., x* to match all parameters starting with 'x').

    # Example conceptual usage
    from getdist.plots import get_single_plotter
    
    # Create a plotter for a single set of samples
    plotter = get_single_plotter(root_name_or_mcsamples)
    
    # Use the plotter to make plots (specific methods depend on the plotter instance)
    # plotter.plot_contour(...)
  9. Change the default analysis settings file

    master

    To use a custom set of default analysis settings, follow these steps:

    1. Create a config.ini file.
    2. Inside config.ini, define a parameter default_getdist_settings and set its value to the name (or path) of your desired .ini settings file.
    3. Set the GETDIST_CONFIG environment variable to the location of your config.ini file.

    This allows you to switch between different global analysis configurations without modifying your code.

    # Example of setting the environment variable
    export GETDIST_CONFIG=/path/to/your/config.ini
  10. Launch the GetDist GUI

    master

    GetDist provides two graphical interfaces for interacting with chain files:

    1. Qt-based Desktop App: Run the command getdist-gui. Requires PySide6.
    2. Streamlit Web Interface: Run the command getdist-streamlit. Requires Streamlit.

    Both interfaces allow you to open folders of chain files, select/compare chains, and view plots and tables visually.

  11. Use LLM context and AI assistants for GetDist help

    master
    For developers using AI assistants or LLM agents, GetDist provides a comprehensive getdist_docs_combined.md context document to improve model accuracy. Additionally, an AI help assistant is available at https://cosmocoffee.info/help_assist.php for direct queries about the package.
  12. Install the standalone GetDist GUI

    master

    Pre-built standalone applications are available for Mac and Windows. These do not require Python or any dependencies to be installed.

    • Mac: Download the DMG file from the GitHub releases page, mount it, and drag the app to your Applications folder.
    • Windows: Download the MSI installer from the GitHub releases page.

    You can find the latest versions on the GitHub releases page.

    https://github.com/cmbant/getdist/releases