@@ -191,13 +191,27 @@ def _get_curry_epoch_info(fname):
191191def _get_curry_meg_normals (fname ):
192192 fname_hdr = _check_curry_header_filename (fname )
193193 normals_str = fname_hdr .read_text ().split ("\n " )
194- i_start , i_stop = [
194+ # i_start, i_stop = [
195+ # i
196+ # for i, ll in enumerate(normals_str)
197+ # if ("NORMALS" in ll and "START_LIST" in ll)
198+ # or ("NORMALS" in ll and "END_LIST" in ll)
199+ # ]
200+ # normals_str = [nn.split("\t") for nn in normals_str[i_start + 1 : i_stop]]
201+ i_list = [
195202 i
196203 for i , ll in enumerate (normals_str )
197204 if ("NORMALS" in ll and "START_LIST" in ll )
198205 or ("NORMALS" in ll and "END_LIST" in ll )
199206 ]
200- normals_str = [nn .split ("\t " ) for nn in normals_str [i_start + 1 : i_stop ]]
207+ assert len (i_list ) % 2 == 0
208+ i_start_list = i_list [::2 ]
209+ i_stop_list = i_list [1 ::2 ]
210+ normals_str = [
211+ nn .split ("\t " )
212+ for i_start , i_stop in zip (i_start_list , i_stop_list )
213+ for nn in normals_str [i_start + 1 : i_stop ]
214+ ]
201215 return np .array ([[float (nnn .strip ()) for nnn in nn ] for nn in normals_str ])
202216
203217
@@ -296,10 +310,18 @@ def _extract_curry_info(fname):
296310 ch_names = [
297311 ch_names_full [i ] for i in np .argsort (chaninfile_full ) if i not in i_drop
298312 ]
313+ ch_pos = np .array (
314+ [
315+ ch_pos [i ]
316+ for i in np .argsort (chaninfile_full )
317+ if (i not in i_drop ) and (i < len (ch_pos ))
318+ ]
319+ )
299320 ch_types = [ch_types [i ] for i in np .argsort (chaninfile_full ) if i not in i_drop ]
300321 units = [units [i ] for i in np .argsort (chaninfile_full ) if i not in i_drop ]
301322
302323 assert len (ch_types ) == len (units ) == len (ch_names ) == n_ch
324+ assert len (ch_pos ) == ch_types .count ("eeg" ) + ch_types .count ("mag" )
303325
304326 # finetune channel types (e.g. stim, eog etc might be identified by name)
305327 # TODO?
@@ -370,8 +392,9 @@ def _make_curry_montage(ch_names, ch_types, ch_pos, landmarks, landmarkslabels):
370392 ch_pos /= 1000.0
371393 landmarks /= 1000.0
372394 # channel locations
373- # TODO - what about misc without pos? can they mess things up if unordered?
395+ # what about misc without pos? can they mess things up if unordered?
374396 assert len (ch_pos ) >= (ch_types .count ("mag" ) + ch_types .count ("eeg" ))
397+ assert len (ch_pos ) == (ch_types .count ("mag" ) + ch_types .count ("eeg" ))
375398 ch_pos_eeg = {
376399 ch_names [i ]: ch_pos [i , :3 ] for i , t in enumerate (ch_types ) if t == "eeg"
377400 }
@@ -417,8 +440,9 @@ def _set_chanloc_curry(inst, ch_types, ch_pos, landmarks, landmarkslabels):
417440 ch_pos /= 1000.0
418441 landmarks /= 1000.0
419442 # channel locations
420- # TODO - what about misc without pos? can they mess things up if unordered?
443+ # what about misc without pos? can they mess things up if unordered?
421444 assert len (ch_pos ) >= (ch_types .count ("mag" ) + ch_types .count ("eeg" ))
445+ assert len (ch_pos ) == (ch_types .count ("mag" ) + ch_types .count ("eeg" ))
422446 ch_pos_meg = {
423447 ch_names [i ]: ch_pos [i , :3 ] for i , t in enumerate (ch_types ) if t == "mag"
424448 }
@@ -433,24 +457,24 @@ def _set_chanloc_curry(inst, ch_types, ch_pos, landmarks, landmarkslabels):
433457 landmark_dict [k ] = None
434458 if len (landmarkslabels ) > 0 :
435459 hpi_pos = landmarks [
436- [i for i , n in enumerate (landmarkslabels ) if re .match ("HPI[1-99]" , n )],
460+ [i for i , n in enumerate (landmarkslabels ) if re .match ("HPI.? [1-99]" , n )],
437461 :,
438462 ]
439463 else :
440464 hpi_pos = None
441465 if len (landmarkslabels ) > 0 :
442466 hsp_pos = landmarks [
443- [i for i , n in enumerate (landmarkslabels ) if re .match ("H[1-99]" , n )], :
467+ [i for i , n in enumerate (landmarkslabels ) if re .match ("H.? [1-99]" , n )], :
444468 ]
445469 else :
446470 hsp_pos = None
447471
448472 add_missing_fiducials = (
449473 True
450474 if (
451- not landmark_dict ["Nas" ]
452- and not landmark_dict ["LPA" ]
453- and not landmark_dict ["LPA" ]
475+ isinstance ( landmark_dict ["Nas" ], type ( None ))
476+ and isinstance ( landmark_dict ["LPA" ], type ( None ))
477+ and isinstance ( landmark_dict ["RPA" ], type ( None ))
454478 )
455479 else False # raises otherwise
456480 )
0 commit comments