Acquiring IK error for each individual marker

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Radhakrishnan Vignesh
Posts: 104
Joined: Tue Jun 01, 2021 8:09 am

Acquiring IK error for each individual marker

Post by Radhakrishnan Vignesh » Thu Dec 09, 2021 9:24 am

Hello,

I am running the scaling tool and IK tool using python scripting. I have gait data from about 50 people and want to compare the IK results for specific marker locations. How can I get this from the script? I am using the InverseKinematicsTool to perform the IK process. Should I use the solver instead?

Thanks
Vignesh

Tags:

User avatar
John Davis
Posts: 56
Joined: Mon Aug 26, 2019 7:42 am

Re: Acquiring IK error for each individual marker

Post by John Davis » Fri Dec 10, 2021 11:35 am

Hi Vignesh,

The strategy I have used is to have an IK setup file with the "report_marker_locations" parameter set to true. This dumps a .sto file with "_ik_model_marker_locations.sto" at the end of it (the first part of the filename is whatever you have set the "Name" property of the IK tool to be).

Then, I use a custom script that reads in this .sto file and the corresponding original .trc file used for IK. Then, for each marker and for each timestamp, I calculate the distance between the experimental marker (in the .trc) and the marker location on the model during IK. It's a little cumbersome, but both the .trc and .sto files are just tab-delimited files that you can read into MATLAB or Python and process as needed.

User avatar
Radhakrishnan Vignesh
Posts: 104
Joined: Tue Jun 01, 2021 8:09 am

Re: Acquiring IK error for each individual marker

Post by Radhakrishnan Vignesh » Fri Dec 10, 2021 12:49 pm

Hello John,

Thank you. I did the same thing. Since I had quite a number of files with different names, there was quite a bit of modification of XML sheets required. Is there a way to ensure the marker names are printed in the same order in the .sto file? I have quite a few which are in different order and I think that is due to the input trc file.

I am not sure if changing the base code would be possible but it would be nice if we can modify some of the functions so that it returns more than a bool variable. I do not have a lot of experience with Python but I found it quite cumbersome for example to create an instance of the IKTool and use some of its functions to build an instance of the InverseKinematicSolver class which has all the interesting data manipulation functions.
As of now, my code changes the XML file in each iteration and contains a significant bit of IO operations to save XML files and models and reload them from the scaling step to IK step.

Thanks again

User avatar
John Davis
Posts: 56
Joined: Mon Aug 26, 2019 7:42 am

Re: Acquiring IK error for each individual marker

Post by John Davis » Sun Dec 12, 2021 7:43 pm

Is there a way to ensure the marker names are printed in the same order in the .sto file? I have quite a few which are in different order and I think that is due to the input trc file.
I often have markers on the model that aren't in the experimental data, or vice versa, so I have a script that programmatically finds the corresponding columns for each marker in the original .trc file, and the .sto file output by IK with the report_marker_locations option.

For example I know my .trc file has a set of three columns for the "R_acr" marker, and the IK marker location .sto file will have "R_acr_tx", "R_acr_ty", and "R_acr_tz" column, So I find these columns using string matching, and match them up. I can share my code if you want, though I'm not sure how helpful it will be since it's in MATLAB and has a few peculiarities to the equipment that we use.

User avatar
Radhakrishnan Vignesh
Posts: 104
Joined: Tue Jun 01, 2021 8:09 am

Re: Acquiring IK error for each individual marker

Post by Radhakrishnan Vignesh » Mon Dec 13, 2021 2:39 am

Thanks a lot. I shall try to implement that,sorry but what are you using to read .trc files in Matlab? importData or fread does not seem to recognise the file type.

If it isnt too much trouble, I would love to peruse your code to see what you have done.

Thanks, and Regards
Vignesh

User avatar
John Davis
Posts: 56
Joined: Mon Aug 26, 2019 7:42 am

Re: Acquiring IK error for each individual marker

Post by John Davis » Tue Dec 14, 2021 1:08 pm

Hi Vignesh,

I set up a self-contained demo using the data distributed with the Rajagopal model here: https://github.com/johnjdavisiv/opensim-ik-errors

One caveat, the read_trc and read_mot functions use the readmatrix() command which wasn't introduced until MATLAB R2019a. If you have an older version, try using dlmread() instead.

I wrote my own functions to read .trc files (and .mot and .sto files) directly from the text (they are in the repo above). The trick is to use fgets() to read the header line-by-line, then skip the header lines and read the rest of the data as a tab-delimited file. You can also repeat the process in reverse to write trc, mot, and sto files that are readable by OpenSim.

I think it is probably "best practice" to use the TRCFileAdapter in the OpenSim API instead, but I have found the conversion process a bit slow, especially when dealing with longer (multi-minute) trials.

Hope you find this useful!

User avatar
Radhakrishnan Vignesh
Posts: 104
Joined: Tue Jun 01, 2021 8:09 am

Re: Acquiring IK error for each individual marker

Post by Radhakrishnan Vignesh » Thu Dec 16, 2021 11:26 am

Hello John,

Thanks a lot. Your code helped a lot. I had some issues with opening my trc file( not sure if the format is different like from different sources) but using readTable helped me. Sorry but I would like to know whether you encounter soft tissue artefacts during your work?

Thanks,
Vignesh

User avatar
John Davis
Posts: 56
Joined: Mon Aug 26, 2019 7:42 am

Re: Acquiring IK error for each individual marker

Post by John Davis » Thu Dec 16, 2021 8:18 pm

Yes, quite often: I mostly collect running data, so there is a lot of soft tissue artifact, especially when subjects are running fast. My current approach is to (1) use lots of markers and clusters of markers, ideally placed on parts of the body less prone to soft tissue motion, and (2) try to get my scaling really good, and trust that a good model + IK with high weights on "good" markers + a tiny bit of filtering will smooth out most of the problems.

The whole reason I wrote that IK marker error script was to make it easier for me to iterate on different IK weightings and pin down what markers were experiencing soft tissue artifact or other modeling issues. Finding "good" markers and IK weights for them is probably going to be situation-dependent: "good" marker locations and IK weights for soccer players doing a cutting task might not be so good for obese subjects walking after a hip replacement, for example.

User avatar
Radhakrishnan Vignesh
Posts: 104
Joined: Tue Jun 01, 2021 8:09 am

Re: Acquiring IK error for each individual marker

Post by Radhakrishnan Vignesh » Fri Dec 17, 2021 2:49 am

That is very interesting. I am new to the biomechanics field and my PhD focus is on soft tissue artefacts. Do you have runners who are of different shapes and ages and do the errors significantly change with those two factors?

I am looking at the dependence of soft tissue artefacts on those two factors

POST REPLY