def test_TwoInputsFromScratch(self):
   i1 = btk.btkAcquisition()
   i1.Init(6, 50)
   i2 = btk.btkAcquisition()
   i2.Init(6, 50)
   i2.SetPointFrequency(100)
   merger = btk.btkMergeAcquisitionFilter()
   merger.SetInput(0, i1)
   merger.SetInput(1, i2)
   merger.Update()
   output = merger.GetOutput()
   self.assertEqual(output.GetPointFrequency(), 100)
   self.assertEqual(output.GetAnalogFrequency(), 100)
   self.assertEqual(output.GetPointNumber(), 12)
   self.assertEqual(output.GetAnalogNumber(), 0)
   self.assertEqual(output.GetPointFrameNumber(), 50)
   self.assertEqual(output.GetAnalogFrameNumber(), 50)
   inc = 1
   it = output.BeginPoint()
   while it != output.EndPoint():
     if (inc <= 6):
       self.assertEqual(it.value().GetLabel(), 'uname*' + str(inc))
     else:
       self.assertEqual(it.value().GetLabel(), 'uname*' + str(inc - 6) + '_2')
     inc = inc + 1
     it.incr()
Example #2
0
 def test_TwoInputsFromScratch(self):
     i1 = btk.btkAcquisition()
     i1.Init(6, 50)
     i2 = btk.btkAcquisition()
     i2.Init(6, 50)
     i2.SetPointFrequency(100)
     merger = btk.btkMergeAcquisitionFilter()
     merger.SetInput(0, i1)
     merger.SetInput(1, i2)
     merger.Update()
     output = merger.GetOutput()
     self.assertEqual(output.GetPointFrequency(), 100)
     self.assertEqual(output.GetAnalogFrequency(), 100)
     self.assertEqual(output.GetPointNumber(), 12)
     self.assertEqual(output.GetAnalogNumber(), 0)
     self.assertEqual(output.GetPointFrameNumber(), 50)
     self.assertEqual(output.GetAnalogFrameNumber(), 50)
     inc = 1
     it = output.BeginPoint()
     while it != output.EndPoint():
         if (inc <= 6):
             self.assertEqual(it.value().GetLabel(), 'uname*' + str(inc))
         else:
             self.assertEqual(it.value().GetLabel(),
                              'uname*' + str(inc - 6) + '_2')
         inc = inc + 1
         it.incr()
Example #3
0
 def test_TwoAcquisitions_NoIMU(self):
     imuse = btk.btkIMUsExtractor()
     imuse.SetInput(0, btk.btkAcquisition())
     imuse.SetInput(1, btk.btkAcquisition())
     output = imuse.GetOutput()
     output.Update()
     self.assertEqual(output.GetItemNumber(), 0)
 def test_TwoAcquisitions_NoIMU(self):
   imuse = btk.btkIMUsExtractor()
   imuse.SetInput(0,btk.btkAcquisition())
   imuse.SetInput(1,btk.btkAcquisition())
   output = imuse.GetOutput()
   output.Update()
   self.assertEqual(output.GetItemNumber(), 0)
Example #5
0
 def test_Test4Over3(self):
     acq = btk.btkAcquisition()
     acq.Init(0, 25, 3, 1)
     data = numpy.empty([25, 1])
     data.fill(5.0)
     acq.GetAnalog(0).SetValues(data)
     data.fill(4.0)
     acq.GetAnalog(1).SetValues(data)
     data.fill(3.0)
     acq.GetAnalog(2).SetValues(data)
     acq2 = btk.btkAcquisition()
     acq2.Init(0, 25, 4, 1)
     data.fill(1.0)
     acq2.GetAnalog(0).SetValues(data)
     data.fill(2.0)
     acq2.GetAnalog(1).SetValues(data)
     data.fill(3.0)
     acq2.GetAnalog(2).SetValues(data)
     data.fill(4.0)
     acq2.GetAnalog(3).SetValues(data)
     remover = btk.btkAnalogOffsetRemover()
     remover.SetRawInput(acq)
     remover.SetOffsetInput(acq2)
     remover.Update()
     output = remover.GetOutput()
     self.assertEqual(output.GetAnalogNumber(), 3)
     self.assertEqual(output.GetAnalog(0).GetValues().sum() / 25.0, 4.0)
     self.assertEqual(output.GetAnalog(1).GetValues().sum() / 25.0, 2.0)
     self.assertEqual(output.GetAnalog(2).GetValues().sum() / 25.0, 0.0)
 def test_Test4Over3(self):
   acq = btk.btkAcquisition()
   acq.Init(0,25,3,1)
   data = numpy.empty([25,1]);
   data.fill(5.0)
   acq.GetAnalog(0).SetValues(data)
   data.fill(4.0)
   acq.GetAnalog(1).SetValues(data)
   data.fill(3.0)
   acq.GetAnalog(2).SetValues(data)
   acq2 = btk.btkAcquisition()
   acq2.Init(0,25,4,1)
   data.fill(1.0)
   acq2.GetAnalog(0).SetValues(data)
   data.fill(2.0)
   acq2.GetAnalog(1).SetValues(data)
   data.fill(3.0)
   acq2.GetAnalog(2).SetValues(data)
   data.fill(4.0)
   acq2.GetAnalog(3).SetValues(data)
   remover = btk.btkAnalogOffsetRemover()
   remover.SetRawInput(acq)
   remover.SetOffsetInput(acq2)
   remover.Update()
   output = remover.GetOutput()
   self.assertEqual(output.GetAnalogNumber(), 3)
   self.assertEqual(output.GetAnalog(0).GetValues().sum() / 25.0, 4.0)
   self.assertEqual(output.GetAnalog(1).GetValues().sum() / 25.0, 2.0)
   self.assertEqual(output.GetAnalog(2).GetValues().sum() / 25.0, 0.0)
 def test_TwoAcquisitions(self):
   # Acquisition #1
   acq1 = btk.btkAcquisition()
   acq1.Init(0,200,6)
   imu = btk.btkMetaDataCreateChild(acq1.GetMetaData(), 'IMU')
   btk.btkMetaDataCreateChild(imu, 'USED', 1)
   btk.btkMetaDataCreateChild(imu, 'DESCRIPTIONS', btk.btkStringArray(1,'BAR'))
   btk.btkMetaDataCreateChild(imu, 'TYPE', btk.btkIntArray(1,1))
   channels = btk.btkIntArray(6); channels[0] = 1; channels[1] = 2; channels[2] = 3; channels[3] = 4; channels[4] = 5; channels[5] = 6
   btk.btkMetaDataCreateChild(imu, 'CHANNEL', channels, 6)
   # Acquisition #2 (two sensors)
   acq2 = btk.btkAcquisition()
   acq2.Init(0,200,15)
   imu = btk.btkMetaDataCreateChild(acq2.GetMetaData(), 'IMU')
   btk.btkMetaDataCreateChild(imu, 'USED', 2)
   btk.btkMetaDataCreateChild(imu, 'LABELS', btk.btkStringArray(2,'Foo'))
   btk.btkMetaDataCreateChild(imu, 'TYPE', btk.btkIntArray(2,1))
   channels.resize(18) 
   channels[0] = 1; channels[1] = 2; channels[2] = 3; channels[3] = 4; channels[4] = 5; channels[5] = 6; channels[6] = -1; channels[7] = -1; channels[8] = -1
   channels[9] = 7; channels[10] = 8; channels[11] = 9; channels[12] = 10; channels[13] = 11; channels[14] = 12; channels[15] = 13; channels[16] = 14; channels[17] = 15
   btk.btkMetaDataCreateChild(imu, 'CHANNEL', channels, 9)
   extra = btk.btkIntArray(2); extra[0] = 0; extra[1] = 3;
   btk.btkMetaDataCreateChild(imu, 'EXTRA', extra)
   imuse = btk.btkIMUsExtractor()
   imuse.SetInput(0, acq1)
   imuse.SetInput(1, acq2)
   output = imuse.GetOutput()
   output.Update()
   self.assertEqual(output.GetItemNumber(), 3)
   self.assertEqual(output.GetItem(0).GetLabel(), 'IMU #1')
   self.assertEqual(output.GetItem(0).GetDescription(), 'BAR')
   self.assertEqual(output.GetItem(0).GetAccelerometerX().GetLabel(), acq1.GetAnalog(0).GetLabel())
   self.assertEqual(output.GetItem(0).GetAccelerometerY().GetLabel(), acq1.GetAnalog(1).GetLabel())
   self.assertEqual(output.GetItem(0).GetAccelerometerZ().GetLabel(), acq1.GetAnalog(2).GetLabel())
   self.assertEqual(output.GetItem(0).GetGyroscopeX().GetLabel(), acq1.GetAnalog(3).GetLabel())
   self.assertEqual(output.GetItem(0).GetGyroscopeY().GetLabel(), acq1.GetAnalog(4).GetLabel())
   self.assertEqual(output.GetItem(0).GetGyroscopeZ().GetLabel(), acq1.GetAnalog(5).GetLabel())
   self.assertEqual(output.GetItem(1).GetLabel(), 'Foo')
   self.assertEqual(output.GetItem(1).GetDescription(), '')
   self.assertEqual(output.GetItem(1).GetAccelerometerX().GetLabel(), acq2.GetAnalog(0).GetLabel())
   self.assertEqual(output.GetItem(1).GetAccelerometerY().GetLabel(), acq2.GetAnalog(1).GetLabel())
   self.assertEqual(output.GetItem(1).GetAccelerometerZ().GetLabel(), acq2.GetAnalog(2).GetLabel())
   self.assertEqual(output.GetItem(1).GetGyroscopeX().GetLabel(), acq2.GetAnalog(3).GetLabel())
   self.assertEqual(output.GetItem(1).GetGyroscopeY().GetLabel(), acq2.GetAnalog(4).GetLabel())
   self.assertEqual(output.GetItem(1).GetGyroscopeZ().GetLabel(), acq2.GetAnalog(5).GetLabel())
   self.assertEqual(output.GetItem(2).GetLabel(), 'Foo')
   self.assertEqual(output.GetItem(2).GetDescription(), '')
   self.assertEqual(output.GetItem(2).GetAccelerometerX().GetLabel(), acq2.GetAnalog(6).GetLabel())
   self.assertEqual(output.GetItem(2).GetAccelerometerY().GetLabel(), acq2.GetAnalog(7).GetLabel())
   self.assertEqual(output.GetItem(2).GetAccelerometerZ().GetLabel(), acq2.GetAnalog(8).GetLabel())
   self.assertEqual(output.GetItem(2).GetGyroscopeX().GetLabel(), acq2.GetAnalog(9).GetLabel())
   self.assertEqual(output.GetItem(2).GetGyroscopeY().GetLabel(), acq2.GetAnalog(10).GetLabel())
   self.assertEqual(output.GetItem(2).GetGyroscopeZ().GetLabel(), acq2.GetAnalog(11).GetLabel())
   self.assertEqual(output.GetItem(2).GetChannel(6).GetLabel(), acq2.GetAnalog(12).GetLabel())
   self.assertEqual(output.GetItem(2).GetChannel(7).GetLabel(), acq2.GetAnalog(13).GetLabel())
   self.assertEqual(output.GetItem(2).GetChannel(8).GetLabel(), acq2.GetAnalog(14).GetLabel())
