Example #1
0
 def test_DataTable(self):
     table = osim.DataTable()
     # Set column labels.
     table.setColumnLabels(['0', '1', '2', '3'])
     assert table.getColumnLabels() == ('0', '1', '2', '3')
     assert table.hasColumn('0')
     assert table.hasColumn('2')
     table.setColumnLabel(0, 'zero')
     table.setColumnLabel(2, 'two')
     assert table.getColumnLabel(0) == 'zero'
     assert table.getColumnLabel(2) == 'two'
     assert table.getColumnIndex('zero') == 0
     assert table.getColumnIndex('two') == 2
     # Append a row to the table.
     row = osim.RowVector([1, 2, 3, 4])
     table.appendRow(0.1, row)
     assert table.getNumRows() == 1
     assert table.getNumColumns() == 4
     row0 = table.getRowAtIndex(0)
     assert (row0[0] == row[0] and row0[1] == row[1] and row0[2] == row[2]
             and row0[3] == row[3])
     # Append another row to the table.
     row[0] *= 2
     row[1] *= 2
     row[2] *= 2
     row[3] *= 2
     table.appendRow(0.2, row)
     assert table.getNumRows() == 2
     assert table.getNumColumns() == 4
     row1 = table.getRow(0.2)
     assert (row1[0] == row[0] and row1[1] == row[1] and row1[2] == row[2]
             and row1[3] == row[3])
     # Append another row to the table.
     row[0] *= 2
     row[1] *= 2
     row[2] *= 2
     row[3] *= 2
     table.appendRow(0.3, row)
     assert table.getNumRows() == 3
     assert table.getNumColumns() == 4
     row2 = table.getRow(0.3)
     assert (row2[0] == row[0] and row2[1] == row[1] and row2[2] == row[2]
             and row2[3] == row[3])
     # Retrieve independent column.
     assert table.getIndependentColumn() == (0.1, 0.2, 0.3)
     # Retrieve dependent columns.
     col1 = table.getDependentColumnAtIndex(1)
     assert (col1[0] == 2 and col1[1] == 4 and col1[2] == 8)
     col3 = table.getDependentColumn('3')
     assert (col3[0] == 4 and col3[1] == 8 and col3[2] == 16)
     assert table.hasColumn(0)
     assert table.hasColumn(2)
Example #2
0
 def test_clone(self):
     # Make sure the clone() method works (we have to implement this in a
     # SWIG interface file).
     dt = osim.DataTable()
     c = dt.clone()
     assert c
     dt = osim.DataTableVec3()
     c = dt.clone()
     assert c
     dt = osim.DataTableUnitVec3()
     c = dt.clone()
     assert c
     dt = osim.DataTableQuaternion()
     c = dt.clone()
     assert c
     dt = osim.DataTableVec6()
     c = dt.clone()
     assert c
     dt = osim.DataTableSpatialVec()
     c = dt.clone()
     assert c
