Skip to content

Commit

Permalink
Standardize logging - final places (gwastro#4665)
Browse files Browse the repository at this point in the history
* start standardizing logging in bin/plotting

* add a default_level option to init_logging

* more work

* named loggers in modules

* CC

* missed comma, typo, etc.

* thinko

* minor typo/thinko

* missed import

* final few places

* copy/paste error

* thinko

* missed again

* I made that mistake a lot

* import order

* Add a file to tell pylint that 'logger' is an allowed variable namex

* comment pylint file, allow 1/2 character variable names

* be more explicit re the single-character variables

* opts != args

* thinko

* pycbc not imported implicitly

* removed line which should have been kept

* remove double import

* grammar

* AT comments

* grammar

* missed some stuff during rebasing

* No idea how that line got deleted

* default level in pycbc_page_snrchi

* default level in bin/plotting/pycbc_page_vetotable

* improve import readability

* default level in  bin/plotting/pycbc_plot_qscan

* remove unused import in bin/pygrb/pycbc_pygrb_minifollowups

* unused import in bin/pygrb/pycbc_pygrb_page_tables

* formatting error in pycbc/transforms.py

* use logger in pycbc/scheme
  • Loading branch information
GarethCabournDavies authored Jul 2, 2024
1 parent 72cfa7a commit 7786c1a
Show file tree
Hide file tree
Showing 139 changed files with 1,115 additions and 709 deletions.
3 changes: 3 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[BASIC]
# Allow certain names for variables
good-names=logger,Run,i,j,k,v,_
2 changes: 1 addition & 1 deletion bin/all_sky_search/pycbc_bin_templates
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ from pycbc.version import git_verbose_msg as version
from pycbc.events import background_bin_from_string

parser = argparse.ArgumentParser(description=__doc__)
pycbc.add_common_pycbc_options(parser)
parser.add_argument('--version', action='version', version=version)
parser.add_argument('--verbose', action="count")
parser.add_argument("--ifo", type=str, required=True)
parser.add_argument("--f-lower", type=float, default=15.,
help='Enforce a uniform low frequency cutoff to '
Expand Down
6 changes: 1 addition & 5 deletions bin/all_sky_search/pycbc_fit_sngls_binned
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,7 @@ if args.output_file is not None and len(args.stat_threshold) > 1:
raise RuntimeError("Cannot plot more than one threshold in a single "
"output file!")

if args.verbose:
log_level = logging.DEBUG
else:
log_level = logging.WARN
logging.basicConfig(format='%(asctime)s : %(message)s', level=log_level)
pycbc.init_logging(args.verbose)

statname = "reweighted SNR" if args.sngl_ranking == "new_snr" else \
args.sngl_ranking.replace("_", " ").replace("snr", "SNR")
Expand Down
2 changes: 0 additions & 2 deletions bin/all_sky_search/pycbc_get_loudest_params
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ from pycbc import init_logging
import pycbc.events
from pycbc.pnutils import mass1_mass2_to_mchirp_eta

logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)

parser = argparse.ArgumentParser(description=__doc__)
pycbc.add_common_pycbc_options(parser)
parser.add_argument('--single-ifo-trigs', type=str, required=True,
Expand Down
9 changes: 4 additions & 5 deletions bin/all_sky_search/pycbc_make_bayestar_skymap
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ from pycbc.io import WaveformArray
from pycbc.io.ligolw import LIGOLWContentHandler

parser = argparse.ArgumentParser(description=__doc__)
pycbc.add_common_pycbc_options(parser)
parser.add_argument('--version', action="version",
version=pycbc.version.git_verbose_msg)
parser.add_argument('--verbose', action='count',
help="Make the logging increasingly more verbose")
parser.add_argument('--bayestar-executable',
help="The bayestar-localize-coinc executable to be run. "
"If not given, will use whatever is available in "
Expand All @@ -52,9 +51,9 @@ parser.add_argument('--output-file', required=True,
wavebank.add_approximant_arg(parser)
args, unknown = parser.parse_known_args()

# Default logging is set higher than normal for this job
logging_level = args.verbose + 1 if args.verbose else None
init_logging(logging_level)
# Default logging level is info: --verbose adds to this
pycbc.init_logging(args.verbose, default_level=1)

logging.info("Starting")

bayestar_exe = args.bayestar_executable or 'bayestar-localize-coincs'
Expand Down
13 changes: 5 additions & 8 deletions bin/all_sky_search/pycbc_prepare_xml_for_gracedb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ import h5py
import matplotlib
matplotlib.use('agg')

import pycbc
import lal
import lal.series
from ligo.lw import lsctables
from ligo.lw import utils as ligolw_utils
from ligo.segments import segment, segmentlist

import pycbc
from pycbc.io.ligolw import (
LIGOLWContentHandler,
snr_series_to_xml,
Expand All @@ -44,8 +45,7 @@ from pycbc.types import MultiDetOptionAction
from pycbc.results import generate_asd_plot, generate_snr_plot

parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--verbose", action='count',
help="Increase logging level, default=info")
pycbc.add_common_pycbc_options(parser)
parser.add_argument("--psd-files", nargs='+', required=True,
help='HDF file(s) containing the PSDs to upload')
parser.add_argument("--snr-timeseries", nargs='+', required=True,
Expand All @@ -72,11 +72,8 @@ parser.add_argument('--delta-f', type=float, default=0.25,

args = parser.parse_args()

if args.verbose:
args.verbose += 1
else:
args.verbose = 1
pycbc.init_logging(args.verbose)
# Default logging level is info: --verbose adds to this
pycbc.init_logging(args.verbose, default_level=1)

xmldoc = ligolw_utils.load_filename(args.input_file,
contenthandler=LIGOLWContentHandler)
Expand Down
4 changes: 3 additions & 1 deletion bin/all_sky_search/pycbc_upload_single_event_to_gracedb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import lal
from pycbc.io.gracedb import gracedb_tag_with_version

parser = argparse.ArgumentParser(description=__doc__)
pycbc.add_common_pycbc_options(parser)
parser.add_argument('--xml-file-for-upload', required=True, type=str,
help='LIGOLW XML file containing the event.')
parser.add_argument('--log-message', type=str, metavar='MESSAGE',
Expand Down Expand Up @@ -62,7 +63,8 @@ parser.add_argument('--labels', nargs='+',

args = parser.parse_args()

pycbc.init_logging(logging.INFO)
# Default logging level is info: --verbose adds to this
pycbc.init_logging(args.verbose, default_level=1)
# Make the scitokens logger a little quieter
# (it is called through GraceDB)
logging.getLogger('scitokens').setLevel(logging.root.level + 10)
Expand Down
5 changes: 2 additions & 3 deletions bin/hwinj/pycbc_generate_hwinj_from_xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ parser.add_argument('--ifos', nargs='+', default=['H1', 'L1'], required=True,
# parse command line
opts = parser.parse_args()

# setup logging - default level is DEBUG (2)
logging_level = 2 if opts.verbose is None else opts.verbose + 2
init_logging(logging_level)
# Default logging level is debug: --verbose adds to this
init_logging(args.verbose, default_level=2)

# read in injection LIGOLW XML file
logging.info('Reading injection file')
Expand Down
5 changes: 2 additions & 3 deletions bin/hwinj/pycbc_insert_frame_hwinj
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ _strain.insert_strain_option_group(parser)
# parse command line
opts = parser.parse_args()

# setup log: default is DEBUG (2)
logging_level = 2 if opts.verbose is None else opts.verbose + 2
init_logging(logging_level)
# Default logging level is debug: --verbose adds to this
init_logging(opts.verbose, default_level=2)

# get strain
strain = _strain.from_cli(opts, precision=opts.precision)
Expand Down
4 changes: 4 additions & 0 deletions bin/inference/pycbc_inference_create_fits
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ import numpy
import argparse
import subprocess

from pycbc import add_common_pycbc_options, init_logging
from pycbc.inference import io

parser = argparse.ArgumentParser(description=__doc__)
add_common_pycbc_options(parser)
parser.add_argument('--input-file', required=True,
help='The inference or posterior hdf file to load.')
parser.add_argument('--output-file', required=True,
Expand Down Expand Up @@ -68,6 +70,8 @@ parser.add_argument('--tc', default='tc',
'"tc".')
opts = parser.parse_args()

init_logging(opts.verbose)

fp = io.loadfile(opts.input_file, 'r')
samples = fp.read_samples([opts.ra, opts.dec, opts.distance, opts.tc])
fp.close()
Expand Down
19 changes: 8 additions & 11 deletions bin/inference/pycbc_inference_plot_gelman_rubin
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@

import argparse
import logging
import matplotlib as mpl; mpl.use("Agg")
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import sys
from pycbc import results
from pycbc import __version__

from pycbc import (
__version__, results, init_logging, add_common_pycbc_options
)
from pycbc.inference import (gelman_rubin, io, option_utils)

# add options to command line
parser = io.ResultsArgumentParser(skip_args=['walkers'])

# verbose option
parser.add_argument("--verbose", action="store_true", default=False,
help="Print logging info.")
add_common_pycbc_options(parser)
parser.add_argument('--version', action='version', version=__version__,
help='show version number and exit')

Expand All @@ -55,11 +56,7 @@ parser.add_argument("--segment-step", type=int, required=True,
opts = parser.parse_args()

# setup log
if opts.verbose:
log_level = logging.DEBUG
else:
log_level = logging.WARN
logging.basicConfig(format="%(asctime)s : %(message)s", level=log_level)
init_logging(opts.verbose)

# enfore that this is not a single iteration
if opts.iteration is not None:
Expand Down
4 changes: 3 additions & 1 deletion bin/inference/pycbc_inference_plot_mcmc_history
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ from pycbc.inference import io
from pycbc.results import metadata

parser = argparse.ArgumentParser(description=__doc__)
pycbc.add_common_pycbc_options(parser)
parser.add_argument('--input-file', type=str, required=True,
help='Path to the input HDF file.')
parser.add_argument('--output-file', type=str, required=True,
Expand All @@ -48,7 +49,8 @@ parser.add_argument('-b', '--plot-nchains-burned-in', action='store_true',
'ensemble samplers, this will be all or nothing.')
opts = parser.parse_args()

pycbc.init_logging(True)
# Default logging level is info: --verbose adds to this
pycbc.init_logging(opts.verbose, default_level=1)

nplots = sum([opts.plot_act, opts.plot_effective_nsamples,
opts.plot_nchains_burned_in, opts.plot_checkpoint_dt])
Expand Down
4 changes: 4 additions & 0 deletions bin/inference/pycbc_inference_plot_skymap
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ import sys
import subprocess
from PIL import Image, PngImagePlugin

from pycbc import add_common_pycbc_options, init_logging

parser = argparse.ArgumentParser(description=__doc__)
add_common_pycbc_options(parser)
parser.add_argument('--input-file', required=True,
help='Input fits file"')
parser.add_argument('--output-file', required=True,
Expand All @@ -42,6 +44,8 @@ parser.add_argument('--colormap',

opts = parser.parse_args()

init_logging(opts.verbose)

cmd = 'ligo-skymap-plot {} -o {} --annotate --contour 50 90'.format(
opts.input_file, opts.output_file)
if opts.colormap is not None:
Expand Down
5 changes: 5 additions & 0 deletions bin/inference/pycbc_inference_plot_thermodynamic_integrand
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ matplotlib.use("agg")
from matplotlib import rc
import matplotlib.pyplot as plt
import numpy

from pycbc import add_common_pycbc_options, init_logging
from pycbc.inference import io
import pycbc.version

parser = argparse.ArgumentParser()
add_common_pycbc_options(parser)
parser.add_argument("--inference-file", type=str,
help="The PyCBC multi-temper inference file.")
parser.add_argument("--thin-start", type=int, default=None,
Expand All @@ -52,6 +55,8 @@ parser.add_argument("--integrand-logarithmic", action="store_true",
parser.add_argument("--output-file", type=str)
args = parser.parse_args()

init_logging(args.verbose)

# Read in the necessary data
fp = io.loadfile(args.inference_file, "r")
logl = fp.read_samples("loglikelihood", thin_start=args.thin_start,
Expand Down
5 changes: 5 additions & 0 deletions bin/inference/pycbc_inference_start_from_samples
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import argparse
import numpy
import h5py
from numpy.random import choice

from pycbc import add_common_pycbc_options, init_logging
from pycbc.inference.io import loadfile
from pycbc.inference.sampler import samplers

parser = argparse.ArgumentParser()
add_common_pycbc_options(parser)
parser.add_argument('--input-file')
parser.add_argument('--output-file')
parser.add_argument('--sampler', default='emcee_pt',
Expand All @@ -18,6 +21,8 @@ parser.add_argument('--ntemps', type=int)
parser.add_argument('--nwalkers', type=int)
args = parser.parse_args()

init_logging(opts.verbose)

# populate an emcee start file with
# values chosen from a dynesty file
# each temperature and walker will get a random
Expand Down
12 changes: 10 additions & 2 deletions bin/inference/pycbc_validate_test_posterior
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ test posterior model.
import sys
import numpy
import argparse
from matplotlib import use; use('Agg')
from matplotlib import use
use('Agg')
import pylab

from scipy.stats import gaussian_kde, ks_2samp

from pycbc.distributions.utils import prior_from_config
from pycbc.inference import models, io
from scipy.stats import gaussian_kde, ks_2samp
from pycbc.io import FieldArray
from pycbc import add_common_pycbc_options, init_logging

numpy.random.seed(0)

parser = argparse.ArgumentParser()
add_common_pycbc_options(parser)
parser.add_argument('--input-file', help='inference posterior file')
parser.add_argument('--output-file', help='diagnostic plot')
parser.add_argument('--p-value-threshold', help='minimum ks test p-value',
Expand All @@ -22,6 +28,8 @@ parser.add_argument('--ind-samples', help='use only this number of samples',
default=1000, type=int)
args = parser.parse_args()

init_logging(args.verbose)

size = int(1e6)
d1 = io.loadfile(args.input_file, 'r')

Expand Down
3 changes: 1 addition & 2 deletions bin/minifollowups/pycbc_foreground_minifollowup
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ wf.add_workflow_settings_cli(parser, include_subdax_opts=True)
args = parser.parse_args()

# Default logging level is info: --verbose adds to this
log_level = 1 if args.verbose is None else args.verbose + 1
init_logging(log_level)
init_logging(args.verbose, default_level=1)

workflow = wf.Workflow(args)

Expand Down
3 changes: 1 addition & 2 deletions bin/minifollowups/pycbc_injection_minifollowup
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ args = parser.parse_args()


# Default logging level is info: --verbose adds to this
log_level = 1 if args.verbose is None else args.verbose + 1
init_logging(log_level)
init_logging(args.verbose, default_level=1)

workflow = wf.Workflow(args)

Expand Down
3 changes: 1 addition & 2 deletions bin/minifollowups/pycbc_sngl_minifollowup
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ stat.insert_statistic_option_group(parser,
args = parser.parse_args()

# Default logging level is info: --verbose adds to this
log_level = 1 if args.verbose is None else args.verbose + 1
init_logging(log_level)
init_logging(args.verbose, default_level=1)

workflow = wf.Workflow(args)
workflow.ifos = [args.instrument]
Expand Down
3 changes: 1 addition & 2 deletions bin/minifollowups/pycbc_upload_prep_minifollowup
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ wf.add_workflow_settings_cli(parser, include_subdax_opts=True)
args = parser.parse_args()

# Default logging level is info: --verbose adds to this
log_level = 1 if args.verbose is None else args.verbose + 1
init_logging(log_level)
init_logging(args.verbose, default_level=1)

workflow = wf.Workflow(args)

Expand Down
Loading

0 comments on commit 7786c1a

Please sign in to comment.