Example #8
0
 def test_InitPointAndAnalog(self):
     test = btk.btkAcquisition()
     test.Init(5, 200, 10, 1)
     self.assertEqual(test.GetPointNumber(), 5)
     self.assertEqual(test.GetAnalogNumber(), 10)
     self.assertEqual(test.GetPointFrameNumber(), 200)
     self.assertEqual(test.GetAnalogFrameNumber(), 200)
Example #9
0
def create_record_object():
    """Returns a data aquisition object consisting of the marker positions of one frame"""
    acq = btk.btkAcquisition()
    btk.btkAcquisition.Reset(acq)
    btk.btkAcquisition.Init(acq, len(m.get_frame_markers()), 1)

    return acq
Example #10
0
 def test_OneAcquisition_MissingChannels(self):
     acq = btk.btkAcquisition()
     acq.Init(0, 200, 6)
     imu = btk.btkMetaDataCreateChild(acq.GetMetaData(), 'IMU')
     btk.btkMetaDataCreateChild(imu, 'USED', 1)
     btk.btkMetaDataCreateChild(imu, 'TYPE', btk.btkIntArray(1, 1))
     channels = btk.btkIntArray(6)
     channels[0] = 6
     channels[1] = 5
     channels[2] = -1
     channels[3] = -1
     channels[4] = 2
     channels[5] = 1
     btk.btkMetaDataCreateChild(imu, 'CHANNEL', channels, 6)
     imuse = btk.btkIMUsExtractor()
     imuse.SetInput(acq)
     output = imuse.GetOutput()
     output.Update()
     self.assertEqual(output.GetItemNumber(), 1)
     self.assertEqual(output.GetItem(0).GetLabel(), 'IMU #1')
     self.assertEqual(output.GetItem(0).GetDescription(), '')
     self.assertEqual(
         output.GetItem(0).GetAccelerometerX().GetLabel(),
         acq.GetAnalog(5).GetLabel())
     self.assertEqual(
         output.GetItem(0).GetAccelerometerY().GetLabel(),
         acq.GetAnalog(4).GetLabel())
     # self.assertTrue(output.GetItem(0).GetAccelerometerZ()._get() == 0)
     # self.assertTrue(output.GetItem(0).GetGyroscopeX()._get() == 0)
     self.assertEqual(
         output.GetItem(0).GetGyroscopeY().GetLabel(),
         acq.GetAnalog(1).GetLabel())
     self.assertEqual(
         output.GetItem(0).GetGyroscopeZ().GetLabel(),
         acq.GetAnalog(0).GetLabel())
 def test_RemoveLastPoint(self):
     test = btk.btkAcquisition()
     test.Init(10, 5)
     self.assertEqual(test.GetFirstFrame(), 1)
     self.assertEqual(test.GetPointNumber(), 10)
     self.assertEqual(test.GetPointFrameNumber(), 5)
     test.RemovePoint("uname*10")
     self.assertEqual(test.GetPointNumber(), 9)
     test.RemovePoint("uname*9")
     self.assertEqual(test.GetPointNumber(), 8)
     test.RemovePoint("uname*8")
     self.assertEqual(test.GetPointNumber(), 7)
     test.RemovePoint("uname*7")
     self.assertEqual(test.GetPointNumber(), 6)
     test.RemovePoint("uname*6")
     self.assertEqual(test.GetPointNumber(), 5)
     test.RemovePoint("uname*5")
     self.assertEqual(test.GetPointNumber(), 4)
     test.RemovePoint("uname*4")
     self.assertEqual(test.GetPointNumber(), 3)
     test.RemovePoint("uname*3")
     self.assertEqual(test.GetPointNumber(), 2)
     test.RemovePoint("uname*2")
     self.assertEqual(test.GetPointNumber(), 1)
     test.RemovePoint("uname*1")
     self.assertEqual(test.GetPointNumber(), 0)
 def test_InitAnalogOnly(self):
     test = btk.btkAcquisition()
     test.Init(0, 200, 10)
     self.assertEqual(test.GetPointNumber(), 0)
     self.assertEqual(test.GetAnalogNumber(), 10)
     self.assertEqual(test.GetPointFrameNumber(), 200)
     self.assertEqual(test.GetAnalogFrameNumber(), 200)
 def test_InitPointAndAnalog(self):
     test = btk.btkAcquisition()
     test.Init(5, 200, 10, 1)
     self.assertEqual(test.GetPointNumber(), 5)
     self.assertEqual(test.GetAnalogNumber(), 10)
     self.assertEqual(test.GetPointFrameNumber(), 200)
     self.assertEqual(test.GetAnalogFrameNumber(), 200)
 def test_Constructor(self):
     test = btk.btkAcquisition()
     self.assertEqual(test.GetPointFrameNumber(), 0)
     self.assertEqual(test.GetAnalogFrameNumber(), 0)
     self.assertEqual(test.GetPointNumber(), 0)
     self.assertEqual(test.GetAnalogNumber(), 0)
     self.assertEqual(test.GetMetaData().GetLabel(), "ROOT")
 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_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)
