eegprep 0.0.2__tar.gz → 0.0.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. {eegprep-0.0.2/src/eegprep.egg-info → eegprep-0.0.4}/PKG-INFO +26 -3
  2. {eegprep-0.0.2 → eegprep-0.0.4}/README.md +23 -1
  3. {eegprep-0.0.2 → eegprep-0.0.4}/pyproject.toml +3 -2
  4. {eegprep-0.0.2 → eegprep-0.0.4}/src/eegprep/ICL_feature_extractor.py +6 -6
  5. eegprep-0.0.4/src/eegprep/__init__.py +14 -0
  6. {eegprep-0.0.2 → eegprep-0.0.4}/src/eegprep/eeg_autocorr.py +3 -3
  7. {eegprep-0.0.2 → eegprep-0.0.4}/src/eegprep/eeg_autocorr_fftw.py +1 -1
  8. {eegprep-0.0.2 → eegprep-0.0.4}/src/eegprep/eeg_autocorr_welch.py +4 -4
  9. {eegprep-0.0.2 → eegprep-0.0.4}/src/eegprep/eeg_checkset.py +1 -1
  10. {eegprep-0.0.2 → eegprep-0.0.4}/src/eegprep/eeg_eeglab2mne.py +3 -3
  11. {eegprep-0.0.2 → eegprep-0.0.4}/src/eegprep/eeg_mne2eeglab.py +2 -2
  12. eegprep-0.0.4/src/eegprep/eeg_picard.py +30 -0
  13. {eegprep-0.0.2 → eegprep-0.0.4}/src/eegprep/eeg_rpsd.py +1 -1
  14. eegprep-0.0.4/src/eegprep/eeglabcompat.py +129 -0
  15. {eegprep-0.0.2 → eegprep-0.0.4}/src/eegprep/iclabel.py +13 -8
  16. {eegprep-0.0.2 → eegprep-0.0.4}/src/eegprep/iclabel_net.py +25 -25
  17. {eegprep-0.0.2 → eegprep-0.0.4}/src/eegprep/iclabel_net_load_py_measures.py +1 -1
  18. {eegprep-0.0.2 → eegprep-0.0.4}/src/eegprep/pop_loadset.py +10 -2
  19. {eegprep-0.0.2 → eegprep-0.0.4}/src/eegprep/pop_reref_helper.py +4 -4
  20. {eegprep-0.0.2 → eegprep-0.0.4}/src/eegprep/pop_resample.py +14 -10
  21. {eegprep-0.0.2 → eegprep-0.0.4}/src/eegprep/pop_saveset.py +2 -1
  22. {eegprep-0.0.2 → eegprep-0.0.4/src/eegprep.egg-info}/PKG-INFO +26 -3
  23. {eegprep-0.0.2 → eegprep-0.0.4}/src/eegprep.egg-info/SOURCES.txt +1 -8
  24. {eegprep-0.0.2 → eegprep-0.0.4}/src/eegprep.egg-info/requires.txt +1 -0
  25. eegprep-0.0.2/src/eegprep/ICL_feature_extractor_compare_helper.py +0 -19
  26. eegprep-0.0.2/src/eegprep/__init__.py +0 -1
  27. eegprep-0.0.2/src/eegprep/eeg_autocorr_compare_helper.py +0 -13
  28. eegprep-0.0.2/src/eegprep/eeg_autocorr_fftw_compare_helper.py +0 -20
  29. eegprep-0.0.2/src/eegprep/eeg_autocorr_welch_compare_helper.py +0 -13
  30. eegprep-0.0.2/src/eegprep/eeg_rpsd_compare_helper.py +0 -17
  31. eegprep-0.0.2/src/eegprep/eeglabcompat.py +0 -117
  32. eegprep-0.0.2/src/eegprep/iclabel_helper.py +0 -26
  33. eegprep-0.0.2/src/eegprep/pop_reref_compare_helper.py +0 -31
  34. eegprep-0.0.2/src/eegprep/topoplot_compare_helper.py +0 -29
  35. {eegprep-0.0.2 → eegprep-0.0.4}/LICENSE +0 -0
  36. {eegprep-0.0.2 → eegprep-0.0.4}/setup.cfg +0 -0
  37. {eegprep-0.0.2 → eegprep-0.0.4}/src/eegprep/eeg_mne2eeglab_epochs.py +0 -0
  38. {eegprep-0.0.2 → eegprep-0.0.4}/src/eegprep/pop_reref.py +0 -0
  39. {eegprep-0.0.2 → eegprep-0.0.4}/src/eegprep/save_struct_as_hdf5.py +0 -0
  40. {eegprep-0.0.2 → eegprep-0.0.4}/src/eegprep/topoplot.py +0 -0
  41. {eegprep-0.0.2 → eegprep-0.0.4}/src/eegprep.egg-info/dependency_links.txt +0 -0
  42. {eegprep-0.0.2 → eegprep-0.0.4}/src/eegprep.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: eegprep
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Summary: EEG preprocessing pipeline on Python
5
5
  Author-email: Arnaud Delorme <adelorme@gmail.com>, Young Truong <dt.young112@gmail.com>
6
6
  License: GNU General Public License
@@ -39,8 +39,20 @@ Requires-Dist: mne>=1.0.0
39
39
  Requires-Dist: oct2py>=5.5.0
40
40
  Requires-Dist: torch>=1.10.0
41
41
  Requires-Dist: h5py>=3.3.0
42
+ Requires-Dist: python-picard
42
43
 
43
- ## how to duplicate a function
44
+ ## Build docker
45
+
46
+ docker run --rm -it -v $(pwd):/usr/src/project dtyoung/eegprep /bin/bash
47
+ docker run -u root --rm -it -v $(pwd):/usr/src/project dtyoung/eegprep /bin/bash
48
+
49
+ # remove
50
+
51
+ docker rmi dtyoung/eegprep
52
+
53
+ Mounted folder in /usr/src/project
54
+
55
+ ## How to convert a function from MATLAB to Python
44
56
 
45
57
  1. Get a MATLAB file to load and process an EEG file
46
58
 
@@ -54,3 +66,14 @@ Requires-Dist: h5py>=3.3.0
54
66
 
55
67
  6. Write the function to compare (see example) and the helper Python function to load the file (note that there could be a general Python helper function)
56
68
 
69
+ ## Install package
70
+ Packaging was done following the tutorial: https://packaging.python.org/en/latest/tutorials/packaging-projects/ with setuptools
71
+
72
+ To install the package, run:
73
+ ```
74
+ pip install eegprep
75
+ ```
76
+
77
+ ## Test
78
+
79
+ use tests/main_compare.m
@@ -1,4 +1,15 @@
1
- ## how to duplicate a function
1
+ ## Build docker
2
+
3
+ docker run --rm -it -v $(pwd):/usr/src/project dtyoung/eegprep /bin/bash
4
+ docker run -u root --rm -it -v $(pwd):/usr/src/project dtyoung/eegprep /bin/bash
5
+
6
+ # remove
7
+
8
+ docker rmi dtyoung/eegprep
9
+
10
+ Mounted folder in /usr/src/project
11
+
12
+ ## How to convert a function from MATLAB to Python
2
13
 
3
14
  1. Get a MATLAB file to load and process an EEG file
4
15
 
@@ -12,3 +23,14 @@
12
23
 
13
24
  6. Write the function to compare (see example) and the helper Python function to load the file (note that there could be a general Python helper function)
14
25
 
