@@ -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
9390if __name__ == "__main__" :
0 commit comments