Skip to content

Commit af85617

Browse files
authored
use get_data instead of ._data (#128)
1 parent c6b268b commit af85617

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

pyprep/find_noisy_channels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def __init__(self, raw, do_detrend=True, random_state=None, matlab_strict=False)
9090
ch_names = np.asarray(self.raw_mne.info["ch_names"])
9191
self.ch_names_original = ch_names
9292
self.n_chans_original = len(ch_names)
93-
self.n_samples = raw._data.shape[1]
93+
self.n_samples = raw.get_data().shape[1]
9494

9595
# Before anything else, flag bad-by-NaNs and bad-by-flats
9696
self.find_bad_by_nan_flat()

pyprep/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def _eeglab_interpolate_bads(raw):
367367
_normalize_vectors(pos_bad)
368368

369369
# Interpolate bad channels
370-
interp = _eeglab_interpolate(raw._data[good_idx, :], pos_good, pos_bad)
370+
interp = _eeglab_interpolate(raw.get_data()[good_idx, :], pos_good, pos_bad)
371371
raw._data[bad_idx, :] = interp
372372

373373
# Clear all bad EEG channels

tests/test_find_noisy_channels.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def _generate_signal(fmin, fmax, timepoints, fcount=1):
5858
def test_bad_by_nan(raw_tmp):
5959
"""Test the detection of channels containing any NaN values."""
6060
# Insert a NaN value into a random channel
61-
n_chans = raw_tmp._data.shape[0]
61+
n_chans = raw_tmp.get_data().shape[0]
6262
nan_idx = int(RNG.randint(0, n_chans, 1))
6363
raw_tmp._data[nan_idx, 3] = np.nan
6464

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

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

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

@@ -125,7 +125,7 @@ def test_bad_by_deviation(raw_tmp):
125125
def test_bad_by_hf_noise(raw_tmp):
126126
"""Test detection of channels with high-frequency noise."""
127127
# Add some noise between 70 & 80 Hz to the signal of a random channel
128-
n_chans = raw_tmp._data.shape[0]
128+
n_chans = raw_tmp.get_data().shape[0]
129129
hf_noise_idx = int(RNG.randint(0, n_chans, 1))
130130
hf_noise = _generate_signal(70, 80, raw_tmp.times, 5) * 10
131131
raw_tmp._data[hf_noise_idx, :] += hf_noise
@@ -147,7 +147,7 @@ def test_bad_by_hf_noise(raw_tmp):
147147
def test_bad_by_dropout(raw_tmp):
148148
"""Test detection of channels with excessive portions of flat signal."""
149149
# Add large dropout portions to the signal of a random channel
150-
n_chans, n_samples = raw_tmp._data.shape
150+
n_chans, n_samples = raw_tmp.get_data().shape
151151
dropout_idx = int(RNG.randint(0, n_chans, 1))
152152
x1, x2 = (int(n_samples / 10), int(2 * n_samples / 10))
153153
raw_tmp._data[dropout_idx, x1:x2] = 0 # flatten 10% of signal
@@ -161,7 +161,7 @@ def test_bad_by_dropout(raw_tmp):
161161
def test_bad_by_correlation(raw_tmp):
162162
"""Test detection of channels that correlate poorly with others."""
163163
# Replace a random channel's signal with uncorrelated values
164-
n_chans, n_samples = raw_tmp._data.shape
164+
n_chans, n_samples = raw_tmp.get_data().shape
165165
low_corr_idx = int(RNG.randint(0, n_chans, 1))
166166
raw_tmp._data[low_corr_idx, :] = _generate_signal(10, 30, raw_tmp.times, 5)
167167

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

@@ -275,7 +275,7 @@ def test_find_bad_by_ransac_err(raw_tmp):
275275
nd.find_bad_by_ransac(n_samples=n_samples)
276276

277277
# Test IOError when too few good channels for RANSAC sample size
278-
n_chans = raw_tmp._data.shape[0]
278+
n_chans = raw_tmp.get_data().shape[0]
279279
nd = NoisyChannels(raw_tmp, do_detrend=False)
280280
nd.bad_by_deviation = raw_tmp.info["ch_names"][0 : int(n_chans * 0.8)]
281281
with pytest.raises(IOError):

tests/test_matprep_compare.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ def test_compare_removeTrend(matprep_artifacts):
184184
sample_rate = matprep_raw.info["sfreq"]
185185

186186
# Apply removeTrend to raw artifact to get expected and actual signals
187-
expected = matprep_detrended._data
187+
expected = matprep_detrended.get_data()
188188
actual = removeTrend(
189-
matprep_raw._data, sample_rate, detrendType="high pass", matlab_strict=True
189+
matprep_raw.get_data(), sample_rate, detrendType="high pass", matlab_strict=True
190190
)
191191

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

388388
# Compare signals at start of recording
389-
pyprep_start = pyprep_reference.raw._data[:, win_size]
390-
matprep_start = matprep_reference._data[:, win_size]
389+
pyprep_start = pyprep_reference.raw.get_data()[:, win_size]
390+
matprep_start = matprep_reference.get_data()[:, win_size]
391391
assert np.allclose(pyprep_start, matprep_start)
392392

393393
# Compare signals at end of recording
394-
pyprep_end = pyprep_reference.raw._data[:, -win_size:]
395-
matprep_end = matprep_reference._data[:, -win_size:]
394+
pyprep_end = pyprep_reference.raw.get_data()[:, -win_size:]
395+
matprep_end = matprep_reference.get_data()[:, -win_size:]
396396
assert np.allclose(pyprep_end, matprep_end)

tests/test_prep_pipeline.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def test_prep_pipeline_non_eeg(raw, montage):
215215

216216
# make arbitrary non eeg channels from the register
217217
sfreq = raw_copy.info["sfreq"] # Sampling frequency
218-
times = np.array(list(range(raw_copy._data.shape[1])))
218+
times = np.array(list(range(raw_copy.get_data().shape[1])))
219219
ch_names_non_eeg = ["misc" + str(i) for i in range(4)]
220220
ch_types_non_eeg = ["misc" for i in range(4)]
221221
raw_non_eeg, _, _ = make_random_mne_object(
@@ -244,11 +244,11 @@ def test_prep_pipeline_non_eeg(raw, montage):
244244
# names of raw (only eeg) same as full names - non eeg names
245245
assert set(prep.raw_eeg.ch_names) == set(raw_copy.ch_names) - set(ch_names_non_eeg)
246246
# quantity of raw (only eeg) same as quantity of all - non eeg lists
247-
assert prep.raw_eeg._data.shape[0] == len(raw_copy.ch_names) - len(
247+
assert prep.raw_eeg.get_data().shape[0] == len(raw_copy.ch_names) - len(
248248
prep.ch_names_non_eeg
249249
)
250250
# quantity of channels in is the same as qty of full raw
251-
assert raw_copy._data.shape[0] == prep.raw._data.shape[0]
251+
assert raw_copy.get_data().shape[0] == prep.raw.get_data().shape[0]
252252

253253

254254
@pytest.mark.usefixtures("raw", "montage")

0 commit comments

Comments
 (0)