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)
88 fitter.appendCoordinateSamplingBounds(
89 '/jointset/hip_r/hip_flexion_r', osim.Vec2(-15, 15))
90 fitter.appendCoordinateSamplingBounds(
91 '/jointset/hip_l/hip_flexion_l', osim.Vec2(-15, 15))
108 plot_coordinate_samples(results_dir, model.getName())
119 plot_path_lengths(results_dir, model.getName())
120 plot_moment_arms(results_dir, model.getName())
132 functionBasedPathsFile = os.path.join(
133 results_dir, f
'{model.getName()}_FunctionBasedPathSet.xml')
134 osim.PolynomialPathFitter.evaluateFunctionBasedPaths(
135 model, osim.TableProcessor(values), functionBasedPathsFile)
143 modelProcessor = osim.ModelProcessor(
'subject_walk_scaled.osim')
144 modelProcessor.append(osim.ModOpReplacePathsWithFunctionBasedPaths(
145 functionBasedPathsFile))
146 model = modelProcessor.process()
148 model.printToXML(
'subject_walk_scaled_fitted_paths.osim')