26
+ ## Install package
27
+ Packaging was done following the tutorial: https://packaging.python.org/en/latest/tutorials/packaging-projects/ with setuptools
28
+
29
+ To install the package, run:
30
+ ```
31
+ pip install eegprep
32
+ ```
33
+
34
+ ## Test
35
+
36
+ use tests/main_compare.m
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "eegprep"
7
- version = "0.0.2"
7
+ version = "0.0.4"
8
8
  authors = [
9
9
  { name="Arnaud Delorme", email="adelorme@gmail.com" },
10
10
  { name="Young Truong", email="dt.young112@gmail.com" },
@@ -26,8 +26,9 @@ dependencies = [
26
26
  "oct2py>=5.5.0",
27
27
  "torch>=1.10.0",
28
28
  "h5py>=3.3.0",
29
+ "python-picard",
29
30
  ]
30
31
 
31
32
  [project.urls]
32
33
  Homepage = "https://github.com/sccn/eegprep"
33
- Issues = "https://github.com/sccn/eegprep/issues"
34
+ Issues = "https://github.com/sccn/eegprep/issues"
@@ -1,12 +1,12 @@
1
1
  import numpy as np
2
- from .topoplot import topoplot
3
- from .eeg_rpsd import eeg_rpsd
4
- from .eeg_autocorr_welch import eeg_autocorr_welch
5
- from .eeg_autocorr import eeg_autocorr
6
- from .eeg_autocorr_fftw import eeg_autocorr_fftw
7
- from .pop_reref import pop_reref
8
2
 
9
3
  def ICL_feature_extractor(EEG, flag_autocorr=False):
4
+ from eegprep import topoplot
5
+ from eegprep import eeg_rpsd
6
+ from eegprep import eeg_autocorr_welch
7
+ from eegprep import eeg_autocorr
8
+ from eegprep import eeg_autocorr_fftw
9
+ from eegprep import pop_reref
10
10
 
11
11
  # Check inputs
12
12
  ncomp = EEG['icawinv'].shape[1]
@@ -0,0 +1,14 @@
1
+ from .iclabel import iclabel
2
+ from .pop_saveset import pop_saveset
3
+ from .pop_loadset import pop_loadset
4
+ from .eeglabcompat import pop_eegfiltnew
5
+ from .eeglabcompat import clean_artifacts
6
+ from .ICL_feature_extractor import ICL_feature_extractor
7
+ from .iclabel_net import ICLabelNet
8
+ from .topoplot import topoplot
9
+ from .eeg_rpsd import eeg_rpsd
10
+ from .eeg_autocorr_welch import eeg_autocorr_welch
11
+ from .eeg_autocorr import eeg_autocorr
12
+ from .eeg_autocorr_fftw import eeg_autocorr_fftw
13
+ from .pop_reref import pop_reref
14
+ from .eeg_picard import eeg_picard
@@ -25,7 +25,7 @@ def eeg_autocorr(EEG, pct_data=None):
25
25
  if EEG['pnts'] < EEG['srate']:
26
26
  ac = np.hstack([c[:, :EEG['pnts']], np.zeros((ncomp, EEG['srate'] - EEG['pnts'] + 1))])
27
27
  else:
28
- ac = c[:, :EEG['srate'] + 1]
28
+ ac = c[:, :int(EEG['srate']) + 1]
29
29
 
30
30
  # Normalize by the 0-tap of the autocorrelation
31
31
  ac /= ac[:, [0]]
@@ -50,7 +50,7 @@ def test_eeg_autocorr():
50
50
  psdmed = eeg_autocorr(EEG, 100)
51
51
 
52
52
  # print information about psdmed
53
- print(psdmed.shape)
53
+ # print(psdmed.shape)
54
54
 
55
55
  #print(psdmed)
56
56
 
@@ -58,4 +58,4 @@ def test_eeg_autocorr():
58
58
  #assert psdmed.shape == (10, 100)
59
59
  #assert np.all(np.isfinite(psdmed))
60
60
 
61
- test_eeg_autocorr()
61
+ # test_eeg_autocorr()
@@ -32,7 +32,7 @@ def eeg_autocorr_fftw(EEG, pct_data=100):
32
32
  # ac = np.hstack( [ac[:, :EEG['pnts']], np.zeros((ncomp , EEG['srate'] - EEG['pnts'] + 1))])
33
33
  ac = np.concatenate((ac[:, :EEG['pnts']], np.zeros((ac.shape[0], EEG['srate'] - EEG['pnts'] + 1))), axis=1)
34
34
  else:
35
- ac = ac[:, :EEG['srate'] + 1]
35
+ ac = ac[:, :int(EEG['srate']) + 1]
36
36
 
37
37
  # Normalize by 0-lag autocorrelation
38
38
  ac = ac / ac[:, 0][:, np.newaxis]
@@ -38,9 +38,9 @@ def eeg_autocorr_welch(EEG, pct_data=100):
38
38
  # normalizefft
39
39
  if EEG['pnts'] < EEG['srate']:
40
40
  ac = np.concatenate([ac[:, :EEG['pnts']] / (ac[:, 0][:, np.newaxis] * np.arange(n_points, 0, -1) / n_points),
41
- np.zeros((ncomp, EEG['srate'] - n_points + 1))], axis=1)
41
+ np.zeros((ncomp, int(EEG['srate']) - n_points + 1))], axis=1)
42
42
  else:
43
- ac = ac[:, :EEG['srate'] + 1] / (ac[:, 0][:, np.newaxis] * np.concatenate((np.arange(n_points, n_points - EEG['srate'], -1), np.array([max(1, n_points - EEG['srate'])]))) / n_points)
43
+ ac = ac[:, :int(EEG['srate']) + 1] / (ac[:, 0][:, np.newaxis] * np.concatenate((np.arange(n_points, n_points - int(EEG['srate']), -1), np.array([max(1, n_points - int(EEG['srate']))]))) / n_points)
44
44
 
45
45
  # resample to 1 second at 100 samples/sec
46
46
  ac = resample_poly(ac.T, up=100, down=EEG['srate']).T
@@ -55,7 +55,7 @@ def test_eeg_autocorr_welch():
55
55
  psdmed = eeg_autocorr_welch(EEG, 100)
56
56
 
57
57
  # print information about psdmed
58
- print(psdmed.shape)
59
- print(psdmed)
58
+ # print(psdmed.shape)
59
+ # print(psdmed)
60
60
 
61
61
  # test_eeg_autocorr_welch()
@@ -1,6 +1,6 @@
1
1
  import numpy as np
2
2
  import os
3
- from pop_loadset import pop_loadset
3
+ from .pop_loadset import pop_loadset
4
4
 
5
5
  def eeg_checkset(EEG):
6
6
 
@@ -1,10 +1,10 @@
1
- from eeg_autocorr import eeg_autocorr
2
- from pop_loadset import pop_loadset
1
+ from .eeg_autocorr import eeg_autocorr
2
+ from .pop_loadset import pop_loadset
3
3
  import mne
4
4
  import tempfile
5
5
  import os
6
6
  from mne.export import export_raw
7
- from pop_saveset import pop_saveset # in development
7
+ from .pop_saveset import pop_saveset # in development
8
8
 
9
9
  # write a funtion that converts a MNE raw object to an EEGLAB set file
10
10
  def eeg_eeglab2mne(EEG):
@@ -1,5 +1,5 @@
1
- from eeg_autocorr import eeg_autocorr
2
- from pop_loadset import pop_loadset
1
+ from .eeg_autocorr import eeg_autocorr
2
+ from .pop_loadset import pop_loadset
3
3
  import mne
4
4
  import tempfile
5
5
  import os
