GetDist
repository·master·Indexed 41 days ago
https://github.com/cmbant/getdistA 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.
What's inside GetDist
- 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.
Handle burn-in in GetDist
masterTo remove burn-in samples when using GetDist, you can either remove them from your arrays before passing them to GetDist, or use the
settingsargument 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)Understand the loglikes convention in GetDist
masterIn GetDist, theloglikesparameter and related variables represent -log(posterior), rather than -log(likelihood). Because the posterior is the product of the likelihood and the prior, theloglikesvalue includes the negative logarithm of both the likelihood and any prior contributions.Understand the plain text samples file format
masterGetDist 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: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.
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.
- Supports LaTeX labels:
xxx.ranges: Defines hard bounds for parameters:param_name lower_limit upper_limit. UseNfor unbounded limits (e.g.,x2 0 N).xxx.properties.ini(Optional): Allows settingburn_removed=Torignore_rows=x(wherexis a fraction0 < x < 1or a fixed number of rows ifx > 1).
Configure analysis settings via .ini files or dictionaries
masterGetDist uses analysis settings to process samples. You can specify these settings in two ways:
- Using a
.inifile: Define your settings in an initialization file. - 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.- Using a
Configure GetDist dependencies
masterGetDist 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.
- Core:
Use the GetDist GUI to plot and analyze chains
masterThe GUI allows you to visualize cosmological parameter chains and grids (including
paramgridandCobaya grids).Workflow
- 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.
- 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.
- Select Parameters: Use the checkboxes to select parameter names (these correspond to names available in the first selected chain).
- 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.
Create a plotter instance with get_single_plotter or get_subplot_plotter
masterTo generate plots from samples, you must first create a plotter instance using either
get_single_plotterorget_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
MCSamplesinstance. - A list of either of the above (used for making comparison plots).
Parameters are referenced by their names (as defined in the
.paramnamesfile or theMCSamplesinstance). 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(...)Change the default analysis settings file
masterTo use a custom set of default analysis settings, follow these steps:
- Create a
config.inifile. - Inside
config.ini, define a parameterdefault_getdist_settingsand set its value to the name (or path) of your desired.inisettings file. - Set the
GETDIST_CONFIGenvironment variable to the location of yourconfig.inifile.
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- Create a
Launch the GetDist GUI
masterGetDist provides two graphical interfaces for interacting with chain files:
- Qt-based Desktop App: Run the command
getdist-gui. RequiresPySide6. - Streamlit Web Interface: Run the command
getdist-streamlit. RequiresStreamlit.
Both interfaces allow you to open folders of chain files, select/compare chains, and view plots and tables visually.
- Qt-based Desktop App: Run the command
Use LLM context and AI assistants for GetDist help
masterFor developers using AI assistants or LLM agents, GetDist provides a comprehensivegetdist_docs_combined.mdcontext document to improve model accuracy. Additionally, anAI help assistantis available athttps://cosmocoffee.info/help_assist.phpfor direct queries about the package.Install the standalone GetDist GUI
masterPre-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