Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A priori 'feature vector size' #50

Closed
jpalma-espinosa opened this issue Jul 8, 2020 · 5 comments
Closed

A priori 'feature vector size' #50

jpalma-espinosa opened this issue Jul 8, 2020 · 5 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@jpalma-espinosa
Copy link

Dear all,

Playing with your tool I wanted to obtain the spectral features for a given signal

cfg = tsfel.get_features_by_domain(domain='spectral')
len(cfg['spectral'].keys())
26

26 spectral features, nice!

But, when I calculated those features

#Fs previously obtained from data
X = tsfel.time_series_features_extractor(cfg, data,fs=Fs)
X.size
335

335 elements!.

I would love to iterate among several time-series, and obtain a feature matrix. I would like to know a priori the size of the X features, as I may create a specific variable array to store the values.
I know that certain features of the signal are computed in time slots (such as FFT_mean_coeff), but is really time consuming to annotate how many results per feature I should expect.

Thus, is there any option to know a priori how many elements will be in the X series?

@mbarandas mbarandas self-assigned this Jul 8, 2020
@mbarandas mbarandas added the enhancement New feature or request label Jul 8, 2020
mbarandas added a commit that referenced this issue Jul 8, 2020
…or counting the total number of features #50. Changed the default value of ECDF percentile
@mbarandas
Copy link
Collaborator

mbarandas commented Jul 8, 2020

Hi! I've just added a function that returns the size of the feature vector on development branch.
You can directly install this version "pip install https://github.com/fraunhoferportugal/tsfel/archive/v0.1.4-dev.zip"

cfg = tsfel.get_features_by_domain(domain='spectral')
tsfel.get_number_features(cfg)
335

If more issues arise, feel free to contact us.

@jpalma-espinosa
Copy link
Author

Thank you!
i'll try it and come back to you

@jpalma-espinosa
Copy link
Author

jpalma-espinosa commented Jul 8, 2020

Dear @mbarandas
i followed your suggestions, but encountered an error. I am providing the exact steps that may help to replicate the error

All of my work is done in Google Colaboratory, in my personal account.

#%pip install tsfel
%pip install https://github.com/fraunhoferportugal/tsfel/archive/v0.1.4-dev.zip#egg=tsfel

Collecting tsfel
  Downloading https://github.com/fraunhoferportugal/tsfel/archive/v0.1.4-dev.zip
     / 2.0MB 577kB/s
Requirement already satisfied: Sphinx>=1.8.5 in /usr/local/lib/python3.6/dist-packages (from tsfel) (1.8.5)
Collecting gspread>=3.1.0
  Downloading https://files.pythonhosted.org/packages/9c/ba/bc8de4f5077bd34bc873bdd67a89cb29c4f181abba8a836d2c6a0a142365/gspread-3.6.0-py3-none-any.whl
Collecting ipython>=7.4.0
  Downloading https://files.pythonhosted.org/packages/23/6a/210816c943c9aeeb29e4e18a298f14bf0e118fe222a23e13bfcc2d41b0a4/ipython-7.16.1-py3-none-any.whl (785kB)
     |████████████████████████████████| 788kB 4.0MB/s 
