Exemplo n.º 1
0
    def detect(self, acq):
        """
        """
        ff = acq.GetFirstFrame()

        progressionAxis, forwardProgression, globalFrame = btkTools.findProgression(
            acq, "LANK")
        longAxisIndex = 0 if progressionAxis == "X" else 1

        sacrum = (acq.GetPoint("LPSI").GetValues() +
                  acq.GetPoint("RPSI").GetValues()) / 2.0

        #Left
        heel_left = acq.GetPoint("LHEE").GetValues()
        toe_left = acq.GetPoint("LTOE").GetValues()

        diffHeel_left = heel_left - sacrum
        diffToe_left = toe_left - sacrum

        #Right
        heel_right = acq.GetPoint("RHEE").GetValues()
        toe_right = acq.GetPoint("RTOE").GetValues()

        diffHeel_right = heel_right - sacrum
        diffToe_right = toe_right - sacrum

        if forwardProgression:
            indexes_fs_left = detect_peaks.detect_peaks(
                diffHeel_left[:, longAxisIndex]) + ff
            indexes_fo_left = detect_peaks.detect_peaks(
                -diffToe_left[:, longAxisIndex]) + ff
        else:
            indexes_fs_left = detect_peaks.detect_peaks(
                -diffHeel_left[:, longAxisIndex]) + ff
            indexes_fo_left = detect_peaks.detect_peaks(
                diffToe_left[:, longAxisIndex]) + ff

        if forwardProgression:
            indexes_fs_right = detect_peaks.detect_peaks(
                diffHeel_right[:, longAxisIndex]) + ff
            indexes_fo_right = detect_peaks.detect_peaks(
                -diffToe_right[:, longAxisIndex]) + ff
        else:
            indexes_fs_right = detect_peaks.detect_peaks(
                -diffHeel_right[:, longAxisIndex]) + ff
            indexes_fo_right = detect_peaks.detect_peaks(
                diffToe_right[:, longAxisIndex]) + ff

        print indexes_fs_left
        print indexes_fs_left + self.footStrikeOffset
        return indexes_fs_left + self.footStrikeOffset, indexes_fo_left + self.footOffOffset, indexes_fs_right + self.footStrikeOffset, indexes_fo_right + self.footOffOffset
Exemplo n.º 2
0
    def _applyMethod(self, values, method, iArgs, frame0):
        if method == "mean":
            val = np.mean(values)
        elif method == "range":
            val = np.abs(np.max(values) - np.min(values))
        elif method == "min":
            val = np.min(values)
        elif method == "max":
            val = np.max(values)
        elif method == "timing-find":
            arg = float(iArgs)
            f = values
            g = np.ones(len(values)) * arg
            idx = np.argwhere(np.diff(np.sign(f - g)) != 0).reshape(-1) + 0

            # -- display curve
            # x = np.arange(0, len(values))
            # plt.plot( f, '-+')
            # plt.plot( g, '-')
            # plt.plot(x[idx], f[idx], 'ro')
            # plt.show()

            if idx.shape[0] == 0:
                val = "NA"
            else:
                val = frame0 + idx[0]

        elif method == "threshold":
            args = iArgs.split(",")
            n = len(values)
            count = 0
            val = "False"
            for value in values:
                if args[1] == "greater":
                    if value > float(args[0]):
                        count += 1
                if args[1] == "lesser":
                    if value < float(args[0]):
                        count += 1

            percentage = (count / n) / 100
            if percentage >= float(args[2]):
                val = "True"

        elif method == "getValue":
            index = int(iArgs)
            val = values[index]

        elif method == "timing-min":
            val = frame0 + np.argmin(values)

        elif method == "timing-max":
            val = frame0 + np.argmax(values)

        elif method == "slope":
            val = values[-1] - values[0]

        elif method == "peak":
            args = iArgs.split(",")
            indexes = detect_peaks(values,
                                   mph=float(args[0]),
                                   mpd=float(args[1]),
                                   show=False,
                                   valley=False)
            if indexes.shape[0] > 2:
                val = "True"
            else:
                val = "False"
        else:
            val = "NA"
        return val
Exemplo n.º 3
0
    def detect(self, acq):
        """
        """
        ff = acq.GetFirstFrame()

        if btkTools.isPointsExist(
                acq, ["LPSI", "RPSI", "LHEE", "LTOE", "RHEE", "RTOE"]):
            pfp = progressionFrame.PelvisProgressionFrameProcedure()
            pff = progressionFrame.ProgressionFrameFilter(acq, pfp)
            pff.compute()
            progressionAxis = pff.outputs["progressionAxis"]
            globalFrame = pff.outputs["globalFrame"]
            forwardProgression = pff.outputs["forwardProgression"]

            longAxisIndex = 0 if progressionAxis == "X" else 1

            sacrum = (acq.GetPoint("LPSI").GetValues() +
                      acq.GetPoint("RPSI").GetValues()) / 2.0

            #Left
            heel_left = acq.GetPoint("LHEE").GetValues()
            toe_left = acq.GetPoint("LTOE").GetValues()

            diffHeel_left = heel_left - sacrum
            diffToe_left = toe_left - sacrum

            #Right
            heel_right = acq.GetPoint("RHEE").GetValues()
            toe_right = acq.GetPoint("RTOE").GetValues()

            diffHeel_right = heel_right - sacrum
            diffToe_right = toe_right - sacrum

            if forwardProgression:
                indexes_fs_left = detect_peaks.detect_peaks(
                    diffHeel_left[:, longAxisIndex]) + ff
                indexes_fo_left = detect_peaks.detect_peaks(
                    -diffToe_left[:, longAxisIndex]) + ff
            else:
                indexes_fs_left = detect_peaks.detect_peaks(
                    -diffHeel_left[:, longAxisIndex]) + ff
                indexes_fo_left = detect_peaks.detect_peaks(
                    diffToe_left[:, longAxisIndex]) + ff

            if forwardProgression:
                indexes_fs_right = detect_peaks.detect_peaks(
                    diffHeel_right[:, longAxisIndex]) + ff
                indexes_fo_right = detect_peaks.detect_peaks(
                    -diffToe_right[:, longAxisIndex]) + ff
            else:
                indexes_fs_right = detect_peaks.detect_peaks(
                    -diffHeel_right[:, longAxisIndex]) + ff
                indexes_fo_right = detect_peaks.detect_peaks(
                    diffToe_right[:, longAxisIndex]) + ff

            return indexes_fs_left + self.footStrikeOffset, indexes_fo_left + self.footOffOffset, indexes_fs_right + self.footStrikeOffset, indexes_fo_right + self.footOffOffset

        else:
            logging.error(
                "[pyCGM2]: Zeni event detector impossible to run. Pelvic LPSI-RPSI or foot markers(HEE or TOE) are missing "
            )
            return 0