@@ -0,0 +1,30 @@
1
+ from picard import picard
2
+ import numpy as np
3
+
4
+ def eeg_picard(EEG):
5
+
6
+ # Assuming EEG['data'] contains the EEG data as a numpy array of shape (channels, timepoints)
7
+ data = EEG['data']
8
+
9
+ # reshape from 3D to 2D
10
+ data = data.reshape(data.shape[0], -1)
11
+
12
+ # Note: Specify the number of components (optional). Default is min(timepoints, channels).
13
+ weighting_matrix, unmixing_matrix, sources = picard(data, ortho=False, random_state=0)
14
+
15
+ # Update EEG['icaweights'] with the separating (unmixing) matrix
16
+ if weighting_matrix is None:
17
+ EEG['icasphere'] = np.eye(EEG['nbchan'])
18
+ else:
19
+ EEG['icasphere'] = weighting_matrix
20
+ EEG['icaweights'] = unmixing_matrix
21
+ EEG['icawinv'] = np.linalg.pinv(EEG['icaweights']*EEG['icasphere'])
22
+
23
+ # Calculate the inverse weights (mixing matrix) and store in EEG['icawinv']
24
+ EEG['icaact'] = sources
25
+
26
+ # reshape EEG['icaact'] back to 3D as EEG['data']
27
+ EEG['icaact'] = EEG['icaact'].reshape(EEG['icaact'].shape[0], EEG['pnts'], EEG['trials'])
28
+ EEG['icachansind'] = np.arange(EEG['nbchan'])
29
+
30
+ return EEG
@@ -40,7 +40,7 @@ def eeg_rpsd(EEG, nfreqs=None, pct_data=100):
40
40
  for it in range(ncomp):
41
41
  temp = np.reshape(EEG['icaact'][it, index, :], (1, index.shape[0], index.shape[1] * EEG['trials']))
42
42
  temp = temp[:, :, subset] * window[:, np.newaxis]
43
- temp = fft(temp, n_points, axis=1)
43
+ temp = fft(temp, int(n_points), axis=1)
44
44
  temp = np.abs(temp) ** 2
45
45
  temp = temp[:, 1:nfreqs + 1, :] * 2 / (EEG['srate'] * np.sum(window ** 2))
46
46
  if nfreqs == nyquist:
@@ -0,0 +1,129 @@
1
+ # import sys
2
+ # sys.path.insert(0, 'src/')
3
+ from .pop_loadset import pop_loadset
4
+ from .pop_saveset import pop_saveset
5
+ import logging
6
+ import os
7
+ eeglab = None
8
+
9
+ def start_eeglab():
10
+ global eeglab
11
+ if eeglab is None:
12
+ from oct2py import Oct2Py, get_log
13
+ eeglab = Oct2Py(logger=get_log())
14
+ oc = Oct2Py(logger=get_log())
15
+ eeglab.logger = get_log("new_log")
16
+ eeglab.logger.setLevel(logging.WARNING)
17
+ eeglab.warning('off', 'backtrace')
18
+
19
+ # On the command line, type "octave-8.4.0" OCTAVE_EXECUTABLE or OCTAVE var
20
+ path2eeglab = 'eeglab' # init >10 seconds
21
+ eeglab.addpath(path2eeglab + '/functions/guifunc')
22
+ eeglab.addpath(path2eeglab + '/functions/popfunc')
23
+ eeglab.addpath(path2eeglab + '/functions/adminfunc')
24
+ eeglab.addpath(path2eeglab + '/plugins/firfilt')
25
+ eeglab.addpath(path2eeglab + '/functions/sigprocfunc')
26
+ eeglab.addpath(path2eeglab + '/functions/miscfunc')
27
+ eeglab.addpath(path2eeglab + '/plugins/dipfit')
28
+ eeglab.addpath(path2eeglab + '/plugins/clean_rawdata')
29
+ #res = eeglab.version()
30
+ #print('Running EEGLAB commands in compatibility mode with Octave ' + res)
31
+ eeglab.logger.setLevel(logging.INFO)
32
+
33
+ def pop_resample( EEG, freq): # 2 additional parameters in MATLAB (never used)
34
+ start_eeglab()
35
+
36
+ pop_saveset(EEG, './tmp.set') # 0.8 seconds
37
+ EEG2 = eeglab.pop_loadset('./tmp.set') # 2 seconds
38
+ EEG2 = eeglab.pop_resample(EEG2, freq) # 2.4 seconds
39
+ eeglab.pop_saveset(EEG2, './tmp2.set') # 2.4 seconds
40
+ EEG3 = pop_loadset('./tmp2.set') # 0.2 seconds
41
+
42
+ # delete temporary files
43
+ os.remove('./tmp.set')
44
+ os.remove('./tmp2.set')
45
+ return EEG3
46
+
47
+
48
+ def pop_eegfiltnew(EEG, locutoff=None,hicutoff=None,revfilt=False,plotfreqz=False):
49
+ start_eeglab()
50
+ # error if locutoff and hicutoff are none
51
+ if locutoff==None and hicutoff==None:
52
+ raise('Cannot have low cutoff and high cutoff not defined')
53
+
54
+ pop_saveset(EEG, './tmp.set') # 0.8 seconds
55
+ EEG2 = eeglab.pop_loadset('./tmp.set') # 2 seconds
56
+ EEG3 = eeglab.pop_eegfiltnew(EEG2, 'locutoff',locutoff,'hicutoff',hicutoff,'revfilt',revfilt,'plotfreqz',plotfreqz)
57
+ eeglab.pop_saveset(EEG3, './tmp2.set') # 2.4 seconds
58
+ EEG4 = pop_loadset('./tmp2.set') # 0.2 seconds
59
+
60
+ # delete temporary files
61
+ # os.remove('./tmp.set')
62
+ # os.remove('./tmp2.set')
63
+ return EEG4
64
+
65
+ def clean_artifacts( EEG, ChannelCriterion=False, LineNoiseCriterion=False, FlatlineCriterion=False, BurstCriterion=False, BurstRejection=False, WindowCriterion=0, Highpass=[0.25, 0.75], WindowCriterionTolerances=[float('-inf'), 8]):
66
+ start_eeglab()
67
+
68
+ if ChannelCriterion == False or ChannelCriterion == 'off':
69
+ ChannelCriterion='off'
70
+
71
+ if LineNoiseCriterion == False or LineNoiseCriterion == 'off':
72
+ LineNoiseCriterion='off'
73
+
74
+ if FlatlineCriterion == False or FlatlineCriterion == 'off':
75
+ FlatlineCriterion='off'
76
+
77
+ if BurstCriterion == False or BurstCriterion == 'off':
78
+ BurstCriterion='off'
79
+
80
+ if Highpass == False or Highpass == 'off':
81
+ Highpass='off'
82
+
83
+ if BurstRejection == False or BurstRejection == 'off':
84
+ BurstRejection='off'
85
+ else:
86
+ BurstRejection='on'
87
+
88
+
89
+ pop_saveset(EEG, './tmp.set') # 0.8 seconds
90
+ EEG2 = eeglab.pop_loadset('./tmp.set') # 2 seconds
91
+ EEG3 = eeglab.clean_artifacts(EEG2, 'ChannelCriterion', ChannelCriterion, \
92
+ 'LineNoiseCriterion', LineNoiseCriterion, \
93
+ 'FlatlineCriterion', FlatlineCriterion, \
94
+ 'BurstCriterion', BurstCriterion, \
95
+ 'BurstRejection', BurstRejection, \
96
+ 'WindowCriterion', WindowCriterion, \
97
+ 'Highpass',Highpass, \
98
+ 'WindowCriterionTolerances', WindowCriterionTolerances)
99
+ eeglab.pop_saveset(EEG3, './tmp2.set') # 2.4 seconds
100
+ EEG4 = pop_loadset('./tmp2.set') # 0.2 seconds
101
+
102
+ # delete temporary files
103
+ os.remove('./tmp.set')
104
+ os.remove('./tmp2.set')
105
+ return EEG4
106
+
107
+ # sys.exit()
108
+ def test_eeglab_compat():
109
+
110
+ eeglab_file_path = '/System/Volumes/Data/data/matlab/eeglab/sample_data/eeglab_data_epochs_ica.set'
111
+
112
+ EEG = pop_loadset(eeglab_file_path)
113
+ EEG = pop_eegfiltnew(EEG, locutoff=5,hicutoff=25,revfilt=True,plotfreqz=False)
114
+ EEG = clean_artifacts(EEG, FlatlineCriterion=5,ChannelCriterion=0.87, LineNoiseCriterion=4,Highpass=False,BurstCriterion= 20, WindowCriterion=0.25, BurstRejection=False, WindowCriterionTolerances=[float('-inf'), 7])
115
+
116
+ # EEG = eeglab.pop_loadset(eeglab_file_path)
117
+ # TMPEEG = eeglab.pop_eegfiltnew(EEG, 'locutoff',5,'hicutoff',25,'revfilt',1,'plotfreqz',0)
118
+ # CLEANEDEEG = eeglab.clean_artifacts(TMPEEG, 'ChannelCriterion', 'off',
119
+ # 'LineNoiseCriterion', 'off',
120
+ # 'FlatlineCriterion', 'off',
121
+ # 'BurstCriterion', 'off',
122
+ # 'WindowCriterion', 0,
123
+ # 'Highpass',[0.25, 0.75],
124
+ # 'WindowCriterionTolerances', [-10000000, 8])
125
+
126
+ # clean_artifacts( EEG, ChannelCriterion='on' )
127
+
128
+
129
+ # test_eeglab_compat()
@@ -1,9 +1,11 @@
1
- from .ICL_feature_extractor import ICL_feature_extractor
2
- from .iclabel_net import ICLabelNet
3
1
  import torch
