TrcDataFrame#
- class pyCGM2.Model.Opensim.opensimIO.TrcDataFrame(DATA_PATH, filename)#
TRC reader/writer using a pandas DataFrame as the internal representation.
Robust to empty fields in TRC rows (common when markers are missing).
Uses TAB splitting to preserve empty columns (do NOT use default split()).
Provides duplicateLastRow() to append a copy of the last frame.
- DataFrame columns:
‘Frame#’
‘Time’
for each marker M: ‘M_X’, ‘M_Y’, ‘M_Z’
- __init__(DATA_PATH, filename)#
Methods
__init__(DATA_PATH, filename)duplicateLastRow([dt])Duplicate the last frame and append it.
Return the dataframe.
save([outDir, filename])Write the TRC file back to disk.
- duplicateLastRow(dt=None)#
Duplicate the last frame and append it. - Frame# increments by 1 - Time increments by dt
- If dt is None:
if >=2 frames: dt = last_time - previous_time (fallback to 0.01 if <=0)
if 1 frame: dt = 0.01
- getDataFrame()#
Return the dataframe.
- Returns:
pd.DataFrame – The data.
- save(outDir=None, filename=None)#
Write the TRC file back to disk.
The header is preserved as much as possible (original lines up to the marker line).
The marker names line is rewritten using the canonical TRC convention:
Frame# <tab> Time <tab> M1 <tab><tab><tab> M2 <tab><tab><tab> ...Data lines are written as TAB-separated values.
NaN values are written as empty fields.
- Parameters:
outDir (str, optional) – Output folder. Defaults to the original folder.
filename (str, optional) – Output filename. Defaults to the original filename.