Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyprep/find_noisy_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __init__(self, raw, do_detrend=True, random_state=None, matlab_strict=False)
ch_names = np.asarray(self.raw_mne.info["ch_names"])
self.ch_names_original = ch_names
self.n_chans_original = len(ch_names)
self.n_samples = raw._data.shape[1]
self.n_samples = raw.get_data().shape[1]

# Before anything else, flag bad-by-NaNs and bad-by-flats
self.find_bad_by_nan_flat()
Expand Down
2 changes: 1 addition & 1 deletion pyprep/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def _eeglab_interpolate_bads(raw):
_normalize_vectors(pos_bad)

# Interpolate bad channels
interp = _eeglab_interpolate(raw._data[good_idx, :], pos_good, pos_bad)
interp = _eeglab_interpolate(raw.get_data()[good_idx, :], pos_good, pos_bad)
raw._data[bad_idx, :] = interp

# Clear all bad EEG channels
Expand Down
18 changes: 9 additions & 9 deletions tests/test_find_noisy_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _generate_signal(fmin, fmax, timepoints, fcount=1):
def test_bad_by_nan(raw_tmp):
"""Test the detection of channels containing any NaN values."""
# Insert a NaN value into a random channel
n_chans = raw_tmp._data.shape[0]
n_chans = raw_tmp.get_data().shape[0]
nan_idx = int(RNG.randint(0, n_chans, 1))
raw_tmp._data[nan_idx, 3] = np.nan

Expand All @@ -74,9 +74,9 @@ def test_bad_by_nan(raw_tmp):
def test_bad_by_flat(raw_tmp):
"""Test the detection of channels with flat or very weak signals."""
# Make the signal for a random channel extremely weak
n_chans = raw_tmp._data.shape[0]
n_chans = raw_tmp.get_data().shape[0]
flat_idx = int(RNG.randint(0, n_chans, 1))
raw_tmp._data[flat_idx, :] = raw_tmp._data[flat_idx, :] * 1e-12
raw_tmp._data[flat_idx, :] = raw_tmp.get_data()[flat_idx, :] * 1e-12

# Test automatic detection of flat channels on NoisyChannels init
nd = NoisyChannels(raw_tmp, do_detrend=False)
Expand All @@ -99,7 +99,7 @@ def test_bad_by_deviation(raw_tmp):
high_dev_factor = 4.0

# Make the signal for a random channel have a very high amplitude
n_chans = raw_tmp._data.shape[0]
n_chans = raw_tmp.get_data().shape[0]
high_dev_idx = int(RNG.randint(0, n_chans, 1))
raw_tmp._data[high_dev_idx, :] *= high_dev_factor

Expand All @@ -125,7 +125,7 @@ def test_bad_by_deviation(raw_tmp):
def test_bad_by_hf_noise(raw_tmp):
"""Test detection of channels with high-frequency noise."""
# Add some noise between 70 & 80 Hz to the signal of a random channel
n_chans = raw_tmp._data.shape[0]
n_chans = raw_tmp.get_data().shape[0]
hf_noise_idx = int(RNG.randint(0, n_chans, 1))
hf_noise = _generate_signal(70, 80, raw_tmp.times, 5) * 10
raw_tmp._data[hf_noise_idx, :] += hf_noise
Expand All @@ -147,7 +147,7 @@ def test_bad_by_hf_noise(raw_tmp):
def test_bad_by_dropout(raw_tmp):
"""Test detection of channels with excessive portions of flat signal."""
# Add large dropout portions to the signal of a random channel
n_chans, n_samples = raw_tmp._data.shape
n_chans, n_samples = raw_tmp.get_data().shape
dropout_idx = int(RNG.randint(0, n_chans, 1))
x1, x2 = (int(n_samples / 10), int(2 * n_samples / 10))
raw_tmp._data[dropout_idx, x1:x2] = 0 # flatten 10% of signal
Expand All @@ -161,7 +161,7 @@ def test_bad_by_dropout(raw_tmp):
def test_bad_by_correlation(raw_tmp):
"""Test detection of channels that correlate poorly with others."""
# Replace a random channel's signal with uncorrelated values
n_chans, n_samples = raw_tmp._data.shape
n_chans, n_samples = raw_tmp.get_data().shape
low_corr_idx = int(RNG.randint(0, n_chans, 1))
raw_tmp._data[low_corr_idx, :] = _generate_signal(10, 30, raw_tmp.times, 5)

