Beispiel #1
0
    def __init__(self, acq, markers=None):
        self.acq = acq

        self.markers = markers if markers is not None else btkTools.GetMarkerNames(
            acq)

        self.state = True
Beispiel #2
0
    def test_functions(self):
        filename = pyCGM2.TEST_DATA_PATH + "LowLevel\\IO\\Hånnibøl_c3d\\gait1.c3d"
        acq = btkTools.smartReader(filename, translators=None)

        btkTools.GetMarkerNames(acq)
        btkTools.findNearestMarker(acq, 0, "LASI")
        btkTools.GetAnalogNames(acq)
        btkTools.isGap(acq, "LASI")
        btkTools.findMarkerGap(acq)
        btkTools.isPointExist(acq, "LASI")
        btkTools.isPointsExist(acq, ["LASI", "RASI"])

        btkTools.clearPoints(acq, ["LASI", "RASI"])
        btkTools.checkFirstAndLastFrame(acq, "LASI")
        btkTools.isGap_inAcq(acq, ["LASI", "RASI"])
        btkTools.findValidFrames(acq, ["LASI", "RASI"])

        btkTools.checkMultipleSubject(acq)
        btkTools.checkMarkers(acq, ["LASI", "RASI"])
        btkTools.clearEvents(acq, ["Foot Strike"])
        btkTools.modifyEventSubject(acq, "Hän")
        btkTools.modifySubject(acq, "Han")

        btkTools.getVisibleMarkersAtFrame(acq, ["LASI", "RASI"], 0)
        btkTools.isAnalogExist(acq, "emg-Hän")
        btkTools.createZeros(acq, ["LASI", "RASI"])
        btkTools.constructEmptyMarker(acq, "zéros", desc="Hän")

        btkTools.getStartEndEvents(acq, "Left")

        btkTools.changeSubjectName(acq, "Hän")
        btkTools.smartGetMetadata(acq, "SUBJECTS", "USED")
        btkTools.smartSetMetadata(acq, "SUBJECTS", "USED", 0, "Hän")
Beispiel #3
0
    def __init__(self, acq, markers=None, title=None):
        self.acq = acq
        self.markers = markers if markers is not None else btkTools.GetMarkerNames(
            acq)
        self.exceptionMode = False
        self.state = True

        self.title = "Marker position" if title is None else title
Beispiel #4
0
    def __init__(self, acq, markers=None, title=None, plot=False):
        self.acq = acq
        self.markers = markers if markers is not None else btkTools.GetMarkerNames(
            acq)
        self.exceptionMode = False
        self.title = "Swapping marker" if title is None else title

        self.state = True
        self.plot = plot
Beispiel #5
0
    def fill(self, acq):
        logging.info("----LowDimensionalKalmanFilter gap filling----")
        btkmarkersLoaded = btkTools.GetMarkerNames(acq)
        ff = acq.GetFirstFrame()
        lf = acq.GetLastFrame()
        pfn = acq.GetPointFrameNumber()

        btkmarkers = []
        for ml in btkmarkersLoaded:
            if btkTools.isPointExist(acq, ml):
                btkmarkers.append(ml)

        # --------

        logging.debug("Populating data matrix")
        rawDatabtk = np.zeros((pfn, len(btkmarkers) * 3))
        for i in range(0, len(btkmarkers)):
            values = acq.GetPoint(btkmarkers[i]).GetValues()
            residualValues = acq.GetPoint(btkmarkers[i]).GetResiduals()
            rawDatabtk[:, 3 * i - 3] = values[:, 0]
            rawDatabtk[:, 3 * i - 2] = values[:, 1]
            rawDatabtk[:, 3 * i - 1] = values[:, 2]
            E = residualValues[:, 0]
            rawDatabtk[np.asarray(E) == -1, 3 * i - 3] = np.nan
            rawDatabtk[np.asarray(E) == -1, 3 * i - 2] = np.nan
            rawDatabtk[np.asarray(E) == -1, 3 * i - 1] = np.nan

        Y2 = self._smooth(rawDatabtk, tol=1e-2, sigR=1e-3, keepOriginal=True)

        logging.debug("writing trajectories")

        # Create new smoothed trjectories
        filledMarkers = list()
        for i in range(0, len(btkmarkers)):
            targetMarker = btkmarkers[i]
            if btkTools.isGap(acq, targetMarker):
                logging.info("marker (%s) --> filled" % (targetMarker))
                filledMarkers.append(targetMarker)
                val_final = np.zeros((pfn, 3))
                val_final[:, 0] = Y2[:, 3 * i - 3]
                val_final[:, 1] = Y2[:, 3 * i - 2]
                val_final[:, 2] = Y2[:, 3 * i - 1]
                btkTools.smartAppendPoint(acq, targetMarker, val_final)
        logging.info(
            "----LowDimensionalKalmanFilter gap filling [complete]----")

        return acq, filledMarkers