4
2
  import numpy as np
3
+ import os
5
4
 
6
5
  def iclabel(EEG, algorithm='default'):
6
+ from eegprep import ICLabelNet
7
+ from eegprep import ICL_feature_extractor
8
+
7
9
  # issue error if algorithm is not 'default'
8
10
  if algorithm != 'default':
9
11
  raise ValueError('Only the default algorithm is supported')
@@ -15,12 +17,14 @@ def iclabel(EEG, algorithm='default'):
15
17
  features[0] = np.single(np.concatenate([features[0],-features[0],features[0][:, ::-1, :, :],-features[0][:, ::-1, :, :]], axis=3))
16
18
  features[1] = np.single(np.tile(features[1], (1, 1, 1, 4)))
17
19
  features[2] = np.single(np.tile(features[2], (1, 1, 1, 4)))
18
- print('Feature 0 shape:', features[0].shape)
19
- print('Feature 1 shape:', features[1].shape)
20
- print('Feature 2 shape:', features[2].shape)
20
+ # print('Feature 0 shape:', features[0].shape)
21
+ # print('Feature 1 shape:', features[1].shape)
22
+ # print('Feature 2 shape:', features[2].shape)
21
23
 
22
24
  # Load the ICLabelNet model
23
- model = ICLabelNet('netICL.mat')
25
+ base_dir = os.path.dirname(os.path.abspath(__file__))
26
+ data_path = os.path.join(base_dir, 'netICL.mat')
27
+ model = ICLabelNet(data_path)
24
28
 
25
29
  # Convert the features to torch tensors
26
30
  image = torch.tensor(features[0]).permute(-1, 2, 0, 1)
@@ -40,10 +44,11 @@ def iclabel(EEG, algorithm='default'):
40
44
  EEG['etc']['ic_classification'] = {}
41
45
  if 'ICLabel' not in EEG['etc']['ic_classification']:
42
46
  EEG['etc']['ic_classification']['ICLabel'] = {}
43
-
47
+
48
+ np.object = object
44
49
  EEG['etc']['ic_classification']['ICLabel']['classes'] = np.array(
45
50
  ['Brain', 'Muscle', 'Eye', 'Heart', 'Line Noise', 'Channel Noise', 'Other'],
46
- dtype=np.object
51
+ dtype=object
47
52
  )
48
53
  EEG['etc']['ic_classification']['ICLabel']['classifications'] = output_np
49
54
  EEG['etc']['ic_classification']['ICLabel']['version'] = 'default'
@@ -25,44 +25,44 @@ class ICLabelNet(torch.nn.Module):
25
25
  super().__init__()
26
26
  iclabel_matlab = scipy.io.loadmat(mat_path)
27
27
  params = iclabel_matlab['params'][0]
28
- i = 11
29
- print('shape of param', i, torch.tensor(params[i][1]).shape)
28
+ # i = 11
29
+ # print('shape of param', i, torch.tensor(params[i][1]).shape)
30
30
  self.discriminator_image_layer1_conv = torch.nn.Conv2d(in_channels=1, out_channels=128, kernel_size=4, stride=2, padding=1, dilation=1)
31
- print(self.discriminator_image_layer1_conv.weight.shape)
32
- self.discriminator_image_layer1_conv.weight = torch.nn.Parameter(torch.tensor(params[0][1]).permute(3, 2, 0, 1))
33
- self.discriminator_image_layer1_conv.bias = torch.nn.Parameter(torch.tensor(params[1][1]).squeeze())
31
+ # print(self.discriminator_image_layer1_conv.weight.shape)
32
+ self.discriminator_image_layer1_conv.weight = torch.nn.Parameter(torch.tensor(params[0][1], dtype=torch.float32).permute(3, 2, 0, 1))
33
+ self.discriminator_image_layer1_conv.bias = torch.nn.Parameter(torch.tensor(params[1][1], dtype=torch.float32).squeeze())
34
34
  self.discriminator_image_layer1_relu = torch.nn.LeakyReLU(0.2)
35
35
  self.discriminator_image_layer2_conv = torch.nn.Conv2d(in_channels=128, out_channels=256, kernel_size=4, stride=2, padding=1, dilation=1)
36
- self.discriminator_image_layer2_conv.weight = torch.nn.Parameter(torch.tensor(params[2][1]).permute(3, 2, 0, 1))
37
- self.discriminator_image_layer2_conv.bias = torch.nn.Parameter(torch.tensor(params[3][1]).squeeze())
36
+ self.discriminator_image_layer2_conv.weight = torch.nn.Parameter(torch.tensor(params[2][1], dtype=torch.float32).permute(3, 2, 0, 1))
37
+ self.discriminator_image_layer2_conv.bias = torch.nn.Parameter(torch.tensor(params[3][1], dtype=torch.float32).squeeze())
38
38
  self.discriminator_image_layer2_relu = torch.nn.LeakyReLU(0.2)
39
39
  self.discriminator_image_layer3_conv = torch.nn.Conv2d(in_channels=256, out_channels=512, kernel_size=4, stride=2, padding=1, dilation=1)
40
- self.discriminator_image_layer3_conv.weight = torch.nn.Parameter(torch.tensor(params[4][1]).permute(3, 2, 0, 1))
41
- self.discriminator_image_layer3_conv.bias = torch.nn.Parameter(torch.tensor(params[5][1]).squeeze())
40
+ self.discriminator_image_layer3_conv.weight = torch.nn.Parameter(torch.tensor(params[4][1], dtype=torch.float32).permute(3, 2, 0, 1))
41
+ self.discriminator_image_layer3_conv.bias = torch.nn.Parameter(torch.tensor(params[5][1], dtype=torch.float32).squeeze())
42
42
  self.discriminator_image_layer3_relu = torch.nn.LeakyReLU(0.2)
43
43
  self.discriminator_psdmed_layer1_conv_conv = torch.nn.Conv2d(in_channels=1, out_channels=128, kernel_size=(1,3), stride=1, padding=(0,1), dilation=1)
44
- self.discriminator_psdmed_layer1_conv_conv.weight = torch.nn.Parameter(torch.tensor(params[6][1]).permute(3, 2, 0, 1))
45
- self.discriminator_psdmed_layer1_conv_conv.bias = torch.nn.Parameter(torch.tensor(params[7][1]).squeeze())
44
+ self.discriminator_psdmed_layer1_conv_conv.weight = torch.nn.Parameter(torch.tensor(params[6][1], dtype=torch.float32).permute(3, 2, 0, 1))
45
+ self.discriminator_psdmed_layer1_conv_conv.bias = torch.nn.Parameter(torch.tensor(params[7][1], dtype=torch.float32).squeeze())
46
46
  self.discriminator_psdmed_layer1_conv_relu = torch.nn.LeakyReLU(0.2)
