Skip to content

Commit 9600fee

Browse files
authored
Merge pull request #1920 from antonsoo/fix/edf-physical-calibration
Map EDF digital endpoints to their physical endpoints
2 parents 6ea15e2 + 33fb16f commit 9600fee

3 files changed

Lines changed: 11 additions & 13 deletions

File tree

‎doc/source/authors.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ and may not be the current affiliation of a contributor.
106106
* Aditya Singh (github)
107107
* Stanley C.
108108
* Axel Coiffard-Donaty
109+
* Anton Soloviev
109110

110111
1. Centre de Recherche en Neuroscience de Lyon, CNRS UMR5292 - INSERM U1028 - Université Claude Bernard Lyon 1
111112
2. Unité de Neuroscience, Information et Complexité, CNRS UPR 3293, Gif-sur-Yvette, France

‎neo/rawio/edfrawio.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ def _parse_header(self):
105105
dtype = "int16" # assume general int16 based on edf documentation
106106
units = sig_dict["dimension"]
107107
physical_range = sig_dict["physical_max"] - sig_dict["physical_min"]
108-
# number of digital steps resolved (+1 to account for '0')
109-
digital_range = sig_dict["digital_max"] - sig_dict["digital_min"] + 1
108+
# The digital endpoints correspond to the physical endpoints.
109+
digital_range = sig_dict["digital_max"] - sig_dict["digital_min"]
110110
gain = physical_range / digital_range
111111
offset = -1 * sig_dict["digital_min"] * gain + sig_dict["physical_min"]
112112

‎neo/test/iotest/test_edfio.py‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ def test_compare_data(self):
6767
"""
6868
Compare data from AnalogSignal with plain data stored in text file
6969
"""
70+
import pyedflib
71+
7072
with EDFIO(self.filename) as io:
7173
plain_data = np.loadtxt(io.filename.replace(".edf", ".txt"), dtype=np.int16)
7274
seg = io.read_segment(lazy=True)
@@ -75,19 +77,14 @@ def test_compare_data(self):
7577
self.assertEqual(len(anasigs), 5) # all channels have different units, so expecting 5
7678
for aidx, anasig in enumerate(anasigs):
7779
# comparing raw data to original values
78-
ana_data = anasig.load(magnitude_mode="raw")
79-
np.testing.assert_array_equal(ana_data.magnitude, plain_data[:, aidx : aidx + 1])
80-
81-
# comparing floating data to original values * gain factor
82-
ch_head = io.edf_reader.getSignalHeader(aidx)
83-
physical_range = ch_head["physical_max"] - ch_head["physical_min"]
84-
# number of digital values used (+1 to account for '0' value)
85-
digital_range = ch_head["digital_max"] - ch_head["digital_min"] + 1
80+
raw_data = io.get_analogsignal_chunk(channel_indexes=[aidx])
81+
np.testing.assert_array_equal(raw_data, plain_data[:, aidx : aidx + 1])
8682

87-
gain = physical_range / digital_range
83+
# Compare calibrated values with pyedflib's physical readout.
8884
ana_data = anasig.load(magnitude_mode="rescaled")
89-
rescaled_data = plain_data[:, aidx : aidx + 1] * gain
90-
np.testing.assert_array_equal(ana_data.magnitude, rescaled_data)
85+
with pyedflib.EdfReader(io.filename) as reader:
86+
rescaled_data = reader.readSignal(aidx)
87+
np.testing.assert_allclose(ana_data.magnitude[:, 0], rescaled_data, rtol=1e-6, atol=1e-5)
9188

9289

9390
if __name__ == "__main__":

0 commit comments

Comments
 (0)