Clean Line noise (Zapline method) function for MNE using MEEGkit toolbox

I wrote a function to clean line noise using zapline method from MEEGkit toolbox to use in MNE with RawArray data:

def zapline_clean(raw, fline):
    data = raw.get_data() # Convert mne data to numpy darray
    sfreq = raw.info['sfreq'] # Extract the sampling freq
   
    #Apply MEEGkit toolbox function
    out, _ = dss.dss_line(data, fline, sfreq, nkeep=1) # fline (Line noise freq) = 50 Hz for Europe

    cleaned_raw = mne.io.RawArray(out, raw.info) # Convert output to mne RawArray again

    return cleaned_raw

To implement this function I use:
cleaned_raw = zapline_clean(raw, 50)

Number 50 is the fline value (50hz line noise in europe)

However, I have a problem when I use this function. This appears in the console: β€œReducing nfft to 32” and then the Python interpreter crashes. Has anyone tried doing something similar?

Hi @rbn13

can you provide the full stack trace? Looking at your function, I assume the problem occurs somewhere in the MEEGKIT code, so it might be a question for the developers of that toolbox.

Scott

1 Like

Thank you again for answering my question. Finally, the error was that the data matrix obtained from an MNE RawArray has a transposed shape, inversely to how it should be implemented in the MEEGtoolkit function. To solve it, it was enough to transpose the data using two alternatives depending on the library we use: data.T (with numpy) or data.transpose (with pandas).

I hope this can be helpful to someone who has encountered the same problem.

2 Likes