Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 994b28d

Browse files
committed
fix issue by reverting to previous version
1 parent 08afb54 commit 994b28d

File tree

1 file changed

+17
-98
lines changed

1 file changed

+17
-98
lines changed

src/eegprep/pop_saveset.py

Lines changed: 17 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -110,32 +110,9 @@ def pop_saveset_old(EEG, file_path):
110110
from mne.datasets import sample
111111
import numpy as np
112112
from scipy.io import savemat
113-
from eegprep.eeg_checkset import eeg_checkset
114-
115-
116-
def is_effectively_empty(x):
117-
# None
118-
if x is None:
119-
return True
120-
# Proper NumPy array with no elements
121-
if isinstance(x, np.ndarray) and x.size == 0:
122-
return True
123-
# One-element object array containing an empty dict/list/None
124-
if (isinstance(x, np.ndarray) and x.size == 1 and x.dtype == object):
125-
elem = x.item()
126-
if elem in (None, {}) or (hasattr(elem, '__len__') and len(elem) == 0):
127-
return True
128-
return False
129-
130-
def _as_array_or_empty(x):
131-
if x is None:
132-
return np.array([])
133-
return x.copy() if isinstance(x, np.ndarray) else np.array(x)
134113

135114
def pop_saveset(EEG, file_name):
136115

137-
EEG = eeg_checkset(EEG)
138-
139116
eeglab_dict = {
140117
'setname' : '',
141118
'filename' : '',
@@ -157,79 +134,32 @@ def pop_saveset(EEG, file_name):
157134
'icawinv' : EEG['icawinv'],
158135
'icasphere' : EEG['icasphere'],
159136
'icaweights' : EEG['icaweights'],
160-
'icachansind' : EEG['icachansind'] if EEG['icachansind'] is not None else {},
137+
'icachansind' : EEG['icachansind'].copy(),
161138
'chanlocs' : EEG['chanlocs'],
162139
'urchanlocs' : EEG['urchanlocs'],
163140
'chaninfo' : EEG['chaninfo'],
164141
'ref' : EEG['ref'],
165-
'event' : EEG['event'] if EEG['event'] is not None else {},
166-
'urevent' : EEG['urevent'] if EEG['urevent'] is not None else {},
167-
'eventdescription': EEG['eventdescription'] if EEG['eventdescription'] is not None else {},
168-
'epoch' : EEG['epoch'] if EEG['epoch'] is not None else {},
169-
'epochdescription': EEG['epochdescription'] if EEG['epochdescription'] is not None else {},
170-
'reject' : EEG['reject'] if EEG['reject'] is not None else {},
171-
'stats' : EEG['stats'] if EEG['stats'] is not None else {},
172-
'specdata' : EEG['specdata'] if EEG['specdata'] is not None else {},
173-
'specicaact' : EEG['specicaact'] if EEG['specicaact'] is not None else {},
174-
'splinefile' : EEG['splinefile'] if EEG['splinefile'] is not None else {},
175-
'icasplinefile' : EEG['icasplinefile'] if EEG['icasplinefile'] is not None else {},
176-
'dipfit' : EEG['dipfit'] if EEG['dipfit'] is not None else {},
142+
'event' : EEG['event'] if 'event' in EEG else np.array([]),
143+
'urevent' : EEG['urevent'] if 'urevent' in EEG else np.array([]),
144+
'eventdescription': EEG['eventdescription'] if 'eventdescription' in EEG else np.array([]),
145+
'epoch' : EEG['epoch'] if 'epoch' in EEG else np.array([]),
146+
'epochdescription': EEG['epochdescription'] if 'epochdescription' in EEG else np.array([]),
147+
'reject' : EEG['reject'] if 'reject' in EEG else np.array([]),
148+
'stats' : EEG['stats'] if 'stats' in EEG else np.array([]),
149+
'specdata' : EEG['specdata'] if 'specdata' in EEG else np.array([]),
150+
'specicaact' : EEG['specicaact'] if 'specicaact' in EEG else np.array([]),
151+
'splinefile' : EEG['splinefile'] if 'splinefile' in EEG else np.array([]),
152+
'icasplinefile' : EEG['icasplinefile'] if 'icasplinefile' in EEG else np.array([]),
153+
'dipfit' : EEG['dipfit'] if 'dipfit' in EEG else np.array([]),
177154
'history' : EEG['history'],
178155
'saved' : EEG['saved'],
179156
'etc' : EEG['etc'],
180-
'run' : EEG['run'] if EEG['run'] is not None else {},
181-
'roi' : EEG['roi'] if EEG['roi'] is not None else {}
182-
}
183-
184-
# eeglab_dict = {
185-
# 'setname' : '',
186-
# 'filename' : '',
187-
# 'filepath' : '',
188-
# 'subject' : '',
189-
# 'group' : '',
190-
# 'condition' : '',
191-
# 'session' : np.array([]),
192-
# 'comments' : '',
193-
# 'nbchan' : float(EEG['nbchan']),
194-
# 'trials' : float(EEG['trials']),
195-
# 'pnts' : float(EEG['pnts']),
196-
# 'srate' : float(EEG['srate']),
197-
# 'xmin' : float(EEG['xmin']),
198-
# 'xmax' : float(EEG['xmax']),
199-
# 'times' : EEG['times'],
200-
# 'data' : EEG['data'],
201-
# 'icaact' : EEG['icaact'],
202-
# 'icawinv' : EEG['icawinv'],
203-
# 'icasphere' : EEG['icasphere'],
204-
# 'icaweights' : EEG['icaweights'],
205-
# 'icachansind' : _as_array_or_empty(EEG['icachansind']),
206-
# 'chanlocs' : EEG['chanlocs'],
207-
# 'urchanlocs' : EEG['urchanlocs'],
208-
# 'chaninfo' : EEG['chaninfo'],
209-
# 'ref' : EEG['ref'],
210-
# 'event' : _as_array_or_empty(EEG['event']),
211-
# 'urevent' : _as_array_or_empty(EEG['urevent']),
212-
# 'eventdescription': _as_array_or_empty(EEG['eventdescription']),
213-
# 'epoch' : _as_array_or_empty(EEG['epoch']),
214-
# 'epochdescription': _as_array_or_empty(EEG['epochdescription']),
215-
# 'reject' : _as_array_or_empty(EEG['reject']),
216-
# 'stats' : _as_array_or_empty(EEG['stats']),
217-
# 'specdata' : _as_array_or_empty(EEG['specdata']),
218-
# 'specicaact' : _as_array_or_empty(EEG['specicaact']),
219-
# 'splinefile' : _as_array_or_empty(EEG['splinefile']),
220-
# 'icasplinefile' : _as_array_or_empty(EEG['icasplinefile']),
221-
# 'dipfit' : _as_array_or_empty(EEG['dipfit']),
222-
# 'history' : EEG['history'],
223-
# 'saved' : EEG['saved'],
224-
# 'etc' : EEG['etc'],
225-
# 'run' : _as_array_or_empty(EEG['run']),
226-
# 'roi' : _as_array_or_empty(EEG['roi']),
227-
# }
157+
'run' : EEG['run'] if 'run' in EEG else np.array([]),
158+
'roi' : EEG['roi'] if 'roi' in EEG else np.array([]),
159+
}
228160

