coganlab / IEEG_Pipelines

A repo of current preprocessing methods for the Cogan Lab
https://ieeg-pipelines.readthedocs.io/en/latest/
MIT License
4 stars 2 forks source link

channel_outlier_marker cannot save bad channels #103

Closed jimzhang629 closed 7 months ago

jimzhang629 commented 7 months ago

channel_outlier_marker produces AttributeError when line noise filtering.

`""" Line noise filtering script

Filters the 60Hz line noise from the data, as well as the harmonics. Includes environment checks for SLURM jobs for convenience """

import mne import os from ieeg.io import save_derivative, raw_from_layout from ieeg.mt_filter import line_filter from ieeg.viz.utils import figure_compare from bids import BIDSLayout

%%

Set up paths

------------

HOME = os.path.expanduser("~")

get box directory depending on OS

if os.name == 'nt': # windows LAB_root = os.path.join(HOME, "Box", "CoganLab") else: # mac LAB_root = os.path.join(HOME, "Library", "CloudStorage", "Box-Box", "CoganLab")

%%

Load Data

---------

layout = get_data("GlobalLocal", root=LAB_root)

Load Data

layout = get_data("GlobalLocal", LAB_root) subjects = layout.get_subjects() subjects.sort() print(subjects)

for subj in subjects:

subj = 'D0077'

raw = raw_from_layout(layout, subject=subj, extension=".edf", desc=None, preload=True)

%%

Filter Data

-----------

A filter length of 700 ms does a good job of removing 60Hz line noise, while

a Filter length of 20000 ms does a good job of removing the harmonics (120Hz,

180Hz, 240Hz)

filt = line_filter(raw, mt_bandwidth=10., n_jobs=6, filter_length='700ms', verbose=10, freqs=[60], notch_widths=20)

%%

plot the data before and after filtering

figure_compare([raw, filt], labels=["Un", ""], avg=True, n_jobs=6, verbose=10, proj=True, fmax=250)

save the data

save_derivative(filt, layout, "clean", True)

filt.info['bads'] += channel_outlier_marker(filt, 3, 2, save=True)`

AttributeError Traceback (most recent call last) c:\Users\jz421\Desktop\GlobalLocal\plot_clean.ipynb Cell 5 line 7 71 # save the data 72 save_derivative(filt, layout, "clean", True) ---> 74 filt.info['bads'] += channel_outlier_marker(filt, 3, 2, save=True)

File :10, in channel_outlier_marker(input_raw, outlier_sd, max_rounds, axis, save, verbose)

File ~\Desktop\GlobalLocal\IEEG_Pipelines\ieeg\navigate.py:152, in channel_outlier_marker(input_raw, outlier_sd, max_rounds, axis, save, verbose) 150 if save: 151 tmp.info['bads'] = bads --> 152 update(tmp, desc) 154 return bads

File c:\Users\jz421\AppData\Local\anaconda3\envs\ieeg\Lib\functools.py:909, in singledispatch..wrapper(*args, *kw) 905 if not args: 906 raise TypeError(f'{funcname} requires at least ' 907 '1 positional argument') --> 909 return dispatch(args[0].class)(args, **kw)

File ~\Desktop\GlobalLocal\IEEG_Pipelines\ieeg\io.py:297, in _(inst, layout, description, verbose) 295 inst.filenames = inst.info['subject_info'].get('files', None) 296 for i, file in enumerate(inst.filenames): --> 297 fname = op.join(layout.root, file) 298 update(fname, inst.info['bads'], description=description, status='bad', 299 verbose=verbose) 300 goods = [ch for ch in inst.ch_names if ch not in inst.info['bads']]

AttributeError: 'list' object has no attribute 'root'

jimzhang629 commented 7 months ago

More specifically, the issue is with the update function. Here is a test case just using update:

bads = ['RFO16', 'RIA10', 'RIP13', 'RTAM15', 'RTMM3', 'RTMM4', 'RIA8', 'RIP14', 'RTAS3', 'RTAM2', 'RTMM2', 'RTMM12']
filt.info['bads'] = bads
update(filt, bads, 'bad')

AttributeError Traceback (most recent call last) Cell In[10], line 3 1 bads = ['RFO16', 'RIA10', 'RIP13', 'RTAM15', 'RTMM3', 'RTMM4', 'RIA8', 'RIP14', 'RTAS3', 'RTAM2', 'RTMM2', 'RTMM12'] 2 filt.info['bads'] = bads ----> 3 update(filt, bads, 'bad')

File c:\Users\jz421\AppData\Local\anaconda3\envs\ieeg\Lib\functools.py:909, in singledispatch..wrapper(*args, *kw) 905 if not args: 906 raise TypeError(f'{funcname} requires at least ' 907 '1 positional argument') --> 909 return dispatch(args[0].class)(args, **kw)

File ~\Desktop\GlobalLocal\IEEG_Pipelines\ieeg\io.py:297, in _(inst, layout, description, verbose) 295 inst.filenames = inst.info['subject_info'].get('files', None) 296 for i, file in enumerate(inst.filenames): --> 297 fname = op.join(layout.root, file) 298 update(fname, inst.info['bads'], description=description, status='bad', 299 verbose=verbose) 300 goods = [ch for ch in inst.ch_names if ch not in inst.info['bads']]

AttributeError: 'list' object has no attribute 'root'