Beispiel #6
0
    def nexus_x2d(cls):

        NEXUS = ViconNexus.ViconNexus()
        NEXUS_PYTHON_CONNECTED = NEXUS.Client.IsConnected()

        DATA_PATH = "C:\\Users\\HLS501\\Documents\\VICON DATA\\pyCGM2-Data\\operations\\gapFilling\\gaitWithGaps_withX2d\\"
        filenameNoExt = "gait_GAP"
        NEXUS.OpenTrial(str(DATA_PATH + filenameNoExt), 30)

        acq_filled = btkTools.smartReader(
            str(DATA_PATH + "gait_GAP.-moGap.c3d"))

        subject = NEXUS.GetSubjectNames()[0]
        print "Gap filling for subject ", subject

        markersLoaded = NEXUS.GetMarkerNames(
            subject)  # nexus2.7 return all makers, even calibration only
        frames = NEXUS.GetFrameCount()

        markers = []
        for i in range(0, len(markersLoaded)):
            data = NEXUS.GetTrajectory(subject, markersLoaded[i])
            if data != ([], [], [], []):
                markers.append(markersLoaded[i])

        #---------
        acq = btkTools.smartReader(str(DATA_PATH + filenameNoExt + ".c3d"))
        btkmarkersLoaded = btkTools.GetMarkerNames(acq)
        ff = acq.GetFirstFrame()
        lf = acq.GetLastFrame()
        pfn = acq.GetPointFrameNumber()

        btkmarkers = []
        for ml in btkmarkersLoaded:
            if btkTools.isPointExist(acq, ml):
                btkmarkers.append(ml)
        #---------

        print "Populating data matrix"
        rawData = np.zeros((frames, len(markers) * 3))
        for i in range(0, len(markers)):
            print i
            rawData[:, 3 * i -
                    3], rawData[:, 3 * i -
                                2], rawData[:, 3 * i -
                                            1], E = NEXUS.GetTrajectory(
                                                subject, markers[i])
            rawData[np.asarray(E) == 0, 3 * i - 3] = np.nan
            rawData[np.asarray(E) == 0, 3 * i - 2] = np.nan
            rawData[np.asarray(E) == 0, 3 * i - 1] = np.nan

        Y = smooth(rawData, tol=1e-2, sigR=1e-3, keepOriginal=True)
        print "Writing new trajectories"
        # Create new smoothed trjectories
        for i in range(0, len(markers)):
            if markers[i] == "LTHAD":
                E = np.ones((len(E), 1)).tolist()
                val0 = Y[:, 3 * i - 3].tolist()
                val1 = Y[:, 3 * i - 2].tolist()
                val2 = Y[:, 3 * i - 1].tolist()
            #NEXUS.SetTrajectory(subject,markers[i],Y[:,3*i-3].tolist(),Y[:,3*i-2].tolist(),Y[:,3*i-1].tolist(),E)
        print "Done"

        # --------
        print "Populating data matrix"
        rawDatabtk = np.zeros((pfn, len(btkmarkers) * 3))
        for i in range(0, len(btkmarkers)):
            values = acq.GetPoint(btkmarkers[i]).GetValues()
            residualValues = acq.GetPoint(btkmarkers[i]).GetResiduals()
            rawDatabtk[:, 3 * i - 3] = values[:, 0]
            rawDatabtk[:, 3 * i - 2] = values[:, 1]
            rawDatabtk[:, 3 * i - 1] = values[:, 2]
            E = residualValues[:, 0]
            rawDatabtk[np.asarray(E) == -1, 3 * i - 3] = np.nan
            rawDatabtk[np.asarray(E) == -1, 3 * i - 2] = np.nan
            rawDatabtk[np.asarray(E) == -1, 3 * i - 1] = np.nan

        Y2 = smooth(rawDatabtk, tol=1e-2, sigR=1e-3, keepOriginal=True)
        print "Writing new trajectories"
        # Create new smoothed trjectories
        for i in range(0, len(btkmarkers)):
            targetMarker = btkmarkers[i]
            if btkTools.isGap(acq, targetMarker):
                val_final = np.zeros((pfn, 3))
                val_final[:, 0] = Y2[:, 3 * i - 3]
                val_final[:, 1] = Y2[:, 3 * i - 2]
                val_final[:, 2] = Y2[:, 3 * i - 1]
                btkTools.smartAppendPoint(acq, targetMarker, val_final)
                nexusTools.setTrajectoryFromAcq(NEXUS, subject, targetMarker,
                                                acq)
        print "Done"