Esempio n. 1
0
def temporalPlot(figAxis,
                 trial,
                 pointLabel,
                 axis,
                 pointLabelSuffix=None,
                 color=None,
                 title=None,
                 xlabel=None,
                 ylabel=None,
                 ylim=None,
                 legendLabel=None,
                 customLimits=None):
    '''

        **Description :** plot descriptive statistical (average and sd corridor) gait traces from a pyCGM2.Processing.analysis.Analysis instance

        :Parameters:
             - `figAxis` (matplotlib::Axis )
             - `trial` (ma.Trial) - a Structure item of an Analysis instance built from AnalysisFilter

        :Return:
            - matplotlib figure

        **Usage**

        .. code:: python

    '''

    pointLabel = pointLabel + "_" + pointLabelSuffix if pointLabelSuffix is not None else pointLabel

    flag = trialTools.isTimeSequenceExist(trial, pointLabel)

    if flag:
        timeseq = trial.findChild(ma.T_TimeSequence, pointLabel)
        lines = figAxis.plot(timeseq.data()[:, axis], '-', color=color)

    if legendLabel is not None and flag: lines[0].set_label(legendLabel)
    if title is not None: figAxis.set_title(title, size=8)
    figAxis.tick_params(axis='x', which='major', labelsize=6)
    figAxis.tick_params(axis='y', which='major', labelsize=6)
    if xlabel is not None: figAxis.set_xlabel(xlabel, size=8)
    if ylabel is not None: figAxis.set_ylabel(ylabel, size=8)
    if ylim is not None: figAxis.set_ylim(ylim)

    if flag:
        for ev in trial.findChildren(ma.T_Event):
            colorContext = plotUtils.colorContext(ev.context())
            if ev.name() == "Foot Strike":
                figAxis.axvline(x=(ev.time() - timeseq.startTime()) *
                                timeseq.sampleRate(),
                                color=colorContext,
                                linestyle="-")
            elif ev.name() == "Foot Off":
                figAxis.axvline(x=(ev.time() - timeseq.startTime()) *
                                timeseq.sampleRate(),
                                color=colorContext,
                                linestyle="--")
Esempio n. 2
0
    def getAnalogTimeSequenceData(self,analogLabel):
        """
            Get analog data of the cycle

            :Parameters:
                - `analogLabel` (str) - analog Label

        """
        if trialTools.isTimeSequenceExist(self.trial,analogLabel):
            return  self.trial.findChild(ma.T_TimeSequence, utils.str(analogLabel)).data()[int((self.begin-self.firstFrame) * self.appf) : int((self.end-self.firstFrame+1) * self.appf),:]
        else:
            logging.debug("[pyCGM2] the Analog Label %s doesn t exist in %s" % (analogLabel,self.trial.name()))
            return None
Esempio n. 3
0
    def getPointTimeSequenceData(self,pointLabel):
        """
            Get temporal point data of the cycle

            :Parameters:
                - `pointLabel` (str) - point Label

        """

        if trialTools.isTimeSequenceExist(self.trial,pointLabel):
            return self.trial.findChild(ma.T_TimeSequence, utils.str(pointLabel)).data()[self.begin-self.firstFrame:self.end-self.firstFrame+1,0:3] # 0.3 because openma::Ts includes a forth column (i.e residual)
        else:
            logging.debug("[pyCGM2] the point Label %s doesn t exist in %s" % (pointLabel,self.trial.name()))
            return None
Esempio n. 4
0
File: cycle.py Progetto: orat/pyCGM2
    def getPointTimeSequenceData(self, pointLabel):
        """
            Get temporal point data of the cycle

            :Parameters:
                - `pointLabel` (str) - point Label

        """

        if trialTools.isTimeSequenceExist(self.trial, pointLabel):
            return self.trial.findChild(ma.T_TimeSequence, pointLabel).data(
            )[self.begin - self.firstFrame:self.end - self.firstFrame + 1, 0:
              3]  # 0.3 because openma::Ts includes a forth column (i.e residual)
        else:
            raise Exception("[pyCGM2] marker %s doesn t exist" % pointLabel)
Esempio n. 5
0
File: cycle.py Progetto: orat/pyCGM2
    def getAnalogTimeSequenceData(self, analogLabel):
        """
            Get analog data of the cycle

            :Parameters:
                - `analogLabel` (str) - analog Label

        """

        if trialTools.isTimeSequenceExist(self.trial, analogLabel):
            return self.trial.findChild(
                ma.T_TimeSequence,
                analogLabel).data()[int((self.begin - self.firstFrame) *
                                        self.appf):int((self.end -
                                                        self.firstFrame + 1) *
                                                       self.appf), :]
        else:
            raise Exception("[pyCGM2] Analog %s doesn t exist" % analogLabel)
