Skip to content

Commit 462226d

Browse files
committed
Changes EDF conversion from PyEDFlib to MNE
1 parent e723c58 commit 462226d

File tree

17 files changed

+879
-364
lines changed

17 files changed

+879
-364
lines changed

demo.ipynb

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __getattr__(cls, name):
5959
# General information about the project.
6060
project = 'wfdb'
6161
copyright = '2018, MIT Lab for Computational Physiology'
62-
author = 'Chen Xie, Julien Dubiel'
62+
author = 'MIT Lab for Computational Physiology'
6363

6464
with open('../wfdb/version.py') as f:
6565
__version__ = f.read().split()[-1].strip("'")
@@ -153,7 +153,7 @@ def __getattr__(cls, name):
153153
# author, documentclass [howto, manual, or own class]).
154154
latex_documents = [
155155
(master_doc, 'wfdb.tex', 'wfdb Documentation',
156-
'Chen Xie, Julien Dubiel', 'manual'),
156+
author, 'manual'),
157157
]
158158

159159

docs/index.rst

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,6 @@ Indices and tables
6363
* :ref:`search`
6464

6565

66-
Authors
67-
-------
68-
69-
`Chen Xie`_
70-
71-
`Julien Dubiel`_
72-
73-
7466
.. _PEP8: https://www.python.org/dev/peps/pep-0008/
7567
.. _docstrings: https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt
7668
.. _existing tests: https://github.com/MIT-LCP/wfdb-python/tree/master/tests
77-
78-
.. _Chen Xie: https://github.com/cx1111/
79-
.. _Julien Dubiel: https://github.com/Dubrzr/

sample-data/test_generator_2.dat

2.58 MB
Binary file not shown.

sample-data/test_generator_2.edf

2.58 MB
Binary file not shown.

sample-data/test_generator_2.hea

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
test_generator_2 12 1 600 12:44:02 10/12/2009
2+
test_generator_2.dat 16x200 32.7675/uV 15 0 3276 0 0 squarewave
3+
test_generator_2.dat 16x200 32.7675/uV 15 0 -3276 480 0 ramp
4+
test_generator_2.dat 16x200 32.7675/uV 15 0 3276 -1920 0 pulse
5+
test_generator_2.dat 16x200 32.7675/uV 15 0 0 21000 0 ECG
6+
test_generator_2.dat 16x200 32.7675/uV 15 0 2752 -12878 0 noise
7+
test_generator_2.dat 16x200 32.7675/uV 15 0 102 0 0 sine 1 Hz
8+
test_generator_2.dat 16x200 32.7675/uV 15 0 814 0 0 sine 8 Hz
9+
test_generator_2.dat 16x200 32.7675/uV 15 0 864 0 0 sine 8.5 Hz
10+
test_generator_2.dat 16x200 32.7675/� 15 0 1487 0 0 sine 15 Hz
11+
test_generator_2.dat 16x200 32.7675/� 15 0 1668 0 0 sine 17 Hz
12+
test_generator_2.dat 16x200 32.7675/uV 15 0 3276 0 0 sine 50 Hz
13+
test_generator_2.dat 16x51 32767.5 15 0 12331 29678 0 EDF Annotations

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
'pandas>=0.19.1',
6464
'scipy>=0.19.0',
6565
'sklearn>=0.0',
66-
'pyedflib>=0.1.17'
66+
'mne>=0.20.5'
6767
],
6868

6969
# List additional groups of dependencies here (e.g. development

tests/test_record.py

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import os
2+
import pdb
23
import shutil
34
import unittest
45

56
import numpy as np
6-
77
import wfdb
88

99

@@ -259,15 +259,25 @@ def test_2f(self):
259259
record_EDF = wfdb.rdrecord('sample-data/n16.edf').__dict__
260260

261261
fields = list(record_MIT.keys())
262-
# MIT format method of checksum is outdated, sometimes the same value though
262+
# Original MIT format method of checksum is outdated, sometimes
263+
# the same value though
263264
fields.remove('checksum')
265+
# Original MIT format units are less comprehensive since they
266+
# default to mV if unknown.. therefore added more default labels
267+
fields.remove('units')
264268

265269
test_results = []
266270
for field in fields:
267271
# Signal value will be slightly off due to C to Python type conversion
268272
if field == 'p_signal':
269-
signal_diff = record_MIT[field] - record_EDF[field]
270-
if abs(max(signal_diff.min(), signal_diff.max(), key=abs)) <= 2:
273+
true_array = np.array(record_MIT[field])
274+
pred_array = np.array(record_EDF[field])
275+
sig_diff = np.abs((pred_array - true_array) / true_array)
276+
sig_diff[sig_diff == -np.inf] = 0
277+
sig_diff[sig_diff == np.inf] = 0
278+
sig_diff = np.nanmean(sig_diff,0)
279+
# 5% tolerance
280+
if np.max(sig_diff) <= 5:
271281
test_results.append(True)
272282
else:
273283
test_results.append(False)
@@ -293,15 +303,31 @@ def test_2g(self):
293303
record_EDF = wfdb.rdrecord('sample-data/SC4001E0-PSG.edf').__dict__
294304

295305
fields = list(record_MIT.keys())
296-
# MIT format method of checksum is outdated, sometimes the same value though
306+
# Original MIT format method of checksum is outdated, sometimes
307+
# the same value though
297308
fields.remove('checksum')
309+
# Original MIT format units are less comprehensive since they
310+
# default to mV if unknown.. therefore added more default labels
311+
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')
298318

299319
test_results = []
300320
for field in fields:
301321
# Signal value will be slightly off due to C to Python type conversion
302322
if field == 'p_signal':
303-
signal_diff = record_MIT[field] - record_EDF[field]
304-
if abs(max(signal_diff.min(), signal_diff.max(), key=abs)) <= 2:
323+
true_array = np.array(record_MIT[field])
324+
pred_array = np.array(record_EDF[field])
325+
sig_diff = np.abs((pred_array - true_array) / true_array)
326+
sig_diff[sig_diff == -np.inf] = 0
327+
sig_diff[sig_diff == np.inf] = 0
328+
sig_diff = np.nanmean(sig_diff,0)
329+
# 5% tolerance
330+
if np.max(sig_diff) <= 5:
305331
test_results.append(True)
306332
else:
307333
test_results.append(False)
@@ -478,6 +504,13 @@ def test_4d(self):
478504

479505
assert np.array_equal(sig_round, sig_target)
480506

507+
def test_header_with_non_utf8(self):
508+
"""
509+
Ignores non-utf8 characters in the header part.
510+
"""
511+
record = wfdb.rdrecord("sample-data/test_generator_2")
512+
sig_units_target = ['uV', 'uV', 'uV', 'uV', 'uV', 'uV', 'uV', 'uV', 'mV', 'mV', 'uV', 'mV']
513+
assert record.units.__eq__(sig_units_target)
481514

482515
@classmethod
483516
def tearDownClass(cls):

0 commit comments

Comments
 (0)