Example #18
0
 def test_InitAnalogOnly(self):
     test = btk.btkAcquisition()
     test.Init(0, 200, 10)
     self.assertEqual(test.GetPointNumber(), 0)
     self.assertEqual(test.GetAnalogNumber(), 10)
     self.assertEqual(test.GetPointFrameNumber(), 200)
     self.assertEqual(test.GetAnalogFrameNumber(), 200)
Example #19
0
 def test_Constructor(self):
     test = btk.btkAcquisition()
     self.assertEqual(test.GetPointFrameNumber(), 0)
     self.assertEqual(test.GetAnalogFrameNumber(), 0)
     self.assertEqual(test.GetPointNumber(), 0)
     self.assertEqual(test.GetAnalogNumber(), 0)
     self.assertEqual(test.GetMetaData().GetLabel(), "ROOT")
Example #20
0
def create_record_object():
    """Returns a data aquisition object consisting of the marker positions of one frame"""
    acq=btk.btkAcquisition()
    btk.btkAcquisition.Reset(acq)
    btk.btkAcquisition.Init(acq,len(m.get_frame_markers()),1)

    return acq
Example #21
0
 def test_RemoveLastPoint(self):
     test = btk.btkAcquisition()
     test.Init(10, 5)
     self.assertEqual(test.GetFirstFrame(), 1)
     self.assertEqual(test.GetPointNumber(), 10)
     self.assertEqual(test.GetPointFrameNumber(), 5)
     test.RemovePoint("uname*10")
     self.assertEqual(test.GetPointNumber(), 9)
     test.RemovePoint("uname*9")
     self.assertEqual(test.GetPointNumber(), 8)
     test.RemovePoint("uname*8")
     self.assertEqual(test.GetPointNumber(), 7)
     test.RemovePoint("uname*7")
     self.assertEqual(test.GetPointNumber(), 6)
     test.RemovePoint("uname*6")
     self.assertEqual(test.GetPointNumber(), 5)
     test.RemovePoint("uname*5")
     self.assertEqual(test.GetPointNumber(), 4)
     test.RemovePoint("uname*4")
     self.assertEqual(test.GetPointNumber(), 3)
     test.RemovePoint("uname*3")
     self.assertEqual(test.GetPointNumber(), 2)
     test.RemovePoint("uname*2")
     self.assertEqual(test.GetPointNumber(), 1)
     test.RemovePoint("uname*1")
     self.assertEqual(test.GetPointNumber(), 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_SetDurationAndFrequency(self):
     test = btk.btkAcquisition()
     test.Init(1, 150, 1, 1)
     test.SetPointFrequency(100)
     self.assertEqual(test.GetPointFrequency(), 100)
     self.assertEqual(test.GetAnalogFrequency(), 100)
     self.assertEqual(test.GetPointFrameNumber(), 150)
     self.assertEqual(test.GetAnalogFrameNumber(), 150)
Example #24
0
 def test_SetDurationAndFrequency(self):
     test = btk.btkAcquisition()
     test.Init(1, 150, 1, 1)
     test.SetPointFrequency(100)
     self.assertEqual(test.GetPointFrequency(), 100)
     self.assertEqual(test.GetAnalogFrequency(), 100)
     self.assertEqual(test.GetPointFrameNumber(), 150)
     self.assertEqual(test.GetAnalogFrameNumber(), 150)
Example #25
0
 def test_TwoInputsFromScratch_FirstFrame2(self):
     i1 = btk.btkAcquisition()
     i1.Init(6, 50)
     i1.SetFirstFrame(25)
     i2 = btk.btkAcquisition()
     i2.Init(6, 50)
     i2.SetPointFrequency(100)
     merger = btk.btkMergeAcquisitionFilter()
     merger.SetInput(0, i1)
     merger.SetInput(1, i2)
     merger.Update()
     output = merger.GetOutput()
     self.assertEqual(output.GetPointFrequency(), 100)
     self.assertEqual(output.GetAnalogFrequency(), 100)
     self.assertEqual(output.GetFirstFrame(), 1)
     self.assertEqual(output.GetPointNumber(), 12)
     self.assertEqual(output.GetAnalogNumber(), 0)
     self.assertEqual(output.GetPointFrameNumber(), 74)
     self.assertEqual(output.GetAnalogFrameNumber(), 74)
 def test_TwoInputsFromScratch_FirstFrame2(self):
   i1 = btk.btkAcquisition()
   i1.Init(6, 50)
   i1.SetFirstFrame(25)
   i2 = btk.btkAcquisition()
   i2.Init(6, 50)
   i2.SetPointFrequency(100)
   merger = btk.btkMergeAcquisitionFilter()
   merger.SetInput(0, i1)
   merger.SetInput(1, i2)
   merger.Update()
   output = merger.GetOutput()
   self.assertEqual(output.GetPointFrequency(), 100)
   self.assertEqual(output.GetAnalogFrequency(), 100)
   self.assertEqual(output.GetFirstFrame(), 1)
   self.assertEqual(output.GetPointNumber(), 12)
   self.assertEqual(output.GetAnalogNumber(), 0)
   self.assertEqual(output.GetPointFrameNumber(), 74)
   self.assertEqual(output.GetAnalogFrameNumber(), 74)
Example #27
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_SetNumber(self):
     test = btk.btkAcquisition()
     test.Init(12, 150, 7, 1)
     test.SetPointFrequency(100)
     self.assertEqual(test.GetPointNumber(), 12)
     self.assertEqual(test.GetAnalogNumber(), 7)
     self.assertEqual(test.GetPointFrameNumber(), 150)
     self.assertEqual(test.GetAnalogFrameNumber(), 150)
     ptPoint = test.GetPoint(0)
     self.assertEqual(ptPoint.GetFrameNumber(), 150)
     ptAnalog = test.GetAnalog(0)
     self.assertEqual(ptAnalog.GetFrameNumber(), 150)
Example #29
0
 def test_SetNumber(self):
     test = btk.btkAcquisition()
     test.Init(12, 150, 7, 1)
     test.SetPointFrequency(100)
     self.assertEqual(test.GetPointNumber(), 12)
     self.assertEqual(test.GetAnalogNumber(), 7)
     self.assertEqual(test.GetPointFrameNumber(), 150)
     self.assertEqual(test.GetAnalogFrameNumber(), 150)
     ptPoint = test.GetPoint(0)
     self.assertEqual(ptPoint.GetFrameNumber(), 150)
     ptAnalog = test.GetAnalog(0)
     self.assertEqual(ptAnalog.GetFrameNumber(), 150)
 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)