Example #3
0
 def test_DataTable(self):
     print
     table = osim.DataTable()
     # Set column labels.
     table.setColumnLabels(['0', '1', '2', '3'])
     assert table.getColumnLabels() == ('0', '1', '2', '3')
     assert table.hasColumn('0')
     assert table.hasColumn('2')
     assert not table.hasColumn('not-found')
     table.setColumnLabel(0, 'zero')
     table.setColumnLabel(2, 'two')
     assert table.getColumnLabel(0) == 'zero'
     assert table.getColumnLabel(2) == 'two'
     assert table.getColumnIndex('zero') == 0
     assert table.getColumnIndex('two') == 2
     # Append a row to the table.
     row = osim.RowVector([1, 2, 3, 4])
     table.appendRow(0.1, row)
     assert table.getNumRows() == 1
     assert table.getNumColumns() == 4
     row0 = table.getRowAtIndex(0)
     assert (row0[0] == row[0] and row0[1] == row[1] and row0[2] == row[2]
             and row0[3] == row[3])
     print table
     # Append another row to the table.
     row[0] *= 2
     row[1] *= 2
     row[2] *= 2
     row[3] *= 2
     table.appendRow(0.2, row)
     assert table.getNumRows() == 2
     assert table.getNumColumns() == 4
     row1 = table.getRow(0.2)
     assert (row1[0] == row[0] and row1[1] == row[1] and row1[2] == row[2]
             and row1[3] == row[3])
     print table
     # Append another row to the table.
     row[0] *= 2
     row[1] *= 2
     row[2] *= 2
     row[3] *= 2
     table.appendRow(0.3, row)
     assert table.getNumRows() == 3
     assert table.getNumColumns() == 4
     row2 = table.getRow(0.3)
     assert (row2[0] == row[0] and row2[1] == row[1] and row2[2] == row[2]
             and row2[3] == row[3])
     print table
     # Retrieve independent column.
     assert table.getIndependentColumn() == (0.1, 0.2, 0.3)
     # Retrieve dependent columns.
     col1 = table.getDependentColumnAtIndex(1)
     assert (col1[0] == 2 and col1[1] == 4 and col1[2] == 8)
     col3 = table.getDependentColumn('3')
     assert (col3[0] == 4 and col3[1] == 8 and col3[2] == 16)
     assert table.hasColumn(0)
     assert table.hasColumn(2)
     # Edit rows of the table.
     row0 = table.getRowAtIndex(0)
     row0[0] = 10
     row0[1] = 10
     row0[2] = 10
     row0[3] = 10
     row0 = table.getRowAtIndex(0)
     assert (row0[0] == 10 and row0[1] == 10 and row0[2] == 10
             and row0[3] == 10)
     row2 = table.getRow(0.3)
     row2[0] = 20
     row2[1] = 20
     row2[2] = 20
     row2[3] = 20
     row2 = table.getRow(0.3)
     assert (row2[0] == 20 and row2[1] == 20 and row2[2] == 20
             and row2[3] == 20)
     print table
     # Edit columns of the table.
     col1 = table.getDependentColumnAtIndex(1)
     col1[0] = 30
     col1[1] = 30
     col1[2] = 30
     col1 = table.getDependentColumnAtIndex(1)
     assert (col1[0] == 30 and col1[1] == 30 and col1[2] == 30)
     col3 = table.getDependentColumn('3')
     col3[0] = 40
     col3[1] = 40
     col3[2] = 40
     col3 = table.getDependentColumn('3')
     assert (col3[0] == 40 and col3[1] == 40 and col3[2] == 40)
     print table
     # Add table metadata.
     table.addTableMetaDataString('subject-name', 'Python')
     table.addTableMetaDataString('subject-yob', '1991')
     assert table.getTableMetaDataString('subject-name') == 'Python'
     assert table.getTableMetaDataString('subject-yob') == '1991'
     print table
     # Access eleemnt with index out of bounds. Exception expected.
     try:
         shouldThrow = row0[5]
         assert false
     except RuntimeError:
         pass
     try:
         shouldThrow = col1[5]
         assert false
     except RuntimeError:
         pass
     # Access row with index out of bounds. Exception expected.
     try:
         shouldThrow = table.getRowAtIndex(5)
         assert false
     except RuntimeError:
         pass
     # Access row with timestamp that does not exist. Exception expected.
     try:
         shouldThrow = table.getRow(5.5)
         assert false
     except RuntimeError:
         pass
     # Access column with index out of bounds. Exception expected.
     try:
         shouldThrow = table.getDependentColumnAtIndex(5)
         assert false
     except RuntimeError:
         pass
     # Access column with label that does not exist. Exception expected.
     try:
         shouldThrow = table.getDependentColumn('not-found')
         assert false
     except RuntimeError:
         pass
     # Test pack-ing of columns of DataTable.
     table = osim.DataTable()
     table.setColumnLabels(
         ('col0_x', 'col0_y', 'col0_z', 'col1_x', 'col1_y', 'col1_z',
          'col2_x', 'col2_y', 'col2_z', 'col3_x', 'col3_y', 'col3_z'))
     row = osim.RowVector([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
     table.appendRow(1, row)
     row = osim.RowVector([2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2])
     table.appendRow(2, row)
     row = osim.RowVector([3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3])
     table.appendRow(3, row)
     assert len(table.getColumnLabels()) == 12
     assert table.getNumRows() == 3
     assert table.getNumColumns() == 12
     print table
     tableVec3 = table.packVec3(('_x', '_y', '_z'))
     tableVec3.getColumnLabels() == ('col0', 'col1', 'col2', 'col3')
     tableVec3.getNumRows() == 3
     tableVec3.getNumColumns() == 4
     print tableVec3
     tableFlat = tableVec3.flatten()
     assert len(tableFlat.getColumnLabels()) == 12
     assert tableFlat.getColumnLabel(0) == 'col0_1'
     assert tableFlat.getColumnLabel(11) == 'col3_3'
     assert tableFlat.getNumRows() == 3
     assert tableFlat.getNumColumns() == 12
     print tableFlat
     tableVec3 = table.packVec3()
     tableVec3.getColumnLabels() == ('col0', 'col1', 'col2', 'col3')
     tableVec3.getNumRows() == 3
     tableVec3.getNumColumns() == 4
     print tableVec3
     tableFlat = tableVec3.flatten()
     assert len(tableFlat.getColumnLabels()) == 12
     assert tableFlat.getColumnLabel(0) == 'col0_1'
     assert tableFlat.getColumnLabel(11) == 'col3_3'
     assert tableFlat.getNumRows() == 3
     assert tableFlat.getNumColumns() == 12
     print tableFlat
     tableUnitVec3 = table.packUnitVec3()
     tableUnitVec3.getColumnLabels() == ('col0', 'col1', 'col2', 'col3')
     tableUnitVec3.getNumRows() == 3
     tableUnitVec3.getNumColumns() == 4
     print tableUnitVec3
     tableFlat = tableUnitVec3.flatten()
     assert len(tableFlat.getColumnLabels()) == 12
     assert tableFlat.getColumnLabel(0) == 'col0_1'
     assert tableFlat.getColumnLabel(11) == 'col3_3'
     assert tableFlat.getNumRows() == 3
     assert tableFlat.getNumColumns() == 12
     print tableFlat
     table.setColumnLabels(
         ('col0.0', 'col0.1', 'col0.2', 'col0.3', 'col1.0', 'col1.1',
          'col1.2', 'col1.3', 'col2.0', 'col2.1', 'col2.2', 'col2.3'))
     tableQuat = table.packQuaternion()
     tableQuat.getColumnLabels() == ('col0', 'col1', 'col2')
     tableQuat.getNumRows() == 3
     tableQuat.getNumColumns() == 3
     print tableQuat
     tableFlat = tableQuat.flatten()
     assert len(tableFlat.getColumnLabels()) == 12
     assert tableFlat.getColumnLabel(0) == 'col0_1'
     assert tableFlat.getColumnLabel(11) == 'col2_4'
     assert tableFlat.getNumRows() == 3
     assert tableFlat.getNumColumns() == 12
     print tableFlat
     table.setColumnLabels(
         ('col0_0', 'col0_1', 'col0_2', 'col0_3', 'col0_4', 'col0_5',
          'col1_0', 'col1_1', 'col1_2', 'col1_3', 'col1_4', 'col1_5'))
     tableSVec = table.packSpatialVec()
     tableSVec.getColumnLabels() == ('col0', 'col1')
     tableSVec.getNumRows() == 3
     tableSVec.getNumColumns() == 2
     print tableSVec
     tableFlat = tableSVec.flatten()
     assert len(tableFlat.getColumnLabels()) == 12
     assert tableFlat.getColumnLabel(0) == 'col0_1'
     assert tableFlat.getColumnLabel(11) == 'col1_6'
     assert tableFlat.getNumRows() == 3
     assert tableFlat.getNumColumns() == 12
     print tableFlat
Example #4
0
 def test_DataTable(self):
     print
     table = osim.DataTable()
     # Set column labels.
     table.setColumnLabels(['0', '1', '2', '3'])
     assert table.getColumnLabels() == ('0', '1', '2', '3')
     assert table.hasColumn('0')
     assert table.hasColumn('2')
     assert not table.hasColumn('not-found')
     table.setColumnLabel(0, 'zero')
     table.setColumnLabel(2, 'two')
     assert table.getColumnLabel(0) == 'zero'
     assert table.getColumnLabel(2) == 'two'
     assert table.getColumnIndex('zero') == 0
     assert table.getColumnIndex('two')  == 2
     # Append a row to the table.
     row = osim.RowVector([1, 2, 3, 4])
     table.appendRow(0.1, row)
     assert table.getNumRows() == 1
     assert table.getNumColumns() == 4
     row0 = table.getRowAtIndex(0)
     assert (row0[0] == row[0] and
             row0[1] == row[1] and
             row0[2] == row[2] and
             row0[3] == row[3])
     print table
     # Append another row to the table.
     row[0] *= 2
     row[1] *= 2
     row[2] *= 2
     row[3] *= 2
     table.appendRow(0.2, row)
     assert table.getNumRows() == 2
     assert table.getNumColumns() == 4
     row1 = table.getRow(0.2)
     assert (row1[0] == row[0] and
             row1[1] == row[1] and
             row1[2] == row[2] and
             row1[3] == row[3])
     print table
     # Append another row to the table.
     row[0] *= 2
     row[1] *= 2
     row[2] *= 2
     row[3] *= 2
     table.appendRow(0.3, row)
     assert table.getNumRows() == 3
     assert table.getNumColumns() == 4
     row2 = table.getRow(0.3)
     assert (row2[0] == row[0] and
             row2[1] == row[1] and
             row2[2] == row[2] and
             row2[3] == row[3])
     print table
     # Retrieve independent column.
     assert table.getIndependentColumn() == (0.1, 0.2, 0.3)
     # Retrieve dependent columns.
     col1 = table.getDependentColumnAtIndex(1)
     assert (col1[0] == 2 and
             col1[1] == 4 and
             col1[2] == 8)
     col3 = table.getDependentColumn('3')
     assert (col3[0] == 4 and
             col3[1] == 8 and
             col3[2] == 16)
     assert table.hasColumn(0)
     assert table.hasColumn(2)
     # Edit rows of the table.
     row0 = table.getRowAtIndex(0)
     row0[0] = 10
     row0[1] = 10
     row0[2] = 10
     row0[3] = 10
     row0 = table.getRowAtIndex(0)
     assert (row0[0] == 10 and
             row0[1] == 10 and
             row0[2] == 10 and
             row0[3] == 10)
     row2 = table.getRow(0.3)
     row2[0] = 20
     row2[1] = 20
     row2[2] = 20
     row2[3] = 20
     row2 = table.getRow(0.3)
     assert (row2[0] == 20 and
             row2[1] == 20 and
             row2[2] == 20 and
             row2[3] == 20)
     print table
     # Edit columns of the table.
     col1 = table.getDependentColumnAtIndex(1)
     col1[0] = 30
     col1[1] = 30
     col1[2] = 30
     col1 = table.getDependentColumnAtIndex(1)
     assert (col1[0] == 30 and
             col1[1] == 30 and
             col1[2] == 30)
     col3 = table.getDependentColumn('3')
     col3[0] = 40
     col3[1] = 40
     col3[2] = 40
     col3 = table.getDependentColumn('3')
     assert (col3[0] == 40 and
             col3[1] == 40 and
             col3[2] == 40)
     print table
     # Access eleemnt with index out of bounds. Exception expected.
     try:
         shouldThrow = row0[5]
         assert false
     except RuntimeError:
         pass
     try:
         shouldThrow = col1[5]
         assert false
     except RuntimeError:
         pass
     # Access row with index out of bounds. Exception expected.
     try:
         shouldThrow = table.getRowAtIndex(5)
         assert false
     except RuntimeError:
         pass
     # Access row with timestamp that does not exist. Exception expected.
     try:
         shouldThrow = table.getRow(5.5)
         assert false
     except RuntimeError:
         pass
     # Access column with index out of bounds. Exception expected.
     try:
         shouldThrow = table.getDependentColumnAtIndex(5)
         assert false
     except RuntimeError:
         pass
     # Access column with label that does not exist. Exception expected.
     try:
         shouldThrow = table.getDependentColumn('not-found')
         assert false
     except RuntimeError:
         pass