Requirement already satisfied: numpy>=1.18.5 in /usr/local/lib/python3.6/dist-packages (from tsfel) (1.18.5)
Requirement already satisfied: oauth2client>=4.1.3 in /usr/local/lib/python3.6/dist-packages (from tsfel) (4.1.3)
Requirement already satisfied: pandas>=0.25.3 in /usr/local/lib/python3.6/dist-packages (from tsfel) (1.0.5)
Requirement already satisfied: scipy>=1.4.1 in /usr/local/lib/python3.6/dist-packages (from tsfel) (1.4.1)
Requirement already satisfied: setuptools>=47.1.1 in /usr/local/lib/python3.6/dist-packages (from tsfel) (47.3.1)
Requirement already satisfied: babel!=2.0,>=1.3 in /usr/local/lib/python3.6/dist-packages (from Sphinx>=1.8.5->tsfel) (2.8.0)
Requirement already satisfied: Jinja2>=2.3 in /usr/local/lib/python3.6/dist-packages (from Sphinx>=1.8.5->tsfel) (2.11.2)
Requirement already satisfied: packaging in /usr/local/lib/python3.6/dist-packages (from Sphinx>=1.8.5->tsfel) (20.4)
Requirement already satisfied: alabaster<0.8,>=0.7 in /usr/local/lib/python3.6/dist-packages (from Sphinx>=1.8.5->tsfel) (0.7.12)
Requirement already satisfied: sphinxcontrib-websupport in /usr/local/lib/python3.6/dist-packages (from Sphinx>=1.8.5->tsfel) (1.2.2)
Requirement already satisfied: imagesize in /usr/local/lib/python3.6/dist-packages (from Sphinx>=1.8.5->tsfel) (1.2.0)
Requirement already satisfied: requests>=2.0.0 in /usr/local/lib/python3.6/dist-packages (from Sphinx>=1.8.5->tsfel) (2.23.0)
Requirement already satisfied: snowballstemmer>=1.1 in /usr/local/lib/python3.6/dist-packages (from Sphinx>=1.8.5->tsfel) (2.0.0)
Requirement already satisfied: Pygments>=2.0 in /usr/local/lib/python3.6/dist-packages (from Sphinx>=1.8.5->tsfel) (2.1.3)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.6/dist-packages (from Sphinx>=1.8.5->tsfel) (1.12.0)
Requirement already satisfied: docutils>=0.11 in /usr/local/lib/python3.6/dist-packages (from Sphinx>=1.8.5->tsfel) (0.15.2)
Requirement already satisfied: google-auth>=1.12.0 in /usr/local/lib/python3.6/dist-packages (from gspread>=3.1.0->tsfel) (1.17.2)
Requirement already satisfied: google-auth-oauthlib>=0.4.1 in /usr/local/lib/python3.6/dist-packages (from gspread>=3.1.0->tsfel) (0.4.1)
Requirement already satisfied: traitlets>=4.2 in /usr/local/lib/python3.6/dist-packages (from ipython>=7.4.0->tsfel) (4.3.3)
Requirement already satisfied: decorator in /usr/local/lib/python3.6/dist-packages (from ipython>=7.4.0->tsfel) (4.4.2)
Requirement already satisfied: jedi>=0.10 in /usr/local/lib/python3.6/dist-packages (from ipython>=7.4.0->tsfel) (0.17.1)
Requirement already satisfied: pickleshare in /usr/local/lib/python3.6/dist-packages (from ipython>=7.4.0->tsfel) (0.7.5)
Requirement already satisfied: pexpect; sys_platform != "win32" in /usr/local/lib/python3.6/dist-packages (from ipython>=7.4.0->tsfel) (4.8.0)
Requirement already satisfied: backcall in /usr/local/lib/python3.6/dist-packages (from ipython>=7.4.0->tsfel) (0.2.0)
Collecting prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0
  Downloading https://files.pythonhosted.org/packages/e4/a7/81b39aa50e9284fe2cb21cc7fb7de7817b224172d42793fd57451d38842b/prompt_toolkit-3.0.5-py3-none-any.whl (351kB)
     |████████████████████████████████| 358kB 15.5MB/s 
Requirement already satisfied: rsa>=3.1.4 in /usr/local/lib/python3.6/dist-packages (from oauth2client>=4.1.3->tsfel) (4.6)
Requirement already satisfied: httplib2>=0.9.1 in /usr/local/lib/python3.6/dist-packages (from oauth2client>=4.1.3->tsfel) (0.17.4)
Requirement already satisfied: pyasn1>=0.1.7 in /usr/local/lib/python3.6/dist-packages (from oauth2client>=4.1.3->tsfel) (0.4.8)
Requirement already satisfied: pyasn1-modules>=0.0.5 in /usr/local/lib/python3.6/dist-packages (from oauth2client>=4.1.3->tsfel) (0.2.8)
Requirement already satisfied: pytz>=2017.2 in /usr/local/lib/python3.6/dist-packages (from pandas>=0.25.3->tsfel) (2018.9)
Requirement already satisfied: python-dateutil>=2.6.1 in /usr/local/lib/python3.6/dist-packages (from pandas>=0.25.3->tsfel) (2.8.1)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python3.6/dist-packages (from Jinja2>=2.3->Sphinx>=1.8.5->tsfel) (1.1.1)
Requirement already satisfied: pyparsing>=2.0.2 in /usr/local/lib/python3.6/dist-packages (from packaging->Sphinx>=1.8.5->tsfel) (2.4.7)
Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.6/dist-packages (from requests>=2.0.0->Sphinx>=1.8.5->tsfel) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests>=2.0.0->Sphinx>=1.8.5->tsfel) (2020.6.20)
Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests>=2.0.0->Sphinx>=1.8.5->tsfel) (2.9)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests>=2.0.0->Sphinx>=1.8.5->tsfel) (1.24.3)
Requirement already satisfied: cachetools<5.0,>=2.0.0 in /usr/local/lib/python3.6/dist-packages (from google-auth>=1.12.0->gspread>=3.1.0->tsfel) (4.1.0)
Requirement already satisfied: requests-oauthlib>=0.7.0 in /usr/local/lib/python3.6/dist-packages (from google-auth-oauthlib>=0.4.1->gspread>=3.1.0->tsfel) (1.3.0)
Requirement already satisfied: ipython-genutils in /usr/local/lib/python3.6/dist-packages (from traitlets>=4.2->ipython>=7.4.0->tsfel) (0.2.0)
Requirement already satisfied: parso<0.8.0,>=0.7.0 in /usr/local/lib/python3.6/dist-packages (from jedi>=0.10->ipython>=7.4.0->tsfel) (0.7.0)
Requirement already satisfied: ptyprocess>=0.5 in /usr/local/lib/python3.6/dist-packages (from pexpect; sys_platform != "win32"->ipython>=7.4.0->tsfel) (0.6.0)
Requirement already satisfied: wcwidth in /usr/local/lib/python3.6/dist-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->ipython>=7.4.0->tsfel) (0.2.5)
Requirement already satisfied: oauthlib>=3.0.0 in /usr/local/lib/python3.6/dist-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib>=0.4.1->gspread>=3.1.0->tsfel) (3.1.0)
Building wheels for collected packages: tsfel
  Building wheel for tsfel (setup.py) ... done
  Created wheel for tsfel: filename=tsfel-0.1.4-cp36-none-any.whl size=45431 sha256=05c2d6beb972bf73bcb23328bd0a371f9c068345220f6a6916a3d1f7e340695c
  Stored in directory: /root/.cache/pip/wheels/93/9c/47/8df02b8e0df9fdf00d2fc7079f201fa7468d2daab831a2d657