47
47
  self.discriminator_psdmed_layer2_conv_conv = torch.nn.Conv2d(in_channels=128, out_channels=256, kernel_size=(1,3), stride=1, padding=(0,1), dilation=1)
48
- self.discriminator_psdmed_layer2_conv_conv.weight = torch.nn.Parameter(torch.tensor(params[8][1]).permute(3, 2, 0, 1))
49
- self.discriminator_psdmed_layer2_conv_conv.bias = torch.nn.Parameter(torch.tensor(params[9][1]).squeeze())
48
+ self.discriminator_psdmed_layer2_conv_conv.weight = torch.nn.Parameter(torch.tensor(params[8][1], dtype=torch.float32).permute(3, 2, 0, 1))
49
+ self.discriminator_psdmed_layer2_conv_conv.bias = torch.nn.Parameter(torch.tensor(params[9][1], dtype=torch.float32).squeeze())
50
50
  self.discriminator_psdmed_layer2_conv_relu = torch.nn.LeakyReLU(0.2)
51
51
  self.discriminator_psdmed_layer3_conv_conv = torch.nn.Conv2d(in_channels=256, out_channels=1, kernel_size=(1,3), stride=1, padding=(0,1), dilation=1)
52
- self.discriminator_psdmed_layer3_conv_conv.weight = torch.nn.Parameter(torch.tensor(params[10][1]).unsqueeze(3).permute(3, 2, 0, 1))
53
- self.discriminator_psdmed_layer3_conv_conv.bias = torch.nn.Parameter(torch.tensor(params[11][1]).squeeze(1))
52
+ self.discriminator_psdmed_layer3_conv_conv.weight = torch.nn.Parameter(torch.tensor(params[10][1], dtype=torch.float32).unsqueeze(3).permute(3, 2, 0, 1))
53
+ self.discriminator_psdmed_layer3_conv_conv.bias = torch.nn.Parameter(torch.tensor(params[11][1], dtype=torch.float32).squeeze(1))
54
54
  self.discriminator_psdmed_layer3_conv_relu = torch.nn.LeakyReLU(0.2)
55
55
  self.discriminator_autocorr_layer1_conv_conv = torch.nn.Conv2d(in_channels=1, out_channels=128, kernel_size=(1,3), stride=1, padding=(0,1), dilation=1)
56
- self.discriminator_autocorr_layer1_conv_conv.weight = torch.nn.Parameter(torch.tensor(params[12][1]).permute(3, 2, 0, 1))
57
- self.discriminator_autocorr_layer1_conv_conv.bias = torch.nn.Parameter(torch.tensor(params[13][1]).squeeze())
56
+ self.discriminator_autocorr_layer1_conv_conv.weight = torch.nn.Parameter(torch.tensor(params[12][1], dtype=torch.float32).permute(3, 2, 0, 1))
57
+ self.discriminator_autocorr_layer1_conv_conv.bias = torch.nn.Parameter(torch.tensor(params[13][1], dtype=torch.float32).squeeze())
58
58
  self.discriminator_autocorr_layer1_conv_relu = torch.nn.LeakyReLU(0.2)
59
59
  self.discriminator_autocorr_layer2_conv_conv = torch.nn.Conv2d(in_channels=128, out_channels=256, kernel_size=(1,3), stride=1, padding=(0,1), dilation=1)
60
- self.discriminator_autocorr_layer2_conv_conv.weight = torch.nn.Parameter(torch.tensor(params[14][1]).permute(3, 2, 0, 1))
61
- self.discriminator_autocorr_layer2_conv_conv.bias = torch.nn.Parameter(torch.tensor(params[15][1]).squeeze())
60
+ self.discriminator_autocorr_layer2_conv_conv.weight = torch.nn.Parameter(torch.tensor(params[14][1], dtype=torch.float32).permute(3, 2, 0, 1))
61
+ self.discriminator_autocorr_layer2_conv_conv.bias = torch.nn.Parameter(torch.tensor(params[15][1], dtype=torch.float32).squeeze())
62
62
  self.discriminator_autocorr_layer2_conv_relu = torch.nn.LeakyReLU(0.2)
63
63
  self.discriminator_autocorr_layer3_conv_conv = torch.nn.Conv2d(in_channels=256, out_channels=1, kernel_size=(1,3), stride=1, padding=(0,1), dilation=1)
64
- self.discriminator_autocorr_layer3_conv_conv.weight = torch.nn.Parameter(torch.tensor(params[16][1]).unsqueeze(3).permute(3, 2, 0, 1))
65
- self.discriminator_autocorr_layer3_conv_conv.bias = torch.nn.Parameter(torch.tensor(params[17][1]).squeeze(1))
64
+ self.discriminator_autocorr_layer3_conv_conv.weight = torch.nn.Parameter(torch.tensor(params[16][1], dtype=torch.float32).unsqueeze(3).permute(3, 2, 0, 1))
65
+ self.discriminator_autocorr_layer3_conv_conv.bias = torch.nn.Parameter(torch.tensor(params[17][1], dtype=torch.float32).squeeze(1))
66
66
  self.discriminator_autocorr_layer3_conv_relu = torch.nn.LeakyReLU(0.2)
67
67
  self.discriminator_psdmed_reshape = Reshape((100, 1, 1))
68
68
  self.discriminator_psdmed_concat1 = Concatenate(dim=2)
@@ -83,7 +83,7 @@ class ICLabelNet(torch.nn.Module):
83
83
  x_image = self.discriminator_image_layer2_relu(x_image)
84
84
  x_image = self.discriminator_image_layer3_conv(x_image)
85
85
  x_image = self.discriminator_image_layer3_relu(x_image)
86
- print('x_image', x_image.shape)
86
+ # print('x_image', x_image.shape)
87
87
 
88
88
  x_psdmed = self.discriminator_psdmed_layer1_conv_conv(psdmed)
89
89
  x_psdmed = self.discriminator_psdmed_layer1_conv_relu(x_psdmed)
@@ -94,7 +94,7 @@ class ICLabelNet(torch.nn.Module):
94
94
  x_psdmed = self.discriminator_psdmed_reshape(x_psdmed)
95
95
  x_psdmed = self.discriminator_psdmed_concat1([x_psdmed]*4)
96
96
  x_psdmed = self.discriminator_psdmed_concat2([x_psdmed]*4)
97
- print('x_psdmed', x_psdmed.shape)
97
+ # print('x_psdmed', x_psdmed.shape)
98
98
 
99
99
  x_autocorr = self.discriminator_autocorr_layer1_conv_conv(autocorr)
100
100
  x_autocorr = self.discriminator_autocorr_layer1_conv_relu(x_autocorr)
@@ -105,11 +105,11 @@ class ICLabelNet(torch.nn.Module):
105
105
  x_autocorr = self.discriminator_autocorr_reshape(x_autocorr)
106
106
  x_autocorr = self.discriminator_autocorr_concat1([x_autocorr]*4)
107
107
  x_autocorr = self.discriminator_autocorr_concat2([x_autocorr]*4)
108
- print('x_autocorr', x_autocorr.shape)
108
+ # print('x_autocorr', x_autocorr.shape)
109
109
 
110
110
  x = self.discriminator_concat([x_image, x_psdmed, x_autocorr])
111
111
  x = self.discriminator_conv(x)
112
- print('x', x.shape)
112
+ # print('x', x.shape)
113
113
  # subtract max value to avoid overflow
114
114
  x = x - torch.max(x, dim=1, keepdim=True).values
115
115
  x = self.discriminator_softmax(x)
@@ -117,7 +117,7 @@ class ICLabelNet(torch.nn.Module):
117
117
  return x
118
118
 
119
119
  if __name__ == "__main__":
120
- model = ICLabelNet('netICL.mat')
120
+ model = ICLabelNet('../../data/netICL.mat')
121
121
  data = scipy.io.loadmat('python_temp_reformated.mat')
122
122
  image_mat = data['grid'][0][0]
123
123
  psdmed_mat = data['grid'][0][1]
