diff --git a/doc/source/authors.rst b/doc/source/authors.rst index 035fdfbe7..81fb794ab 100644 --- a/doc/source/authors.rst +++ b/doc/source/authors.rst @@ -106,6 +106,7 @@ and may not be the current affiliation of a contributor. * Aditya Singh (github) * Stanley C. * Axel Coiffard-Donaty +* Anton Soloviev 1. Centre de Recherche en Neuroscience de Lyon, CNRS UMR5292 - INSERM U1028 - Université Claude Bernard Lyon 1 2. Unité de Neuroscience, Information et Complexité, CNRS UPR 3293, Gif-sur-Yvette, France diff --git a/neo/rawio/edfrawio.py b/neo/rawio/edfrawio.py index 9936b2cb8..79cc62eb8 100644 --- a/neo/rawio/edfrawio.py +++ b/neo/rawio/edfrawio.py @@ -105,8 +105,8 @@ def _parse_header(self): dtype = "int16" # assume general int16 based on edf documentation units = sig_dict["dimension"] physical_range = sig_dict["physical_max"] - sig_dict["physical_min"] - # number of digital steps resolved (+1 to account for '0') - digital_range = sig_dict["digital_max"] - sig_dict["digital_min"] + 1 + # The digital endpoints correspond to the physical endpoints. + digital_range = sig_dict["digital_max"] - sig_dict["digital_min"] gain = physical_range / digital_range offset = -1 * sig_dict["digital_min"] * gain + sig_dict["physical_min"] diff --git a/neo/test/iotest/test_edfio.py b/neo/test/iotest/test_edfio.py index bf73a642c..cd6a9b024 100644 --- a/neo/test/iotest/test_edfio.py +++ b/neo/test/iotest/test_edfio.py @@ -67,6 +67,8 @@ def test_compare_data(self): """ Compare data from AnalogSignal with plain data stored in text file """ + import pyedflib + with EDFIO(self.filename) as io: plain_data = np.loadtxt(io.filename.replace(".edf", ".txt"), dtype=np.int16) seg = io.read_segment(lazy=True) @@ -75,19 +77,14 @@ def test_compare_data(self): self.assertEqual(len(anasigs), 5) # all channels have different units, so expecting 5 for aidx, anasig in enumerate(anasigs): # comparing raw data to original values - ana_data = anasig.load(magnitude_mode="raw") - np.testing.assert_array_equal(ana_data.magnitude, plain_data[:, aidx : aidx + 1]) - - # comparing floating data to original values * gain factor - ch_head = io.edf_reader.getSignalHeader(aidx) - physical_range = ch_head["physical_max"] - ch_head["physical_min"] - # number of digital values used (+1 to account for '0' value) - digital_range = ch_head["digital_max"] - ch_head["digital_min"] + 1 + raw_data = io.get_analogsignal_chunk(channel_indexes=[aidx]) + np.testing.assert_array_equal(raw_data, plain_data[:, aidx : aidx + 1]) - gain = physical_range / digital_range + # Compare calibrated values with pyedflib's physical readout. ana_data = anasig.load(magnitude_mode="rescaled") - rescaled_data = plain_data[:, aidx : aidx + 1] * gain - np.testing.assert_array_equal(ana_data.magnitude, rescaled_data) + with pyedflib.EdfReader(io.filename) as reader: + rescaled_data = reader.readSignal(aidx) + np.testing.assert_allclose(ana_data.magnitude[:, 0], rescaled_data, rtol=1e-6, atol=1e-5) if __name__ == "__main__":