Example #31
0
 def test_Test0(self):
     acq = btk.btkAcquisition()
     acq.Init(0, 25, 1, 1)
     data = numpy.empty([25, 1])
     data.fill(5.0)
     acq.GetAnalog(0).SetValues(data)
     remover = btk.btkAnalogOffsetRemover()
     remover.SetRawInput(acq)
     remover.SetOffsetInput(acq)
     remover.Update()
     output = remover.GetOutput()
     self.assertEqual(output.GetAnalogNumber(), 1)
     self.assertEqual(output.GetAnalog(0).GetValues().sum(), 0.0)
 def test_Test0(self):
   acq = btk.btkAcquisition()
   acq.Init(0,25,1,1)
   data = numpy.empty([25,1]);
   data.fill(5.0)
   acq.GetAnalog(0).SetValues(data)
   remover = btk.btkAnalogOffsetRemover()
   remover.SetRawInput(acq)
   remover.SetOffsetInput(acq)
   remover.Update()
   output = remover.GetOutput()
   self.assertEqual(output.GetAnalogNumber(), 1)
   self.assertEqual(output.GetAnalog(0).GetValues().sum(), 0.0)
 def test_ResizeFromEnd(self):
     test = btk.btkAcquisition()
     test.Init(2, 200, 10, 2)
     self.assertEqual(test.GetFirstFrame(), 1)
     self.assertEqual(test.GetPointNumber(), 2)
     self.assertEqual(test.GetAnalogNumber(), 10)
     self.assertEqual(test.GetPointFrameNumber(), 200)
     self.assertEqual(test.GetAnalogFrameNumber(), 400)
     test.ResizeFrameNumberFromEnd(50)
     self.assertEqual(test.GetFirstFrame(), 151)
     self.assertEqual(test.GetPointNumber(), 2)
     self.assertEqual(test.GetAnalogNumber(), 10)
     self.assertEqual(test.GetPointFrameNumber(), 50)
     self.assertEqual(test.GetAnalogFrameNumber(), 100)
Example #34
0
 def test_ResizeFromEnd(self):
     test = btk.btkAcquisition()
     test.Init(2, 200, 10, 2)
     self.assertEqual(test.GetFirstFrame(), 1)
     self.assertEqual(test.GetPointNumber(), 2)
     self.assertEqual(test.GetAnalogNumber(), 10)
     self.assertEqual(test.GetPointFrameNumber(), 200)
     self.assertEqual(test.GetAnalogFrameNumber(), 400)
     test.ResizeFrameNumberFromEnd(50)
     self.assertEqual(test.GetFirstFrame(), 151)
     self.assertEqual(test.GetPointNumber(), 2)
     self.assertEqual(test.GetAnalogNumber(), 10)
     self.assertEqual(test.GetPointFrameNumber(), 50)
     self.assertEqual(test.GetAnalogFrameNumber(), 100)
Example #35
0
    def test_ConversionForAnalog(self):
        input = btk.btkAcquisition()
        input.Init(0, 5, 2)
        a1 = input.GetAnalog(0)
        a1.SetUnit('Nmm')
        a = a1.GetValues()
        a[0, 0] = 1234.56
        a[1, 0] = 34.65
        a[2, 0] = 98.08
        a[3, 0] = 987.12
        a[4, 0] = 654.12
        a1.SetValues(a)
        a2 = input.GetAnalog(1)
        b = a2.GetValues()
        b[0, 0] = 1.56
        b[1, 0] = 1.65
        b[2, 0] = 1.54
        b[3, 0] = 0.98712
        b[4, 0] = 1.8964
        a2.SetValues(b)

        uc = btk.btkAcquisitionUnitConverter()
        uc.SetInput(input)
        uc.SetUnit(btk.btkAcquisitionUnitConverter.Length, 'm')
        uc.SetUnit(btk.btkAcquisitionUnitConverter.Moment, 'Nm')
        uc.Update()
        output = uc.GetOutput()
        self.assertEqual(output.GetPointUnit(btk.btkPoint.Marker), 'm')
        self.assertEqual(output.GetPointUnit(btk.btkPoint.Angle), 'deg')
        self.assertEqual(output.GetPointUnit(btk.btkPoint.Force), 'N')
        self.assertEqual(output.GetPointUnit(btk.btkPoint.Moment), 'Nm')
        self.assertEqual(output.GetPointUnit(btk.btkPoint.Power), 'W')

        a1 = output.GetAnalog(0)
        a = a1.GetValues()
        a2 = output.GetAnalog(1)
        b = a2.GetValues()

        self.assertAlmostEqual(a[0], 1.23456, 10)
        self.assertAlmostEqual(a[1], 0.03465, 10)
        self.assertAlmostEqual(a[2], 0.09808, 10)
        self.assertAlmostEqual(a[3], 0.98712, 10)
        self.assertAlmostEqual(a[4], 0.65412, 10)

        self.assertAlmostEqual(b[0], 1.5600, 10)
        self.assertAlmostEqual(b[1], 1.6500, 10)
        self.assertAlmostEqual(b[2], 1.5400, 10)
        self.assertAlmostEqual(b[3], 0.98712, 10)
        self.assertAlmostEqual(b[4], 1.8964, 10)