@@ -19,7 +19,7 @@ def loadset(file_path):
19
19
 
20
20
  def pop_loadset(file_path):
21
21
  # Load MATLAB file
22
- EEG = scipy.io.loadmat(file_path, struct_as_record=False, squeeze_me=True)
22
+ EEG = scipy.io.loadmat(file_path, struct_as_record=False, squeeze_me=True, appendmat=False)
23
23
 
24
24
  def new_check(obj):
25
25
  # check if obj is a dictionary and apply recursively the function to each object not changing the struture of the dictionary
@@ -39,7 +39,7 @@ def pop_loadset(file_path):
39
39
  elif obj.dtype.kind in ['i', 'u', 'f', 'c']:
40
40
  return obj
41
41
  else:
42
- return np.array([new_check(item) for item in obj])
42
+ return np.array([new_check(item) for item in obj], dtype=object)
43
43
  # check if it is a scalar or a string and return it
44
44
  elif np.isscalar(obj) or isinstance(obj, str):
45
45
  return obj
@@ -57,6 +57,14 @@ def pop_loadset(file_path):
57
57
  if 'EEG' in EEG:
58
58
  EEG = EEG['EEG']
59
59
 
60
+ # convert EEG['nbchan] to integer
61
+ if 'nbchan' in EEG:
62
+ EEG['nbchan'] = int(EEG['nbchan'])
63
+ if 'trials' in EEG:
64
+ EEG['trials'] = int(EEG['trials'])
65
+ if 'pnts' in EEG:
66
+ EEG['pnts'] = int(EEG['pnts'])
67
+
60
68
  if 'data' in EEG and isinstance(EEG['data'], str):
61
69
  # get path from file_path
62
70
  EEG['filepath'] = os.path.dirname(file_path)
@@ -1,7 +1,7 @@
1
- from ICL_feature_extractor import ICL_feature_extractor
2
- from pop_loadset import pop_loadset
3
- from pop_saveset import pop_saveset
4
- from pop_reref import pop_reref
1
+ from .ICL_feature_extractor import ICL_feature_extractor
2
+ from .pop_loadset import pop_loadset
3
+ from .pop_saveset import pop_saveset
4
+ from .pop_reref import pop_reref
5
5
  import sys
6
6
 
7
7
  # check if a parameter is present and if it is assign eeglab_file_path to it
@@ -2,14 +2,18 @@
2
2
  import os
3
3
  from scipy.io import savemat
4
4
  import tempfile # need to do something with tempfile
5
- from pop_loadset import pop_loadset
6
- from pop_saveset import pop_saveset
5
+ import sys
6
+ sys.path.insert(0, '/Users/arno/Python/eegprep/src/')
7
+ sys.path.insert(0, '/usr/src/project/src/')
8
+ from eegprep import pop_loadset
9
+ from eegprep import pop_saveset
7
10
  from oct2py import octave as eeglab
8
11
 
9
12
  def pop_resample( EEG, freq): # 2 additional parameters in MATLAB (never used)
10
13
 
11
- pop_saveset(EEG, 'tmp.set') # 0.8 seconds
14
+ pop_saveset(EEG, './tmp.set') # 0.8 seconds
12
15
 
16
+ eeglab.warning('off', 'backtrace')
13
17
  path2eeglab = '/System/Volumes/Data/data/matlab/eeglab/' # init >10 seconds
14
18
  eeglab.addpath(path2eeglab + '/functions/guifunc')
15
19
  eeglab.addpath(path2eeglab + '/functions/popfunc')
@@ -19,24 +23,24 @@ def pop_resample( EEG, freq): # 2 additional parameters in MATLAB (never used)
19
23
  eeglab.addpath(path2eeglab + '/functions/miscfunc')
20
24
  eeglab.addpath(path2eeglab + '/plugins/dipfit')
21
25
 
22
- EEG2 = eeglab.pop_loadset('tmp.set') # 2 seconds
26
+ EEG2 = eeglab.pop_loadset('./tmp.set') # 2 seconds
23
27
  EEG2 = eeglab.pop_resample(EEG2, freq) # 2.4 seconds
24
- eeglab.pop_saveset(EEG2, 'tmp2.set') # 2.4 seconds
28
+ eeglab.pop_saveset(EEG2, './tmp2.set') # 2.4 seconds
25
29
 
26
- EEG3 = pop_loadset('tmp2.set') # 0.2 seconds
30
+ EEG3 = pop_loadset('./tmp2.set') # 0.2 seconds
27
31
 
28
32
  # delete temporary files
29
- os.remove('tmp.set')
30
- os.remove('tmp2.set')
33
+ os.remove('./tmp.set')
34
+ os.remove('./tmp2.set')
31
35
  return EEG3
32
36
 
33
37
  def test_pop_resample():
34
- eeglab_file_path = './eeglab_data_with_ica_tmp.set'
38
+ eeglab_file_path = '/Users/arno/Python/eegprep/data/eeglab_data_with_ica_tmp.set'
35
39
  EEG = pop_loadset(eeglab_file_path)
36
40
  EEG2 = pop_resample(EEG, 100)
37
41
  print(EEG2.keys())
38
42
  print(EEG2['srate'])
39
43
 
40
- # test_pop_resample()
44
+ test_pop_resample()
41
45
 
42
46
 
@@ -183,9 +183,10 @@ def pop_saveset2(EEG, file_name):
183
183
  # # Step 4: Save the EEGLAB dataset as a .mat file
184
184
  savemat(file_name, eeglab_dict)
185
185
 
186
- from pop_loadset import pop_loadset
187
186
 
188
187
  def test_pop_saveset():
188
+ from eegprep import pop_loadset
189
+
189
190
  file_path = './eeglab_data_with_ica_tmp.set'
190
191
  EEG = pop_loadset(file_path)
191
192
  pop_saveset( EEG, 'tmp.set')
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: eegprep
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Summary: EEG preprocessing pipeline on Python
5
5
  Author-email: Arnaud Delorme <adelorme@gmail.com>, Young Truong <dt.young112@gmail.com>
6
6
  License: GNU General Public License
@@ -39,8 +39,20 @@ Requires-Dist: mne>=1.0.0
39
39
  Requires-Dist: oct2py>=5.5.0
40
40
  Requires-Dist: torch>=1.10.0
41
41
  Requires-Dist: h5py>=3.3.0
42
+ Requires-Dist: python-picard
42
43
 
43
- ## how to duplicate a function
44
+ ## Build docker
45
+
46
+ docker run --rm -it -v $(pwd):/usr/src/project dtyoung/eegprep /bin/bash
47
+ docker run -u root --rm -it -v $(pwd):/usr/src/project dtyoung/eegprep /bin/bash
48
+
49
+ # remove
50
+
51
+ docker rmi dtyoung/eegprep
52
+
53
+ Mounted folder in /usr/src/project
54
+
55
+ ## How to convert a function from MATLAB to Python
44
56
 
45
57
  1. Get a MATLAB file to load and process an EEG file
46
58
 
@@ -54,3 +66,14 @@ Requires-Dist: h5py>=3.3.0
54
66
 
55
67
  6. Write the function to compare (see example) and the helper Python function to load the file (note that there could be a general Python helper function)
56
68
 
69
+ ## Install package
70
+ Packaging was done following the tutorial: https://packaging.python.org/en/latest/tutorials/packaging-projects/ with setuptools
71
+
72
+ To install the package, run:
73
+ ```
74
+ pip install eegprep
75
+ ```
76
+
77
+ ## Test
78
+
79
+ use tests/main_compare.m
@@ -2,34 +2,27 @@ LICENSE
2
2
  README.md
3
3
  pyproject.toml
4
4
  src/eegprep/ICL_feature_extractor.py
5
- src/eegprep/ICL_feature_extractor_compare_helper.py
6
5
  src/eegprep/__init__.py
7
6
  src/eegprep/eeg_autocorr.py