Esempio n. 6
0
    def __computeSpatioTemporalParameter(self):

        duration = np.divide((self.end-self.begin),self.pointfrequency)
        stanceDuration=np.divide(np.abs(self.m_contraFO - self.begin) , self.pointfrequency)
        swingDuration=np.divide(np.abs(self.m_contraFO - self.end) , self.pointfrequency)
        stepDuration=np.divide(np.abs(self.m_oppositeFS - self.begin) , self.pointfrequency)

        pst = ma.Node("stp",self)
        pst.setProperty("duration", duration)
        pst.setProperty("cadence", np.divide(60.0,duration))

        pst.setProperty("stanceDuration", stanceDuration)
        pst.setProperty("swingDuration", swingDuration)
        pst.setProperty("stepDuration", stepDuration)
        pst.setProperty("doubleStance1Duration", np.divide(np.abs(self.m_oppositeFO - self.begin) , self.pointfrequency))
        pst.setProperty("doubleStance2Duration", np.divide(np.abs(self.m_contraFO - self.m_oppositeFS) , self.pointfrequency))
        pst.setProperty("simpleStanceDuration", np.divide(np.abs(self.m_oppositeFO - self.m_oppositeFS) , self.pointfrequency))


        pst.setProperty("stancePhase", round(np.divide(stanceDuration,duration)*100))
        pst.setProperty("swingPhase", round(np.divide(swingDuration,duration)*100 ))
        pst.setProperty("doubleStance1", round(np.divide(np.divide(np.abs(self.m_oppositeFO - self.begin) , self.pointfrequency),duration)*100))
        pst.setProperty("doubleStance2", round(np.divide(np.divide(np.abs(self.m_contraFO - self.m_oppositeFS) , self.pointfrequency),duration)*100))
        pst.setProperty("simpleStance", round(np.divide(np.divide(np.abs(self.m_oppositeFO - self.m_oppositeFS) , self.pointfrequency),duration)*100))
        pst.setProperty("stepPhase", round(np.divide(stepDuration,duration)*100))
        #pst.setProperty("simpleStance3 ",15.0 )
        if self.context == "Left":

            if trialTools.isTimeSequenceExist(self.trial,"LHEE") and trialTools.isTimeSequenceExist(self.trial,"RHEE") and trialTools.isTimeSequenceExist(self.trial,"LTOE"):


                progressionAxis,forwardProgression,globalFrame = trialTools.findProgression(self.trial,"LHEE")
                longitudinal_axis=0  if progressionAxis =="X" else 1
                lateral_axis=1  if progressionAxis =="X" else 0


                strideLength=np.abs(self.getPointTimeSequenceData("LHEE")[self.end-self.begin,longitudinal_axis] -\
                                    self.getPointTimeSequenceData("LHEE")[0,longitudinal_axis])/1000.0
                pst.setProperty("strideLength", strideLength)

                stepLength = np.abs(self.getPointTimeSequenceData("RHEE")[self.m_oppositeFS-self.begin,longitudinal_axis] -\
                                    self.getPointTimeSequenceData("LHEE")[0,longitudinal_axis])/1000.0
                pst.setProperty("stepLength", stepLength)

                strideWidth = np.abs(self.getPointTimeSequenceData("LTOE")[self.end-self.begin,lateral_axis] -\
                                     self.getPointTimeSequenceData("RHEE")[0,lateral_axis])/1000.0
                pst.setProperty("strideWidth", strideWidth)

                pst.setProperty("speed",np.divide(strideLength,duration))


        if self.context == "Right":

            if trialTools.isTimeSequenceExist(self.trial,"RHEE") and trialTools.isTimeSequenceExist(self.trial,"LHEE") and trialTools.isTimeSequenceExist(self.trial,"RTOE"):

                progressionAxis,forwardProgression,globalFrame = trialTools.findProgression(self.trial,"RHEE")

                longitudinal_axis=0  if progressionAxis =="X" else 1
                lateral_axis=1  if progressionAxis =="X" else 0

                strideLength=np.abs(self.getPointTimeSequenceData("RHEE")[self.end-self.begin,longitudinal_axis] -\
                                    self.getPointTimeSequenceData("RHEE")[0,longitudinal_axis])/1000.0

                strideWidth = np.abs(self.getPointTimeSequenceData("RTOE")[self.end-self.begin,lateral_axis] -\
                                 self.getPointTimeSequenceData("LHEE")[0,lateral_axis])/1000.0

                pst.setProperty("strideLength", strideLength)
                pst.setProperty("strideWidth", strideWidth)

                stepLength = np.abs(self.getPointTimeSequenceData("RHEE")[self.m_oppositeFS-self.begin,longitudinal_axis] -\
                                    self.getPointTimeSequenceData("LHEE")[0,longitudinal_axis])/1000.0
                pst.setProperty("stepLength", stepLength)

                pst.setProperty("speed",np.divide(strideLength,duration))