Example #36
0
    def test_ConversionToMeter(self):
        input = btk.btkAcquisition()
        input.Init(2, 5)
        p1 = input.GetPoint(0)
        a = p1.GetValues()
        a[0, 0] = 1234.56
        a[1, 0] = 34.65
        a[2, 0] = 98.08
        a[3, 0] = 987.12
        a[4, 0] = 654.12
        p1.SetValues(a)
        p2 = input.GetPoint(1)
        p2.SetType(btk.btkPoint.Moment)
        b = p2.GetValues()
        b[0, 0] = 1234.56
        b[1, 0] = 1134.65
        b[2, 0] = 1000.54
        b[3, 0] = 987.12
        b[4, 0] = 1435.896
        p2.SetValues(b)

        uc = btk.btkAcquisitionUnitConverter()
        uc.SetInput(input)
        uc.SetUnit(btk.btkAcquisitionUnitConverter.Length, 'm')
        uc.SetUnit(btk.btkAcquisitionUnitConverter.Moment, 'Nm')
        uc.Update()
        output = uc.GetOutput()
        self.assertEqual(output.GetPointUnit(btk.btkPoint.Marker), 'm')
        self.assertEqual(output.GetPointUnit(btk.btkPoint.Angle), 'deg')
        self.assertEqual(output.GetPointUnit(btk.btkPoint.Force), 'N')
        self.assertEqual(output.GetPointUnit(btk.btkPoint.Moment), 'Nm')
        self.assertEqual(output.GetPointUnit(btk.btkPoint.Power), 'W')

        p1 = output.GetPoint(0)
        a = p1.GetValues()
        p2 = output.GetPoint(1)
        b = p2.GetValues()

        self.assertAlmostEqual(a[0, 0], 1.23456, 10)
        self.assertAlmostEqual(a[1, 0], 0.03465, 10)
        self.assertAlmostEqual(a[2, 0], 0.09808, 10)
        self.assertAlmostEqual(a[3, 0], 0.98712, 10)
        self.assertAlmostEqual(a[4, 0], 0.65412, 10)

        self.assertAlmostEqual(b[0, 0], 1.23456, 10)
        self.assertAlmostEqual(b[1, 0], 1.13465, 10)
        self.assertAlmostEqual(b[2, 0], 1.00054, 10)
        self.assertAlmostEqual(b[3, 0], 0.98712, 10)
        self.assertAlmostEqual(b[4, 0], 1.435896, 10)
Example #37
0
 def test_TestNoCommonLabel(self):
     acq = btk.btkAcquisition()
     acq.Init(0, 25, 3, 1)
     acq.GetAnalog(0).SetLabel("FOO")
     acq.GetAnalog(1).SetLabel("BAR")
     acq.GetAnalog(2).SetLabel("FOOBAR")
     acq2 = btk.btkAcquisition()
     acq2.Init(0, 25, 3, 1)
     data = numpy.empty([25, 1])
     data.fill(1.0)
     acq2.GetAnalog(0).SetValues(data)
     data.fill(2.0)
     acq2.GetAnalog(1).SetValues(data)
     data.fill(3.0)
     acq2.GetAnalog(2).SetValues(data)
     remover = btk.btkAnalogOffsetRemover()
     remover.SetRawInput(acq)
     remover.SetOffsetInput(acq2)
     remover.Update()
     output = remover.GetOutput()
     self.assertEqual(output.GetAnalogNumber(), 3)
     self.assertEqual(output.GetAnalog(0).GetValues().sum(), 0.0)
     self.assertEqual(output.GetAnalog(1).GetValues().sum(), 0.0)
     self.assertEqual(output.GetAnalog(2).GetValues().sum(), 0.0)
 def test_TestNoCommonLabel(self):
   acq = btk.btkAcquisition()
   acq.Init(0,25,3,1)
   acq.GetAnalog(0).SetLabel("FOO")
   acq.GetAnalog(1).SetLabel("BAR")
   acq.GetAnalog(2).SetLabel("FOOBAR")
   acq2 = btk.btkAcquisition()
   acq2.Init(0,25,3,1)
   data = numpy.empty([25,1]);
   data.fill(1.0)
   acq2.GetAnalog(0).SetValues(data)
   data.fill(2.0)
   acq2.GetAnalog(1).SetValues(data)
   data.fill(3.0)
   acq2.GetAnalog(2).SetValues(data)
   remover = btk.btkAnalogOffsetRemover()
   remover.SetRawInput(acq)
   remover.SetOffsetInput(acq2)
   remover.Update()
   output = remover.GetOutput()
   self.assertEqual(output.GetAnalogNumber(), 3)
   self.assertEqual(output.GetAnalog(0).GetValues().sum(), 0.0)
   self.assertEqual(output.GetAnalog(1).GetValues().sum(), 0.0)
   self.assertEqual(output.GetAnalog(2).GetValues().sum(), 0.0)
Example #39
0
 def test_OneInput(self):
     test = btk.btkAcquisition()
     test.Init(6, 50, 2, 2)
     test.SetPointFrequency(100)
     merger = btk.btkMergeAcquisitionFilter()
     merger.SetInput(0, test)
     merger.Update()
     output = merger.GetOutput()
     self.assertEqual(output.GetPointFrequency(), 100)
     self.assertEqual(output.GetAnalogFrequency(), 200)
     self.assertEqual(output.GetPointNumber(), 6)
     self.assertEqual(output.GetAnalogNumber(), 2)
     self.assertEqual(output.GetPointFrameNumber(), 50)
     self.assertEqual(output.GetAnalogFrameNumber(), 100)
     ptPoint = output.GetPoint(0)
     self.assertEqual(ptPoint.GetFrameNumber(), 50)
     ptAnalog = output.GetAnalog(0)
     self.assertEqual(ptAnalog.GetFrameNumber(), 100)
 def test_OneInput(self):
   test = btk.btkAcquisition()
   test.Init(6, 50, 2, 2)
   test.SetPointFrequency(100)
   merger = btk.btkMergeAcquisitionFilter()
   merger.SetInput(0, test)
   merger.Update()
   output = merger.GetOutput()
   self.assertEqual(output.GetPointFrequency(), 100)
   self.assertEqual(output.GetAnalogFrequency(), 200)
   self.assertEqual(output.GetPointNumber(), 6)
   self.assertEqual(output.GetAnalogNumber(), 2)
   self.assertEqual(output.GetPointFrameNumber(), 50)
   self.assertEqual(output.GetAnalogFrameNumber(), 100)
   ptPoint = output.GetPoint(0)
   self.assertEqual(ptPoint.GetFrameNumber(), 50)
   ptAnalog = output.GetAnalog(0)
   self.assertEqual(ptAnalog.GetFrameNumber(), 100)
