raphaelvallat / entropy

EntroPy: complexity of time-series in Python (DEPRECATED)
https://raphaelvallat.com/entropy/
BSD 3-Clause "New" or "Revised" License
156 stars 47 forks source link

module 'entropy' has no attribute error for all entropy/complexity tests #6

Closed apavlo89 closed 4 years ago

apavlo89 commented 4 years ago

A bizzare issue that has come up after formatting my pc and reinstalling entropy. I am not sure if I'm making a mistake or the newest version of entropy broke something.

This is the code I am using for a two-channel resting-state EEG study.

` import yasa import mne import numpy as np import seaborn as sns import pandas as pd import entropy as ent sns.set(font_scale=1.2)

P1

Load data as a eeglab file

f = mne.io.read_raw_eeglab('D:/study/EEGLAB/resting state/Recordings/bandpass 0point5 - 45Hz +ASR/1_EEG_LR_RS.set', eog=(), preload=True, uint16_codec=None, verbose=None)

Load data

data = f._data * 1e6

sf = f.info['sfreq'] chan = f.ch_names times = np.arange(data.shape[1]) / sf

print(data.shape, np.round(data[0:5], 3))

Convert the EEG data to 30-sec data

times, data_win = yasa.sliding_window(data, sf, window=51)

Convert times to minutes

times /= 60

from numpy import apply_along_axis as apply

def lziv(x): """Binarize the EEG signal and calculate the Lempel-Ziv complexity. """ return ent.lziv_complexity(x > x.mean(), normalize=True)

df_all = []

for i, c in enumerate(chan): data_win_ep = data_win[i, :, :]

Calculate entropy for this channel

df_chan = {
# Entropy
'perm_entropy': apply(ent.perm_entropy, axis=1, arr=data_win_ep, normalize=True),
'svd_entropy': apply(ent.svd_entropy, 1, data_win_ep, normalize=True),
'spec_entropy': apply(ent.spectral_entropy, 1, data_win_ep, sf=sf, nperseg=data_win_ep.shape[1], normalize=True),
'sample_entropy': apply(ent.sample_entropy, 1, data_win_ep),
# Fractal dimension
'dfa': apply(ent.detrended_fluctuation, 1, data_win_ep),
'petrosian': apply(ent.petrosian_fd, 1, data_win_ep),
'katz': apply(ent.katz_fd, 1, data_win_ep),
'higuchi': apply(ent.higuchi_fd, 1, data_win_ep),
'lziv': apply(lziv, 1, data_win_ep),
}

df_chan['Channel'] = f
# Append to a larger dataframe
df_all.append(df_chan)

df_all = pd.DataFrame(df_all) df_all.to_csv(r'D:\study\EEGLAB\resting state\nonlinear - ASR + BANDPASS\1_nonlinear.csv')`

Error: AttributeError: module 'entropy' has no attribute 'perm_entropy'. This happens with all different types of entropy/complexity is just stops at the first one.

Thank you for your help in the matter.