Hi all,
I'm working with the API (OpenSim 4.4) in Matlab and when I read my c3d with osimC3D(c3dpath,1) I get NaNs in the CoP, therefore forceTable = c3d.getTable_forces() has NaNs that get written to my mot when I use c3d.writeMOT. Is there a way to fix this? I couldn't find any answer in the forum...
I also tried to modify the c3d.writeMOT method/function: I manage to get the CoP columns in Matlab and modify them (fixing the NaNs in Matlab), but then I have problems writing them back in the forces TimeSeriesTableVec3. Is there a smart way to do that? I'm not too familiar with OOP and I was not able to just update the position columns, how do you do that? At the moment I'm using the following piece of code, but it's not great
for i = 0 : labels.size() - 1
% Get the label as a string
label = char(labels.get(i));
%% interpolate for NaN
NaNmatrix=forces.getDependentColumn(label).getAsMat;
len_vec= 1:size(NaNmatrix,1);
vec_x=fillmissing(NaNmatrix(:,1),'linear','SamplePoints',len_vec);
vec_y=fillmissing(NaNmatrix(:,2),'linear','SamplePoints',len_vec);
vec_z=fillmissing(NaNmatrix(:,3),'linear','SamplePoints',len_vec);
vec3matrix=[vec_x, vec_y, vec_z];
aa=VectorVec3().createFromMat(vec3matrix);
try
forces.removeColumn(label)
catch
%throws error but it works
end
forces.appendColumn(label,aa)
end
It's also worth to mention that when I use removeColumn I get the following error (even if it seems to work just fine):
Java exception occurred:
java.lang.RuntimeException: Key = units expected = 11 received = 12
Thrown at DataTable.h:1629 in validateDependentsMetaData().
at org.opensim.modeling.opensimCommonJNI.DataTableVec3_removeColumn(Native Method)
at org.opensim.modeling.DataTableVec3.removeColumn(DataTableVec3.java:357)
Thanks in advance if anyone could help me!
NaN in mot files [API]
- Matilde Bertoli
- Posts: 3
- Joined: Tue Sep 13, 2022 11:43 pm
- Carmichael Ong
- Posts: 380
- Joined: Fri Feb 24, 2012 11:50 am
Re: NaN in mot files [API]
There are a couple of examples in the provided MATLAB examples and utilities that work with a TimeSeriesTableVec3. One that might be helpful to look at for an example is the utility osimTableFromStruct.m
This utility creates a table from scratch, so it may provide an example for creating a table for your case too.
This utility creates a table from scratch, so it may provide an example for creating a table for your case too.
- Matilde Bertoli
- Posts: 3
- Joined: Tue Sep 13, 2022 11:43 pm
Re: NaN in mot files [API]
Thanks for your reply.
I was hoping for a 'column based' method rather than adding row by row, but it will do.
I was hoping for a 'column based' method rather than adding row by row, but it will do.
- Mohammadreza Rezaie
- Posts: 390
- Joined: Fri Nov 24, 2017 12:48 am
Re: NaN in mot files [API]
Hi, there is such possibility. I suggest creating a new TimeSeriesTable and append your fixed columns (1D) into it by a loop, you don't need Vec3. This is an example (Python):
Code: Select all
file = osim.TimeSeriesTable(osim.StdVectorDouble(time))
file.appendColumn('column_label', osim.Vector(fixed_variable))
osim.STOFileAdapter().write(file, 'force.mot')
- Matilde Bertoli
- Posts: 3
- Joined: Tue Sep 13, 2022 11:43 pm
Re: NaN in mot files [API]
Thanks! I actually realized that I can create the external loads also with px,py,pz defined as OriginOfForcePlate instead of CoP, therefore (using osimC3D(c3dpath,0) instead of osimC3D(c3dpath,1)) I no longer have the NaNs issue...
- Mohammadreza Rezaie
- Posts: 390
- Joined: Fri Nov 24, 2017 12:48 am
Re: NaN in mot files [API]
Hi, in this case you will get a constant value (force plate origin) as COP, i.e., the point of force vector on the ground won't move at all. NaN typically occurs when there is no force (i.e., denominator is either 0 or NaN). In your COP, which currently contains NaN, you can set zero for the time frames that the vertical force is below a certain threshold (e.g., 10N).