Exemple #1
0
def main():

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

    if NEXUS_PYTHON_CONNECTED:  # run Operation

        DATA_PATH, filenameLabelledNoExt = NEXUS.GetTrialName()

        logging.info("data Path: " + DATA_PATH)
        logging.info("file: " + filenameLabelledNoExt)

        subject = NEXUS.GetSubjectNames()[0]
        logging.info("Gap filling for subject %s" % (subject))

        # btkAcq builder
        nacf = nexusFilters.NexusConstructAcquisitionFilter(
            DATA_PATH, filenameLabelledNoExt, subject)
        acq = nacf.build()

        #acq = btkTools.smartReader(str(DATA_PATH+filenameLabelledNoExt+".c3d"))

        gfp = gapFilling.LowDimensionalKalmanFilterProcedure()
        gff = gapFilling.GapFillingFilter(gfp, acq)
        gff.fill()

        filledAcq = gff.getFilledAcq()
        filledMarkers = gff.getFilledMarkers()

        for marker in filledMarkers:
            nexusTools.setTrajectoryFromAcq(NEXUS, subject, marker, filledAcq)

    else:
        raise Exception("NO Nexus connection. Turn on Nexus")
Exemple #2
0
def main():

    parser = argparse.ArgumentParser(description='')
    parser.add_argument('--markers', nargs='+')
    parser.add_argument('--noCorrection',
                        action='store_true',
                        help='disable correction')

    args = parser.parse_args()

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

    if NEXUS_PYTHON_CONNECTED:  # run Operation

        DATA_PATH, filename = NEXUS.GetTrialName()

        LOGGER.logger.info(" Path: " + DATA_PATH)
        LOGGER.logger.info(" file: " + filename)

        # --------------------------SUBJECT ------------------------------------
        subjects = NEXUS.GetSubjectNames()
        subject = nexusTools.getActiveSubject(
            NEXUS)  #checkActivatedSubject(NEXUS,subjects)
        Parameters = NEXUS.GetSubjectParamNames(subject)

        # --------------------------PULL ------------------------------------
        nacf = nexusFilters.NexusConstructAcquisitionFilter(
            DATA_PATH, filename, subject)
        acq = nacf.build()

        # --------------------------process ------------------------------------
        # Work with BTK Here

        markers = args.markers
        # markers = cgm.CGM1.LOWERLIMB_TRACKING_MARKERS

        madp = AnomalyDetectionProcedure.MarkerAnomalyDetectionRollingProcedure(
            markers, plot=False, window=5, threshold=3)
        adf = AnomalyFilter.AnomalyDetectionFilter(acq, filename, madp)
        anomaly = adf.run()

        if not args.noCorrection:
            macp = AnomalyCorrectionProcedure.MarkerAnomalyCorrectionProcedure(
                markers, anomaly["Output"], plot=False, distance_threshold=20)
            acf = AnomalyFilter.AnomalyCorrectionFilter(acq, filename, macp)
            acqo = acf.run()

            # --------------------------PUSH ------------------------------------
            for marker in markers:
                nexusTools.setTrajectoryFromAcq(NEXUS, subject, marker, acqo)
Exemple #3
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"