Skip to content

Commit

Permalink
detrend_correction (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
yjmantilla committed Apr 8, 2020
1 parent d81c5cf commit 7e9899d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea/*
/idea
/src
/.pytest_*
docs/generated
Expand Down
9 changes: 9 additions & 0 deletions docs/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Current
Changelog
~~~~~~~~~

- Included a boolean which indicates if detrend should be done internally or not for the use of find_noisy_channels in reference.py. `Yorguin Mantilla`_
- Robust average referencing + tests by `Victor Xiang`_
- Removing trend in the EEG data by high pass filtering and local linear regression + tests `Aamna Lawrence`_
- Finding noisy channels with comparable output to Matlab +tests-including test for ransac `Aamna Lawrence`_
Expand All @@ -30,6 +31,12 @@ Changelog
- Finding the reason for the difference between the Matlab and Pyprep’s output- Probably minor differences in the filter functions and also rounding done by functions like quantile `Victor Xiang`_ and `Aamna Lawrence`_
- Overall debugging `Victor Xiang`_ and `Aamna Lawrence`_


Bug
~~~

- In find_noisy_channels the signal detrend is accidentally undone which destabilized the RANSAC. The detrend is now done over the NoisyChannels.raw_mne object to avoid this bug and to force that any signal in there is detrended like in matlab's prep. By `Yorguin Mantilla`_ (`#29 <https://github.com/sappelhoff/pyprep/pull/9>`_)

API
~~~

Expand Down Expand Up @@ -75,8 +82,10 @@ People who contributed to this software (in alphabetical order)
* Aamna Lawrence
* Adam Li
* Victor Xiang
* Yorguin Mantilla

.. _Stefan Appelhoff: http://stefanappelhoff.com/
.. _Aamna Lawrence: https://github.com/AamnaLawrence
.. _Adam Li: https://github.com/adam2392/
.. _Victor Xiang: https://github.com/Nick3151
.. _Yorguin Mantilla: https://github.com/yjmantilla
10 changes: 7 additions & 3 deletions pyprep/find_noisy_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@ class NoisyChannels:
"""

def __init__(self, raw):
def __init__(self, raw, do_detrend=True):
"""Initialize the class."""
# Make sure that we got an MNE object
assert isinstance(raw, mne.io.BaseRaw)

self.raw_mne = raw.copy()
self.sample_rate = raw.info["sfreq"]
if do_detrend:
self.raw_mne._data = removeTrend(
self.raw_mne.get_data(), sample_rate=self.sample_rate
)

self.EEGData = self.raw_mne.get_data(picks="eeg")
self.EEGData = removeTrend(self.EEGData, sample_rate=self.sample_rate)
self.EEGData_beforeFilt = self.EEGData
self.ch_names_original = np.asarray(raw.info["ch_names"])
self.n_chans_original = len(self.ch_names_original)
Expand Down Expand Up @@ -237,7 +241,7 @@ def find_bad_by_hfnoise(self, HF_zscore_threshold=5.0):
return None

def find_bad_by_correlation(
self, correlation_secs=1.0, correlation_threshold=0.4, frac_bad=0.1
self, correlation_secs=1.0, correlation_threshold=0.4, frac_bad=0.01
):
"""Find correlation between the low frequency components of the EEG below 50 Hz.
Expand Down
2 changes: 1 addition & 1 deletion pyprep/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def robust_reference(self):
raw._data = removeTrend(raw.get_data(), sample_rate=self.sfreq)

# Determine unusable channels and remove them from the reference channels
noisy_detector = NoisyChannels(raw)
noisy_detector = NoisyChannels(raw, do_detrend=False)
noisy_detector.find_all_bads(ransac=self.ransac)
self.noisy_channels_original = {
"bad_by_nan": noisy_detector.bad_by_nan,
Expand Down

0 comments on commit 7e9899d

Please sign in to comment.