Skip to content

Commit 20dda53

Browse files
committed
Improves EDF speed / fixes bugs
1 parent 8269d41 commit 20dda53

11 files changed

+278
-250
lines changed

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __getattr__(cls, name):
3030
return MagicMock()
3131

3232
MOCK_MODULES = ['numpy', 'matplotlib', 'matplotlib.pyplot', 'pandas', 'scipy',
33-
'sklearn', 'sklearn.preprocessing', 'mne']
33+
'sklearn', 'sklearn.preprocessing']
3434
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
3535

3636
# -- General configuration ------------------------------------------------

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ idna==2.9
55
joblib==0.14.1
66
kiwisolver==1.2.0
77
matplotlib==3.2.1
8-
mne==0.20.5
98
nose==1.3.7
109
numpy==1.18.5
1110
pandas==1.0.3

sample-data/SC4001E0-PSG.edf

-46.1 MB
Binary file not shown.

sample-data/SC4001E0_PSG.dat

-46.1 MB
Binary file not shown.

sample-data/SC4001E0_PSG.hea

Lines changed: 0 additions & 8 deletions
This file was deleted.

sample-data/wave_4.dat

9.12 MB
Binary file not shown.

sample-data/wave_4.edf

9.12 MB
Binary file not shown.

sample-data/wave_4.hea

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
wave_4 7 1 3659 0:00 01/01/2001
2+
wave_4.dat 16x1000 1(1)/uV 15 0 5393 -12624 0 ECG
3+
wave_4.dat 16x100 2(1)/mg 13 0 1371 18209 0 Accelerometer_X
4+
wave_4.dat 16x100 2(1)/mg 13 0 1273 29556 0 Accelerometer_Y
5+
wave_4.dat 16x100 2(1)/mg 13 0 -473 -31584 0 Accelerometer_Z
6+
wave_4.dat 16 1(1) 15 0 32766 -29151 0 Marker
7+
wave_4.dat 16x5 1(-32767)/ms 15 0 -32768 13833 0 HRV
8+
wave_4.dat 16 -19.3447902992(3064)/degC 11 2048 2461 27731 0 DEV_Temperature

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
'joblib>=0.11',
6464
'kiwisolver>=1.1.0',
6565
'matplotlib>=2.0.0',
66-
'mne>=0.18.0',
6766
'numpy>=1.10.1',
6867
'pandas>=0.17.0',
6968
'pyparsing>=2.0.4',

tests/test_record.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def test_2f(self):
256256
"""
257257
# Uniform sample rates
258258
record_MIT = wfdb.rdrecord('sample-data/n16').__dict__
259-
record_EDF = wfdb.rdrecord('sample-data/n16.edf').__dict__
259+
record_EDF = wfdb.edf2mit('sample-data/n16.edf').__dict__
260260

261261
fields = list(record_MIT.keys())
262262
# Original MIT format method of checksum is outdated, sometimes
@@ -270,8 +270,13 @@ def test_2f(self):
270270
for field in fields:
271271
# Signal value will be slightly off due to C to Python type conversion
272272
if field == 'p_signal':
273-
true_array = np.array(record_MIT[field])
274-
pred_array = np.array(record_EDF[field])
273+
true_array = np.array(record_MIT[field]).flatten()
274+
pred_array = np.array(record_EDF[field]).flatten()
275+
# Prevent divide by zero warning
276+
for i,v in enumerate(true_array):
277+
if v == 0:
278+
true_array[i] = 1
279+
pred_array[i] = 1
275280
sig_diff = np.abs((pred_array - true_array) / true_array)
276281
sig_diff[sig_diff == -np.inf] = 0
277282
sig_diff[sig_diff == np.inf] = 0
@@ -299,8 +304,8 @@ def test_2g(self):
299304
300305
"""
301306
# Non-uniform sample rates
302-
record_MIT = wfdb.rdrecord('sample-data/SC4001E0_PSG').__dict__
303-
record_EDF = wfdb.rdrecord('sample-data/SC4001E0-PSG.edf').__dict__
307+
record_MIT = wfdb.rdrecord('sample-data/wave_4').__dict__
308+
record_EDF = wfdb.edf2mit('sample-data/wave_4.edf').__dict__
304309

305310
fields = list(record_MIT.keys())
306311
# Original MIT format method of checksum is outdated, sometimes
@@ -309,19 +314,18 @@ def test_2g(self):
309314
# Original MIT format units are less comprehensive since they
310315
# default to mV if unknown.. therefore added more default labels
311316
fields.remove('units')
312-
# Initial value of signal will be off due to resampling done by
313-
# MNE in the EDF reading phase
314-
fields.remove('init_value')
315-
# Samples per frame will be off due to resampling done by MNE in
316-
# the EDF reading phase... I should probably fix this later
317-
fields.remove('samps_per_frame')
318317

319318
test_results = []
320319
for field in fields:
321320
# Signal value will be slightly off due to C to Python type conversion
322321
if field == 'p_signal':
323-
true_array = np.array(record_MIT[field])
324-
pred_array = np.array(record_EDF[field])
322+
true_array = np.array(record_MIT[field]).flatten()
323+
pred_array = np.array(record_EDF[field]).flatten()
324+
# Prevent divide by zero warning
325+
for i,v in enumerate(true_array):
326+
if v == 0:
327+
true_array[i] = 1
328+
pred_array[i] = 1
325329
sig_diff = np.abs((pred_array - true_array) / true_array)
326330
sig_diff[sig_diff == -np.inf] = 0
327331
sig_diff[sig_diff == np.inf] = 0

0 commit comments

Comments
 (0)