Example #41
0
 def test_OneAcquisition(self):
     acq = btk.btkAcquisition()
     acq.Init(0, 200, 6)
     imu = btk.btkMetaDataCreateChild(acq.GetMetaData(), 'IMU')
     btk.btkMetaDataCreateChild(imu, 'USED', 1)
     btk.btkMetaDataCreateChild(imu, 'LABELS', btk.btkStringArray(1, 'Foo'))
     btk.btkMetaDataCreateChild(imu, 'DESCRIPTIONS',
                                btk.btkStringArray(1, 'BAR'))
     btk.btkMetaDataCreateChild(imu, 'TYPE', btk.btkIntArray(1, 1))
     channels = btk.btkIntArray(6)
     channels[0] = 1
     channels[1] = 2
     channels[2] = 3
     channels[3] = 4
     channels[4] = 5
     channels[5] = 6
     btk.btkMetaDataCreateChild(imu, 'CHANNEL', channels, 6)
     imuse = btk.btkIMUsExtractor()
     imuse.SetInput(acq)
     output = imuse.GetOutput()
     output.Update()
     self.assertEqual(output.GetItemNumber(), 1)
     self.assertEqual(output.GetItem(0).GetLabel(), 'Foo')
     self.assertEqual(output.GetItem(0).GetDescription(), 'BAR')
     self.assertEqual(
         output.GetItem(0).GetAccelerometerX().GetLabel(),
         acq.GetAnalog(0).GetLabel())
     self.assertEqual(
         output.GetItem(0).GetAccelerometerY().GetLabel(),
         acq.GetAnalog(1).GetLabel())
     self.assertEqual(
         output.GetItem(0).GetAccelerometerZ().GetLabel(),
         acq.GetAnalog(2).GetLabel())
     self.assertEqual(
         output.GetItem(0).GetGyroscopeX().GetLabel(),
         acq.GetAnalog(3).GetLabel())
     self.assertEqual(
         output.GetItem(0).GetGyroscopeY().GetLabel(),
         acq.GetAnalog(4).GetLabel())
     self.assertEqual(
         output.GetItem(0).GetGyroscopeZ().GetLabel(),
         acq.GetAnalog(5).GetLabel())
    def test_ConversionForAnalog(self):
        input = btk.btkAcquisition()
        input.Init(0,5,2)
        a1 = input.GetAnalog(0)
        a1.SetUnit('Nmm')
        a = a1.GetValues()
        a[0,0] = 1234.56; a[1,0] = 34.65; a[2,0] = 98.08; a[3,0] = 987.12; a[4,0] = 654.12
        a1.SetValues(a)
        a2 = input.GetAnalog(1)
        b = a2.GetValues()
        b[0,0] = 1.56; b[1,0] = 1.65; b[2,0] = 1.54; b[3,0] = 0.98712; b[4,0] = 1.8964;
        a2.SetValues(b)

        uc = btk.btkAcquisitionUnitConverter()
        uc.SetInput(input)
        uc.SetUnit(btk.btkAcquisitionUnitConverter.Length, 'm')
        uc.SetUnit(btk.btkAcquisitionUnitConverter.Moment, 'Nm')
        uc.Update()
        output = uc.GetOutput()
        self.assertEqual(output.GetPointUnit(btk.btkPoint.Marker), 'm')
        self.assertEqual(output.GetPointUnit(btk.btkPoint.Angle), 'deg')
        self.assertEqual(output.GetPointUnit(btk.btkPoint.Force), 'N')
        self.assertEqual(output.GetPointUnit(btk.btkPoint.Moment), 'Nm')
        self.assertEqual(output.GetPointUnit(btk.btkPoint.Power), 'W')

        a1 = output.GetAnalog(0)
        a = a1.GetValues()
        a2 = output.GetAnalog(1)
        b = a2.GetValues()

        self.assertAlmostEqual(a[0], 1.23456, 10)
        self.assertAlmostEqual(a[1], 0.03465, 10)
        self.assertAlmostEqual(a[2], 0.09808, 10)
        self.assertAlmostEqual(a[3], 0.98712, 10)
        self.assertAlmostEqual(a[4], 0.65412, 10)

        self.assertAlmostEqual(b[0], 1.5600, 10)
        self.assertAlmostEqual(b[1], 1.6500, 10)
        self.assertAlmostEqual(b[2], 1.5400, 10)
        self.assertAlmostEqual(b[3], 0.98712, 10)
        self.assertAlmostEqual(b[4], 1.8964, 10)
    def test_ConversionToMeter(self):
        input = btk.btkAcquisition()
        input.Init(2,5)
        p1 = input.GetPoint(0)
        a = p1.GetValues()
        a[0,0] = 1234.56; a[1,0] = 34.65; a[2,0] = 98.08; a[3,0] = 987.12; a[4,0] = 654.12
        p1.SetValues(a)
        p2 = input.GetPoint(1)
        p2.SetType(btk.btkPoint.Moment)
        b = p2.GetValues()
        b[0,0] = 1234.56; b[1,0] = 1134.65; b[2,0] = 1000.54; b[3,0] = 987.12; b[4,0] = 1435.896
        p2.SetValues(b)
        
        uc = btk.btkAcquisitionUnitConverter()
        uc.SetInput(input)
        uc.SetUnit(btk.btkAcquisitionUnitConverter.Length, 'm')
        uc.SetUnit(btk.btkAcquisitionUnitConverter.Moment, 'Nm')
        uc.Update()
        output = uc.GetOutput()
        self.assertEqual(output.GetPointUnit(btk.btkPoint.Marker), 'm')
        self.assertEqual(output.GetPointUnit(btk.btkPoint.Angle), 'deg')
        self.assertEqual(output.GetPointUnit(btk.btkPoint.Force), 'N')
        self.assertEqual(output.GetPointUnit(btk.btkPoint.Moment), 'Nm')
        self.assertEqual(output.GetPointUnit(btk.btkPoint.Power), 'W')

        p1 = output.GetPoint(0)
        a = p1.GetValues()
        p2 = output.GetPoint(1)
        b = p2.GetValues()

        self.assertAlmostEqual(a[0,0], 1.23456, 10); 
        self.assertAlmostEqual(a[1,0], 0.03465, 10); 
        self.assertAlmostEqual(a[2,0], 0.09808, 10); 
        self.assertAlmostEqual(a[3,0], 0.98712, 10); 
        self.assertAlmostEqual(a[4,0], 0.65412, 10)

        self.assertAlmostEqual(b[0,0], 1.23456, 10)
        self.assertAlmostEqual(b[1,0], 1.13465, 10)
        self.assertAlmostEqual(b[2,0], 1.00054, 10)
        self.assertAlmostEqual(b[3,0], 0.98712, 10)
        self.assertAlmostEqual(b[4,0], 1.435896, 10)
 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_OneAcquisition_MissingChannels(self):
   acq = btk.btkAcquisition()
   acq.Init(0,200,6)
   imu = btk.btkMetaDataCreateChild(acq.GetMetaData(), 'IMU')
   btk.btkMetaDataCreateChild(imu, 'USED', 1)
   btk.btkMetaDataCreateChild(imu, 'TYPE', btk.btkIntArray(1,1))
   channels = btk.btkIntArray(6); channels[0] = 6; channels[1] = 5; channels[2] = -1; channels[3] = -1; channels[4] = 2; channels[5] = 1
   btk.btkMetaDataCreateChild(imu, 'CHANNEL', channels, 6)
   imuse = btk.btkIMUsExtractor()
   imuse.SetInput(acq)
   output = imuse.GetOutput()
   output.Update()
   self.assertEqual(output.GetItemNumber(), 1)
   self.assertEqual(output.GetItem(0).GetLabel(), 'IMU #1')
   self.assertEqual(output.GetItem(0).GetDescription(), '')
   self.assertEqual(output.GetItem(0).GetAccelerometerX().GetLabel(), acq.GetAnalog(5).GetLabel())
   self.assertEqual(output.GetItem(0).GetAccelerometerY().GetLabel(), acq.GetAnalog(4).GetLabel())
   # self.assertTrue(output.GetItem(0).GetAccelerometerZ()._get() == 0)
   # self.assertTrue(output.GetItem(0).GetGyroscopeX()._get() == 0)
   self.assertEqual(output.GetItem(0).GetGyroscopeY().GetLabel(), acq.GetAnalog(1).GetLabel())
   self.assertEqual(output.GetItem(0).GetGyroscopeZ().GetLabel(), acq.GetAnalog(0).GetLabel())
