From 203357f1d0c71a786b3b12029054d9884b2a0ea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADlia=20Barandas?= Date: Tue, 27 Aug 2024 11:10:35 +0100 Subject: [PATCH] Add domain list option to get_feature_by_domain --- tests/test_features_settings.py | 2 -- tsfel/feature_extraction/features.py | 14 ++++++++ tsfel/feature_extraction/features_settings.py | 33 +++++++++++++++---- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/tests/test_features_settings.py b/tests/test_features_settings.py index 943cbda..6d5b533 100644 --- a/tests/test_features_settings.py +++ b/tests/test_features_settings.py @@ -14,8 +14,6 @@ settings4 = tsfel.get_features_by_domain(None) -# settings5 = tsfel.extract_sheet('Features') - settings6 = tsfel.get_features_by_tag("audio") settings7 = tsfel.get_features_by_tag("inertial") diff --git a/tsfel/feature_extraction/features.py b/tsfel/feature_extraction/features.py index 866635f..75cbf5f 100644 --- a/tsfel/feature_extraction/features.py +++ b/tsfel/feature_extraction/features.py @@ -12,6 +12,10 @@ + str(FEATURES_MIN_SIZE) + " data points." ) + +future_warn_flag = False +warnings.simplefilter("once", FutureWarning) + # ############################################# TEMPORAL DOMAIN ##################################################### # @@ -488,6 +492,16 @@ def hist(signal, nbins=10, r=1): nd-array The values of the histogram """ + global future_warn_flag + + if not future_warn_flag: + warnings.warn( + ("The histogram feature was deprecated in version 0.1.8 and will be replaced by the mode of histogram in 0.1.9." + " From then on, only a single feature value will be returned."), + FutureWarning + ) + future_warn_flag = True + # TODO: r value must be revised! histsig, bin_edges = np.histogram(signal, bins=nbins, range=[-r, r]) diff --git a/tsfel/feature_extraction/features_settings.py b/tsfel/feature_extraction/features_settings.py index f4b499d..8f22265 100644 --- a/tsfel/feature_extraction/features_settings.py +++ b/tsfel/feature_extraction/features_settings.py @@ -42,23 +42,42 @@ def get_features_by_domain(domain=None, json_path=None): Dict Dictionary with the features settings """ + + valid_domains = ["statistical", "temporal", "spectral", "fractal", "all"] if json_path is None: json_path = tsfel.__path__[0] + "/feature_extraction/features.json" - if domain not in ["statistical", "temporal", "spectral", "fractal", None]: - raise SystemExit( - "No valid domain. Choose: statistical, temporal, spectral, fractal or None (for all feature settings).", + if isinstance(domain, str) and domain not in valid_domains: + raise ValueError( + f"Domain {domain} is invalid. Please choose from `statistical`, `temporal`, `spectral`, `fractal` or `all`.", + ) + elif isinstance(domain, list) and not np.all([d in valid_domains for d in domain]): + raise ValueError( + "At least one invalid domain was provided. Please choose from `statistical`, `temporal`, `spectral`, `fractal` or `all`.", + ) + elif not isinstance(domain, (str, list)) and domain is not None: + raise TypeError( + "The 'domain' argument must be a string or a list of strings.", ) dict_features = load_json(json_path) if domain is None: return dict_features else: - if domain == "fractal": - for k in dict_features[domain]: - dict_features[domain][k]["use"] = "yes" - return {domain: dict_features[domain]} + if domain == "all": + domain = ["statistical", "temporal", "spectral", "fractal"] + + if isinstance(domain, str): + domain = [domain] + + d_feat = {} + for d in domain: + if d == "fractal": + for k in dict_features[d]: + dict_features[d][k]["use"] = "yes" + d_feat.update({d: dict_features[d]}) + return d_feat def get_features_by_tag(tag=None, json_path=None):