Skip to content

Commit

Permalink
Add domain list option to get_feature_by_domain
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarandas committed Aug 27, 2024
1 parent 7dcaa08 commit 203357f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
2 changes: 0 additions & 2 deletions tests/test_features_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 14 additions & 0 deletions tsfel/feature_extraction/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
+ str(FEATURES_MIN_SIZE)
+ " data points."
)

future_warn_flag = False
warnings.simplefilter("once", FutureWarning)

# ############################################# TEMPORAL DOMAIN ##################################################### #


Expand Down Expand Up @@ -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])

Expand Down
33 changes: 26 additions & 7 deletions tsfel/feature_extraction/features_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 203357f

Please sign in to comment.