8
- src/eegprep/eeg_autocorr_compare_helper.py
9
7
  src/eegprep/eeg_autocorr_fftw.py
10
- src/eegprep/eeg_autocorr_fftw_compare_helper.py
11
8
  src/eegprep/eeg_autocorr_welch.py
12
- src/eegprep/eeg_autocorr_welch_compare_helper.py
13
9
  src/eegprep/eeg_checkset.py
14
10
  src/eegprep/eeg_eeglab2mne.py
15
11
  src/eegprep/eeg_mne2eeglab.py
16
12
  src/eegprep/eeg_mne2eeglab_epochs.py
13
+ src/eegprep/eeg_picard.py
17
14
  src/eegprep/eeg_rpsd.py
18
- src/eegprep/eeg_rpsd_compare_helper.py
19
15
  src/eegprep/eeglabcompat.py
20
16
  src/eegprep/iclabel.py
21
- src/eegprep/iclabel_helper.py
22
17
  src/eegprep/iclabel_net.py
23
18
  src/eegprep/iclabel_net_load_py_measures.py
24
19
  src/eegprep/pop_loadset.py
25
20
  src/eegprep/pop_reref.py
26
- src/eegprep/pop_reref_compare_helper.py
27
21
  src/eegprep/pop_reref_helper.py
28
22
  src/eegprep/pop_resample.py
29
23
  src/eegprep/pop_saveset.py
30
24
  src/eegprep/save_struct_as_hdf5.py
31
25
  src/eegprep/topoplot.py
32
- src/eegprep/topoplot_compare_helper.py
33
26
  src/eegprep.egg-info/PKG-INFO
34
27
  src/eegprep.egg-info/SOURCES.txt
35
28
  src/eegprep.egg-info/dependency_links.txt
@@ -5,3 +5,4 @@ mne>=1.0.0
5
5
  oct2py>=5.5.0
6
6
  torch>=1.10.0
7
7
  h5py>=3.3.0
