From 3d1e55fa87abccef768c4e94c8dee71f7bcfcb0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Luk=C3=A1ny?= Date: Wed, 13 Sep 2023 12:02:09 +0200 Subject: [PATCH] refactor: simplify error handling in TimeSeriesAnalysis section --- .../timeseries_analysis.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/edvart/report_sections/timeseries_analysis/timeseries_analysis.py b/edvart/report_sections/timeseries_analysis/timeseries_analysis.py index 09d841f..a069dfc 100644 --- a/edvart/report_sections/timeseries_analysis/timeseries_analysis.py +++ b/edvart/report_sections/timeseries_analysis/timeseries_analysis.py @@ -144,6 +144,17 @@ def __init__( enum_to_implementation[subsec.ShortTimeFT] = ShortTimeFT( sampling_rate, stft_window_size, verbosity_short_time_ft, columns ) + elif subsections is not None and subsec.ShortTimeFT in subsections: + raise ValueError( + "Need to set an `stft_window_size` to plot Short-time Fourier transform." + ) + elif subsections is not None: + if subsec.FourierTransform in subsections: + raise ValueError("Need to set a `sampling_rate` to plot Fourier transform.") + if subsec.ShortTimeFT in subsections: + raise ValueError( + "Need to set a `sampling_rate` to plot Short-time Fourier transform." + ) # By default use all subsections, FT and STFT only if required parameters specified if subsections is None: @@ -162,17 +173,6 @@ def __init__( if subsections is None: subsections_implementations = list(enum_to_implementation.values()) else: - if sampling_rate is None: - if subsec.FourierTransform in subsections: - raise ValueError("Need to set a `sampling_rate` to plot Fourier transform.") - if subsec.ShortTimeFT in subsections: - raise ValueError( - "Need to set a `sampling_rate` to plot Short-time Fourier transform." - ) - if stft_window_size is None and subsec.ShortTimeFT in subsections: - raise ValueError( - "Need to set an `stft_window_size` to plot Short-time Fourier transform." - ) subsections_implementations = [enum_to_implementation[sub] for sub in subsections] super().__init__(subsections_implementations, verbosity, columns)