def compute(self): for nodeLabel in self.scoreProcedure.m_scoreDefinition.keys(): try: proxLabel = self.scoreProcedure.m_scoreDefinition[nodeLabel][ "proximal"] distLabel = self.scoreProcedure.m_scoreDefinition[nodeLabel][ "distal"] proxNode = self.m_model.getSegment(proxLabel).getReferential( 'TF').getNodeTrajectory(nodeLabel) distNode = self.m_model.getSegment(distLabel).getReferential( 'TF').getNodeTrajectory(nodeLabel) score = numeric.rms((proxNode - distNode), axis=1) scoreValues = np.array([ score, np.zeros(self.acq.GetPointFrameNumber()), np.zeros(self.acq.GetPointFrameNumber()) ]).T btkTools.smartAppendPoint(self.acq, str(nodeLabel + "_Score"), scoreValues, PointType=btk.btkPoint.Scalar, desc="Score") except: LOGGER.logger.error( "[pyCGM2] Score residual for node (%s) not computed" % (nodeLabel))
def compute(self): for nodeLabel in self.scoreProcedure.m_scoreDefinition.keys(): proxLabel = self.scoreProcedure.m_scoreDefinition[nodeLabel][ "proximal"] distLabel = self.scoreProcedure.m_scoreDefinition[nodeLabel][ "distal"] proxNode = self.m_model.getSegment( proxLabel).anatomicalFrame.getNodeTrajectory(nodeLabel) distNode = self.m_model.getSegment( distLabel).anatomicalFrame.getNodeTrajectory(nodeLabel) score = numeric.rms((proxNode - distNode), axis=1) scoreValues = np.array([ score, np.zeros(self.acq.GetPointFrameNumber()), np.zeros(self.acq.GetPointFrameNumber()) ]).T btkTools.smartAppendPoint(self.acq, str(nodeLabel + "_Score"), scoreValues, PointType=btk.btkPoint.Scalar, desc="Score")
def test_point_rms(acq, RefLabel, LabelToTest, threshold, init=-1, end=-1): init = 0 if init == -1 else init - acq.GetFirstFrame() end = acq.GetLastFrame() - acq.GetFirstFrame( ) if end == -1 else end - acq.GetFirstFrame() np.testing.assert_array_less( numeric.rms(acq.GetPoint(RefLabel).GetValues()[init:end, :] - acq.GetPoint(LabelToTest).GetValues()[init:end, :], axis=0), threshold)
def comparisonOpensimVsCGM(motFilename, acqIK, pointLabelSuffix): # note : assert_almost_equal tests fail. Prefer rmsd computation values = osimProcessing.mot2pointValues( motFilename, ["hip_flexion_r", "hip_adduction_r", "hip_rotation_r"], orientation=[1.0, 1.0, 1.0]) myValues = acqIK.GetPoint(str("RHipAngles" + "_" + pointLabelSuffix)).GetValues() #np.testing.assert_almost_equal( values,myValues, decimal =3) np.testing.assert_array_less(numeric.rms((values - myValues), axis=0), 0.05) values = osimProcessing.mot2pointValues( motFilename, ["knee_flexion_r", "knee_adduction_r", "knee_rotation_r"], orientation=[-1.0, 1.0, 1.0]) myValues = acqIK.GetPoint(str("RKneeAngles" + "_" + pointLabelSuffix)).GetValues() #np.testing.assert_almost_equal( values,myValues, decimal =3) np.testing.assert_array_less(numeric.rms((values - myValues), axis=0), 0.05) values = osimProcessing.mot2pointValues( motFilename, ["ankle_flexion_r", "ankle_rotation_r", "ankle_adduction_r"], orientation=[1.0, -1.0, 1.0]) myValues = acqIK.GetPoint(str("RAnkleAngles" + "_" + pointLabelSuffix)).GetValues() #np.testing.assert_almost_equal( values,myValues, decimal =3) np.testing.assert_array_less(numeric.rms((values - myValues), axis=0), 0.05) values = osimProcessing.mot2pointValues( motFilename, ["forefoot_flexion_r", "forefoot_adduction_r", "forefoot_rotation_r"], orientation=[1.0, 1.0, -1.0]) myValues = acqIK.GetPoint(str("RForeFootAngles" + "_" + pointLabelSuffix)).GetValues() #np.testing.assert_almost_equal( values,myValues, decimal =3) np.testing.assert_array_less(numeric.rms((values - myValues), axis=0), 0.05)
def compareKinetics(acqGait, init, end, forceThreshold, momentThreshold, powerThreshold): forceArrayThreshold = np.array( [forceThreshold, forceThreshold, forceThreshold]) np.testing.assert_array_less( numeric.rms( (acqGait.GetPoint("LHipForce").GetValues()[init:end, :] - acqGait.GetPoint("LHipForce_cgm1_6dof").GetValues()[init:end, :]), axis=0), forceArrayThreshold) np.testing.assert_array_less( numeric.rms(( acqGait.GetPoint("LKneeForce").GetValues()[init:end, :] - acqGait.GetPoint("LKneeForce_cgm1_6dof").GetValues()[init:end, :]), axis=0), forceArrayThreshold) np.testing.assert_array_less( numeric.rms( (acqGait.GetPoint("LAnkleForce").GetValues()[init:end, :] - acqGait.GetPoint("LAnkleForce_cgm1_6dof").GetValues()[init:end, :] ), axis=0), forceArrayThreshold) np.testing.assert_array_less( numeric.rms( (acqGait.GetPoint("RHipForce").GetValues()[init:end, :] - acqGait.GetPoint("RHipForce_cgm1_6dof").GetValues()[init:end, :]), axis=0), forceArrayThreshold) np.testing.assert_array_less( numeric.rms(( acqGait.GetPoint("RKneeForce").GetValues()[init:end, :] - acqGait.GetPoint("RKneeForce_cgm1_6dof").GetValues()[init:end, :]), axis=0), forceArrayThreshold) np.testing.assert_array_less( numeric.rms( (acqGait.GetPoint("RAnkleForce").GetValues()[init:end, :] - acqGait.GetPoint("RAnkleForce_cgm1_6dof").GetValues()[init:end, :] ), axis=0), forceArrayThreshold) momentArrayThreshold = np.array( [momentThreshold, momentThreshold, momentThreshold]) np.testing.assert_array_less( numeric.rms(( acqGait.GetPoint("RHipMoment").GetValues()[init:end, :] - acqGait.GetPoint("RHipMoment_cgm1_6dof").GetValues()[init:end, :]), axis=0), momentArrayThreshold) np.testing.assert_array_less( numeric.rms( (acqGait.GetPoint("RKneeMoment").GetValues()[init:end, :] - acqGait.GetPoint("RKneeMoment_cgm1_6dof").GetValues()[init:end, :] ), axis=0), momentArrayThreshold) np.testing.assert_array_less( numeric.rms(( acqGait.GetPoint("RAnkleMoment").GetValues()[init:end, :] - acqGait.GetPoint("RAnkleMoment_cgm1_6dof").GetValues()[init:end, :] ), axis=0), momentArrayThreshold) np.testing.assert_array_less( numeric.rms(( acqGait.GetPoint("LHipMoment").GetValues()[init:end, :] - acqGait.GetPoint("LHipMoment_cgm1_6dof").GetValues()[init:end, :]), axis=0), momentArrayThreshold) np.testing.assert_array_less( numeric.rms( (acqGait.GetPoint("LKneeMoment").GetValues()[init:end, :] - acqGait.GetPoint("LKneeMoment_cgm1_6dof").GetValues()[init:end, :] ), axis=0), momentArrayThreshold) np.testing.assert_array_less( numeric.rms(( acqGait.GetPoint("LAnkleMoment").GetValues()[init:end, :] - acqGait.GetPoint("LAnkleMoment_cgm1_6dof").GetValues()[init:end, :] ), axis=0), momentArrayThreshold) powerThreshold = powerThreshold np.testing.assert_array_less( numeric.rms( (acqGait.GetPoint("LHipPower").GetValues()[init:end, :] - acqGait.GetPoint("LHipPower_cgm1_6dof").GetValues()[init:end, :]), axis=0)[2], powerThreshold) np.testing.assert_array_less( numeric.rms(( acqGait.GetPoint("LKneePower").GetValues()[init:end, :] - acqGait.GetPoint("LKneePower_cgm1_6dof").GetValues()[init:end, :]), axis=0)[2], powerThreshold) np.testing.assert_array_less( numeric.rms( (acqGait.GetPoint("LAnklePower").GetValues()[init:end, :] - acqGait.GetPoint("LAnklePower_cgm1_6dof").GetValues()[init:end, :] ), axis=0)[2], powerThreshold) np.testing.assert_array_less( numeric.rms( (acqGait.GetPoint("RHipPower").GetValues()[init:end, :] - acqGait.GetPoint("RHipPower_cgm1_6dof").GetValues()[init:end, :]), axis=0)[2], powerThreshold) np.testing.assert_array_less( numeric.rms(( acqGait.GetPoint("RKneePower").GetValues()[init:end, :] - acqGait.GetPoint("RKneePower_cgm1_6dof").GetValues()[init:end, :]), axis=0)[2], powerThreshold) np.testing.assert_array_less( numeric.rms( (acqGait.GetPoint("RAnklePower").GetValues()[init:end, :] - acqGait.GetPoint("RAnklePower_cgm1_6dof").GetValues()[init:end, :] ), axis=0)[2], powerThreshold)
def compute(self,analysis,normativeData): gvs = dict() nLeftCycles,nRightCycles = analysis.getKinematicCycleNumbers() # --- MAP --- # left cycles for label,context in self.matchingNormativeDataLabel.keys(): matchingNormativeDataLabel = self.matchingNormativeDataLabel[label,context] if context == "Left": left_rms_local = np.zeros((nLeftCycles,3)) for i in range(0,nLeftCycles): values = analysis.kinematicStats.data[label, context]["values"][i] valuesNorm = normativeData[matchingNormativeDataLabel]["mean"] if valuesNorm.shape[0] == 51: rms = numeric.rms(values[0:101:2]-valuesNorm,axis=0) else: rms = numeric.rms(values-valuesNorm,axis=0) left_rms_local[i,:] = rms gvs[label,context]=left_rms_local # right cycles for label,context in self.matchingNormativeDataLabel.keys(): matchingNormativeDataLabel = self.matchingNormativeDataLabel[label,context] if context == "Right": right_rms_local = np.zeros((nRightCycles,3)) for i in range(0,nRightCycles): values = analysis.kinematicStats.data[label, context]["values"][i] valuesNorm = normativeData[matchingNormativeDataLabel]["mean"] if valuesNorm.shape[0] == 51: rms = numeric.rms(values[0:101:2]-valuesNorm,axis=0) else: rms = numeric.rms(values-valuesNorm,axis=0) right_rms_local[i,:] = rms gvs[label,context]=right_rms_local # --- GPS --- # number of axis. 15 according articles ( left ) n_axis =0 for axis in self.axes: n_axis = n_axis + len(self.axes[axis]) # computation of rms for left cycles left_rms_global = np.zeros((nLeftCycles,n_axis)) for i in range(0,nLeftCycles): cumAxis =0 for label,context in gvs.keys(): if context == "Left": axisIndex = self.axes[self.matchingNormativeDataLabel[label,context]] # use of the tip here for axis in axisIndex: left_rms_global[i,cumAxis] = gvs[label,context][i,axis] cumAxis+=1 # computation of rms for right cycles right_rms_global = np.zeros((nRightCycles,n_axis)) for i in range(0,nRightCycles): cumAxis =0 for label,context in gvs.keys(): if context == "Right": axisIndex = self.axes[self.matchingNormativeDataLabel[label,context]] for axis in axisIndex: right_rms_global[i,cumAxis] = gvs[label,context][i,axis] cumAxis+=1 # output dictionnary outDict_gvs = dict() outDict_gps_context = dict() outDict_gps = dict() for label,context in self.matchingNormativeDataLabel.keys(): outDict_gvs[label,context]={'mean':np.mean(gvs[label, context],axis=0), 'std':np.std(gvs[label, context],axis=0), 'median': np.median(gvs[label, context],axis=0), 'values':gvs[label,context]} for context in ["Left","Right"]: gpsValues = left_rms_global if context == "Left" else right_rms_global # construction of the global dictionnary outputs outDict_gps_context[context]={'mean':np.array([np.mean(gpsValues.mean(axis=1))]), 'std':np.array([np.std(gpsValues.mean(axis=1))]), 'median': np.array([np.median(gpsValues.mean(axis=1))]), 'values': gpsValues.mean(axis=1)} overall_gps_values = np.concatenate((outDict_gps_context["Right"]["values"],outDict_gps_context["Left"]["values"])) outDict_gps={'mean':np.array([np.mean(overall_gps_values)]), 'std':np.array([np.std(overall_gps_values)]), 'median': np.array([np.median(overall_gps_values)]), 'values': overall_gps_values} return outDict_gvs, outDict_gps_context,outDict_gps
def test_point_rms(acq, RefLabel, LabelToTest, threshold): np.testing.assert_array_less( numeric.rms( (acq.GetPoint(utils.str(RefLabel)).GetValues() - acq.GetPoint(utils.str(LabelToTest)).GetValues()[init:end, :]), axis=0), threshold)