Page 1 of 1
FunctionBasedPath Custom Path Points
Posted: Mon Dec 02, 2024 3:38 pm
by christianbrown
Hey there,
Background: I've been modeling (non-human) jumping in OpenSim and now that I have inverse dynamics results, it's time to solve the muscle redundancy problem using MocoInverse. I was having some trouble getting the solver code to work, so I switched from using Millard muscles to DeGroote-Fregly2016 muscles in my model. However, when I went to tweak my custom pathpoints (easy to do in Millard muscles and vital for the research question), I realized that there is no longer such code. Instead, I discovered the FunctionBasedPath released on March 7, 2024.
My question is: Do you know of any way in which I could customize that FunctionBasedPath, say to re-route my muscles over some skeletal elements at the midfoot joint?
Potentially helpful context: When I open my model with the DGF muscles, OpenSim can clearly read their attributes but will not display the muscles on the skeleton in the display window. So, I have no way of seeing visually if the FunctionBasedPath successfully re-routes over the skeletal elements at the midfoot. When I first brought my CT-scanned foot into the Millard muscle OpenSim model, OpenSim would simply route the Millard muscles straight through those skeletal elements until I used CustomPPs to route over the bones. I suspect the FunctionBasedPath runs right through the bones again, but honesty cannot tell.
Re: FunctionBasedPath Custom Path Points
Posted: Thu Dec 05, 2024 3:55 pm
by aafox
Hi Christian,
I've had this same GUI visualizer bug (maybe it's a feature and not a bug?) you mention with respect to muscles with function based paths not showing as well - so that behaviour seems consistent.
I've checked some models I've used that have converted Millard muscles to the DeGrooteFregley variant, and the custom path points remain in those muscles - perhaps it is just that these path points are not as easily accessible through the API when the muscle is converted? At the very least I think you could be confident that those path points would still be there - but the way I checked was by having the .osim printed to a file and looking at the muscles in NotePad++ (and the path points were still there).
From what I understand, the function based paths work by positioning the model with sampled coordinate values and then taking the muscle paths, moment arms etc. from these sampled positions to then fit a polynomial function to these values. In doing this sampling, I would assume that the path points in the muscles would be considered/accounted for in doing the fitting. I them think if you updated the muscle to use the function based path instead of path points/wrapping surfaces, they would then be removed as the muscles path is being controlled by the polynomial function rather than any other objects.
Hope that makes sense.
Aaron
Re: FunctionBasedPath Custom Path Points
Posted: Thu Dec 05, 2024 4:44 pm
by nbianco
Hi Christian and Aaron,
Aaron is correct --
FunctionBasedPaths do not support a method for visualization in OpenSim currently.
FunctionBasedPaths compute muscle lengths, velocities, and moment arms directly from user-provided functions. In that sense, there is no longer any physical geometry that can be visualized. (If you followed
examplePolynomialPathFitter, then these functions will be
MultivariatePolynomialFunctions.) If you want to visualize a simulation result and see muscle activation changes, you can use the original model with
GeometryPath elements in them (provided that the fitted paths represent the original paths well).
If you need to update the muscle paths, you will need to update the path points in the original model and then fit a new set of
FunctionBasePaths to them. Also note that this is not specific to DeGrooteFregly2016Muscle or the Millard muscle: both can use either
GeometryPath or
FunctionBasedPath to calculate muscle lengths, velocities, and moment arms.
Hopefully that clarifies a few things.
Best,
Nick
Re: FunctionBasedPath Custom Path Points
Posted: Fri Dec 13, 2024 2:55 pm
by christianbrown
Hey Nick,
Thanks so much for your help (Aaron too!). I am still having some trouble - can you tell me where to access the coordinates.sto file from the example you linked to? I am not exactly sure how to generate that .sto file or how to build it using the TimeSeriesTable function.
If I understand correctly, the MultivariatePolynomialFunction can be changed by changing the coefficients in my code. I am trying to access the coordinates.sto file for my model so that I can try that.
I tried adding my old geometrypath and pathpoints to my DGF muscles, but hit an error. Do you think this is a more fruitful path towards achieving my goal of rerouting my muscle path over a skeletal element? As compared to changing coefficients of the functionbasedpath?
Cheers,
Re: FunctionBasedPath Custom Path Points
Posted: Sun Dec 15, 2024 12:51 pm
by nbianco
Hi Christian,
If you are using OpenSim 4.5, then the full example in both Matlab and Python with reference files and plotting utilities are available to you. Look for the "PolynomialPathFitter" folder under the examples in the distribution and you will find all the files you need there.
In general, the "coordinates.sto" can be replaced with a STO file containing coordinate values of whatever motion you are interested in simulating. That way, you can have confidence that the fitted function-based paths produce accurate muscle lengths and moment arms for the joint angle ranges you care about. You can also construct a "coordinates.sto" file that samples the entire set of joint angle ranges of your model.
If I understand correctly, the MultivariatePolynomialFunction can be changed by changing the coefficients in my code. I am trying to access the coordinates.sto file for my model so that I can try that.
You can change these coefficients manually if you know exactly what path length vs joint angle relationships you want to model. Otherwise, you can let PolynomialPathFitter find these coefficients automatically based on your "coordinates.sto" file.
I tried adding my old geometrypath and pathpoints to my DGF muscles, but hit an error. Do you think this is a more fruitful path towards achieving my goal of rerouting my muscle path over a skeletal element? As compared to changing coefficients of the functionbasedpath?
It sounds like you are trying to change the muscle geometry in your model. I would recommend using GeometryPath to update the geometry of the model, and then fit a set of function-based paths once you have updated the geometry. The function-based paths are (currently) designed to create a function-based "replica" of the muscle geometry in an existing model which can be swapped in to speed up simulations. It's not really (again, currently) designed to be a model-building tool. I would recommend checking out
OpenSim Creator for model building.
Best,
Nick
Re: FunctionBasedPath Custom Path Points
Posted: Wed Dec 18, 2024 2:23 pm
by christianbrown
Hey Nick,
Okay, this really helped orient me and I feel like I am finally understanding clearly and heading in the right direction. I am currently putting my OSIM model (the one with the idealized geometry paths) and .sto file into the examplePolynomialPathFitter code with the hopes of generating the "..._fitted_paths.osim" version of my model.
At first, fitter.setUseStepwiseRegression was not recognized, but then I realized that the stepwiseregression was not added until 4.5.1 (I was using 4.5).
Just downloaded the source code now. Hopefully, this will all work smoothly once I can update to the newest version.
Best,
Re: FunctionBasedPath Custom Path Points
Posted: Fri Dec 20, 2024 6:40 am
by nbianco
Hi Christian,
The stepwise regression feature is only available in OpenSim 4.5.1. If you're using Python, you can install 4.5.1 using our Conda package support:
https://opensimconfluence.atlassian.net ... +in+Python.
Otherwise, just use the examplePolynomialPathFitter.m script included in your OpenSim 4.5 distribution.
Best,
Nick
Re: FunctionBasedPath Custom Path Points
Posted: Fri Dec 20, 2024 11:59 am
by christianbrown
Thank you! That worked, and I have my "..._fitted_paths.osim" file
Back to Moco to solve this muscle redundancy problem...
Sincerely grateful for all your replies. Happy holidays!
Re: FunctionBasedPath Custom Path Points
Posted: Sat Dec 21, 2024 8:05 am
by nbianco
You're welcome -- glad it worked!
Happy holidays!