<NME> test_DataAdapter.py
<BEF> """
Test DataAdapter interface.
"""
import os, unittest
import opensim as osim

test_dir = os.path.join(os.path.dirname(os.path.abspath(osim.__file__)),
                        'tests')

class TestDataAdapter(unittest.TestCase):
    def test_TRCFileAdapter(self):
        table = osim.TimeSeriesTableVec3(os.path.join(test_dir, 
                             'futureOrientationInverseKinematics.trc'))
        assert table.getNumRows()    == 1202
        assert table.getNumColumns() == 2

        table = osim.TimeSeriesTableVec3(os.path.join(test_dir, 'dataWithNaNsOfDifferentCases.trc'))
        assert table.getNumRows()    == 5
        assert table.getNumRows()    == 5
        assert table.getNumColumns() == 14

    def test_MOTFileAdapter(self):
        adapter = osim.MOTFileAdapter()
        table = adapter.read(os.path.join(test_dir, 'subject02_grf_HiFreq.mot'))
        assert table.getNumRows()    == 439
        assert table.getNumColumns() == 18
                                          'std_subject01_walk1_ik.mot'))
        assert table.getNumRows()    == 73
        assert table.getNumColumns() == 23

    def test_C3DFileAdapter(self):
        try:
            adapter = osim.C3DFileAdapter()
        except AttributeError:
            # C3D support not available. OpenSim was not compiled with ezc3d.
            return
        tables = adapter.read(os.path.join(test_dir, 'walking2.c3d'))
        forces = adapter.getForcesTable(tables)
        markers = adapter.getMarkersTable(tables)
        
        assert markers.getNumRows()    == 1249
        assert markers.getNumColumns() == 44
        assert forces.getNumRows()     == 9992
        assert forces.getNumColumns()  == 6
        adapter.setLocationForForceExpression(1)
        tables2 = adapter.read(os.path.join(test_dir, 'walking5.c3d'))

        # Marker data read from C3D.
        markers = adapter.getMarkersTable(tables2)
        assert markers.getNumRows()    == 1103
        assert markers.getNumColumns() == 40
        assert markers.getTableMetaDataString('DataRate') == '250.000000'
        assert markers.getTableMetaDataString('Units') == 'mm'

        # Flatten marker data.
        markersFlat = markers.flatten()
        assert markersFlat.getNumRows()    == 1103
        assert markersFlat.getNumColumns() == 40 * 3

        # Make sure flattenned marker data is writable/readable to/from file.
        markersFilename = 'markers.sto'
        stoAdapter = osim.STOFileAdapter()
        stoAdapter.write(markersFlat, markersFilename)
        markersDouble = osim.TimeSeriesTable(markersFilename)
        assert markersDouble.getNumRows()    == 1103
        assert markersDouble.getNumColumns() == 40 * 3

        # Forces data read from C3d.
        forces = adapter.getForcesTable(tables2)
        assert forces.getNumRows()     == 8824
        assert forces.getNumColumns()  == 6
        assert forces.getTableMetaDataString('DataRate') == '2000.000000'
        assert forces.getTableMetaDataVectorUnsigned('Types') == (2, 2)
        fpCalMats = forces.getTableMetaDataVectorMatrix("CalibrationMatrices")
        assert len(fpCalMats) == 2
        assert fpCalMats[0].nrow() == 6
        assert fpCalMats[0].ncol() == 6
        assert fpCalMats[1].nrow() == 6
        assert fpCalMats[1].ncol() == 6
        fpCorners = forces.getTableMetaDataVectorMatrix("Corners")
        assert len(fpCorners) == 2
        assert fpCorners[0].nrow() == 3
        assert fpCorners[0].ncol() == 4
        assert fpCorners[1].nrow() == 3
        assert fpCorners[1].ncol() == 4
        fpOrigins = forces.getTableMetaDataVectorMatrix("Origins")
        assert len(fpOrigins) == 2
        assert fpOrigins[0].nrow() == 3
        assert fpOrigins[0].ncol() == 1
        assert fpOrigins[1].nrow() == 3
        assert fpOrigins[1].ncol() == 1
        assert forces.getDependentsMetaDataString('units') == ('N', 'mm', 'Nmm',
                                                               'N', 'mm', 'Nmm')

        # Flatten forces data.
        forcesFlat = forces.flatten()
        assert forcesFlat.getNumRows()    == 8824
        assert forcesFlat.getNumColumns() == 6 * 3

        # Make sure flattenned forces data is writable/readable to/from file.
        forcesFilename = 'forces.sto'
        stoAdapter.write(forcesFlat, forcesFilename)
        forcesDouble = osim.TimeSeriesTable(forcesFilename)
        assert forcesDouble.getNumRows()    == 8824
        assert forcesDouble.getNumColumns() == 6 * 3

        # Clean up.
        os.remove(markersFilename)
        os.remove(forcesFilename)

