question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question on dss_line() usage

See original GitHub issue

Hi, its awesome that there is an implementation of the ZAPline algorithm in Python! I’m trying to use it, but I somehow fail to remove the noise components with it. I’m convinced that I must be doing something obvious wrong - any idea what it may be?

I’m using Elekta MEG data (322 MEG channels, after Signal Space Separation) that show an artifact at 60Hz stemming from a presentation display. Here is its PSD: psd022

Here’s the code I am running:

>>> import mne
>>> from meegkit.dss import dss_line
# read in the data with mne-python
>>> raw_fname = Path(datadir) / f'sub-{subject}/meg' / f'sub-{subject}_task-memento_proc-sss_meg.fif'
>>> raw = mne.io.read_raw_fif(raw_fname)
>>> raw.load_data()
>>> data, artifact = dss_line(raw._data.T, fline=60, sfreq=1000)
Power of components removed by DSS: 0.00

Putting the data back into the MNE Raw Object and visualizing the psd plot shows an almost identical profile, with the 60Hz component being pretty much unaffected. after_dss

Any idea what I might be doing wrong here? Thanks much in advance!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
nbaracommented, Oct 15, 2021

I can confirm that that was part of the problem. The other problem seems to be that your 60hz peak is not really at 60hz. Using 61Hz works well I think.

Here’s the code I used:

import mne
import matplotlib.pyplot as plt
from meegkit.dss import dss_line

raw = mne.io.read_raw('./examples/sub-xxx_task-memento_proc-sss_meg.fif', preload=True)

# First problem : be careful how you pick your data from Raw objects
print(f'raw._data shape: {raw._data.shape}')
data = raw.get_data(picks=['meg'])
print(f'raw.get_data() shape: {data.shape}')

raw.crop(60, 260)  # we don't need that much signal

# Only take MEG channels (same as raw.get_data(picks=['meg']))
meg_ch_idx = mne.pick_types(raw.info, meg=True)
data = raw.get_data(picks=meg_ch_idx)
# Second problem: the peak seems to be closer to 61 hz
clean, artifact = dss_line(data.T, fline=61, sfreq=1000, nremove=10)

# Plot before/after
f, ax = plt.subplots(2, 2)
raw.plot_psd(ax=ax[0, :], show=False, fmin=1, fmax=150)
raw._data[meg_ch_idx] = clean.T  # put clean data back in raw
raw.plot_psd(ax=ax[1, :], show=True, fmin=1, fmax=150)
Screenshot 2021-10-15 at 16 50 28
1reaction
nbaracommented, Oct 15, 2021

I’ll have a look. There’s at least a couple of reasons I can think of.

Btw, just a quick comment, raw._data.T is probably not the best way to access the raw data (even though I’m guilty of using it myself sometimes), as it will include all kinds of system and misc channels (on top of the grad and mag channels).

raw.get_data(picks=['meg']) is probably safer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

OpenDSS / Discussion / Help: Best way to iteratively solve?
Hiho,. So I'm currently adressing some performance issues, that I have (On my side of things, using Java, etc. Not really important, here.) ......
Read more >
Questions about the DSS keys on Yealink T21P E2
It looks like I have different options to program the green DSS buttons on our phones. One of the options is Park. To...
Read more >
Ultimate MACD Indicator for ThinkorSwim
Here is a MACD indicator for ThinkorSwim. It uses a color coded MACD line to show changes. There is a moving average of...
Read more >
Questions to GUI users on available GUIs [Archive] - Doom9's ...
I hope the thread will be useful to explore different natures of GUIs and users. 1.) How much experience do you have in...
Read more >
Tips to fix your SSH authentication issues - ARDC Support
an extensive list of what can go wrong with SSH access, and how to troubleshoot.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found