Example #46
0
    def convert(self, bvh, output_file):
        acq = btk.btkAcquisition()
        acq.Init(0, bvh.frame_count)
        acq.SetPointFrequency(1 / bvh.frame_time)

        self.points_dict = {}
        marker_count = 0
        for key in bvh.channel_dict.keys():
            point = btk.btkPoint('Marker_' + key, bvh.frame_count)
            point.SetLabel('Marker_' + key)
            self.points_dict[key] = point
            marker_count += 1

        self.calculate_joint_position(bvh)
        for key in self.points_dict.keys():
            acq.AppendPoint(self.points_dict[key])

        writer = btk.btkAcquisitionFileWriter()
        writer.SetInput(acq)
        writer.SetFilename(output_file)
        writer.Update()
 def test_OneAcquisition(self):
   acq = btk.btkAcquisition()
   acq.Init(0,200,6)
   imu = btk.btkMetaDataCreateChild(acq.GetMetaData(), 'IMU')
   btk.btkMetaDataCreateChild(imu, 'USED', 1)
   btk.btkMetaDataCreateChild(imu, 'LABELS', btk.btkStringArray(1,'Foo'))
   btk.btkMetaDataCreateChild(imu, 'DESCRIPTIONS', btk.btkStringArray(1,'BAR'))
   btk.btkMetaDataCreateChild(imu, 'TYPE', btk.btkIntArray(1,1))
   channels = btk.btkIntArray(6); channels[0] = 1; channels[1] = 2; channels[2] = 3; channels[3] = 4; channels[4] = 5; channels[5] = 6
   btk.btkMetaDataCreateChild(imu, 'CHANNEL', channels, 6)
   imuse = btk.btkIMUsExtractor()
   imuse.SetInput(acq)
   output = imuse.GetOutput()
   output.Update()
   self.assertEqual(output.GetItemNumber(), 1)
   self.assertEqual(output.GetItem(0).GetLabel(), 'Foo')
   self.assertEqual(output.GetItem(0).GetDescription(), 'BAR')
   self.assertEqual(output.GetItem(0).GetAccelerometerX().GetLabel(), acq.GetAnalog(0).GetLabel())
   self.assertEqual(output.GetItem(0).GetAccelerometerY().GetLabel(), acq.GetAnalog(1).GetLabel())
   self.assertEqual(output.GetItem(0).GetAccelerometerZ().GetLabel(), acq.GetAnalog(2).GetLabel())
   self.assertEqual(output.GetItem(0).GetGyroscopeX().GetLabel(), acq.GetAnalog(3).GetLabel())
   self.assertEqual(output.GetItem(0).GetGyroscopeY().GetLabel(), acq.GetAnalog(4).GetLabel())
   self.assertEqual(output.GetItem(0).GetGyroscopeZ().GetLabel(), acq.GetAnalog(5).GetLabel())
 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())
Example #49
0
 def test_SetAnalogFrequencyOnly(self):
     test = btk.btkAcquisition()
     test.Init(0, 200, 1, 1)
     self.assertEqual(test.GetPointFrameNumber(), 200)
     self.assertEqual(test.GetAnalogFrameNumber(), 200)
 def test_SetAnalogFrequencyOnly(self):
     test = btk.btkAcquisition()
     test.Init(0, 200, 1, 1)
     self.assertEqual(test.GetPointFrameNumber(), 200)
     self.assertEqual(test.GetAnalogFrameNumber(), 200)
Example #51
0
 def test_TwoAcquisitions(self):
     # Acquisition #1
     acq1 = btk.btkAcquisition()
     acq1.Init(0, 200, 6)
     imu = btk.btkMetaDataCreateChild(acq1.GetMetaData(), 'IMU')
     btk.btkMetaDataCreateChild(imu, 'USED', 1)
     btk.btkMetaDataCreateChild(imu, 'DESCRIPTIONS',
                                btk.btkStringArray(1, 'BAR'))
     btk.btkMetaDataCreateChild(imu, 'TYPE', btk.btkIntArray(1, 1))
     channels = btk.btkIntArray(6)
     channels[0] = 1
     channels[1] = 2
     channels[2] = 3
     channels[3] = 4
     channels[4] = 5
     channels[5] = 6
     btk.btkMetaDataCreateChild(imu, 'CHANNEL', channels, 6)
     # Acquisition #2 (two sensors)
     acq2 = btk.btkAcquisition()
     acq2.Init(0, 200, 15)
     imu = btk.btkMetaDataCreateChild(acq2.GetMetaData(), 'IMU')
     btk.btkMetaDataCreateChild(imu, 'USED', 2)
     btk.btkMetaDataCreateChild(imu, 'LABELS', btk.btkStringArray(2, 'Foo'))
     btk.btkMetaDataCreateChild(imu, 'TYPE', btk.btkIntArray(2, 1))
     channels.resize(18)
     channels[0] = 1
     channels[1] = 2
     channels[2] = 3
     channels[3] = 4
     channels[4] = 5
     channels[5] = 6
     channels[6] = -1
     channels[7] = -1
     channels[8] = -1
     channels[9] = 7
     channels[10] = 8
     channels[11] = 9
     channels[12] = 10
     channels[13] = 11
     channels[14] = 12
     channels[15] = 13
     channels[16] = 14
     channels[17] = 15
     btk.btkMetaDataCreateChild(imu, 'CHANNEL', channels, 9)
     extra = btk.btkIntArray(2)
     extra[0] = 0
     extra[1] = 3
     btk.btkMetaDataCreateChild(imu, 'EXTRA', extra)
     imuse = btk.btkIMUsExtractor()
     imuse.SetInput(0, acq1)
     imuse.SetInput(1, acq2)
     output = imuse.GetOutput()
     output.Update()
     self.assertEqual(output.GetItemNumber(), 3)
     self.assertEqual(output.GetItem(0).GetLabel(), 'IMU #1')
     self.assertEqual(output.GetItem(0).GetDescription(), 'BAR')
     self.assertEqual(
         output.GetItem(0).GetAccelerometerX().GetLabel(),
         acq1.GetAnalog(0).GetLabel())
     self.assertEqual(
         output.GetItem(0).GetAccelerometerY().GetLabel(),
         acq1.GetAnalog(1).GetLabel())
     self.assertEqual(
         output.GetItem(0).GetAccelerometerZ().GetLabel(),
         acq1.GetAnalog(2).GetLabel())
     self.assertEqual(
         output.GetItem(0).GetGyroscopeX().GetLabel(),
         acq1.GetAnalog(3).GetLabel())
     self.assertEqual(
         output.GetItem(0).GetGyroscopeY().GetLabel(),
         acq1.GetAnalog(4).GetLabel())
     self.assertEqual(
         output.GetItem(0).GetGyroscopeZ().GetLabel(),
         acq1.GetAnalog(5).GetLabel())
     self.assertEqual(output.GetItem(1).GetLabel(), 'Foo')
     self.assertEqual(output.GetItem(1).GetDescription(), '')
     self.assertEqual(
         output.GetItem(1).GetAccelerometerX().GetLabel(),
         acq2.GetAnalog(0).GetLabel())
     self.assertEqual(
         output.GetItem(1).GetAccelerometerY().GetLabel(),
         acq2.GetAnalog(1).GetLabel())
     self.assertEqual(
         output.GetItem(1).GetAccelerometerZ().GetLabel(),
         acq2.GetAnalog(2).GetLabel())
     self.assertEqual(
         output.GetItem(1).GetGyroscopeX().GetLabel(),
         acq2.GetAnalog(3).GetLabel())
     self.assertEqual(
         output.GetItem(1).GetGyroscopeY().GetLabel(),
         acq2.GetAnalog(4).GetLabel())
     self.assertEqual(
         output.GetItem(1).GetGyroscopeZ().GetLabel(),
         acq2.GetAnalog(5).GetLabel())
     self.assertEqual(output.GetItem(2).GetLabel(), 'Foo')
     self.assertEqual(output.GetItem(2).GetDescription(), '')
     self.assertEqual(
         output.GetItem(2).GetAccelerometerX().GetLabel(),
         acq2.GetAnalog(6).GetLabel())
     self.assertEqual(
         output.GetItem(2).GetAccelerometerY().GetLabel(),
         acq2.GetAnalog(7).GetLabel())
     self.assertEqual(
         output.GetItem(2).GetAccelerometerZ().GetLabel(),
         acq2.GetAnalog(8).GetLabel())
     self.assertEqual(
         output.GetItem(2).GetGyroscopeX().GetLabel(),
         acq2.GetAnalog(9).GetLabel())
     self.assertEqual(
         output.GetItem(2).GetGyroscopeY().GetLabel(),
         acq2.GetAnalog(10).GetLabel())
     self.assertEqual(
         output.GetItem(2).GetGyroscopeZ().GetLabel(),
         acq2.GetAnalog(11).GetLabel())
     self.assertEqual(
         output.GetItem(2).GetChannel(6).GetLabel(),
         acq2.GetAnalog(12).GetLabel())
     self.assertEqual(
         output.GetItem(2).GetChannel(7).GetLabel(),
         acq2.GetAnalog(13).GetLabel())
     self.assertEqual(
         output.GetItem(2).GetChannel(8).GetLabel(),
         acq2.GetAnalog(14).GetLabel())