8
+ python-picard
@@ -1,19 +0,0 @@
1
- from ICL_feature_extractor import ICL_feature_extractor
2
- from pop_loadset import pop_loadset
3
- import sys
4
-
5
- # check if a parameter is present and if it is assign eeglab_file_path to it
6
- if len(sys.argv) > 1:
7
- eeglab_file_path = sys.argv[1]
8
- else:
9
- eeglab_file_path = './eeglab_data_with_ica_tmp.set'
10
- eeglab_file_path = '/Users/arno/Downloads/STUDYstern/S01/Memorize.set'
11
- EEG = pop_loadset(eeglab_file_path)
12
-
13
- # Print the loaded data
14
- res = ICL_feature_extractor(EEG, True)
15
-
16
- # save in a matlab file
17
- import scipy.io
18
- scipy.io.savemat('python_temp.mat', {'grid': res})
19
- print('Saved python_temp.mat')
@@ -1 +0,0 @@
1
- from .iclabel import iclabel
@@ -1,13 +0,0 @@
1
- from eeg_autocorr import eeg_autocorr
2
- from pop_loadset import pop_loadset
3
-
4
- eeglab_file_path = './eeglab_data_with_ica_tmp.set'
5
- EEG = pop_loadset(eeglab_file_path)
6
-
7
- # Print the loaded data
8
- res = eeg_autocorr(EEG, 100)
9
-
10
- # save in a matlab file
11
- import scipy.io
12
- scipy.io.savemat('eeg_autocorr_data.mat', {'grid': res})
13
- print('Saved eeg_autocorr_data.mat')
@@ -1,20 +0,0 @@
1
- from eeg_autocorr_fftw import eeg_autocorr_fftw
2
- from pop_loadset import pop_loadset
3
- from pop_reref import pop_reref
4
- import sys
5
-
6
- # check if a parameter is present and if it is assign eeglab_file_path to it
7
- if len(sys.argv) > 1:
8
- eeglab_file_path = sys.argv[1]
9
- else:
10
- eeglab_file_path = './eeglab_data_with_ica_tmp.set'
11
- EEG = pop_loadset(eeglab_file_path)
12
- EEG = pop_reref(EEG, [])
13
-
14
- # Print the loaded data
15
- res = eeg_autocorr_fftw(EEG, 100)
16
-
17
- # save in a matlab file
18
- import scipy.io
19
- scipy.io.savemat('eeg_autocorr_data.mat', {'grid': res})
20
- print('Saved eeg_autocorr_data.mat')
@@ -1,13 +0,0 @@
1
- from eeg_autocorr_welch import eeg_autocorr_welch
2
- from pop_loadset import pop_loadset
3
-
4
- eeglab_file_path = './eeglab_data_with_ica_tmp.set'
5
- EEG = pop_loadset(eeglab_file_path)
6
-
7
- # Print the loaded data
8
- res = eeg_autocorr_welch(EEG, 100)
9
-
10
- # save in a matlab file
11
- import scipy.io
12
- scipy.io.savemat('eeg_autocorr_welch_data.mat', {'grid': res})
13
- print('Saved eeg_autocorr_welch_data.mat')
@@ -1,17 +0,0 @@
1
- from eeg_rpsd import eeg_rpsd
2
- from pop_loadset import pop_loadset
3
- import sys
4
-
5
- if len(sys.argv) > 1:
6
- eeglab_file_path = sys.argv[1]
7
- else:
8
- eeglab_file_path = '/System/Volumes/Data/data/matlab/eeglab/sample_data/eeglab_data_epochs_ica.set'
9
- EEG = pop_loadset(eeglab_file_path)
10
-
11
- # Print the loaded data
12
- res = eeg_rpsd(EEG, 100)
13
-
14
- # save in a matlab file
15
- import scipy.io
16
- scipy.io.savemat('eeg_rpsd_data.mat', {'grid': res})
17
- print('Saved eeg_rpsd_data.mat')
@@ -1,117 +0,0 @@
1
- from oct2py import Oct2Py, get_log
2
- from pop_saveset import pop_saveset
3
- from pop_loadset import pop_loadset
4
- import logging
5
- import os
6
- import sys
7
-
8
- eeglab = Oct2Py(logger=get_log())
9
- oc = Oct2Py(logger=get_log())
10
- eeglab.logger = get_log("new_log")
11
-
12
- def pop_resample( EEG, freq): # 2 additional parameters in MATLAB (never used)
13
-
14
- pop_saveset(EEG, 'tmp.set') # 0.8 seconds
15
- EEG2 = eeglab.pop_loadset('tmp.set') # 2 seconds
16
- EEG2 = eeglab.pop_resample(EEG2, freq) # 2.4 seconds
17
- eeglab.pop_saveset(EEG2, 'tmp2.set') # 2.4 seconds
18
- EEG3 = pop_loadset('tmp2.set') # 0.2 seconds
19
-
20
- # delete temporary files
21
- os.remove('tmp.set')
22
- os.remove('tmp2.set')
23
- return EEG3
24
-
25
-
26
- def pop_eegfiltnew(locutoff=None,hicutoff=None,revfilt=False,plotfreqz=False):
27
- # error if locutoff and hicutoff are none
28
- if locutoff==None and hicutoff==None:
29
- raise('Cannot have low cutoff and high cutoff not defined')
30
-
31
- pop_saveset(EEG, 'tmp.set') # 0.8 seconds
32
- EEG2 = eeglab.pop_loadset('tmp.set') # 2 seconds
33
- EEG3 = pop_eegfiltnew(EEG2, 'locutoff',locutoff,'hicutoff',hicutoff,'revfilt',revfilt,'plotfreqz',plotfreqz)
34
- eeglab.pop_saveset(EEG2, 'tmp2.set') # 2.4 seconds
35
- EEG4 = pop_loadset('tmp2.set') # 0.2 seconds
36
-
37
- # delete temporary files
38
- os.remove('tmp.set')
39
- os.remove('tmp2.set')
40
- return EEG4
41
-
42
- def clean_artifacts( EEG, ChannelCriterion=False, LineNoiseCriterion=False, FlatlineCriterion=False, BurstCriterion=False, WindowCriterion=0, Highpass=[0.25, 0.75], WindowCriterionTolerances=[float('-inf'), 8]):
43
-
44
- if ChannelCriterion == False or ChannelCriterion == 'off':
45
- ChannelCriterion='off'
46
- else:
47
- ChannelCriterion='on'
48
-
49
- if LineNoiseCriterion == False or LineNoiseCriterion == 'off':
50
- LineNoiseCriterion='off'
51
- else:
52
- LineNoiseCriterion='on'
53
-
54
- if FlatlineCriterion == False or FlatlineCriterion == 'off':
55
- FlatlineCriterion='off'
56
- else:
57
- FlatlineCriterion='on'
58
-
59
- if BurstCriterion == False or BurstCriterion == 'off':
60
- BurstCriterion='off'
61
- else:
62
- BurstCriterion='on'
63
-
64
- pop_saveset(EEG, 'tmp.set') # 0.8 seconds
65
- EEG2 = eeglab.pop_loadset('tmp.set') # 2 seconds
66
- EEG3 = eeglab.clean_artifacts(EEG2, 'ChannelCriterion', ChannelCriterion, \
67
- 'LineNoiseCriterion', LineNoiseCriterion, \
68
- 'FlatlineCriterion', FlatlineCriterion, \
69
- 'BurstCriterion', BurstCriterion, \
70
- 'WindowCriterion', WindowCriterion, \
71
- 'Highpass',Highpass, \
72
- 'WindowCriterionTolerances', WindowCriterionTolerances)
73
- eeglab.pop_saveset(EEG3, 'tmp2.set') # 2.4 seconds
74
- EEG4 = pop_loadset('tmp2.set') # 0.2 seconds
75
-
76
- # delete temporary files
77
- os.remove('tmp.set')
78
- os.remove('tmp2.set')
79
- return EEG3
80
-
81
- # sys.exit()
82
-
83
- eeglab.logger.setLevel(logging.WARNING)
84
- eeglab.warning('off', 'backtrace')
85
-
86
- # On the command line, type "octave-8.4.0" OCTAVE_EXECUTABLE or OCTAVE var
87
- path2eeglab = '/System/Volumes/Data/data/matlab/eeglab/' # init >10 seconds
88
- eeglab.addpath(path2eeglab + '/functions/guifunc')
89
- eeglab.addpath(path2eeglab + '/functions/popfunc')
90
- eeglab.addpath(path2eeglab + '/functions/adminfunc')
91
- eeglab.addpath(path2eeglab + '/plugins/firfilt')
92
- eeglab.addpath(path2eeglab + '/functions/sigprocfunc')
93
- eeglab.addpath(path2eeglab + '/functions/miscfunc')
94
- eeglab.addpath(path2eeglab + '/plugins/dipfit')
95
- eeglab.addpath(path2eeglab + '/plugins/clean_rawdata')
96
- res = eeglab.version()
97
- print('Running EEGLAB commands in compatibility mode with Octave ' + res)
98
- eeglab.logger.setLevel(logging.INFO)
99
-
100
- eeglab_file_path = '/System/Volumes/Data/data/matlab/eeglab/sample_data/eeglab_data_epochs_ica.set'
101
-
102
- EEG = pop_loadset(eeglab_file_path)
103
- EEG = pop_eegfiltnew(EEG, locutoff=5,hicutoff=25,revfilt=True,plotfreqz=False)
104
-
105
- # EEG = eeglab.pop_loadset(eeglab_file_path)
106
- # TMPEEG = eeglab.pop_eegfiltnew(EEG, 'locutoff',5,'hicutoff',25,'revfilt',1,'plotfreqz',0)
107
- # CLEANEDEEG = eeglab.clean_artifacts(TMPEEG, 'ChannelCriterion', 'off',
108
- # 'LineNoiseCriterion', 'off',
109
- # 'FlatlineCriterion', 'off',
110
- # 'BurstCriterion', 'off',
111
- # 'WindowCriterion', 0,
112
- # 'Highpass',[0.25, 0.75],
113
- # 'WindowCriterionTolerances', [-10000000, 8])
114
-
115
- # clean_artifacts( EEG, ChannelCriterion='on' )
116
-
117
-
@@ -1,26 +0,0 @@
1
- from iclabel import iclabel
2
- from pop_loadset import pop_loadset
3
- from pop_saveset import pop_saveset
4
- import sys
5
-
6
- # check if there are 2 arguments otherwise issue an error
7
- if len(sys.argv) != 3:
8
- raise ValueError('Please provide the input and output file paths as command line arguments')
9
-
10
- # get first command line argument
11
- eeglab_file_path_in = sys.argv[1]
12
- eeglab_file_path_out = sys.argv[2]
13
-
14
- EEG = pop_loadset(eeglab_file_path_in)
15
- # EEG['data'] = EEG['data'].reshape(EEG['data'].shape[0], -1)
16
- # EEG['icaact'] = EEG['icaact'].reshape(EEG['icaact'].shape[0], -1)
17
- # EEG['nbchan'] = EEG['data'].shape[0]
18
- # EEG['pnts'] = EEG['data'].shape[1]
19
- # EEG['trials'] = 1
20
-
21
- # Print the loaded data
22
- print('Data shape:', EEG['data'].shape)
23
- EEG = iclabel(EEG, 'default')
24
-
25
- # save dataset
26
- pop_saveset(EEG, eeglab_file_path_out)
@@ -1,31 +0,0 @@
1
- from pop_reref import pop_reref
2
- from pop_loadset import pop_loadset
3
- import sys
4
- import os
5
- import scipy.io
6
-
7
- # Check if a parameter was provided
8
- if len(sys.argv) > 1:
9
- # The first element in sys.argv is the script name, so we access the second one for the argument
10
- file_name = sys.argv[1]
11
- print(f"The EEG file is: {file_name}")
12
- print(f"Output will be in python_temp.mat (result field)")
13
- else:
14
- file_name = './eeglab_data_with_ica_tmp.set'
15
- # raise("Provide the name of a file containing EEG (full path) as the first parameter.")
16
-
17
- # check if file name exists on disk
18
- if not os.path.isfile(file_name):
19
- raise(f"File {file_name} does not exist.")
20
-
21
- EEG = pop_loadset(file_name)
22
- EEG = pop_reref(EEG, None)
23
- EEG['chanlocs'] = []
24
- EEG['urchanlocs'] = []
25
- EEG['event'] = []
26
- EEG['urevent'] = []
27
- EEG['epoch'] = []
28
-
29
- # save in a matlab file
30
- scipy.io.savemat('python_temp.mat', EEG)
31
- print('Saved python_temp.mat')
@@ -1,29 +0,0 @@
1
- from topoplot import topoplot
2
- from pop_loadset import pop_loadset
3
- import sys
4
-
5
- print('Topoplot compare helper')
6
-
7
- # need 2 arguments or error
8
- if len(sys.argv) != 3:
9
- print(f'len(sys.argv) = {len(sys.argv)}')
10
- print('Usage: need 2 arguments python topoplot_compare_helper.py <eeglab_file_path> <comp_num>')
11
- sys.exit(1)
12
-
13
- # Load the data
14
- eeglab_file_path = sys.argv[1]
15
- comp_num = int(sys.argv[2])
16
-
17
- # '/System/Volumes/Data/data/matlab/eeglab/sample_data/eeglab_data_epochs_ica.set'
18
- EEG = pop_loadset(eeglab_file_path)
19
-
20
- # Print the loaded data
21
- res = topoplot(EEG['icawinv'].transpose()[comp_num], EEG['chanlocs'], noplot='on')
22
-
23
- grid = res[1]
24
-
25
- # save in a matlab file
26
- import scipy.io
27
- scipy.io.savemat('topoplot_data.mat', {'grid': grid})
28
- print('Saved topoplot_data.mat')
29
-
File without changes
File without changes
File without changes