Skip to content

Commit

Permalink
Merge pull request #647 from frheault/logging_fixes
Browse files Browse the repository at this point in the history
Fix logging across scilpy
  • Loading branch information
arnaudbore authored Nov 14, 2022
2 parents e838867 + 256a466 commit 4670671
Show file tree
Hide file tree
Showing 79 changed files with 129 additions and 134 deletions.
24 changes: 24 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[pytest]
filterwarnings =
default
once:::dipy
once:::fury
ignore:::h5py
ignore:::matplotlib
ignore:::nibabel
ignore:::nilearn
ignore:::numpy
ignore:::Pillow
once:::bids-validator
once:::pybids
ignore:::scikit-learn
ignore:::sklearn
ignore:::scipy
ignore:::vtk
default:::trimeshpy
ignore:::nilearn
once:::bctpy
once:::statsmodels
once:::dmri-commit
once:::cvxpy
once:::dmri-amico
2 changes: 1 addition & 1 deletion scilpy/utils/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def compute_snr(dwi, bval, bvec, b0_thr, mask,
Set to use logging
"""
if verbose:
logging.basicConfig(level=logging.INFO)
logging.getLogger().setLevel(logging.INFO)

img = nib.load(dwi)
data = img.get_fdata(dtype=np.float32)
Expand Down
Empty file modified scripts/scil_analyse_lesions_load.py
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion scripts/scil_apply_transform_to_tractogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def main():
args = parser.parse_args()

if args.verbose:
logging.basicConfig(level=logging.DEBUG)
logging.getLogger().setLevel(logging.DEBUG)

assert_inputs_exist(parser, [args.in_moving_tractogram,
args.in_target_file,
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_assign_custom_color_to_tractogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def save_colorbar(cmap, lbound, ubound, args):
def main():
parser = _build_arg_parser()
args = parser.parse_args()
logging.basicConfig(level=logging.WARNING)
logging.getLogger().setLevel(logging.WARNING)

assert_inputs_exist(parser, args.in_tractogram)
assert_outputs_exist(parser, args, args.out_tractogram,
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_assign_uniform_color_to_tractograms.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _build_arg_parser():
def main():
parser = _build_arg_parser()
args = parser.parse_args()
logging.basicConfig(level=logging.WARNING)
logging.getLogger().setLevel(logging.WARNING)

if len(args.in_tractograms) > 1 and args.out_tractogram:
parser.error('Using multiple inputs, use --out_suffix.')
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_clean_qbx_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def keypress_callback(obj, _):
create_dir=True)

if args.verbose:
logging.basicConfig(level=logging.INFO)
logging.getLogger().setLevel(logging.INFO)

if args.min_cluster_size < 1:
parser.error('Minimum cluster size must be at least 1.')
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_compare_connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def main():
assert_outputs_exist(parser, args, args.out_pval_matrix)

if args.verbose:
logging.basicConfig(level=logging.DEBUG)
logging.getLogger().setLevel(logging.DEBUG)

if args.filtering_mask:
filtering_mask = load_matrix_in_any_format(args.filtering_mask)
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_compute_NODDI.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def main():
# COMMIT has some c-level stdout and non-logging print that cannot
# be easily stopped. Manual redirection of all printed output
if args.verbose:
logging.basicConfig(level=logging.DEBUG)
logging.getLogger().setLevel(logging.DEBUG)
redirected_stdout = redirect_stdout(sys.stdout)
else:
f = io.StringIO()
Expand Down
6 changes: 2 additions & 4 deletions scripts/scil_compute_NODDI_priors.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,8 @@ def main():

assert_same_resolution([args.in_AD, args.in_FA, args.in_MD])

if args.verbose:
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)
log_level = logging.DEBUG if args.verbose else logging.INFO
logging.getLogger().setLevel(log_level)

fa_img = nib.load(args.in_FA)
fa_data = fa_img.get_fdata(dtype=np.float32)
Expand Down
Empty file modified scripts/scil_compute_asym_odf_metrics.py
100644 → 100755
Empty file.
6 changes: 2 additions & 4 deletions scripts/scil_compute_connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,8 @@ def main():
assert_inputs_exist(parser, [args.in_hdf5, args.in_labels],
args.force_labels_list)

log_level = logging.WARNING
if args.verbose:
log_level = logging.INFO
logging.basicConfig(level=log_level)
log_level = logging.INFO if args.verbose else logging.WARNING
logging.getLogger().setLevel(log_level)
coloredlogs.install(level=log_level)

measures_to_compute = []
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_compute_fodf_max_in_ventricles.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def main():
[args.max_value_output, args.mask_output])

if args.verbose:
logging.basicConfig(level=logging.DEBUG)
logging.getLogger().setLevel(logging.DEBUG)

# Load input image
img_fODFs = nib.load(args.in_fodfs)
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_compute_freewater.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def main():
# COMMIT has some c-level stdout and non-logging print that cannot
# be easily stopped. Manual redirection of all printed output
if args.verbose:
logging.basicConfig(level=logging.DEBUG)
logging.getLogger().setLevel(logging.DEBUG)
redirected_stdout = redirect_stdout(sys.stdout)
else:
f = io.StringIO()
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_compute_lobe_specific_fodf_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def main():
parser = _build_arg_parser()
args = parser.parse_args()
if args.verbose:
logging.basicConfig(level=logging.INFO)
logging.getLogger().setLevel(logging.INFO)

if not args.not_all:
args.out_fd = args.out_fd or 'fd.nii.gz'
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_compute_local_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def main():
args = parser.parse_args()

if args.verbose:
logging.basicConfig(level=logging.DEBUG)
logging.getLogger().setLevel(logging.DEBUG)

assert_inputs_exist(parser, [args.in_odf, args.in_seed, args.in_mask])
assert_outputs_exist(parser, args, args.out_tractogram)
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_compute_local_tracking_dev.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def main():
args = parser.parse_args()

if args.verbose:
logging.basicConfig(level=logging.DEBUG)
logging.getLogger().setLevel(logging.DEBUG)

if not nib.streamlines.is_supported(args.out_tractogram):
parser.error('Invalid output streamline file format (must be trk or ' +
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_compute_local_tracking_gpu.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def main():
args = parser.parse_args()

if args.verbose:
logging.basicConfig(level=logging.INFO)
logging.getLogger().setLevel(logging.INFO)

assert_inputs_exist(parser, [args.in_odf, args.in_mask, args.in_seed])
assert_outputs_exist(parser, args, args.out_tractogram)
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_compute_maps_for_particle_filter_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def main():
args = parser.parse_args()

if args.verbose:
logging.basicConfig(level=logging.DEBUG)
logging.getLogger().setLevel(logging.DEBUG)

assert_inputs_exist(parser, [args.in_wm, args.in_gm, args.in_csf])
assert_outputs_exist(parser, args,
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_compute_mean_frf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _build_arg_parser():
def main():
parser = _build_arg_parser()
args = parser.parse_args()
logging.basicConfig(level=logging.INFO)
logging.getLogger().setLevel(logging.INFO)

assert_inputs_exist(parser, args.frf_files)
assert_outputs_exist(parser, args, args.mean_frf)
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_compute_msmt_fodf.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def _build_arg_parser():
def main():
parser = _build_arg_parser()
args = parser.parse_args()
logging.basicConfig(level=logging.INFO)
logging.getLogger().setLevel(logging.INFO)

if not args.not_all:
args.wm_out_fODF = args.wm_out_fODF or 'wm_fodf.nii.gz'
Expand Down
10 changes: 4 additions & 6 deletions scripts/scil_compute_msmt_frf.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
def buildArgsParser():

p = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)

p.add_argument('in_dwi',
help='Path to the input diffusion volume.')
Expand Down Expand Up @@ -163,10 +163,8 @@ def main():
parser = buildArgsParser()
args = parser.parse_args()

if args.verbose:
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)
log_level = logging.DEBUG if args.verbose else logging.INFO
logging.getLogger().setLevel(log_level)

assert_inputs_exist(parser, [args.in_dwi, args.in_bval, args.in_bvec])
assert_outputs_exist(parser, args, [args.out_wm_frf, args.out_gm_frf,
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_compute_pft.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def main():
args = parser.parse_args()

if args.verbose:
logging.basicConfig(level=logging.DEBUG)
logging.getLogger().setLevel(logging.DEBUG)

assert_inputs_exist(parser, [args.in_sh, args.in_seed,
args.in_map_include,
Expand Down
8 changes: 2 additions & 6 deletions scripts/scil_compute_powder_average.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@
being averaged.
"""

from os.path import splitext
import re

import argparse
import logging

import nibabel as nib
from nibabel.tmpdirs import InTemporaryDirectory

import numpy as np

Expand Down Expand Up @@ -86,7 +82,7 @@ def main():
assert_outputs_exist(parser, args, args.out_avg)

if args.verbose:
logging.basicConfig(level=logging.DEBUG)
logging.getLogger().setLevel(logging.DEBUG)

img = nib.load(args.in_dwi)
data = img.get_fdata(dtype=np.float32)
Expand All @@ -103,7 +99,7 @@ def main():
bvals, _ = read_bvals_bvecs(args.in_bval, None)

# Select diffusion volumes to average
if not(args.shells):
if not (args.shells):
# If no shell given, average all diffusion weighted images
pwd_avg_idx = np.squeeze(np.where(bvals > 0 + args.b0_thr))
logging.debug('Calculating powder average from all diffusion'
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_compute_qbx.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def main():
create_dir=True)

if args.verbose:
logging.basicConfig(level=logging.INFO)
logging.getLogger().setLevel(logging.INFO)

sft = load_tractogram_with_reference(parser, args, args.in_tractogram)
streamlines = sft.streamlines
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_compute_ssst_fodf.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _build_arg_parser():
def main():
parser = _build_arg_parser()
args = parser.parse_args()
logging.basicConfig(level=logging.INFO)
logging.getLogger().setLevel(logging.INFO)

assert_inputs_exist(parser, [args.in_dwi, args.in_bval, args.in_bvec,
args.frf_file])
Expand Down
6 changes: 2 additions & 4 deletions scripts/scil_compute_ssst_frf.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@ def main():
parser = _build_arg_parser()
args = parser.parse_args()

if args.verbose:
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)
log_level = logging.DEBUG if args.verbose else logging.INFO
logging.getLogger().setLevel(log_level)