Successfully built tsfel
ERROR: jupyter-console 5.2.0 has requirement prompt-toolkit<2.0.0,>=1.0.0, but you'll have prompt-toolkit 3.0.5 which is incompatible.
ERROR: google-colab 1.0.0 has requirement ipython~=5.5.0, but you'll have ipython 7.16.1 which is incompatible.
Installing collected packages: gspread, prompt-toolkit, ipython, tsfel
  Found existing installation: gspread 3.0.1
    Uninstalling gspread-3.0.1:
      Successfully uninstalled gspread-3.0.1
  Found existing installation: prompt-toolkit 1.0.18
    Uninstalling prompt-toolkit-1.0.18:
      Successfully uninstalled prompt-toolkit-1.0.18
  Found existing installation: ipython 5.5.0
    Uninstalling ipython-5.5.0:
      Successfully uninstalled ipython-5.5.0
Successfully installed gspread-3.6.0 ipython-7.16.1 prompt-toolkit-3.0.5 tsfel-0.1.4
WARNING: Upgrading ipython, ipykernel, tornado, prompt-toolkit or pyzmq can
cause your runtime to repeatedly crash or behave in unexpected ways and is not
recommended. If your runtime won't connect or execute code, you can reset it
with "Factory reset runtime" from the "Runtime" menu.
WARNING: The following packages were previously imported in this runtime:
  [IPython,prompt_toolkit]
You must restart the runtime in order to use newly installed versions.

So I restarted the runtime

after that, I imported the libraries

import numpy as np
import matplotlib.pyplot as plt
import rhd #libraries for opening a specific electrophysiology data
import tsfel

and run your code

cfg = tsfel.get_features_by_domain(domain='spectral')
tsfel.get_number_features(cfg)

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-3-26479f8d98cd> in <module>
      1 cfg = tsfel.get_features_by_domain(domain='spectral')
----> 2 tsfel.get_number_features(cfg)

/usr/local/lib/python3.6/dist-packages/tsfel/feature_extraction/features_settings.py in get_number_features(dict_features)
     68     number_features = 0
     69     for domain in dict_features:
---> 70         for feat in cfg[domain]:
     71             if cfg[domain][feat]["use"] == "no":
     72                 continue

NameError: name 'cfg' is not defined

I first thought that it was a variable name, so I decided to get rid of that by

feats = tsfel.get_features_by_domain(domain='spectral')
tsfel.get_number_features(feats)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-2-ce38cc1f0e1e> in <module>
      1 feats = tsfel.get_features_by_domain(domain='spectral')
----> 2 tsfel.get_number_features(feats)

/usr/local/lib/python3.6/dist-packages/tsfel/feature_extraction/features_settings.py in get_number_features(dict_features)
     68     number_features = 0
     69     for domain in dict_features:
---> 70         for feat in cfg[domain]:
     71             if cfg[domain][feat]["use"] == "no":
     72                 continue

NameError: name 'cfg' is not defined

given that I still got the same mistake, I decided to test another approach

tsfel.get_number_features(tsfel.get_features_by_domain(domain='spectral'))
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-10-b7a01fc5db9a> in <module>()
----> 1 tsfel.get_number_features(tsfel.get_features_by_domain(domain='spectral'))

/usr/local/lib/python3.6/dist-packages/tsfel/feature_extraction/features_settings.py in get_number_features(dict_features)
     68     number_features = 0
     69     for domain in dict_features:
---> 70         for feat in cfg[domain]:
     71             if cfg[domain][feat]["use"] == "no":
     72                 continue

NameError: name 'cfg' is not defined

Do you have any idea on what might be going on? Is it possible that a local variable is thought as global variable or parameter within the get_features_by_domain function?

mbarandas added a commit that referenced this issue Jul 9, 2020
@mbarandas
Copy link
Collaborator

Hi @jpalma-espinosa.
Thanks for testing and report the issue. I changed the variable name and I forgot to update the name on the entire function.
I've just fixed the bug and updated the release v0.1.4-dev.

You can install again this version:
pip install https://github.com/fraunhoferportugal/tsfel/archive/v0.1.4-dev.zip

@jpalma-espinosa
Copy link
Author

Sorry for my delay.
I just tested the feature and it works perfectly.
Tested with the three domains and got the desired output.
Thank you!

@dmfolgado dmfolgado added this to the v0.1.4 milestone Jul 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants