diff --git a/phys2denoise/cli/run.py b/phys2denoise/cli/run.py index 58fea9e..64f14c1 100644 --- a/phys2denoise/cli/run.py +++ b/phys2denoise/cli/run.py @@ -90,7 +90,7 @@ def _get_parser(): "--respiratory-pattern-variability", dest="metrics", action="append_const", - const=respiratory_pattern_variability, + const="respiratory_pattern_variability", help="Respiratory pattern variability. Requires the following " "input: window.", default=[], @@ -100,7 +100,7 @@ def _get_parser(): "--envelope", dest="metrics", action="append_const", - const=env, + const="env", help="Respiratory pattern variability calculated across a sliding " "window. Requires the following inputs: sample-rate, window and lags.", default=[], @@ -416,6 +416,7 @@ def _get_parser(): return parser +@logger.catch() def main(): """ Main function to run the parser. @@ -434,8 +435,7 @@ def main(): logger.info(f"Running phys2denoise version: {__version__}") - LGR.debug(f"Arguments: {args}") - LGR.debug(f"Metrics to export: {args.metrics_to_export}") + LGR.debug(f"Arguments Provided: {args}") if args.metrics_to_export is None or args.metrics_to_export == "all": args.metrics_to_export = "all" @@ -452,12 +452,13 @@ def main(): args.slice_timings = ( np.array(args.slice_timings) if args.slice_timings is not None else None ) + args.lags = np.array(args.lags) if args.lags is not None else None metric_args = dict() for metric in args.metrics: metric_args[metric] = tasks.select_input_args(globals()[metric], vars(args)) - logger.debug(f"Metric args: {metric_args}") + logger.debug(f"Metrics: {args.metrics}") wf = workflow.build( input_file=args.filename, diff --git a/phys2denoise/metrics/chest_belt.py b/phys2denoise/metrics/chest_belt.py index 4e080fc..f2f7fdd 100644 --- a/phys2denoise/metrics/chest_belt.py +++ b/phys2denoise/metrics/chest_belt.py @@ -1,6 +1,7 @@ """Denoising metrics for chest belt recordings.""" import numpy as np import pandas as pd +from loguru import logger from physutils import io, physio from scipy.interpolate import interp1d from scipy.stats import zscore @@ -229,6 +230,7 @@ def _respiratory_pattern_variability(data, window): # Convert window to Hertz window = int(window * data.fs) + logger.debug(f"Window size in samples: {window}") # Calculate RPV across a rolling window diff --git a/phys2denoise/tasks.py b/phys2denoise/tasks.py index 8a65d60..3b5c35b 100644 --- a/phys2denoise/tasks.py +++ b/phys2denoise/tasks.py @@ -117,10 +117,17 @@ def export_metrics( if metrics == "all": LGR.info("Exporting all computed metrics") for metric in phys.computed_metrics.keys(): + if metric == "respiratory_pattern_variability": + LGR.warning( + f"respiratory_pattern_variability will not be exported, since it is a single value metric " + f"and not a timeseries. RPV value is {phys.computed_metrics[metric].data}" + ) + continue has_lags = ( True if "has_lags" in phys.computed_metrics[metric].args else False ) prefix = outdir + f"/{metric}" + LGR.debug(f"Exporting {metric} to {prefix}") export_metric( phys.computed_metrics[metric], phys.fs, tr, prefix, has_lags=has_lags ) @@ -131,10 +138,17 @@ def export_metrics( if metric not in phys.computed_metrics.keys(): LGR.warning(f"Metric {metric} not computed. Skipping") continue + if metric == "respiratory_pattern_variability": + LGR.warning( + f"respiratory_pattern_variability will not be exported, since it is a single value metric" + f"and not a timeseries. RPV value is {phys.computed_metrics[metric]}" + ) + continue has_lags = ( True if "has_lags" in phys.computed_metrics[metric].args else False ) prefix = outdir + f"/{metric}" + LGR.debug(f"Exporting {metric} to {prefix}") export_metric( phys.computed_metrics[metric], phys.fs, diff --git a/phys2denoise/tests/data/fake_phys.phys b/phys2denoise/tests/data/fake_phys.phys index 214aae7..17a4430 100644 Binary files a/phys2denoise/tests/data/fake_phys.phys and b/phys2denoise/tests/data/fake_phys.phys differ