@@ -110,32 +110,9 @@ def pop_saveset_old(EEG, file_path):
110
110
from mne .datasets import sample
111
111
import numpy as np
112
112
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 )
134
113
135
114
def pop_saveset (EEG , file_name ):
136
115
137
- EEG = eeg_checkset (EEG )
138
-
139
116
eeglab_dict = {
140
117
'setname' : '' ,
141
118
'filename' : '' ,
@@ -157,79 +134,32 @@ def pop_saveset(EEG, file_name):
157
134
'icawinv' : EEG ['icawinv' ],
158
135
'icasphere' : EEG ['icasphere' ],
159
136
'icaweights' : EEG ['icaweights' ],
160
- 'icachansind' : EEG ['icachansind' ] if EEG [ 'icachansind' ] is not None else {} ,
137
+ 'icachansind' : EEG ['icachansind' ]. copy () ,
161
138
'chanlocs' : EEG ['chanlocs' ],
162
139
'urchanlocs' : EEG ['urchanlocs' ],
163
140
'chaninfo' : EEG ['chaninfo' ],
164
141
'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 ([]) ,
177
154
'history' : EEG ['history' ],
178
155
'saved' : EEG ['saved' ],
179
156
'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
+ }
228
160
229
161
# 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 :
233
163
eeglab_dict ['icachansind' ] = eeglab_dict ['icachansind' ] + 1
234
164
235
165
# check if EEG['urchan'] is 0-based
@@ -289,17 +219,6 @@ def pop_saveset(EEG, file_name):
289
219
for key in eeglab_dict :
290
220
if isinstance (eeglab_dict [key ], np .ndarray ) and len (eeglab_dict [key ]) > 0 and isinstance (eeglab_dict [key ][0 ], dict ):
291
221
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
-
303
222
# # Step 4: Save the EEGLAB dataset as a .mat file
304
223
scipy .io .savemat (file_name , eeglab_dict , appendmat = False )
305
224
0 commit comments