Expand All @@ -186,7 +186,7 @@ def test_bad_by_correlation(raw_tmp):
def test_bad_by_SNR(raw_tmp):
"""Test detection of channels that have low signal-to-noise ratios."""
# Replace a random channel's signal with uncorrelated values
n_chans = raw_tmp._data.shape[0]
n_chans = raw_tmp.get_data().shape[0]
low_snr_idx = int(RNG.randint(0, n_chans, 1))
raw_tmp._data[low_snr_idx, :] = _generate_signal(10, 30, raw_tmp.times, 5)

Expand Down Expand Up @@ -275,7 +275,7 @@ def test_find_bad_by_ransac_err(raw_tmp):
nd.find_bad_by_ransac(n_samples=n_samples)

# Test IOError when too few good channels for RANSAC sample size
n_chans = raw_tmp._data.shape[0]
n_chans = raw_tmp.get_data().shape[0]
nd = NoisyChannels(raw_tmp, do_detrend=False)
nd.bad_by_deviation = raw_tmp.info["ch_names"][0 : int(n_chans * 0.8)]
with pytest.raises(IOError):
Expand Down
12 changes: 6 additions & 6 deletions tests/test_matprep_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ def test_compare_removeTrend(matprep_artifacts):
sample_rate = matprep_raw.info["sfreq"]

# Apply removeTrend to raw artifact to get expected and actual signals
expected = matprep_detrended._data
expected = matprep_detrended.get_data()
actual = removeTrend(
matprep_raw._data, sample_rate, detrendType="high pass", matlab_strict=True
matprep_raw.get_data(), sample_rate, detrendType="high pass", matlab_strict=True
)

# Check MATLAB equivalence at start of recording
Expand Down Expand Up @@ -386,11 +386,11 @@ def test_full_signal(self, pyprep_reference, matprep_reference):
win_size = 500 # window of samples to check

# Compare signals at start of recording
pyprep_start = pyprep_reference.raw._data[:, win_size]
matprep_start = matprep_reference._data[:, win_size]
pyprep_start = pyprep_reference.raw.get_data()[:, win_size]
matprep_start = matprep_reference.get_data()[:, win_size]
assert np.allclose(pyprep_start, matprep_start)

# Compare signals at end of recording
pyprep_end = pyprep_reference.raw._data[:, -win_size:]
matprep_end = matprep_reference._data[:, -win_size:]
pyprep_end = pyprep_reference.raw.get_data()[:, -win_size:]
matprep_end = matprep_reference.get_data()[:, -win_size:]
assert np.allclose(pyprep_end, matprep_end)
6 changes: 3 additions & 3 deletions tests/test_prep_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def test_prep_pipeline_non_eeg(raw, montage):

# make arbitrary non eeg channels from the register
sfreq = raw_copy.info["sfreq"] # Sampling frequency
times = np.array(list(range(raw_copy._data.shape[1])))
times = np.array(list(range(raw_copy.get_data().shape[1])))
ch_names_non_eeg = ["misc" + str(i) for i in range(4)]
ch_types_non_eeg = ["misc" for i in range(4)]
raw_non_eeg, _, _ = make_random_mne_object(
Expand Down Expand Up @@ -244,11 +244,11 @@ def test_prep_pipeline_non_eeg(raw, montage):
# names of raw (only eeg) same as full names - non eeg names
assert set(prep.raw_eeg.ch_names) == set(raw_copy.ch_names) - set(ch_names_non_eeg)
# quantity of raw (only eeg) same as quantity of all - non eeg lists
assert prep.raw_eeg._data.shape[0] == len(raw_copy.ch_names) - len(
assert prep.raw_eeg.get_data().shape[0] == len(raw_copy.ch_names) - len(
prep.ch_names_non_eeg
)
# quantity of channels in is the same as qty of full raw
assert raw_copy._data.shape[0] == prep.raw._data.shape[0]
assert raw_copy.get_data().shape[0] == prep.raw.get_data().shape[0]


@pytest.mark.usefixtures("raw", "montage")
Expand Down