pycbc icon indicating copy to clipboard operation
pycbc copied to clipboard

Bugfix to `plot_posterior` when plotting extracted posterior files

Open acorreia61201 opened this issue 3 months ago • 2 comments

This PR fixes a bug when running pycbc_inference_plot_posterior with an extracted posterior file and wildcard parameters.

Standard information about the request

This is a bug fix. This change affects posterior plotting via plot_posterior. This change changes the behavior of plot_posterior when using a wildcard parameter argument to call only the parameters present in the file.

Motivation

Currently, if using a wildcard (i.e. --parameters '*'), this script calls the variable_params section of the file, which assumes that the parameters to be plotted are the same as the parameters that were sampled over during PE. However, if the user provides a posterior extracted using pycbc_inference_extract_samples, the parameters stored in the file are not guaranteed to be the same as the variable_params (e.g., a waveform transform may have been applied during extraction). Thus, the script will attempt to call parameter names that may not be in the posterior and throw an error. Ideally, the wildcard should call all the parameters present in the file regardless of what was sampled over during PE.

Contents

This PR changes the behavior of plot_posterior (via the ResultsArgumentParser call) to plot all parameters in the file rather than the variable_params section when using the '*' wildcard. All other functionality remains unchanged; i.e. if the user specifies all of the parameters manually, this PR has no effect.

Additional notes

This largely produces the same expected functionality of the wildcard parameter. There is one additional side effect: if the posterior contains likelihood parameters (e.g. loglikelihood, logwt), those will be plotted as their own scatter plots. Ideally, these wouldn't be plotted, but they have no effect on the plotting otherwise. Additional changes can be made to this PR to exclude these parameters if that is the optimal behavior.

  • [ x ] The author of this pull request confirms they will adhere to the code of conduct

acorreia61201 avatar Sep 22 '25 19:09 acorreia61201

@aleynaakyuz Can you please review this?

ahnitz avatar Sep 22 '25 19:09 ahnitz

I've added in a few lines to the ResultsArgumentParser that mimics the behavior of defaultparams = 'all', except avoiding parameters that share the names of likelihood stats (e.g. loglikelihood, logwt). This avoids plotting the likelihood stats when using a wildcard unless specified by the user (so, e.g. if someone specifies --parameters loglikelihood '*', it will plot the loglikelihood and not logwt in the scatter/corner plots).

acorreia61201 avatar Oct 01 '25 00:10 acorreia61201