pyCGM_Single.pyCGM.writeResult¶
-
pyCGM_Single.pyCGM.
writeResult
(data, filename, **kargs)¶ Writes the result of the calculation into a csv file.
Lines 0-6 of the output csv are headers. Lines 7 and onwards are angle or axis calculations for each frame. For example, line 7 of the csv is output for frame 0 of the motion capture. The first element of each row of ouput is the frame number.
- Parameters
- dataarray_like
Motion capture data as a matrix of frames as rows. Each row is a numpy array of length 273. Indices 0-56 correspond to the values for angles. Indices 57-272 correspond to the values for axes. See Examples.
- filenamestr
Full path of the csv to be saved. Do not include ‘.csv’.
- **kargsdict
Dictionary of keyword arguments as follows.
- delimiterstr, optional
String to be used as the delimiter for the csv file. The default delimiter is ‘,’.
- anglesbool or array, optional
True or false to save angles, or a list of angles to save. True by default.
- axisbool or array, optional
True or false to save axis, or a list of axis to save. True by default.
Examples
>>> from numpy import array, zeros >>> import os >>> from shutil import rmtree >>> import tempfile >>> tmpdirName = tempfile.mkdtemp()
Prepare a frame of data to write to csv. This example writes joint angle values for the first joint, the pelvis, and axis values for the pelvis origin, PELO.
>>> frame = zeros(273) >>> angles = array([-0.308494914509454, -6.12129279337001, 7.57143110215171]) >>> for i in range(len(angles)): ... frame[i] = angles[i] >>> axis = array([-934.314880371094, -4.44443511962891, 852.837829589844]) >>> for i in range(len(axis)): ... frame[i+57] = axis[i] >>> data = [frame] >>> outfile = os.path.join(tmpdirName, 'output')
Writing angles only.
>>> writeResult(data, outfile, angles=True, axis=False) >>> with open(outfile + '.csv') as file: ... lines = file.readlines() >>> result = lines[7].strip().split(',') >>> result ['0.000000000000000', '-0.308494914509454', '-6.121292793370010', '7.571431102151710',...]
Writing axis only.
>>> writeResult(data, outfile, angles=False, axis=True) (1, 273)... >>> with open(outfile + '.csv') as file: ... lines = file.readlines() >>> result = lines[7].strip().split(',') >>> result ['0.000000000000000', '-934.314880371093977', '-4.444435119628910', '852.837829589843977',...] >>> rmtree(tmpdirName)