This example demonstrates how to use PolynomialPathFitter to create a set of FunctionBasedPaths for a model.
25 import opensim
as osim
26 from examplePolynomialPathFitter_plotting
import (plot_coordinate_samples,
36 fitter = osim.PolynomialPathFitter()
45 model = osim.Model(
'subject_walk_scaled.osim')
47 fitter.setModel(osim.ModelProcessor(model))
56 values = osim.TimeSeriesTable(
'coordinates.sto')
57 times = values.getIndependentColumn()
58 for i
in range(len(times)):
60 values.removeRow(times[i])
62 fitter.setCoordinateValues(osim.TableProcessor(values))
76 results_dir =
'results' 77 fitter.setOutputDirectory(results_dir)
83 fitter.setMaximumPolynomialOrder(5)
87 fitter.setNumSamplesPerFrame(10)
92 fitter.appendCoordinateSamplingBounds(
93 '/jointset/hip_r/hip_flexion_r', osim.Vec2(-15, 15))
94 fitter.appendCoordinateSamplingBounds(
95 '/jointset/hip_l/hip_flexion_l', osim.Vec2(-15, 15))
101 fitter.setGlobalCoordinateSamplingBounds(osim.Vec2(-30, 30))
109 fitter.setUseStepwiseRegression(
True)
117 fitter.setPathLengthTolerance(1e-3)
118 fitter.setMomentArmTolerance(1e-3)
135 plot_coordinate_samples(results_dir, model.getName())
146 plot_path_lengths(results_dir, model.getName())
147 plot_moment_arms(results_dir, model.getName())
159 functionBasedPathsFile = os.path.join(
160 results_dir, f
'{model.getName()}_FunctionBasedPathSet.xml')
161 osim.PolynomialPathFitter.evaluateFunctionBasedPaths(
162 model, osim.TableProcessor(values), functionBasedPathsFile)
170 modelProcessor = osim.ModelProcessor(
'subject_walk_scaled.osim')
171 modelProcessor.append(osim.ModOpReplacePathsWithFunctionBasedPaths(
172 functionBasedPathsFile))
173 model = modelProcessor.process()
175 model.printToXML(
'subject_walk_scaled_fitted_paths.osim')