def test_parse_annotation(): """Test parsing the tal channel """ # test the parser annot = ( b"+180\x14Lights off\x14Close door\x14\x00\x00\x00\x00\x00" b"+180\x14Lights off\x14\x00\x00\x00\x00\x00\x00\x00\x00" b"+180\x14Close door\x14\x00\x00\x00\x00\x00\x00\x00\x00" b"+3.14\x1504.20\x14nothing\x14\x00\x00\x00\x00" b"+1800.2\x1525.5\x14Apnea\x14\x00\x00\x00\x00\x00\x00\x00" b"+123\x14\x14\x00\x00\x00\x00\x00\x00\x00" ) annot = [a for a in iterbytes(annot)] annot[1::2] = [a * 256 for a in annot[1::2]] tal_channel = map(sum, zip(annot[0::2], annot[1::2])) events = edfmodule._parse_tal_channel(tal_channel) assert_equal( events, [ [180.0, 0, "Lights off"], [180.0, 0, "Close door"], [180.0, 0, "Lights off"], [180.0, 0, "Close door"], [3.14, 4.2, "nothing"], [1800.2, 25.5, "Apnea"], ], )
def test_parse_annotation(): """Test parsing the tal channel.""" # test the parser annot = (b'+180\x14Lights off\x14Close door\x14\x00\x00\x00\x00\x00' b'+180\x14Lights off\x14\x00\x00\x00\x00\x00\x00\x00\x00' b'+180\x14Close door\x14\x00\x00\x00\x00\x00\x00\x00\x00' b'+3.14\x1504.20\x14nothing\x14\x00\x00\x00\x00' b'+1800.2\x1525.5\x14Apnea\x14\x00\x00\x00\x00\x00\x00\x00' b'+123\x14\x14\x00\x00\x00\x00\x00\x00\x00') annot = [a for a in iterbytes(annot)] annot[1::2] = [a * 256 for a in annot[1::2]] tal_channel = map(sum, zip(annot[0::2], annot[1::2])) assert_equal(_parse_tal_channel([tal_channel]), [[180.0, 0, 'Lights off'], [180.0, 0, 'Close door'], [180.0, 0, 'Lights off'], [180.0, 0, 'Close door'], [3.14, 4.2, 'nothing'], [1800.2, 25.5, 'Apnea']])
def test_parse_annotation(): """Test parsing the tal channel.""" # test the parser annot = (b'+180\x14Lights off\x14Close door\x14\x00\x00\x00\x00\x00' b'+180\x14Lights off\x14\x00\x00\x00\x00\x00\x00\x00\x00' b'+180\x14Close door\x14\x00\x00\x00\x00\x00\x00\x00\x00' b'+3.14\x1504.20\x14nothing\x14\x00\x00\x00\x00' b'+1800.2\x1525.5\x14Apnea\x14\x00\x00\x00\x00\x00\x00\x00' b'+123\x14\x14\x00\x00\x00\x00\x00\x00\x00') annot = [a for a in iterbytes(annot)] annot[1::2] = [a * 256 for a in annot[1::2]] tal_channel = map(sum, zip(annot[0::2], annot[1::2])) onset, duration, description = _read_annotations_edf([tal_channel]) assert_equal(np.column_stack((onset, duration, description)), [[180., 0., 'Lights off'], [180., 0., 'Close door'], [180., 0., 'Lights off'], [180., 0., 'Close door'], [3.14, 4.2, 'nothing'], [1800.2, 25.5, 'Apnea']])