Skip to main content

Feature extraction for time series and EEG signals

Project description

SignaLytica

A Python package for feature extraction in time series and EEG signals

Installation

pip install signalytica

Dependencies

Utilization

Import modules

import numpy as np
import matplotlib.pyplot as plt
from signalytica import SignaLytica

Example time series data

np.random.seed(1234)
x = np.random.normal(size=128)
plt.figure(figsize=(6,2))
plt.plot(x)
plt.title('Example time serie'); plt.xlabel('Samples'); plt.ylabel('Amplitude')
plt.tight_layout()
plt.savefig('example_time_serie.png')

Output:

List all the available metrics in the package

signa = SignaLytica()
available_metrics = signa.list_metrics()
print(available_metrics)

Output:

['mean', 'std', 'coeff_var', 'median', 'mode', 'max', 'min', 'first_quartile', 'third_quartile', 'inter_quartile_range', 'kurtosis', 'skewness', 'activity_hjorth_param', 'mobility_hjorth_param', 'complexity_hjorth_param', 'total_power_spectral_density', 'centroid_power_spectral_density', 'relative_delta_power', 'relative_theta_power', 'relative_alpha_power', 'relative_beta_power', 'relative_gamma_power', 'determinism', 'trapping_time', 'diagonal_line_entropy', 'average_diagonal_line_length', 'compute_recurrence_rate', 'spectral_edge_frequency_25', 'spectral_edge_frequency_50', 'spectral_edge_frequency_75', 'delta_amplitude', 'theta_amplitude', 'beta_amplitude', 'alpha_amplitude', 'gamma_amplitude', 'hurst_exponent']

Extract specific features from time serie/EEG signal

features = ['coeff_var', 'inter_quartile_range', 'kurtosis', 'total_power_spectral_density', 'trapping_time']
signa.extract_features(x, features)

Output:

{ 'coeff_var': 0.9296511098623816, 'inter_quartile_range': 1.1642928949004765, 'kurtosis': 0.9355744131054928, 'total_power_spectral_density': 1.03503685376608, 'trapping_time': 2.2205882352941178 }

Calculate individual features

Activity Hjorth Paramater

hurst_exp = signa.activity_hjorth_param(x)
print(hurst_exp)

Output:

0.9296511098623816

Total power spectral density

hurst_exp = signa.total_power_spectral_density(x)
print(hurst_exp)

Output:

1.03503685376608

Determinism

hurst_exp = signa.determinism(x)
print(hurst_exp)

Output:

4.315972222222222

Alpha amplitude

hurst_exp = signa.alpha_amplitude(x)
print(hurst_exp)

Output:

0.19518190403498442

Hurst Exponent

hurst_exp = signa.hurst_exponent(x)
print(hurst_exp)

Output:

0.5074992385199263

Extract all feautres

Instead of use a list indicating the features, you can use the parameter all to calculate all the features.

all_features_calculated = signa.extract_features(x, 'all')
all_features_calculated

Output:

{'mean': 0.006880339575229891, 'std': 0.9641841680210175, 'coeff_var': 0.9296511098623816, 'median': 0.07802095042293272, 'mode': 0.47143516373249306, 'max': 2.390960515463033, 'min': -3.5635166606247353, 'first_quartile': -0.4874633299633267, 'third_quartile': 0.6768295649371497, 'inter_quartile_range': 1.1642928949004765, 'kurtosis': 0.9355744131054928, 'skewness': -0.5940081255524681, 'activity_hjorth_param': 0.9296511098623816, 'mobility_hjorth_param': 1.5772426970445614, 'complexity_hjorth_param': 1.1381489369369338, 'total_power_spectral_density': 1.03503685376608, 'centroid_power_spectral_density': 39.785545239633095, 'relative_delta_power': 0.014199533696614332, 'relative_theta_power': 0.024773922507739236, 'relative_alpha_power': 0.06670507211034518, 'relative_beta_power': 0.16222741368578988, 'relative_gamma_power': 0.1944461143387118, 'determinism': 4.315972222222222, 'trapping_time': 2.2205882352941178, 'diagonal_line_entropy': 2.794104878439014, 'average_diagonal_line_length': 26.28700906344411, 'compute_recurrence_rate': 0.063720703125, 'spectral_edge_frequency_25': 27.0, 'spectral_edge_frequency_50': 46.0, 'spectral_edge_frequency_75': 55.0, 'delta_amplitude': 0.332883261842357, 'theta_amplitude': 0.1334128596782051, 'beta_amplitude': 0.44829663314331475, 'alpha_amplitude': 0.19518190403498442, 'gamma_amplitude': 0.36127348831240264, 'hurst_exponent': 0.5074992385199263}

Convert the features into a feature vector

feature_vector = list(all_features_calculated.values())
print('features:', feature_vector)
print('n_features:', len(feature_vector))

Output:

features: [0.006880339575229891, 0.9641841680210175, 0.9296511098623816, 0.07802095042293272, 0.47143516373249306, 2.390960515463033, -3.5635166606247353, -0.4874633299633267, 0.6768295649371497, 1.1642928949004765, 0.9355744131054928, -0.5940081255524681, 0.9296511098623816, 1.5772426970445614, 1.1381489369369338, 1.03503685376608, 39.785545239633095, 0.014199533696614332, 0.024773922507739236, 0.06670507211034518, 0.16222741368578988, 0.1944461143387118, 4.315972222222222, 2.2205882352941178, 2.794104878439014, 26.28700906344411, 0.063720703125, 27.0, 46.0, 55.0, 0.332883261842357, 0.1334128596782051, 0.44829663314331475, 0.19518190403498442, 0.36127348831240264, 0.5074992385199263]

n_features: 36

Development

SignaLytica was created and is maintained by Edgar Lara. Contributions are more than welcome so feel free to contact me, open an issue or submit a pull request!

To see the code or report a bug, please visit the GitHub repository.

Note that this program is provided with NO WARRANTY OF ANY KIND. Always double check the results.

Acknowledgement

This package was inspired by the research work of Hernández Nava, G. (2023). Predicción de eventos epilépticos mediantes técnicas de aprendizaje profundo usando señales de EEG.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

signalytica-0.1.19.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

signalytica-0.1.19-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

Details for the file signalytica-0.1.19.tar.gz.

File metadata

  • Download URL: signalytica-0.1.19.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.16

File hashes

Hashes for signalytica-0.1.19.tar.gz
Algorithm Hash digest
SHA256 f930fccb83d6f99fc9832ff618568340cee5ccb6e5cd107efd95623735c709f4
MD5 b55e65541fa506fddebec1f0cec00a3d
BLAKE2b-256 b83fd3db0c1556815dceb9fc4344417a177c7d46053cb169e112d7d123d93ae8

See more details on using hashes here.

File details

Details for the file signalytica-0.1.19-py3-none-any.whl.

File metadata

  • Download URL: signalytica-0.1.19-py3-none-any.whl
  • Upload date:
  • Size: 20.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.16

File hashes

Hashes for signalytica-0.1.19-py3-none-any.whl
Algorithm Hash digest
SHA256 103f80b75c457a9c49aecc158e7c4350f59f6856beed4ce8cba42309421eade7
MD5 1491a322108e850fa0a6461409319c65
BLAKE2b-256 ef40ac3722bb63492e1e6fffe50eed59efa4d737dbdb8924dbf5ae143b4530b4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page