From 54b813b0dd4d5d0e21d7f782168dd6ae56bb3616 Mon Sep 17 00:00:00 2001 From: Ariel Rokem Date: Fri, 12 Aug 2022 22:48:06 -0700 Subject: [PATCH 1/3] Sets logging level to be a little bit more verbose for file saving. Addresses #857 --- AFQ/tasks/decorators.py | 1 + 1 file changed, 1 insertion(+) diff --git a/AFQ/tasks/decorators.py b/AFQ/tasks/decorators.py index a285d0f2e..69a988c27 100644 --- a/AFQ/tasks/decorators.py +++ b/AFQ/tasks/decorators.py @@ -20,6 +20,7 @@ logger = logging.getLogger('AFQ.api') +logger.setLevel(10) # get args and kwargs from function From 21626d62ab257fcedbb9539bb83b1f72bc37f612 Mon Sep 17 00:00:00 2001 From: Ariel Rokem Date: Fri, 12 Aug 2022 22:52:46 -0700 Subject: [PATCH 2/3] Use internal logging levles from the logging module, instead of numerical. --- AFQ/api/group.py | 2 ++ AFQ/tasks/decorators.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/AFQ/api/group.py b/AFQ/api/group.py index f4ad142bb..f51ae6d22 100644 --- a/AFQ/api/group.py +++ b/AFQ/api/group.py @@ -137,6 +137,8 @@ def __init__(self, raise TypeError("bids_layout_kwargs must be a dict") self.logger = logging.getLogger('AFQ.api') + self.logger.setLevel(logging.INFO) + self.parallel_params = parallel_params self.wf_dict = {} diff --git a/AFQ/tasks/decorators.py b/AFQ/tasks/decorators.py index 69a988c27..18fd17890 100644 --- a/AFQ/tasks/decorators.py +++ b/AFQ/tasks/decorators.py @@ -20,7 +20,7 @@ logger = logging.getLogger('AFQ.api') -logger.setLevel(10) +logger.setLevel(logging.INFO) # get args and kwargs from function From 47fcd444cabf9ba1bc24b663ea494982dd34b564 Mon Sep 17 00:00:00 2001 From: 36000 Date: Fri, 19 Aug 2022 09:44:36 -0700 Subject: [PATCH 3/3] everything uses AFQ logger --- AFQ/api/bundle_dict.py | 2 +- AFQ/api/group.py | 2 +- AFQ/api/participant.py | 2 +- AFQ/data/fetch.py | 12 ++++++------ AFQ/definitions/mapping.py | 2 +- AFQ/segmentation.py | 2 +- AFQ/tasks/decorators.py | 2 +- AFQ/tasks/mapping.py | 2 +- AFQ/tasks/segmentation.py | 2 +- AFQ/tasks/tractography.py | 2 +- AFQ/tasks/viz.py | 2 +- AFQ/tractography.py | 2 +- AFQ/utils/volume.py | 2 +- AFQ/viz/fury_backend.py | 2 +- AFQ/viz/plot.py | 2 +- AFQ/viz/plotly_backend.py | 2 +- AFQ/viz/utils.py | 2 +- bin/pyAFQ | 2 +- examples/plot_callosal_tract_profile.py | 3 +-- 19 files changed, 24 insertions(+), 25 deletions(-) diff --git a/AFQ/api/bundle_dict.py b/AFQ/api/bundle_dict.py index 0d38b7207..5ac4684fc 100644 --- a/AFQ/api/bundle_dict.py +++ b/AFQ/api/bundle_dict.py @@ -168,7 +168,7 @@ def __init__(self, for bundle_name in bundle_info: self.bundle_names.append(bundle_name) - self.logger = logging.getLogger('AFQ.api') + self.logger = logging.getLogger('AFQ') if self.seg_algo == "afq": if "FP" in self.bundle_names\ diff --git a/AFQ/api/group.py b/AFQ/api/group.py index f51ae6d22..dc23ed5b0 100644 --- a/AFQ/api/group.py +++ b/AFQ/api/group.py @@ -136,7 +136,7 @@ def __init__(self, if not isinstance(bids_layout_kwargs, dict): raise TypeError("bids_layout_kwargs must be a dict") - self.logger = logging.getLogger('AFQ.api') + self.logger = logging.getLogger('AFQ') self.logger.setLevel(logging.INFO) self.parallel_params = parallel_params diff --git a/AFQ/api/participant.py b/AFQ/api/participant.py index 4c2a1acb1..149e6cac0 100644 --- a/AFQ/api/participant.py +++ b/AFQ/api/participant.py @@ -88,7 +88,7 @@ def __init__(self, "unrecognized parameter tractography_params, " "did you mean tracking_params ?")) - self.logger = logging.getLogger('AFQ.api') + self.logger = logging.getLogger('AFQ') self.output_dir = output_dir kwargs = dict( diff --git a/AFQ/data/fetch.py b/AFQ/data/fetch.py index ea3ac1e5f..33f6cf75c 100644 --- a/AFQ/data/fetch.py +++ b/AFQ/data/fetch.py @@ -163,7 +163,7 @@ def read_callosum_templates(as_img=True, resample_to=False): dict with: keys: names of template ROIs and values: nibabel Nifti1Image objects from each of the ROI nifti files. """ - logger = logging.getLogger('AFQ.data') + logger = logging.getLogger('AFQ') logger.debug('loading callosum templates') tic = time.perf_counter() @@ -555,7 +555,7 @@ def read_templates(as_img=True, resample_to=False): dict with: keys: names of template ROIs and values: nibabel Nifti1Image objects from each of the ROI nifti files. """ - logger = logging.getLogger('AFQ.data') + logger = logging.getLogger('AFQ') logger.debug('loading AFQ templates') tic = time.perf_counter() @@ -649,7 +649,7 @@ def read_or_templates(as_img=True, resample_to=False): dict with: keys: names of template ROIs and values: nibabel Nifti1Image objects from each of the ROI nifti files. """ - logger = logging.getLogger('AFQ.data') + logger = logging.getLogger('AFQ') logger.debug('loading or templates') tic = time.perf_counter() @@ -795,7 +795,7 @@ def organize_stanford_data(path=None, clear_previous_afq=False): If clear_previous_afq is True and there is an afq folder in derivatives, it will be removed. """ - logger = logging.getLogger('AFQ.data') + logger = logging.getLogger('AFQ') # fetches data for first subject and session logger.info('fetching Stanford HARDI data') @@ -1188,7 +1188,7 @@ def bundles_to_aal(bundles, atlas=None): targets[bundle + "_" + region_name] = nib.Nifti1Image( aal_roi, atlas.affine) else: - logger = logging.getLogger('AFQ.data') + logger = logging.getLogger('AFQ') logger.warning(f"Segmentation end points undefined for {bundle}," + " continuing without end points") targets[bundle + "_start"] = None @@ -1309,7 +1309,7 @@ def read_ukbb_fa_template(mask=True): ) if not op.exists(fa_path): - logger = logging.getLogger('AFQ.data') + logger = logging.getLogger('AFQ') logger.warning( "Downloading brain MRI group mean statistics from UK Biobank. " + "This download is approximately 1.1 GB. " diff --git a/AFQ/definitions/mapping.py b/AFQ/definitions/mapping.py index a27c2ea07..2d2a15a1c 100644 --- a/AFQ/definitions/mapping.py +++ b/AFQ/definitions/mapping.py @@ -29,7 +29,7 @@ __all__ = ["FnirtMap", "SynMap", "SlrMap", "AffMap", "ItkMap"] -logger = logging.getLogger('AFQ.definitions.mapping') +logger = logging.getLogger('AFQ') # For map defintions, get_for_subses should return only the mapping diff --git a/AFQ/segmentation.py b/AFQ/segmentation.py index 8222d7297..40e488723 100644 --- a/AFQ/segmentation.py +++ b/AFQ/segmentation.py @@ -203,7 +203,7 @@ def __init__(self, matter anatomy and tract-specific quantification. Neuroimage 39: 336-347 """ - self.logger = logging.getLogger('AFQ.Segmentation') + self.logger = logging.getLogger('AFQ') self.nb_points = nb_points self.nb_streamlines = nb_streamlines diff --git a/AFQ/tasks/decorators.py b/AFQ/tasks/decorators.py index 18fd17890..40a395af2 100644 --- a/AFQ/tasks/decorators.py +++ b/AFQ/tasks/decorators.py @@ -19,7 +19,7 @@ __all__ = ["as_file", "as_fit_deriv", "as_img"] -logger = logging.getLogger('AFQ.api') +logger = logging.getLogger('AFQ') logger.setLevel(logging.INFO) diff --git a/AFQ/tasks/mapping.py b/AFQ/tasks/mapping.py index e760224ed..dea3a94d6 100644 --- a/AFQ/tasks/mapping.py +++ b/AFQ/tasks/mapping.py @@ -19,7 +19,7 @@ from dipy.io.stateful_tractogram import Space -logger = logging.getLogger('AFQ.api.mapping') +logger = logging.getLogger('AFQ') @pimms.calc("b0_warped") diff --git a/AFQ/tasks/segmentation.py b/AFQ/tasks/segmentation.py index 44abd1aca..e5b48ecad 100644 --- a/AFQ/tasks/segmentation.py +++ b/AFQ/tasks/segmentation.py @@ -24,7 +24,7 @@ from dipy.tracking.streamline import set_number_of_points, values_from_volume -logger = logging.getLogger('AFQ.api.seg') +logger = logging.getLogger('AFQ') @pimms.calc("bundles") diff --git a/AFQ/tasks/tractography.py b/AFQ/tasks/tractography.py index f628e4e52..13383f20b 100644 --- a/AFQ/tasks/tractography.py +++ b/AFQ/tasks/tractography.py @@ -11,7 +11,7 @@ from AFQ.tasks.utils import get_default_args from AFQ.definitions.image import ScalarImage -logger = logging.getLogger('AFQ.api') +logger = logging.getLogger('AFQ') @pimms.calc("seed") diff --git a/AFQ/tasks/viz.py b/AFQ/tasks/viz.py index ba4a15836..5a21d6469 100644 --- a/AFQ/tasks/viz.py +++ b/AFQ/tasks/viz.py @@ -17,7 +17,7 @@ from plotly.subplots import make_subplots -logger = logging.getLogger('AFQ.api.viz') +logger = logging.getLogger('AFQ') def _viz_prepare_vol(vol, xform, mapping, scalar_dict): diff --git a/AFQ/tractography.py b/AFQ/tractography.py index 4dfcb6e7a..d652d612b 100644 --- a/AFQ/tractography.py +++ b/AFQ/tractography.py @@ -99,7 +99,7 @@ def track(params_file, directions="prob", max_angle=30., sphere=None, Descoteaux, M. Towards quantitative connectivity analysis: reducing tractography biases. NeuroImage, 98, 266-278, 2014. """ - logger = logging.getLogger('AFQ.tractography') + logger = logging.getLogger('AFQ') logger.info("Loading Image...") if isinstance(params_file, str): diff --git a/AFQ/utils/volume.py b/AFQ/utils/volume.py index aaee5ca1b..95e770da2 100644 --- a/AFQ/utils/volume.py +++ b/AFQ/utils/volume.py @@ -11,7 +11,7 @@ from dipy.tracking.streamline import select_random_set_of_streamlines import dipy.tracking.utils as dtu -logger = logging.getLogger('AFQ.utils.volume') +logger = logging.getLogger('AFQ') def transform_inverse_roi(roi, mapping, bundle_name="ROI"): diff --git a/AFQ/viz/fury_backend.py b/AFQ/viz/fury_backend.py index 6d3f47f3f..d2e61e6d7 100644 --- a/AFQ/viz/fury_backend.py +++ b/AFQ/viz/fury_backend.py @@ -15,7 +15,7 @@ except (ImportError, ModuleNotFoundError): raise ImportError(vut.viz_import_msg_error("fury")) -viz_logger = logging.getLogger("AFQ.viz") +viz_logger = logging.getLogger("AFQ") def _inline_interact(scene, inline, interact): diff --git a/AFQ/viz/plot.py b/AFQ/viz/plot.py index ee1c5c4d4..cb1fbdabe 100644 --- a/AFQ/viz/plot.py +++ b/AFQ/viz/plot.py @@ -334,7 +334,7 @@ def __init__(self, out_folder, csv_fnames, names, is_special="", Can be 'ICC1, 'ICC2', 'ICC3', 'ICC1k', 'ICC2k', 'ICC3k'. Default: "ICC2" """ - self.logger = logging.getLogger('AFQ.csv') + self.logger = logging.getLogger('AFQ') self.ICC_func = ICC_func if "k" in self.ICC_func: self.ICC_func_name = f"ICC({self.ICC_func[3]},k)" diff --git a/AFQ/viz/plotly_backend.py b/AFQ/viz/plotly_backend.py index 0142a09cb..84ac63fad 100644 --- a/AFQ/viz/plotly_backend.py +++ b/AFQ/viz/plotly_backend.py @@ -21,7 +21,7 @@ scope = pio.kaleido.scope -viz_logger = logging.getLogger("AFQ.viz") +viz_logger = logging.getLogger("AFQ") def _inline_interact(figure, show, show_inline): diff --git a/AFQ/viz/utils.py b/AFQ/viz/utils.py index d25d9e0e2..0907a5c41 100644 --- a/AFQ/viz/utils.py +++ b/AFQ/viz/utils.py @@ -18,7 +18,7 @@ __all__ = ["Viz"] -viz_logger = logging.getLogger("AFQ.viz") +viz_logger = logging.getLogger("AFQ") tableau_20 = [ (0.12156862745098039, 0.4666666666666667, 0.7058823529411765), (0.6823529411764706, 0.7803921568627451, 0.9098039215686274), diff --git a/bin/pyAFQ b/bin/pyAFQ index 43b1f3648..b2bf70960 100644 --- a/bin/pyAFQ +++ b/bin/pyAFQ @@ -14,7 +14,7 @@ with warnings.catch_warnings(): import AFQ.utils.bin as afb import logging - logger = logging.getLogger('pyAFQ') + logger = logging.getLogger('AFQ') logger.setLevel(level=logging.INFO) usage = \ diff --git a/examples/plot_callosal_tract_profile.py b/examples/plot_callosal_tract_profile.py index c23754472..3acc634f3 100644 --- a/examples/plot_callosal_tract_profile.py +++ b/examples/plot_callosal_tract_profile.py @@ -50,8 +50,7 @@ # Ensure segmentation logging information is included in this example's output root = logging.getLogger() root.setLevel(logging.ERROR) -logging.getLogger('AFQ.Segmentation').setLevel(logging.INFO) -logging.getLogger('AFQ.tractography').setLevel(logging.INFO) +logging.getLogger('AFQ').setLevel(logging.INFO) handler = logging.StreamHandler(sys.stdout) handler.setLevel(logging.INFO) root.addHandler(handler)