def test_iterator_remove_end(self): ec = btk.btkEventCollection() ec.InsertItem( btk.btkEvent('FOO', 1.52, 'Right', btk.btkEvent.Manual, 'Bar', '', 1)) ec.InsertItem( btk.btkEvent('BAR', 2.03, 'Left', btk.btkEvent.Automatic, 'Foo', '', 2)) ec.InsertItem( btk.btkEvent('FOOBAR', 5.05, 'General', btk.btkEvent.Automatic, 'FooBar', '', 3)) self.assertEqual(ec.GetItemNumber(), 3) i = ec.End() i.decr() ec.RemoveItem(i) self.assertEqual(ec.GetItemNumber(), 2) e1 = ec.GetItem(0) self.assertEqual(e1.GetLabel(), 'FOO') self.assertEqual(e1.GetTime(), 1.52) self.assertEqual(e1.GetFrame(), -1) self.assertEqual(e1.GetContext(), 'Right') self.assertEqual(e1.GetDetectionFlags(), btk.btkEvent.Manual) self.assertEqual(e1.GetSubject(), 'Bar') self.assertEqual(e1.GetDescription(), '') self.assertEqual(e1.GetId(), 1) e2 = ec.GetItem(1) self.assertEqual(e2.GetLabel(), 'BAR') self.assertEqual(e2.GetTime(), 2.03) self.assertEqual(e2.GetFrame(), -1) self.assertEqual(e2.GetContext(), 'Left') self.assertEqual(e2.GetDetectionFlags(), btk.btkEvent.Automatic) self.assertEqual(e2.GetSubject(), 'Foo') self.assertEqual(e2.GetDescription(), '') self.assertEqual(e2.GetId(), 2)
def test_iterator_take_begin(self): ec = btk.btkEventCollection() ec.InsertItem(btk.btkEvent('FOO', 1.52, 'Right', btk.btkEvent.Manual, 'Bar', '', 1)) ec.InsertItem(btk.btkEvent('BAR', 2.03, 'Left', btk.btkEvent.Automatic, 'Foo', '', 2)) ec.InsertItem(btk.btkEvent('FOOBAR', 5.05, 'General', btk.btkEvent.Automatic, 'FooBar', '', 3)) self.assertEqual(ec.GetItemNumber(), 3) e1 = ec.TakeItem(ec.Begin()) self.assertEqual(ec.GetItemNumber(), 2) self.assertEqual(e1.GetLabel(), 'FOO') self.assertEqual(e1.GetTime(), 1.52) self.assertEqual(e1.GetFrame(), -1) self.assertEqual(e1.GetContext(), 'Right') self.assertEqual(e1.GetDetectionFlags(), btk.btkEvent.Manual) self.assertEqual(e1.GetSubject(), 'Bar') self.assertEqual(e1.GetDescription(), '') self.assertEqual(e1.GetId(), 1) e2 = ec.GetItem(0) self.assertEqual(e2.GetLabel(), 'BAR') self.assertEqual(e2.GetTime(), 2.03) self.assertEqual(e2.GetFrame(), -1) self.assertEqual(e2.GetContext(), 'Left') self.assertEqual(e2.GetDetectionFlags(), btk.btkEvent.Automatic) self.assertEqual(e2.GetSubject(), 'Foo') self.assertEqual(e2.GetDescription(), '') self.assertEqual(e2.GetId(), 2) e3 = ec.GetItem(1) self.assertEqual(e3.GetLabel(), 'FOOBAR') self.assertEqual(e3.GetTime(), 5.05) self.assertEqual(e3.GetFrame(), -1) self.assertEqual(e3.GetContext(), 'General') self.assertEqual(e3.GetDetectionFlags(), btk.btkEvent.Automatic) self.assertEqual(e3.GetSubject(), 'FooBar') self.assertEqual(e3.GetDescription(), '') self.assertEqual(e3.GetId(), 3)
def test_insert_index_last(self): ec = btk.btkEventCollection() ec.InsertItem( 0, btk.btkEvent('FOO', 1.52, 'Right', btk.btkEvent.Manual, 'Bar', '', 1)) ec.InsertItem( 1, btk.btkEvent('BAR', 2.03, 'Left', btk.btkEvent.Automatic, 'Foo', '', 2)) e2 = ec.GetItem(1) self.assertEqual(e2.GetLabel(), 'BAR') self.assertEqual(e2.GetTime(), 2.03) self.assertEqual(e2.GetFrame(), -1) self.assertEqual(e2.GetContext(), 'Left') self.assertEqual(e2.GetDetectionFlags(), btk.btkEvent.Automatic) self.assertEqual(e2.GetSubject(), 'Foo') self.assertEqual(e2.GetDescription(), '') self.assertEqual(e2.GetId(), 2) e1 = ec.GetItem(0) self.assertEqual(e1.GetLabel(), 'FOO') self.assertEqual(e1.GetTime(), 1.52) self.assertEqual(e1.GetFrame(), -1) self.assertEqual(e1.GetContext(), 'Right') self.assertEqual(e1.GetDetectionFlags(), btk.btkEvent.Manual) self.assertEqual(e1.GetSubject(), 'Bar') self.assertEqual(e1.GetDescription(), '') self.assertEqual(e1.GetId(), 1)
def test_take(self): ec = btk.btkEventCollection() ec.InsertItem(btk.btkEvent('FOO', 1.52, 'Right', btk.btkEvent.Manual, 'Bar', '', 1)) ec.InsertItem(btk.btkEvent('BAR', 2.03, 'Left', btk.btkEvent.Automatic, 'Foo', '', 2)) self.assertEqual(ec.GetItemNumber(), 2) e1 = ec.TakeItem(0) self.assertEqual(ec.GetItemNumber(), 1) self.assertEqual(e1.GetLabel(), 'FOO') self.assertEqual(e1.GetTime(), 1.52) self.assertEqual(e1.GetFrame(), -1) self.assertEqual(e1.GetContext(), 'Right') self.assertEqual(e1.GetDetectionFlags(), btk.btkEvent.Manual) self.assertEqual(e1.GetSubject(), 'Bar') self.assertEqual(e1.GetDescription(), '') self.assertEqual(e1.GetId(), 1) e2 = ec.GetItem(0) self.assertEqual(e2.GetLabel(), 'BAR') self.assertEqual(e2.GetTime(), 2.03) self.assertEqual(e2.GetFrame(), -1) self.assertEqual(e2.GetContext(), 'Left') self.assertEqual(e2.GetDetectionFlags(), btk.btkEvent.Automatic) self.assertEqual(e2.GetSubject(), 'Foo') self.assertEqual(e2.GetDescription(), '') self.assertEqual(e2.GetId(), 2) ec.Clear() self.assertEqual(ec.GetItemNumber(), 0)
def test_insert_index_middle(self): ec = btk.btkEventCollection() ec.InsertItem(btk.btkEvent('FOO', 1.52, 'Right', btk.btkEvent.Manual, 'Bar', '', 1)) ec.InsertItem(btk.btkEvent('BAR', 2.03, 'Left', btk.btkEvent.Automatic, 'Foo', '', 2)) ec.InsertItem(1, btk.btkEvent('FOOBAR', 5.05, 'General', btk.btkEvent.Automatic, 'FooBar', '', 3)) self.assertEqual(ec.GetItemNumber(), 3) e = ec.GetItem(1) self.assertEqual(e.GetLabel(), 'FOOBAR') self.assertEqual(e.GetTime(), 5.05) self.assertEqual(e.GetFrame(), -1) self.assertEqual(e.GetContext(), 'General') self.assertEqual(e.GetDetectionFlags(), btk.btkEvent.Automatic) self.assertEqual(e.GetSubject(), 'FooBar') self.assertEqual(e.GetDescription(), '') self.assertEqual(e.GetId(), 3)
def test_TestOnlyPoints(self): acq = btk.btkAcquisition() acq.Init(10, 25, 5, 2) acq.AppendEvent(btk.btkEvent("", 12)) acq.SetFirstFrame(10) acq.SetPointFrequency(25.0) for i in range(0, 10): acq.GetPoint(i).SetValue(0, 0, 10.0) for i in range(0, 5): acq.GetAnalog(i).SetValue(2, 10.0) sub = btk.btkSubAcquisitionFilter() sub.SetInput(acq) sub.SetFramesIndex(0, 9) sub.SetExtractionOption(btk.btkSubAcquisitionFilter.PointsOnly) sub.Update() output = sub.GetOutput() self.assertEqual(output.GetFirstFrame(), acq.GetFirstFrame()) self.assertEqual(output.GetPointFrequency(), acq.GetPointFrequency()) self.assertEqual(output.GetPointFrameNumber(), 10) self.assertEqual(output.GetNumberAnalogSamplePerFrame(), acq.GetNumberAnalogSamplePerFrame()) self.assertEqual(output.GetEventNumber(), 0) self.assertEqual(output.GetPointNumber(), acq.GetPointNumber()) self.assertEqual(output.GetAnalogNumber(), 0) # self.assertEqual(output.GetMetaData(), acq.GetMetaData()) for i in range(0, 10): self.assertEqual(output.GetPoint(i).GetValues()[0, 0], 10.0)
def test_clone(self): e1 = btk.btkEvent('FOO', 1.52, 144, 'Right', btk.btkEvent.Manual, 'Bar', 'Simple test', 1) e2 = e1.Clone(); self.assertEqual(e2.GetLabel(), 'FOO') self.assertEqual(e2.GetTime(), 1.52) self.assertEqual(e2.GetFrame(), 144) self.assertEqual(e2.GetContext(), 'Right') self.assertEqual(e2.GetDetectionFlags(), btk.btkEvent.Manual) self.assertEqual(e2.GetSubject(), 'Bar') self.assertEqual(e2.GetDescription(), 'Simple test') self.assertEqual(e2.GetId(), 1) e2.SetLabel('ALLO') e2.SetTime(2.03) e2.SetFrame(789) e2.SetContext('Left') e2.SetDetectionFlags(btk.btkEvent.Automatic) e2.SetSubject('Heinz') e2.SetDescription('Test for the clone') e2.SetId(2) self.assertEqual(e1.GetLabel(), 'FOO') self.assertEqual(e1.GetTime(), 1.52) self.assertEqual(e1.GetFrame(), 144) self.assertEqual(e1.GetContext(), 'Right') self.assertEqual(e1.GetDetectionFlags(), btk.btkEvent.Manual) self.assertEqual(e1.GetSubject(), 'Bar') self.assertEqual(e1.GetDescription(), 'Simple test') self.assertEqual(e1.GetId(), 1) self.assertEqual(e2.GetLabel(), 'ALLO') self.assertEqual(e2.GetTime(), 2.03) self.assertEqual(e2.GetFrame(), 789) self.assertEqual(e2.GetContext(), 'Left') self.assertEqual(e2.GetDetectionFlags(), btk.btkEvent.Automatic) self.assertEqual(e2.GetSubject(), 'Heinz') self.assertEqual(e2.GetDescription(), 'Test for the clone') self.assertEqual(e2.GetId(), 2)
def test_copy(self): e1 = btk.btkEvent('FOO', 1.52, 144, 'Right', btk.btkEvent.Manual, 'Bar', 'Simple test', 1) e2 = e1 self.assertEqual(e2.GetLabel(), 'FOO') self.assertEqual(e2.GetTime(), 1.52) self.assertEqual(e2.GetFrame(), 144) self.assertEqual(e2.GetContext(), 'Right') self.assertEqual(e2.GetDetectionFlags(), btk.btkEvent.Manual) self.assertEqual(e2.GetSubject(), 'Bar') self.assertEqual(e2.GetDescription(), 'Simple test') self.assertEqual(e2.GetId(), 1) e2.SetLabel('ALLO') e2.SetTime(2.03) e2.SetFrame(789) e2.SetContext('Left') e2.SetDetectionFlags(btk.btkEvent.Automatic) e2.SetSubject('Heinz') e2.SetDescription('Test for the copy') e2.SetId(2) self.assertEqual(e1.GetLabel(), e2.GetLabel()) self.assertEqual(e1.GetTime(), e2.GetTime()) self.assertEqual(e1.GetFrame(), e2.GetFrame()) self.assertEqual(e1.GetContext(), e2.GetContext()) self.assertEqual(e1.GetDetectionFlags(), e2.GetDetectionFlags()) self.assertEqual(e1.GetSubject(), e2.GetSubject()) self.assertEqual(e1.GetDescription(), e2.GetDescription()) self.assertEqual(e1.GetId(), e2.GetId())
def test_TestOnlyTwoAnalogsSubFrame(self): acq = btk.btkAcquisition() acq.Init(10,25,5,2) acq.AppendEvent(btk.btkEvent("", 12)) acq.SetFirstFrame(10) acq.SetPointFrequency(25.0) for i in range(0,10): acq.GetPoint(i).SetValue(0,0,10.0) for i in range(0,5): acq.GetAnalog(i).SetValue(2,10.0) sub = btk.btkSubAcquisitionFilter() sub.SetInput(acq) sub.SetFramesIndex(1,9) ids = [1,3] sub.SetExtractionOption(btk.btkSubAcquisitionFilter.AnalogsOnly, ids) sub.Update() output = sub.GetOutput() self.assertEqual(output.GetFirstFrame(), acq.GetFirstFrame()) self.assertEqual(output.GetPointFrequency(), acq.GetPointFrequency()) self.assertEqual(output.GetPointFrameNumber(), 9) self.assertEqual(output.GetNumberAnalogSamplePerFrame(), acq.GetNumberAnalogSamplePerFrame()) self.assertEqual(output.GetEventNumber(), 0) self.assertEqual(output.GetPointNumber(), 0) self.assertEqual(output.GetAnalogNumber(), 2) # self.assertEqual(output.GetMetaData(), acq.GetMetaData()) self.assertEqual(output.GetAnalog(0).GetLabel(), "uname*2") self.assertEqual(output.GetAnalog(1).GetLabel(), "uname*4") for i in range(0,2): self.assertEqual(output.GetAnalog(i).GetValues()[0], 10.0)
def test_TestOnlyTwoAnalogsSubFrame(self): acq = btk.btkAcquisition() acq.Init(10, 25, 5, 2) acq.AppendEvent(btk.btkEvent("", 12)) acq.SetFirstFrame(10) acq.SetPointFrequency(25.0) for i in range(0, 10): acq.GetPoint(i).SetValue(0, 0, 10.0) for i in range(0, 5): acq.GetAnalog(i).SetValue(2, 10.0) sub = btk.btkSubAcquisitionFilter() sub.SetInput(acq) sub.SetFramesIndex(1, 9) ids = [1, 3] sub.SetExtractionOption(btk.btkSubAcquisitionFilter.AnalogsOnly, ids) sub.Update() output = sub.GetOutput() self.assertEqual(output.GetFirstFrame(), acq.GetFirstFrame()) self.assertEqual(output.GetPointFrequency(), acq.GetPointFrequency()) self.assertEqual(output.GetPointFrameNumber(), 9) self.assertEqual(output.GetNumberAnalogSamplePerFrame(), acq.GetNumberAnalogSamplePerFrame()) self.assertEqual(output.GetEventNumber(), 0) self.assertEqual(output.GetPointNumber(), 0) self.assertEqual(output.GetAnalogNumber(), 2) # self.assertEqual(output.GetMetaData(), acq.GetMetaData()) self.assertEqual(output.GetAnalog(0).GetLabel(), "uname*2") self.assertEqual(output.GetAnalog(1).GetLabel(), "uname*4") for i in range(0, 2): self.assertEqual(output.GetAnalog(i).GetValues()[0], 10.0)
def test_TestOnlyPoints(self): acq = btk.btkAcquisition() acq.Init(10,25,5,2) acq.AppendEvent(btk.btkEvent("", 12)) acq.SetFirstFrame(10) acq.SetPointFrequency(25.0) for i in range(0,10): acq.GetPoint(i).SetValue(0,0,10.0) for i in range(0,5): acq.GetAnalog(i).SetValue(2,10.0) sub = btk.btkSubAcquisitionFilter() sub.SetInput(acq) sub.SetFramesIndex(0,9) sub.SetExtractionOption(btk.btkSubAcquisitionFilter.PointsOnly) sub.Update() output = sub.GetOutput() self.assertEqual(output.GetFirstFrame(), acq.GetFirstFrame()) self.assertEqual(output.GetPointFrequency(), acq.GetPointFrequency()) self.assertEqual(output.GetPointFrameNumber(), 10) self.assertEqual(output.GetNumberAnalogSamplePerFrame(), acq.GetNumberAnalogSamplePerFrame()) self.assertEqual(output.GetEventNumber(), 0) self.assertEqual(output.GetPointNumber(), acq.GetPointNumber()) self.assertEqual(output.GetAnalogNumber(), 0) # self.assertEqual(output.GetMetaData(), acq.GetMetaData()) for i in range(0,10): self.assertEqual(output.GetPoint(i).GetValues()[0,0], 10.0)
def test_insert(self): ec = btk.btkEventCollection() ec.InsertItem( btk.btkEvent('FOO', 1.52, 'Right', btk.btkEvent.Manual, 'Bar', '', 1)) self.assertEqual(ec.GetItemNumber(), 1) e1 = ec.GetItem(0) self.assertEqual(e1.GetLabel(), 'FOO') self.assertEqual(e1.GetTime(), 1.52) self.assertEqual(e1.GetFrame(), -1) self.assertEqual(e1.GetContext(), 'Right') self.assertEqual(e1.GetDetectionFlags(), btk.btkEvent.Manual) self.assertEqual(e1.GetSubject(), 'Bar') self.assertEqual(e1.GetDescription(), '') self.assertEqual(e1.GetId(), 1) e2 = btk.btkEvent('BAR', 2.03, 'Left', btk.btkEvent.Automatic, 'Foo', '', 2) ec.InsertItem(e2) e2_ = ec.GetItem(1) self.assertEqual(e2.GetLabel(), e2_.GetLabel()) self.assertEqual(e2.GetTime(), e2_.GetTime()) self.assertEqual(e2.GetFrame(), e2_.GetFrame()) self.assertEqual(e2.GetContext(), e2_.GetContext()) self.assertEqual(e2.GetDetectionFlags(), e2_.GetDetectionFlags()) self.assertEqual(e2.GetSubject(), e2_.GetSubject()) self.assertEqual(e2.GetDescription(), e2_.GetDescription()) self.assertEqual(e2.GetId(), e2_.GetId()) e2.SetLabel('Unknown') self.assertEqual(e2.GetLabel(), e2_.GetLabel()) self.assertEqual(e2.GetTime(), e2_.GetTime()) self.assertEqual(e2.GetFrame(), e2_.GetFrame()) self.assertEqual(e2.GetContext(), e2_.GetContext()) self.assertEqual(e2.GetDetectionFlags(), e2_.GetDetectionFlags()) self.assertEqual(e2.GetSubject(), e2_.GetSubject()) self.assertEqual(e2.GetDescription(), e2_.GetDescription()) self.assertEqual(e2.GetId(), e2_.GetId()) e2_.SetTime(1.45) self.assertEqual(e2.GetLabel(), e2_.GetLabel()) self.assertEqual(e2.GetTime(), e2_.GetTime()) self.assertEqual(e2.GetFrame(), e2_.GetFrame()) self.assertEqual(e2.GetContext(), e2_.GetContext()) self.assertEqual(e2.GetDetectionFlags(), e2_.GetDetectionFlags()) self.assertEqual(e2.GetSubject(), e2_.GetSubject()) self.assertEqual(e2.GetDescription(), e2_.GetDescription()) self.assertEqual(e2.GetId(), e2_.GetId())
def test_default_ctor(self): e = btk.btkEvent() self.assertEqual(e.GetLabel(), '') self.assertEqual(e.GetTime(), -1.0) self.assertEqual(e.GetFrame(), -1) self.assertEqual(e.GetContext(), '') self.assertEqual(e.GetDetectionFlags(), btk.btkEvent.Unknown) self.assertEqual(e.GetSubject(), '') self.assertEqual(e.GetDescription(), '') self.assertEqual(e.GetId(), 0)
def test_ctor_both(self): e = btk.btkEvent('FOO', 1.52, 144, 'Right', btk.btkEvent.Manual, 'Bar', 'Simple test with both', 1) self.assertEqual(e.GetLabel(), 'FOO') self.assertEqual(e.GetTime(), 1.52) self.assertEqual(e.GetFrame(), 144) self.assertEqual(e.GetContext(), 'Right') self.assertEqual(e.GetDetectionFlags(), btk.btkEvent.Manual) self.assertEqual(e.GetSubject(), 'Bar') self.assertEqual(e.GetDescription(), 'Simple test with both') self.assertEqual(e.GetId(), 1)
def test_insert(self): ec = btk.btkEventCollection() ec.InsertItem(btk.btkEvent('FOO', 1.52, 'Right', btk.btkEvent.Manual, 'Bar', '', 1)) self.assertEqual(ec.GetItemNumber(), 1) e1 = ec.GetItem(0) self.assertEqual(e1.GetLabel(), 'FOO') self.assertEqual(e1.GetTime(), 1.52) self.assertEqual(e1.GetFrame(), -1) self.assertEqual(e1.GetContext(), 'Right') self.assertEqual(e1.GetDetectionFlags(), btk.btkEvent.Manual) self.assertEqual(e1.GetSubject(), 'Bar') self.assertEqual(e1.GetDescription(), '') self.assertEqual(e1.GetId(), 1) e2 = btk.btkEvent('BAR', 2.03, 'Left', btk.btkEvent.Automatic, 'Foo', '', 2) ec.InsertItem(e2) e2_ = ec.GetItem(1); self.assertEqual(e2.GetLabel(), e2_.GetLabel()) self.assertEqual(e2.GetTime(), e2_.GetTime()) self.assertEqual(e2.GetFrame(), e2_.GetFrame()) self.assertEqual(e2.GetContext(), e2_.GetContext()) self.assertEqual(e2.GetDetectionFlags(), e2_.GetDetectionFlags()) self.assertEqual(e2.GetSubject(), e2_.GetSubject()) self.assertEqual(e2.GetDescription(), e2_.GetDescription()) self.assertEqual(e2.GetId(), e2_.GetId()) e2.SetLabel('Unknown') self.assertEqual(e2.GetLabel(), e2_.GetLabel()) self.assertEqual(e2.GetTime(), e2_.GetTime()) self.assertEqual(e2.GetFrame(), e2_.GetFrame()) self.assertEqual(e2.GetContext(), e2_.GetContext()) self.assertEqual(e2.GetDetectionFlags(), e2_.GetDetectionFlags()) self.assertEqual(e2.GetSubject(), e2_.GetSubject()) self.assertEqual(e2.GetDescription(), e2_.GetDescription()) self.assertEqual(e2.GetId(), e2_.GetId()) e2_.SetTime(1.45) self.assertEqual(e2.GetLabel(), e2_.GetLabel()) self.assertEqual(e2.GetTime(), e2_.GetTime()) self.assertEqual(e2.GetFrame(), e2_.GetFrame()) self.assertEqual(e2.GetContext(), e2_.GetContext()) self.assertEqual(e2.GetDetectionFlags(), e2_.GetDetectionFlags()) self.assertEqual(e2.GetSubject(), e2_.GetSubject()) self.assertEqual(e2.GetDescription(), e2_.GetDescription()) self.assertEqual(e2.GetId(), e2_.GetId())
def test_iterator_remove_clear(self): ec = btk.btkEventCollection() ec.SetItemNumber(5) for i in range(0,5): e = btk.btkEvent() e.SetId(i) ec.SetItem(i, e) i = ec.Begin() while i != ec.End(): i = ec.RemoveItem(i) self.assertEqual(ec.GetItemNumber(), 0)
def test_iterator_remove_clear(self): ec = btk.btkEventCollection() ec.SetItemNumber(5) for i in range(0, 5): e = btk.btkEvent() e.SetId(i) ec.SetItem(i, e) i = ec.Begin() while i != ec.End(): i = ec.RemoveItem(i) self.assertEqual(ec.GetItemNumber(), 0)
def test_SetFirstFrame(self): test = btk.btkAcquisition() test.SetPointFrequency(100) test.GetEvents().InsertItem(btk.btkEvent('FOO', 140)) test.SetFirstFrame(100) self.assertEqual(test.GetFirstFrame(), 100) self.assertEqual(test.GetEvent(0).GetFrame(), 140) self.assertEqual(test.GetEvent(0).GetTime(), -1.0) test.SetFirstFrame(200, True) self.assertEqual(test.GetFirstFrame(), 200) self.assertEqual(test.GetEvent(0).GetFrame(), 240) self.assertEqual(test.GetEvent(0).GetTime(), 2.39)
def test_insert_index_middle(self): ec = btk.btkEventCollection() ec.InsertItem( btk.btkEvent('FOO', 1.52, 'Right', btk.btkEvent.Manual, 'Bar', '', 1)) ec.InsertItem( btk.btkEvent('BAR', 2.03, 'Left', btk.btkEvent.Automatic, 'Foo', '', 2)) ec.InsertItem( 1, btk.btkEvent('FOOBAR', 5.05, 'General', btk.btkEvent.Automatic, 'FooBar', '', 3)) self.assertEqual(ec.GetItemNumber(), 3) e = ec.GetItem(1) self.assertEqual(e.GetLabel(), 'FOOBAR') self.assertEqual(e.GetTime(), 5.05) self.assertEqual(e.GetFrame(), -1) self.assertEqual(e.GetContext(), 'General') self.assertEqual(e.GetDetectionFlags(), btk.btkEvent.Automatic) self.assertEqual(e.GetSubject(), 'FooBar') self.assertEqual(e.GetDescription(), '') self.assertEqual(e.GetId(), 3)
def test_modifiers(self): e = btk.btkEvent() e.SetLabel('FOO') e.SetTime(1.52) e.SetFrame(144) e.SetContext('Right') e.SetDetectionFlags(btk.btkEvent.Manual) e.SetSubject('Bar') e.SetDescription('Test for the modifiers') e.SetId(1) self.assertEqual(e.GetLabel(), 'FOO') self.assertEqual(e.GetTime(), 1.52) self.assertEqual(e.GetFrame(), 144) self.assertEqual(e.GetContext(), 'Right') self.assertEqual(e.GetDetectionFlags(), btk.btkEvent.Manual) self.assertEqual(e.GetSubject(), 'Bar') self.assertEqual(e.GetDescription(), 'Test for the modifiers') self.assertEqual(e.GetId(), 1)
def process(filename_in, filename_out, sacr=True, debug=True): filename_in = filename_in.encode() filename_out = filename_out.encode() curves, markers, kin, first_frame = extract_kinematics('L', filename_in, sacr=sacr) events = {} events[("Foot Strike", "Left")] = ml_method(curves, modelHS, first_frame, filename_out) events[("Foot Off", "Left")] = ml_method(curves, modelFO, first_frame, filename_out) if debug: plt.show() reader = btk.btkAcquisitionFileReader() reader.SetFilename(filename_in) reader.Update() acq = reader.GetOutput() acq.ClearEvents() print("First_frame: " + str(first_frame)) for k, v in events.items(): for frame in v: fps = 100.0 event = btk.btkEvent() event.SetLabel(k[0]) event.SetContext(k[1]) event.SetId(2 - (k[0] == "Foot Strike")) event.SetFrame(int(frame)) event.SetTime(frame / fps) acq.AppendEvent(event) writer = btk.btkAcquisitionFileWriter() writer.SetInput(acq) writer.SetFilename(filename_out) writer.Update() return
def process(filename_in, filename_out): idxL = [(i / 3) * 3 + i for i in range(30)] idxR = [3 + (i / 3) * 3 + i for i in range(30)] inputs = extract_kinematics('L', filename_in) inputsL = inputs[:, idxL] inputsR = inputs[:, idxR] XL, YL = convert_data(inputsL) XR, YR = convert_data(inputsR) events = {} events[("Foot Strike", "Left")] = neural_method(XR, modelFO) events[("Foot Strike", "Right")] = neural_method(XL, modelFO) events[("Foot Off", "Left")] = neural_method(XR, modelHS) events[("Foot Off", "Right")] = neural_method(XL, modelHS) reader = btk.btkAcquisitionFileReader() reader.SetFilename(filename_in) reader.Update() acq = reader.GetOutput() first_frame = acq.GetFirstFrame() acq.ClearEvents() print(first_frame) for k, v in events.items(): for frame in v: frame_true = first_frame + frame fps = 120.0 event = btk.btkEvent() event.SetLabel(k[0]) event.SetContext(k[1]) event.SetId(2 - (k[0] == "Foot Strike")) event.SetFrame(np.round(frame_true)) event.SetTime(frame_true / fps) acq.AppendEvent(event) writer = btk.btkAcquisitionFileWriter() writer.SetInput(acq) writer.SetFilename(filename_out) writer.Update() return
def test_iterator(self): ec = btk.btkEventCollection() ec.SetItemNumber(5) for i in range(0, 5): e = btk.btkEvent() e.SetId(i) ec.SetItem(i, e) inc = 0 i = ec.Begin() while i != ec.End(): self.assertEqual(i.value().GetId(), inc) inc = inc + 1 i.incr() inc = 0 i = ec.Begin() while i != ec.End(): i.value().SetId(inc * 10) self.assertEqual(i.value().GetId(), inc * 10) inc = inc + 1 i.incr()
def test_iterator(self): ec = btk.btkEventCollection() ec.SetItemNumber(5) for i in range(0,5): e = btk.btkEvent() e.SetId(i) ec.SetItem(i, e) inc = 0 i = ec.Begin() while i != ec.End(): self.assertEqual(i.value().GetId(), inc) inc = inc + 1 i.incr() inc = 0 i = ec.Begin() while i != ec.End(): i.value().SetId(inc * 10) self.assertEqual(i.value().GetId(), inc * 10) inc = inc + 1 i.incr()
def test_TestAllNoEffect(self): acq = btk.btkAcquisition() acq.Init(10,25,5,2) acq.AppendEvent(btk.btkEvent()) acq.SetFirstFrame(10) acq.SetPointFrequency(25.0) sub = btk.btkSubAcquisitionFilter() sub.SetInput(acq) sub.Update() output = sub.GetOutput() # self.assertEqual(output.GetPoints(), acq.GetPoints()) # self.assertEqual(output.GetAnalogs(), acq.GetAnalogs()) # self.assertEqual(output.GetEvents(), acq.GetEvents()) # self.assertEqual(output.GetMetaData(), acq.GetMetaData()) self.assertEqual(output.GetFirstFrame(), acq.GetFirstFrame()) self.assertEqual(output.GetPointFrequency(), acq.GetPointFrequency()) self.assertEqual(output.GetPointFrameNumber(), acq.GetPointFrameNumber()) self.assertEqual(output.GetPointNumber(), acq.GetPointNumber()) self.assertEqual(output.GetAnalogNumber(), acq.GetAnalogNumber()) self.assertEqual(output.GetEventNumber(), 1) self.assertEqual(output.GetNumberAnalogSamplePerFrame(), acq.GetNumberAnalogSamplePerFrame())
def test_TestAllNoEffect(self): acq = btk.btkAcquisition() acq.Init(10, 25, 5, 2) acq.AppendEvent(btk.btkEvent()) acq.SetFirstFrame(10) acq.SetPointFrequency(25.0) sub = btk.btkSubAcquisitionFilter() sub.SetInput(acq) sub.Update() output = sub.GetOutput() # self.assertEqual(output.GetPoints(), acq.GetPoints()) # self.assertEqual(output.GetAnalogs(), acq.GetAnalogs()) # self.assertEqual(output.GetEvents(), acq.GetEvents()) # self.assertEqual(output.GetMetaData(), acq.GetMetaData()) self.assertEqual(output.GetFirstFrame(), acq.GetFirstFrame()) self.assertEqual(output.GetPointFrequency(), acq.GetPointFrequency()) self.assertEqual(output.GetPointFrameNumber(), acq.GetPointFrameNumber()) self.assertEqual(output.GetPointNumber(), acq.GetPointNumber()) self.assertEqual(output.GetAnalogNumber(), acq.GetAnalogNumber()) self.assertEqual(output.GetEventNumber(), 1) self.assertEqual(output.GetNumberAnalogSamplePerFrame(), acq.GetNumberAnalogSamplePerFrame())
def addEvents(trialC3D): #Read in the C3D file readerC3D = btk.btkAcquisitionFileReader() #Load in experimental c3d trial readerC3D.SetFilename(trialC3D) #Update reader readerC3D.Update() #Get the btk acquisition object acqC3D = readerC3D.GetOutput() if 'UpwardReach' in trialC3D: #Use the horizontal velocity of the hand marker to see where it starts #moving forward and backwards (X-axis) to identify movement segments #Get the X-axis hand marker data xHand = acqC3D.GetPoint('R.HAND').GetValues()[:,0] #Calculate the difference between subsequent marker positions xHandDiff = np.diff(xHand) #Find the first element with a negative value (skipping over the first #few frames to avoid any movements at the beginning). This will indicate #the index where the weight has been picked off the shelf. This also #uses a threshold of 1 to avoid any small movements liftOff1 = np.where(xHandDiff[100:-1] < -1)[0][0] + 100 #The next point where positive data occurs will be the reach to put the #weight back on the shelf putBack1 = np.where(xHandDiff[liftOff1:-1] > 1)[0][0] + liftOff1 #The next negative point after this will be the point where the weight #has been placed back on the shelf liftOff2 = np.where(xHandDiff[putBack1:-1] < -1)[0][0] + putBack1 #Add the events back into the C3D file with relevant labels #Get the start frame to add to the identified row index firstFrame = acqC3D.GetFirstFrame() #Get sampling rate to calculate time fs = acqC3D.GetPointFrequency() #Concentric start point conStart = btk.btkEvent(); conStart.SetFrame(int(putBack1) + firstFrame-1); conStart.SetLabel('conStart') conStart.SetTime((putBack1 + firstFrame-1) * (1/fs)) acqC3D.AppendEvent(conStart) #Concentric end point conEnd = btk.btkEvent(); conEnd.SetFrame(int(liftOff2) + firstFrame-1); conEnd.SetLabel('conEnd') conEnd.SetTime((liftOff2 + firstFrame-1) * (1/fs)) acqC3D.AppendEvent(conEnd) #Eccentric start point eccStart = btk.btkEvent(); eccStart.SetFrame(int(liftOff1) + firstFrame-1); eccStart.SetLabel('eccStart') eccStart.SetTime((liftOff1 + firstFrame-1) * (1/fs)) acqC3D.AppendEvent(eccStart) #Eccentric end point eccEnd = btk.btkEvent(); eccEnd.SetFrame(int(putBack1-1) + firstFrame-1); eccEnd.SetLabel('eccEnd') eccEnd.SetTime((putBack1-1 + firstFrame-1) * (1/fs)) acqC3D.AppendEvent(eccEnd) #Update acquisition object acqC3D.Update() #Re-write C3D file writerC3D = btk.btkAcquisitionFileWriter() writerC3D.SetInput(acqC3D) writerC3D.SetFilename(trialC3D) writerC3D.Update() return('Events added to C3D file')
def compute(FilenameIn, FilenameOut): json_file = open('deepevent/data/DeepEventModel.json', 'r') loaded_model_json = json_file.read() json_file.close() load_model = model_from_json(loaded_model_json) load_model.load_weights("deepevent/data/DeepEventWeight.h5") #Read the FilenameIn.c3d reader = btk.btkAcquisitionFileReader() reader.SetFilename(FilenameIn) reader.Update() acq = reader.GetOutput() md = acq.GetMetaData() SubjectInfo = md.FindChild("SUBJECTS").value().FindChild( "NAMES").value().GetInfo() SubjectValue = SubjectInfo.ToString() markers = ["LANK", "RANK", "LTOE", "RTOE", "LHEE", "RHEE"] nframes = 1536 nb_data_in = 36 #6 markers x 3 # Filter and derivate the input inputs = np.zeros((1, nframes, nb_data_in)) for k in range(6): inputs[0, 0:acq.GetPointFrameNumber(), k * 3:(k + 1) * 3] = filter( acq, acq.GetPoint(markers[k]).GetValues(), 6) inputs[0, 0:acq.GetPointFrameNumber(), 3 * len(markers) + k * 3:3 * len(markers) + (k + 1) * 3] = derive_centre(acq, inputs[0, :, k * 3:(k + 1) * 3]) # Prediction with the model predicted = load_model.predict( inputs ) #shape[1,nb_frames,5] 0: no event, 1: Left Foot Strike, 2: Right Foot Strike, 3:Left Toe Off, 4: Right Toe Off #Threshold to set the gait events predicted_seuil = predicted for j in range(nframes): if predicted[0, j, 1] <= 0.01: predicted_seuil[0, j, 1] = 0 if predicted[0, j, 2] <= 0.01: predicted_seuil[0, j, 2] = 0 if predicted[0, j, 3] <= 0.01: predicted_seuil[0, j, 3] = 0 if predicted[0, j, 4] <= 0.01: predicted_seuil[0, j, 4] = 0 predicted_seuil_max = np.zeros((1, nframes, 5)) for j in range(1, 5): predicted_seuil_max[0, argrelextrema(predicted_seuil[0, :, j], np.greater)[0], j] = 1 for j in range(nframes): if np.sum(predicted_seuil_max[0, j, :]) == 0: predicted_seuil_max[0, j, 0] = 1 eventLFS = np.argwhere(predicted_seuil_max[0, :, 1]) for ind_indice in range(eventLFS.shape[0]): newEvent = btk.btkEvent() newEvent.SetLabel("Foot Strike") newEvent.SetContext("Left") newEvent.SetTime((acq.GetFirstFrame() - 1) / acq.GetPointFrequency() + float(eventLFS[ind_indice] / acq.GetPointFrequency())) newEvent.SetSubject(SubjectValue[0]) newEvent.SetId(1) acq.AppendEvent(newEvent) eventRFS = np.argwhere(predicted_seuil_max[0, :, 2]) for ind_indice in range(eventRFS.shape[0]): newEvent = btk.btkEvent() newEvent.SetLabel("Foot Strike") newEvent.SetContext("Right") newEvent.SetTime((acq.GetFirstFrame() - 1) / acq.GetPointFrequency() + float(eventRFS[ind_indice] / acq.GetPointFrequency())) newEvent.SetSubject(SubjectValue[0]) newEvent.SetId(1) acq.AppendEvent(newEvent) eventLFO = np.argwhere(predicted_seuil_max[0, :, 3]) for ind_indice in range(eventLFO.shape[0]): newEvent = btk.btkEvent() newEvent.SetLabel("Foot Off") newEvent.SetContext("Left") # newEvent.SetTime((acq.GetFirstFrame() - 1) / acq.GetPointFrequency() + float(eventLFO[ind_indice] / acq.GetPointFrequency())) newEvent.SetSubject(SubjectValue[0]) newEvent.SetId(2) acq.AppendEvent(newEvent) eventRFO = np.argwhere(predicted_seuil_max[0, :, 4]) for ind_indice in range(eventRFO.shape[0]): newEvent = btk.btkEvent() newEvent.SetLabel("Foot Off") newEvent.SetContext("Right") # newEvent.SetTime((acq.GetFirstFrame() - 1) / acq.GetPointFrequency() + float(eventRFO[ind_indice] / acq.GetPointFrequency())) newEvent.SetSubject(SubjectValue[0]) newEvent.SetId(2) acq.AppendEvent(newEvent) #Write the FilenameOut.c3d writer = btk.btkAcquisitionFileWriter() writer.SetInput(acq) writer.SetFilename(FilenameOut) writer.Update()