pyCGM_Single.pyCGM.dataAsArray¶
-
pyCGM_Single.pyCGM.
dataAsArray
(data)¶ Converts a dictionary of markers and their corresponding x, y, and z coordinate values to an array of dictionaries.
Assumes all markers have the same length of data.
- Parameters
- datadict
Dictionary of motion capture data. Keys are marker names and values are lists of x, y, and z coordinate arrays. Indices of each value correspond to frames in the trial.
- Returns
- dataArrayarray
List of dictionaries. Indices of dataArray correspond to frames in the trial. Keys are marker names, and values are markers’ x, y, and z coordinates in that frame.
Examples
This example uses a loop and
numpy.array_equal
to test the equality of individual dictionary elements since python does not guarantee the order of dictionary elements.Example for motion capture data for 3 markers, each with data for one frame of trial.
>>> from numpy import array, array_equal >>> data = {'RFHD': [array([325.83]), array([402.55]), array([1722.50])], ... 'LFHD': [array([184.55]), array([409.69]), array([1721.34])], ... 'LBHD': [array([197.86]), array([251.29]), array([1696.90])]} >>> result = dataAsArray(data) >>> expected = [{'RFHD': array([325.83, 402.55, 1722.50]), ... 'LFHD': array([184.55, 409.69, 1721.34]), ... 'LBHD': array([197.86, 251.29, 1696.90])}] >>> flag = True # False if any values are not equal >>> for i in range(len(result)): ... for key in result[i]: ... if (not array_equal(result[i][key], expected[i][key])): ... flag = False >>> flag True