229161
# add 1 to EEG['icachansind'] to make it 1-based
230-
if ('icachansind' in eeglab_dict and
231-
hasattr(eeglab_dict['icachansind'], 'size') and
232-
eeglab_dict['icachansind'].size > 0):
162+
if 'icachansind' in eeglab_dict and eeglab_dict['icachansind'].size > 0:
233163
eeglab_dict['icachansind'] = eeglab_dict['icachansind'] + 1
234164

235165
# check if EEG['urchan'] is 0-based
@@ -289,17 +219,6 @@ def pop_saveset(EEG, file_name):
289219
for key in eeglab_dict:
290220
if isinstance(eeglab_dict[key], np.ndarray) and len(eeglab_dict[key]) > 0 and isinstance(eeglab_dict[key][0], dict):
291221
eeglab_dict[key] = flatten_dict(eeglab_dict[key])
292-
# for key in eeglab_dict:
293-
# arr = eeglab_dict[key]
294-
# if isinstance(arr, np.ndarray) and not is_effectively_empty(arr):
295-
# if not arr.ndim == 0:
296-
# if arr.shape != () and arr.shape[0] > 0 and isinstance(arr[0], dict):
297-
# eeglab_dict[key] = flatten_dict(arr)
298-
# else:
299-
# elem = arr.item()
300-
# if isinstance(elem, dict):
301-
# eeglab_dict[key] = flatten_dict([elem]) # wrap single dict
302-
303222
# # Step 4: Save the EEGLAB dataset as a .mat file
304223
scipy.io.savemat(file_name, eeglab_dict, appendmat=False)
305224

0 commit comments

Comments
 (0)