Example #52
0
            index[9] = index[9] + 1
        if "RFootProgressAnglesY" in line:
            temp = line.split('=')
            temp = temp[1].split('\n')
            value = temp[0].split(',')
            RFootProgressAngles[:, index[9]] = value
            index[9] = index[9] + 1
        if "RFootProgressAnglesZ" in line:
            temp = line.split('=')
            temp = temp[1].split('\n')
            value = temp[0].split(',')
            RFootProgressAngles[:, index[9]] = value
            index[9] = index[9] + 1

if NbLeftFiles < 1 and NbRightFiles < 1:
    newAcq = btk.btkAcquisition()
    newAcq.Init(0, 101, 0, 1)
    newAcq.SetPointFrequency(100)
    for num in range(int(sys.argv[1])):
        label = "LPelvisAngles" + str(num + 1)
        newpoint = btk.btkPoint(label, newAcq.GetPointFrameNumber())
        newpoint.SetValues(LPelvisAngles[:, range(num * 3, num * 3 + 2 + 1)])
        newpoint.SetType(btk.btkPoint.Angle)
        newAcq.AppendPoint(newpoint)

        label = "LHipAngles" + str(num + 1)
        newpoint = btk.btkPoint(label, newAcq.GetPointFrameNumber())
        newpoint.SetValues(LHipAngles[:, range(num * 3, num * 3 + 2 + 1)])
        newpoint.SetType(btk.btkPoint.Angle)
        newAcq.AppendPoint(newpoint)
Example #53
0
def writeC3D(fileName, data, copyFromFile=None):
    """Write to C3D file.

    Parameters
    ----------
    fileName : str
        Full path of the C3D file.

    data : dict
        Data dictionary that can contain the following keys:

        - markers: this is marker-related data. This dictionary contains:
            - data: dictionary where each key is a point label, and each
              value is a N x 3 np.ndarray of 3D coordinates (in *mm*), where N is
              the number of time frames. This field is always necessary.
            - framesNumber: number of data points per marker.
              This field is necessary when creating files from scratch.
            - unit: string indicating the markers measurement unit. Available
              strings are 'mm' and 'm'.
              This field is necessary when creating files from scratch.
            - freq: number indicating the markers acquisition frequency.
              This field is necessary when creating files from scratch.

    copyFromFile : str
        If None, it creates a new file from scratch.
        If str indicating the path of an existing C3D file, it adds/owerwrite data copied from that file.

    """

    if copyFromFile is not None:
        # Open C3D pointer
        reader = btk.btkAcquisitionFileReader()
        reader.SetFilename(copyFromFile)
        reader.Update()
        acq = reader.GetOutput()
        if 'markers' in data:
            nMarkerFrames = acq.GetPointFrameNumber()
            pointUnit = acq.GetPointUnit()
    else:
        # Create new acquisition
        acq = btk.btkAcquisition()
        if 'markers' in data:
            nMarkerFrames = data['markers']['framesNumber']
            acq.Init(0, nMarkerFrames)
            pointUnit = data['markers']['unit']
            acq.SetPointUnit(pointUnit)
            pointFreq = data['markers']['freq']
            acq.SetPointFrequency(pointFreq)

    if 'markers' in data:
        # Write marker data
        markers = data['markers']['data']
        for m in markers:
            newMarker = btk.btkPoint(m, nMarkerFrames)
            if pointUnit == 'm':
                markerData = markers[m] / 1000.
            elif pointUnit == 'mm':
                markerData = markers[m].copy()
            newMarker.SetValues(markerData)
            acq.AppendPoint(newMarker)

    # Write to C3D
    writer = btk.btkAcquisitionFileWriter()
    writer.SetInput(acq)
    writer.SetFilename(fileName)
    writer.Update()
Example #54
0
def writeC3D(fileName, data, copyFromFile=None):
    """Write to C3D file.
    
    Parameters
    ----------
    fileName : str
        Full path of the C3D file.
        
    data : dict
        Data dictionary that can contain the following keys: 
        
        - markers: this is marker-related data. This dictionary contains:
            - data: dictionary where each key is a point label, and each
              value is a N x 3 np.ndarray of 3D coordinates (in *mm*), where N is
              the number of time frames. This field is always necessary.
            - framesNumber: number of data points per marker.
              This field is necessary when creating files from scratch.
            - unit: string indicating the markers measurement unit. Available
              strings are 'mm' and 'm'.
              This field is necessary when creating files from scratch.
            - freq: number indicating the markers acquisition frequency.
              This field is necessary when creating files from scratch.
    
    copyFromFile : str
        If None, it creates a new file from scratch.
        If str indicating the path of an existing C3D file, it adds/owerwrite data copied from that file.
        
    """
    
    if copyFromFile is not None:
        # Open C3D pointer
        reader = btk.btkAcquisitionFileReader()
        reader.SetFilename(copyFromFile)
        reader.Update() 
        acq = reader.GetOutput()
        if 'markers' in data:
            nMarkerFrames = acq.GetPointFrameNumber()
            pointUnit = acq.GetPointUnit()
    else:
        # Create new acquisition
        acq = btk.btkAcquisition()
        if 'markers' in data:
            nMarkerFrames = data['markers']['framesNumber']
            acq.Init(0, nMarkerFrames)
            pointUnit = data['markers']['unit']
            acq.SetPointUnit(pointUnit)
            pointFreq = data['markers']['freq']
            acq.SetPointFrequency(pointFreq)
    
    if 'markers' in data:
        # Write marker data
        markers = data['markers']['data']
        for m in markers:
            newMarker = btk.btkPoint(m, nMarkerFrames)
            if pointUnit == 'm':    
                markerData = markers[m] / 1000.
            elif pointUnit == 'mm':
                markerData = markers[m].copy()
            newMarker.SetValues(markerData)
            acq.AppendPoint(newMarker)
        
    # Write to C3D
    writer = btk.btkAcquisitionFileWriter()
    writer.SetInput(acq)
    writer.SetFilename(fileName)
    writer.Update()