Skip to content

Commit

Permalink
Standardize logging in bin/inference (gwastro#4621)
Browse files Browse the repository at this point in the history
* inference: standardize verbose argument

Only change scripts that already had a verbose argument

* revert logging change in pycbc_inference_plot_gelman_rubin

Partially reverts 9b7fa3d
  • Loading branch information
mj-will authored Feb 9, 2024
1 parent 02f77b6 commit ddaa94d
Show file tree
Hide file tree
Showing 18 changed files with 19 additions and 41 deletions.
3 changes: 1 addition & 2 deletions bin/inference/pycbc_inference
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ from pycbc.workflow import configuration
# command line usage
parser = argparse.ArgumentParser(usage=__file__ + " [--options]",
description=__doc__)
pycbc.add_common_pycbc_options(parser)
parser.add_argument("--version", action="version", version=__version__,
help="Prints version information.")
parser.add_argument("--verbose", action="store_true", default=False,
help="Print logging messages.")
# output options
parser.add_argument("--output-file", type=str, required=True,
help="Output file path.")
Expand Down
4 changes: 1 addition & 3 deletions bin/inference/pycbc_inference_extract_samples
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def isthesame(current_val, val):

parser = ResultsArgumentParser(defaultparams='all', autoparamlabels=False,
description=__doc__)

pycbc.add_common_pycbc_options(parser)
parser.add_argument("--output-file", type=str, required=True,
help="Output file to create.")
parser.add_argument("--force", action="store_true", default=False,
Expand All @@ -85,8 +85,6 @@ parser.add_argument("--skip-groups", default=None, nargs="+",
"to write all groups if only one file is provided, "
"and all groups from the first file except "
"sampler_info if multiple files are provided.")
parser.add_argument("--verbose", action="store_true", default=False,
help="Be verbose")

opts = parser.parse_args()

Expand Down
3 changes: 1 addition & 2 deletions bin/inference/pycbc_inference_model_stats
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ from pycbc.workflow import WorkflowConfigParser


parser = argparse.ArgumentParser(description=__doc__)
pycbc.add_common_pycbc_options(parser)
parser.add_argument("--input-file", type=str, required=True,
help="Input HDF file to read. Can be either an inference "
"file or a posterior file.")
Expand All @@ -51,8 +52,6 @@ parser.add_argument("--nprocesses", type=int, default=1,
parser.add_argument("--config-file", nargs="+", type=str, default=None,
help="Override the config file stored in the input file "
"with the given file(s).")
parser.add_argument("--verbose", action="count", default=0,
help="Print logging messages.")
parser.add_argument('--reconstruct-parameters', action="store_true",
help="Reconstruct marginalized parameters")

Expand Down
2 changes: 1 addition & 1 deletion bin/inference/pycbc_inference_monitor
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import os, sys, time, glob, shutil, logging, argparse, pycbc
import pycbc.workflow as wf

parser = argparse.ArgumentParser()
pycbc.add_common_pycbc_options(parser)
parser.add_argument('--inference-file', help="The name of the inference file")
parser.add_argument('--check-interval', default=10, type=int,
help="Polling interval to check for file changes (s)")
parser.add_argument('--output-dir', help="Output plots / results directory")
parser.add_argument('--allow-failure', action='store_true',
help="Allow for a failure in plot generation")
parser.add_argument('--verbose', action='store_true')

wf.add_workflow_command_line_group(parser)
args = parser.parse_args()
Expand Down
4 changes: 1 addition & 3 deletions bin/inference/pycbc_inference_plot_acceptance_rate
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ parser = argparse.ArgumentParser(
usage="pycbc_inference_plot_acceptance_rate [--options]",
description="Plots histogram of the fractions of steps "
"accepted by walkers.")
pycbc.add_common_pycbc_options(parser)
parser.add_argument("--input-file", type=str, required=True,
help="Path to input HDF file.")
parser.add_argument('--version', action='version', version=__version__,
Expand All @@ -56,9 +57,6 @@ parser.add_argument("--temps", type=int, nargs="+", default=None,
# add number of bins for histogram
parser.add_argument("--bins", type=int, default=10,
help="Specify number of bins for the histogram plot.")
# verbose option
parser.add_argument("--verbose", action="store_true", default=False,
help="")

# parse the command line
opts = parser.parse_args()
Expand Down
4 changes: 1 addition & 3 deletions bin/inference/pycbc_inference_plot_acf
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ from pycbc.inference.sampler import samplers
parser = io.ResultsArgumentParser(skip_args='thin-interval',
description="Plots autocorrelation function "
"from inference samples.")
# verbose option
parser.add_argument("--verbose", action="store_true", default=False,
help="Print logging info.")
pycbc.add_common_pycbc_options(parser)
parser.add_argument('--version', action='version', version=__version__,
help='show version number and exit')
# output plot options
Expand Down
3 changes: 1 addition & 2 deletions bin/inference/pycbc_inference_plot_acl
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ parser = io.ResultsArgumentParser(skip_args=['thin-interval', 'temps'],
description="Histograms autocorrelation "
"length per walker from an MCMC "
"sampler.")
parser.add_argument("--verbose", action="store_true", default=False,
help="Print logging info.")
pycbc.add_common_pycbc_options(parser)
parser.add_argument('--version', action='version', version=__version__,
help='show version number and exit')
# output plot options
Expand Down
4 changes: 1 addition & 3 deletions bin/inference/pycbc_inference_plot_dynesty_run
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ parser = argparse.ArgumentParser(
usage="pycbc_inference_plot_dynesty_run [--options]",
description="Plots various figures showing evolution of "
"dynesty run.")
pycbc.add_common_pycbc_options(parser)
parser.add_argument("--input-file", type=str, required=True,
help="Path to input HDF file.")
parser.add_argument('--version', action='version', version=__version__,
Expand All @@ -42,9 +43,6 @@ parser.add_argument('--version', action='version', version=__version__,
parser.add_argument("--output-file", type=str, required=True,
help="Path to output plot.")

parser.add_argument("--verbose", action="store_true", default=False,
help="")

# parse the command line
opts = parser.parse_args()

Expand Down
3 changes: 1 addition & 2 deletions bin/inference/pycbc_inference_plot_dynesty_traceplot
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ parser = argparse.ArgumentParser(
description="Plots various figures showing evolution of "
"dynesty run.")

pycbc.add_common_pycbc_options(parser)
parser.add_argument("--input-file", type=str, required=True,
help="Path to input HDF file.")
parser.add_argument('--version', action='version', version=__version__,
Expand All @@ -44,8 +45,6 @@ parser.add_argument('--version', action='version', version=__version__,
parser.add_argument("--output-file", type=str, required=True,
help="Path to output plot.")

parser.add_argument("--verbose", action="store_true", default=False,
help="")
# parse the command line
opts = parser.parse_args()

Expand Down
6 changes: 2 additions & 4 deletions bin/inference/pycbc_inference_plot_geweke
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ from pycbc.inference import (io, geweke, option_utils)
# add options to command line
parser = io.ResultsArgumentParser(skip_args=['walkers'])

# program-specific
pycbc.add_common_pycbc_options(parser)

# verbose option
parser.add_argument("--verbose", action="store_true", default=False,
help="Print logging info.")
# program-specific

parser.add_argument('--version', action='version', version=__version__,
help='show version number and exit')
Expand Down
3 changes: 1 addition & 2 deletions bin/inference/pycbc_inference_plot_inj_recovery
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ from pycbc.results import save_fig_with_metadata
# parse command line
parser = io.ResultsArgumentParser(description=__doc__)

pycbc.add_common_pycbc_options(parser)
parser.add_argument("--version", action="version", version=__version__,
help="Prints version information.")
parser.add_argument("--output-file", required=True, type=str,
help="Path to save output plot.")
parser.add_argument("--verbose", action="store_true",
help="Allows print statements.")
parser.add_argument("--percentiles", nargs=2, type=float, default=[5, 95],
help="Percentiles to use as limits.")
option_utils.add_scatter_option_group(parser)
Expand Down
2 changes: 1 addition & 1 deletion bin/inference/pycbc_inference_plot_movie
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def integer_logspace(start, end, num):
# the frame number/step options
skip_args = ['thin-start', 'thin-interval', 'thin-end', 'iteration']
parser = io.ResultsArgumentParser(description=__doc__, skip_args=skip_args)
pycbc.add_common_pycbc_options(parser)
parser.add_argument("--version", action="version", version=__version__,
help="show version number and exit")
# make frame number and frame step mutually exclusive
Expand All @@ -135,7 +136,6 @@ parser.add_argument("--log-steps", action="store_true", default=False,
parser.add_argument("--output-prefix", type=str, required=True,
help="Output path and prefix for the frame files "
"(without extension).")
parser.add_argument('--verbose', action='store_true')
parser.add_argument('--dpi', type=int, default=200,
help='Set the dpi for each frame; default is 200')
parser.add_argument("--nprocesses", type=int, default=None,
Expand Down
3 changes: 1 addition & 2 deletions bin/inference/pycbc_inference_plot_posterior
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,12 @@ use('agg')

# add options to command line
parser = io.ResultsArgumentParser()
pycbc.add_common_pycbc_options(parser)
# program-specific
parser.add_argument("--version", action="version", version=__version__,
help="Prints version information.")
parser.add_argument("--output-file", type=str, required=True,
help="Output plot path.")
parser.add_argument("--verbose", action="store_true", default=False,
help="Be verbose")
parser.add_argument("--plot-prior", nargs="+", type=str,
help="Plot the prior on the 1D marginal plots using the "
"given config file(s).")
Expand Down
3 changes: 1 addition & 2 deletions bin/inference/pycbc_inference_plot_pp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ from pycbc import __version__

# parse command line
parser = io.ResultsArgumentParser(description=__doc__)
pycbc.add_common_pycbc_options(parser)
parser.add_argument('--version', action='version', version=__version__,
help='show version number and exit')
parser.add_argument("--output-file", required=True, type=str,
help="Path to save output plot.")
parser.add_argument("--verbose", action="store_true",
help="Allows print statements.")
parser.add_argument("--injection-hdf-group", default="injections",
help="HDF group that contains injection values. "
"Default is 'injections'.")
Expand Down
4 changes: 1 addition & 3 deletions bin/inference/pycbc_inference_plot_prior
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def cartesian(arrays):
parser = argparse.ArgumentParser(
usage="pycbc_inference_plot_prior [--options]",
description="Plots prior distributions.")
pycbc.add_common_pycbc_options(parser)
# add input options
parser.add_argument("--config-files", type=str, nargs="+", required=True,
help="A file parsable by "
Expand Down Expand Up @@ -75,9 +76,6 @@ parser.add_argument("--nsamples", type=int, default=10000,
"plotting. Default is 10000.")
parser.add_argument("--output-file", type=str, required=True,
help="Path to output plot.")
# verbose option
parser.add_argument("--verbose", action="store_true", default=False,
help="")
parser.add_argument("--version", action="version", version=__version__,
help="show version number and exit")

Expand Down
3 changes: 1 addition & 2 deletions bin/inference/pycbc_inference_plot_samples
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ import sys
# command line usage
parser = argparse.parser = io.ResultsArgumentParser(
skip_args=['chains', 'iteration'])
parser.add_argument("--verbose", action="store_true", default=False,
help="Print logging info.")
pycbc.add_common_pycbc_options(parser)
parser.add_argument("--version", action="version", version=__version__,
help="show version number and exit")
parser.add_argument("--chains", nargs='+', default=None,
Expand Down
3 changes: 1 addition & 2 deletions bin/inference/pycbc_inference_pp_table_summary
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ from pycbc.inference.io import (ResultsArgumentParser, results_from_cli,
injections_from_cli)

parser = ResultsArgumentParser(description=__doc__)
parser.add_argument("--verbose", action="store_true", default=False,
help="Print logging info.")
pycbc.add_common_pycbc_options(parser)
parser.add_argument("--output-file", type=str, required=True,
help="Path to output plot.")
add_injsamples_map_opt(parser)
Expand Down
3 changes: 1 addition & 2 deletions bin/inference/pycbc_inference_table_summary
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ from pycbc.inference.io import ResultsArgumentParser, results_from_cli

parser = ResultsArgumentParser(
description="Makes a table of posterior results.")
parser.add_argument("--verbose", action="store_true", default=False,
help="Print logging info.")
pycbc.add_common_pycbc_options(parser)
parser.add_argument("--output-file", type=str, required=True,
help="Path to output plot.")
parser.add_argument("--print-metadata", nargs="+", metavar="PARAM[:LABEL]",
Expand Down

0 comments on commit ddaa94d

Please sign in to comment.