示例#1
0
    def test_integrity_checks(self):
        model = osim.Model(
            os.path.join(test_dir, "gait10dof18musc_subject01.osim"))
        state = model.initSystem()
        states = osim.StatesTrajectory()
        states.append(state)
        state.setTime(1.0)
        states.append(state)
        self.assertTrue(states.isNondecreasingInTime())
        self.assertTrue(states.isConsistent())
        self.assertTrue(states.hasIntegrity())

        # Cannot append a state with an earlier time than the last one.
        state.setTime(0.5)
        self.assertRaises(RuntimeError, states.append, state)

        # However, since python doesn't have constness, we can edit the time of
        # a state in the trajectory.
        state.setTime(1.5)
        states.append(state)
        self.assertTrue(states.isNondecreasingInTime())
        states.back().setTime(0.25)
        self.assertFalse(states.isNondecreasingInTime())
        self.assertTrue(states.isConsistent())
        self.assertFalse(states.hasIntegrity())
示例#2
0
    def test_populate_trajectory(self):
        model = osim.Model(
            os.path.join(test_dir, "gait10dof18musc_subject01.osim"))
        state = model.initSystem()
        states = osim.StatesTrajectory()
        states.append(state)
        state.setTime(1.0)
        states.append(state)

        self.assertEqual(states.getSize(), 2)
        self.assertEqual(states[1].getTime(), 1.0)
示例#3
0
    def test_out_of_range(self):
        model = osim.Model(
            os.path.join(test_dir, "gait10dof18musc_subject01.osim"))
        state = model.initSystem()
        states = osim.StatesTrajectory()
        states.append(state)
        state.setTime(1.0)
        states.append(state)

        # TODO this exception message could be better...
        self.assertRaises(RuntimeError, lambda: states[2].getTime())
示例#4
0
import opensim

model = opensim.Model('subject01_adjusted.osim')
states = opensim.StatesTrajectory('subject01_fast_trial01_cmc.osimstates')

# InverseStudy drives time from states traj.
# Here, using convenience constructor.
study = opensim.InverseStudy(model, states)

met = opensim.Umberger2010MuscleMetabolics('Rajagopal2015_metabolics.xml')
met.setName('metabolics')

# Append metabolics model to model.
model.append(met)

reporter = opensim.FileReporter()
# Alternatively, `opensim.DataSink()`. I think the two concepts are actually
# the same.
# Can only set file prefix, since multiple files may actually be written if the
# inputs are of multiple types?
reporter.setFilePrefix('subject01_fast_trial01_metabolics')
# Print CSV files.
reporter.setFileFormat('csv')

# The Reporter must have a flexible number of inputs.
# With just one argument, the name of the first element of the input is the
# full path of the associated output ('metabolics/total_rate').
reporter.getMultiInput('input').append(met.getOutput('total_rate'))
# Optionally, a distinct name can be provided as well.
reporter.getMultiInput('input').append(met.getOutput('total_work_rate'),
                                       'met_total_rate')