assert_inputs_exist(parser, [args.in_dwi, args.in_bval, args.in_bvec])
assert_outputs_exist(parser, args, args.frf_file)
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_compute_todi.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _build_arg_parser():
def main():
parser = _build_arg_parser()
args = parser.parse_args()
logging.basicConfig(level=logging.INFO)
logging.getLogger().setLevel(logging.INFO)

assert_inputs_exist(parser, args.in_tractogram,
[args.mask, args.reference])
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_connectivity_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def main():
args = parser.parse_args()

if args.verbose:
logging.basicConfig(level=logging.INFO)
logging.getLogger().setLevel(logging.INFO)

assert_outputs_exist(parser, args, args.out_matrix)

Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_convert_gradients_fsl_to_mrtrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def main():
args = parser.parse_args()

if args.verbose:
logging.basicConfig(level=logging.INFO)
logging.getLogger().setLevel(logging.INFO)

assert_gradients_filenames_valid(parser, [args.fsl_bval, args.fsl_bvec],
'fsl')
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_convert_gradients_mrtrix_to_fsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def main():
args = parser.parse_args()

if args.verbose:
logging.basicConfig(level=logging.INFO)
logging.getLogger().setLevel(logging.INFO)

assert_gradients_filenames_valid(parser, args.mrtrix_enc, 'mrtrix')
assert_gradients_filenames_valid(parser, [args.fsl_bval, args.fsl_bvec],
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_convert_tensors.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import nibabel as nib
import numpy as np

from scilpy.io.utils import (add_overwrite_arg, add_reference_arg,
from scilpy.io.utils import (add_overwrite_arg,
assert_inputs_exist, assert_outputs_exist)
from scilpy.reconst.dti import (supported_tensor_formats,
tensor_format_description,
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_cut_streamlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def main():
args = parser.parse_args()

if args.verbose:
logging.basicConfig(level=logging.INFO)
logging.getLogger().setLevel(logging.INFO)

assert_inputs_exist(parser, [args.in_tractogram, args.in_mask])
assert_outputs_exist(parser, args, args.out_tractogram)
Expand Down
6 changes: 2 additions & 4 deletions scripts/scil_decompose_connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,8 @@ def main():
assert_output_dirs_exist_and_empty(parser, args, args.out_dir,
create_dir=True)

log_level = logging.WARNING
if args.verbose:
log_level = logging.INFO
logging.basicConfig(level=log_level)
log_level = logging.INFO if args.verbose else logging.WARNING
logging.getLogger().setLevel(log_level)
coloredlogs.install(level=log_level)
set_sft_logger_level('WARNING')

Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_dilate_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _build_arg_parser():
def main():
parser = _build_arg_parser()
args = parser.parse_args()
logging.basicConfig(level=logging.INFO)
logging.getLogger().setLevel(logging.INFO)

assert_inputs_exist(parser, args.in_file, optional=args.mask)
assert_outputs_exist(parser, args, args.out_file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def main():
args = parser.parse_args()

if args.verbose:
logging.basicConfig(level=logging.INFO)
logging.getLogger().setLevel(logging.INFO)

assert_inputs_exist(parser, args.in_bundles)
assert_outputs_exist(parser, args, args.out_json)
Expand Down
2 changes: 1 addition & 1 deletion scripts/scil_evaluate_connectivity_graph_measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def main():
args.in_conn_matrix])

if args.verbose:
logging.basicConfig(level=logging.DEBUG)
logging.getLogger().setLevel(logging.DEBUG)

if not args.append_json:
assert_outputs_exist(parser, args, args.out_json)
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion scripts/scil_execute_angle_aware_bilateral_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def main():
parser = _build_arg_parser()
args = parser.parse_args()
if args.verbose:
logging.basicConfig(level=logging.INFO)
logging.getLogger().setLevel(logging.INFO)

# Checking args
outputs = [args.out_sh]
Expand Down
Loading

0 comments on commit 4670671

Please sign in to comment.