From e1b73b68b26c34e94b08c7d7f24b76adfdc63734 Mon Sep 17 00:00:00 2001 From: maestroque Date: Mon, 13 May 2024 15:36:56 +0300 Subject: [PATCH 1/3] Add loguru to setup.cfg --- setup.cfg | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setup.cfg b/setup.cfg index 8b89352..8a0ce00 100644 --- a/setup.cfg +++ b/setup.cfg @@ -53,10 +53,13 @@ test = coverage devtools = pre-commit +logger = + loguru dev = %(devtools)s %(doc)s %(test)s + %(logger)s [options.entry_points] console_scripts = From 3e7b3e776678f8eb50ff0f975b37b9aaf35e621f Mon Sep 17 00:00:00 2001 From: maestroque Date: Mon, 13 May 2024 22:27:41 +0300 Subject: [PATCH 2/3] Initial integration of loguru --- phys2denoise/metrics/cardiac.py | 2 ++ phys2denoise/metrics/utils.py | 11 ++++------- phys2denoise/workflow.py | 14 ++++++++++---- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/phys2denoise/metrics/cardiac.py b/phys2denoise/metrics/cardiac.py index 40ebc47..1c132f3 100644 --- a/phys2denoise/metrics/cardiac.py +++ b/phys2denoise/metrics/cardiac.py @@ -6,8 +6,10 @@ from .responses import crf from .utils import apply_function_in_sliding_window as afsw from .utils import convolve_and_rescale +from loguru import logger +@logger.catch def _cardiac_metrics(card, peaks, samplerate, metric, window=6, central_measure="mean"): """ Compute cardiac metrics. diff --git a/phys2denoise/metrics/utils.py b/phys2denoise/metrics/utils.py index 34fb21b..81d1b5a 100644 --- a/phys2denoise/metrics/utils.py +++ b/phys2denoise/metrics/utils.py @@ -5,9 +5,7 @@ from numpy.lib.stride_tricks import sliding_window_view as swv from scipy.interpolate import interp1d from scipy.stats import zscore - -LGR = logging.getLogger(__name__) -LGR.setLevel(logging.INFO) +from loguru import logger def print_metric_call(metric, args): @@ -33,7 +31,7 @@ def print_metric_call(metric, args): msg = f"{msg}\n" - LGR.info(msg) + logger.info(msg) def mirrorpad_1d(arr, buffer=250): @@ -58,10 +56,9 @@ def mirrorpad_1d(arr, buffer=250): post_mirror = np.take(mirror, idx, axis=0) except IndexError: len(arr) - LGR.warning( + logger.warning( f"Requested buffer size ({buffer}) is longer than input array length " - f"({len(arr)}). Fixing buffer size to array length." - ) + f"({len(arr)}). Fixing buffer size to array length.") idx = range(arr.shape[0] - len(arr), arr.shape[0]) pre_mirror = np.take(mirror, idx, axis=0) idx = range(len(arr)) diff --git a/phys2denoise/workflow.py b/phys2denoise/workflow.py index 170abeb..d09265d 100644 --- a/phys2denoise/workflow.py +++ b/phys2denoise/workflow.py @@ -29,11 +29,13 @@ ) from phys2denoise.metrics.retroicor import retroicor +from loguru import logger + from . import __version__ from .due import Doi, due -LGR = logging.getLogger(__name__) -LGR.setLevel(logging.INFO) +# LGR = logging.getLogger(__name__) +# LGR.setLevel(logging.INFO) def save_bash_call(outdir): @@ -59,6 +61,7 @@ def save_bash_call(outdir): f.close() +@logger.catch def select_input_args(metric, metric_args): """ Retrieve required args for metric from a dictionary of possible arguments. @@ -112,6 +115,7 @@ def select_input_args(metric, metric_args): version=__version__, cite_module=True, ) +@logger.catch def phys2denoise( filename, outdir=".", @@ -182,8 +186,10 @@ def phys2denoise( ) version_number = __version__ - LGR.info(f"Currently running phys2denoise version {version_number}") - LGR.info(f"Input file is {filename}") + # LGR.info(f"Currently running phys2denoise version {version_number}") + # LGR.info(f"Input file is {filename}") + logger.info(f"Currently running phys2denoise version {version_number}") + logger.info(f"Input file is {filename}") # Check options to make them internally coherent pt. II # #!# This can probably be done while parsing? From 6171f0b5e61066f044007f6b4801ea92ec61562d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 13 May 2024 19:27:54 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- phys2denoise/metrics/cardiac.py | 2 +- phys2denoise/metrics/utils.py | 5 +++-- phys2denoise/workflow.py | 3 +-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/phys2denoise/metrics/cardiac.py b/phys2denoise/metrics/cardiac.py index 1c132f3..0c102ec 100644 --- a/phys2denoise/metrics/cardiac.py +++ b/phys2denoise/metrics/cardiac.py @@ -1,12 +1,12 @@ """Denoising metrics for cardio recordings.""" import numpy as np +from loguru import logger from .. import references from ..due import due from .responses import crf from .utils import apply_function_in_sliding_window as afsw from .utils import convolve_and_rescale -from loguru import logger @logger.catch diff --git a/phys2denoise/metrics/utils.py b/phys2denoise/metrics/utils.py index 81d1b5a..6005347 100644 --- a/phys2denoise/metrics/utils.py +++ b/phys2denoise/metrics/utils.py @@ -2,10 +2,10 @@ import logging import numpy as np +from loguru import logger from numpy.lib.stride_tricks import sliding_window_view as swv from scipy.interpolate import interp1d from scipy.stats import zscore -from loguru import logger def print_metric_call(metric, args): @@ -58,7 +58,8 @@ def mirrorpad_1d(arr, buffer=250): len(arr) logger.warning( f"Requested buffer size ({buffer}) is longer than input array length " - f"({len(arr)}). Fixing buffer size to array length.") + f"({len(arr)}). Fixing buffer size to array length." + ) idx = range(arr.shape[0] - len(arr), arr.shape[0]) pre_mirror = np.take(mirror, idx, axis=0) idx = range(len(arr)) diff --git a/phys2denoise/workflow.py b/phys2denoise/workflow.py index d09265d..222c601 100644 --- a/phys2denoise/workflow.py +++ b/phys2denoise/workflow.py @@ -18,6 +18,7 @@ import numpy as np import pandas as pd +from loguru import logger from phys2denoise.cli.run import _get_parser from phys2denoise.metrics.cardiac import crf @@ -29,8 +30,6 @@ ) from phys2denoise.metrics.retroicor import retroicor -from loguru import logger - from . import __version__ from .due import Doi, due