<MSG> MOT to STO in bindings.

<DFF> @@ -19,8 +19,8 @@ class TestDataAdapter(unittest.TestCase):
         assert table.getNumRows()    == 5
         assert table.getNumColumns() == 14
 
-    def test_MOTFileAdapter(self):
-        adapter = osim.MOTFileAdapter()
+    def test_STOFileAdapter(self):
+        adapter = osim.STOFileAdapter()
         table = adapter.read(os.path.join(test_dir, 'subject02_grf_HiFreq.mot'))
         assert table.getNumRows()    == 439
         assert table.getNumColumns() == 18

{'commit': "diff --git a/Bindings/Python/tests/test_DataAdapter.py b/Bindings/Python/tests/test_DataAdapter.py\nindex eee823295..ba7573f7a 100644\n--- a/Bindings/Python/tests/test_DataAdapter.py\n+++ b/Bindings/Python/tests/test_DataAdapter.py\n@@ -19,8 +19,8 @@ class TestDataAdapter(unittest.TestCase):\n         assert table.getNumRows()    == 5\n         assert table.getNumColumns() == 14\n \n-    def test_MOTFileAdapter(self):\n-        adapter = osim.MOTFileAdapter()\n+    def test_STOFileAdapter(self):\n+        adapter = osim.STOFileAdapter()\n         table = adapter.read(os.path.join(test_dir, 'subject02_grf_HiFreq.mot'))\n         assert table.getNumRows()    == 439\n         assert table.getNumColumns() == 18\n", 'commit_subject': 'MOT to STO in bindings.', 'repo_name': 'opensim-org/opensim-core', 'committer': {'name': 'Shrinidhi KL', 'email': 'd95ab70d9f94fe9e94415764048b7c0104d27b27@gmail.com', 'time_sec': '1463444702', 'tz_offset': '-420', 'date': {'seconds': '1463444702'}}, 'commit_tree': '3d47c21abf9c4f5639cf1af6678ce6759ecff62a', 'commit_message': 'MOT to STO in bindings.\n', 'language_name': 'MATLAB', 'license': 'apache-2.0', 'hunks': "@@ -19,8 +19,8 @@ class TestDataAdapter(unittest.TestCase):\n         assert table.getNumRows()    == 5\n         assert table.getNumColumns() == 14\n \n-    def test_MOTFileAdapter(self):\n-        adapter = osim.MOTFileAdapter()\n+    def test_STOFileAdapter(self):\n+        adapter = osim.STOFileAdapter()\n         table = adapter.read(os.path.join(test_dir, 'subject02_grf_HiFreq.mot'))\n         assert table.getNumRows()    == 439\n         assert table.getNumColumns() == 18\n", 'addition_count': 2, 'deletion_count': 2, 'src_file': 'a/Bindings/Python/tests/test_DataAdapter.py', 'tgt_file': 'b/Bindings/Python/tests/test_DataAdapter.py', 'file_extension': '.py', 'before_file': '"""\nTest DataAdapter interface.\n"""\nimport os, unittest\nimport opensim as osim\n\ntest_dir = os.path.join(os.path.dirname(os.path.abspath(osim.__file__)),\n                        \'tests\')\n\nclass TestDataAdapter(unittest.TestCase):\n    def test_TRCFileAdapter(self):\n        table = osim.TimeSeriesTableVec3(os.path.join(test_dir, \n                             \'futureOrientationInverseKinematics.trc\'))\n        assert table.getNumRows()    == 1202\n        assert table.getNumColumns() == 2\n\n        table = osim.TimeSeriesTableVec3(os.path.join(test_dir, \'dataWithNaNsOfDifferentCases.trc\'))\n        assert table.getNumRows()    == 5\n        assert table.getNumRows()    == 5\n        assert table.getNumColumns() == 14\n\n    def test_MOTFileAdapter(self):\n        adapter = osim.MOTFileAdapter()\n        table = adapter.read(os.path.join(test_dir, \'subject02_grf_HiFreq.mot\'))\n        assert table.getNumRows()    == 439\n        assert table.getNumColumns() == 18\n                                          \'std_subject01_walk1_ik.mot\'))\n        assert table.getNumRows()    == 73\n        assert table.getNumColumns() == 23\n\n    def test_C3DFileAdapter(self):\n        try:\n            adapter = osim.C3DFileAdapter()\n        except AttributeError:\n            # C3D support not available. OpenSim was not compiled with ezc3d.\n            return\n        tables = adapter.read(os.path.join(test_dir, \'walking2.c3d\'))\n        forces = adapter.getForcesTable(tables)\n        markers = adapter.getMarkersTable(tables)\n        \n        assert markers.getNumRows()    == 1249\n        assert markers.getNumColumns() == 44\n        assert forces.getNumRows()     == 9992\n        assert forces.getNumColumns()  == 6\n        adapter.setLocationForForceExpression(1)\n        tables2 = adapter.read(os.path.join(test_dir, \'walking5.c3d\'))\n\n        # Marker data read from C3D.\n        markers = adapter.getMarkersTable(tables2)\n        assert markers.getNumRows()    == 1103\n        assert markers.getNumColumns() == 40\n        assert markers.getTableMetaDataString(\'DataRate\') == \'250.000000\'\n        assert markers.getTableMetaDataString(\'Units\') == \'mm\'\n\n        # Flatten marker data.\n        markersFlat = markers.flatten()\n        assert markersFlat.getNumRows()    == 1103\n        assert markersFlat.getNumColumns() == 40 * 3\n\n        # Make sure flattenned marker data is writable/readable to/from file.\n        markersFilename = \'markers.sto\'\n        stoAdapter = osim.STOFileAdapter()\n        stoAdapter.write(markersFlat, markersFilename)\n        markersDouble = osim.TimeSeriesTable(markersFilename)\n        assert markersDouble.getNumRows()    == 1103\n        assert markersDouble.getNumColumns() == 40 * 3\n\n        # Forces data read from C3d.\n        forces = adapter.getForcesTable(tables2)\n        assert forces.getNumRows()     == 8824\n        assert forces.getNumColumns()  == 6\n        assert forces.getTableMetaDataString(\'DataRate\') == \'2000.000000\'\n        assert forces.getTableMetaDataVectorUnsigned(\'Types\') == (2, 2)\n        fpCalMats = forces.getTableMetaDataVectorMatrix("CalibrationMatrices")\n        assert len(fpCalMats) == 2\n        assert fpCalMats[0].nrow() == 6\n        assert fpCalMats[0].ncol() == 6\n        assert fpCalMats[1].nrow() == 6\n        assert fpCalMats[1].ncol() == 6\n        fpCorners = forces.getTableMetaDataVectorMatrix("Corners")\n        assert len(fpCorners) == 2\n        assert fpCorners[0].nrow() == 3\n        assert fpCorners[0].ncol() == 4\n        assert fpCorners[1].nrow() == 3\n        assert fpCorners[1].ncol() == 4\n        fpOrigins = forces.getTableMetaDataVectorMatrix("Origins")\n        assert len(fpOrigins) == 2\n        assert fpOrigins[0].nrow() == 3\n        assert fpOrigins[0].ncol() == 1\n        assert fpOrigins[1].nrow() == 3\n        assert fpOrigins[1].ncol() == 1\n        assert forces.getDependentsMetaDataString(\'units\') == (\'N\', \'mm\', \'Nmm\',\n                                                               \'N\', \'mm\', \'Nmm\')\n\n        # Flatten forces data.\n        forcesFlat = forces.flatten()\n        assert forcesFlat.getNumRows()    == 8824\n        assert forcesFlat.getNumColumns() == 6 * 3\n\n        # Make sure flattenned forces data is writable/readable to/from file.\n        forcesFilename = \'forces.sto\'\n        stoAdapter.write(forcesFlat, forcesFilename)\n        forcesDouble = osim.TimeSeriesTable(forcesFilename)\n        assert forcesDouble.getNumRows()    == 8824\n        assert forcesDouble.getNumColumns() == 6 * 3\n\n        # Clean up.\n        os.remove(markersFilename)\n        os.remove(forcesFilename)\n', 'message': 'MOT to STO in bindings.\n', 'author_name': 'Shrinidhi KL', 'lang': 'py'}