Exemple #1
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")
Exemple #2
0
def calibration2Dof(model, DATA_PATH, reconstructFilenameLabelled, translators,
                    side, beginFrame, endFrame, jointRange, **kwargs):

    # --- btk acquisition ----
    if "forceBtkAcq" in kwargs.keys():
        acqFunc = kwargs["forceBtkAcq"]
    else:
        acqFunc = btkTools.smartReader(
            (DATA_PATH + reconstructFilenameLabelled))

    btkTools.checkMultipleSubject(acqFunc)
    acqFunc = btkTools.applyTranslators(acqFunc, translators)

    # filtering
    # -----------------------
    if "fc_lowPass_marker" in kwargs.keys(
    ) and kwargs["fc_lowPass_marker"] != 0:
        trackingMarkers = model.getTrackingMarkers(acqFunc)
        fc = kwargs["fc_lowPass_marker"]
        order = 4
        if "order_lowPass_marker" in kwargs.keys():
            order = kwargs["order_lowPass_marker"]
        signal_processing.markerFiltering(acqFunc,
                                          trackingMarkers,
                                          order=order,
                                          fc=fc)

    #---get frame range of interest---
    ff = acqFunc.GetFirstFrame()
    lf = acqFunc.GetLastFrame()

    # motion
    if side is None:
        side = detectSide(acqFunc, "LANK", "RANK")
        LOGGER.logger.info("Detected motion side : %s" % (side))

    start, end = btkTools.getStartEndEvents(acqFunc, side)

    if start is not None:
        LOGGER.logger.info("Start event detected")
        initFrame = start
    else:
        initFrame = beginFrame if beginFrame is not None else ff

    if end is not None:
        LOGGER.logger.info("End event detected")
        endFrame = end
    else:
        endFrame = endFrame if endFrame is not None else lf

    iff = initFrame - ff
    ilf = endFrame - ff

    if model.version in ["CGM1.0", "CGM1.1", "CGM2.1", "CGM2.2"]:
        validFrames, vff, vlf = btkTools.findValidFrames(
            acqFunc, cgm.CGM1.LOWERLIMB_TRACKING_MARKERS)

    # --------------------------RESET OF THE STATIC File---------
    # load btkAcq from static file
    staticFilename = model.m_staticFilename
    acqStatic = btkTools.smartReader((DATA_PATH + staticFilename))
    btkTools.checkMultipleSubject(acqStatic)
    acqStatic = btkTools.applyTranslators(acqStatic, translators)

    # initial calibration ( i.e calibration from Calibration operation)
    leftFlatFoot = model.m_properties["CalibrationParameters"]["leftFlatFoot"]
    rightFlatFoot = model.m_properties["CalibrationParameters"][
        "rightFlatFoot"]
    headFlat = model.m_properties["CalibrationParameters"]["headFlat"]

    markerDiameter = model.m_properties["CalibrationParameters"][
        "markerDiameter"]

    if side == "Left":
        # remove other functional calibration
        model.mp_computed["LeftKneeFuncCalibrationOffset"] = 0

    if side == "Right":
        # remove other functional calibration
        model.mp_computed["RightKneeFuncCalibrationOffset"] = 0

    # no rotation on both thigh - re init anatonical frame
    scp = modelFilters.StaticCalibrationProcedure(model)
    modelFilters.ModelCalibrationFilter(
        scp,
        acqStatic,
        model,
        leftFlatFoot=leftFlatFoot,
        rightFlatFoot=rightFlatFoot,
        headFlat=headFlat,
        markerDiameter=markerDiameter).compute()

    if model.version in ["CGM1.0", "CGM1.1", "CGM2.1", "CGM2.2"]:

        modMotion = modelFilters.ModelMotionFilter(
            scp, acqFunc, model, enums.motionMethod.Determinist)
        modMotion.compute()

    elif model.version in ["CGM2.3", "CGM2.4", "CGM2.5"]:
        if side == "Left":
            thigh_markers = model.getSegment("Left Thigh").m_tracking_markers
            shank_markers = model.getSegment("Left Shank").m_tracking_markers

        elif side == "Right":
            thigh_markers = model.getSegment("Right Thigh").m_tracking_markers
            shank_markers = model.getSegment("Right Shank").m_tracking_markers

        validFrames, vff, vlf = btkTools.findValidFrames(
            acqFunc, thigh_markers + shank_markers)

        proximalSegmentLabel = (side + " Thigh")
        distalSegmentLabel = (side + " Shank")

        # Motion
        modMotion = modelFilters.ModelMotionFilter(
            scp, acqFunc, model, enums.motionMethod.Sodervisk)
        modMotion.segmentalCompute([proximalSegmentLabel, distalSegmentLabel])

    # calibration decorators
    modelDecorator.KneeCalibrationDecorator(model).calibrate2dof(
        side, indexFirstFrame=iff, indexLastFrame=ilf, jointRange=jointRange)

    # --------------------------FINAL CALIBRATION OF THE STATIC File---------

    # ----  Calibration
    modelFilters.ModelCalibrationFilter(
        scp,
        acqStatic,
        model,
        leftFlatFoot=leftFlatFoot,
        rightFlatFoot=rightFlatFoot,
        headFlat=headFlat,
        markerDiameter=markerDiameter).compute()

    return model, acqFunc, side
Exemple #3
0
def sara(model, DATA_PATH, reconstructFilenameLabelled, translators, side,
         beginFrame, endFrame, **kwargs):

    # --- btk acquisition ----
    if "forceBtkAcq" in kwargs.keys():
        acqFunc = kwargs["forceBtkAcq"]
    else:
        acqFunc = btkTools.smartReader(
            str(DATA_PATH + reconstructFilenameLabelled))

    btkTools.checkMultipleSubject(acqFunc)
    acqFunc = btkTools.applyTranslators(acqFunc, translators)

    #---get frame range of interest---
    ff = acqFunc.GetFirstFrame()
    lf = acqFunc.GetLastFrame()

    start, end = btkTools.getStartEndEvents(acqFunc, side)

    if start is not None:
        logging.info("Start event detected")
        initFrame = start
    else:
        initFrame = beginFrame if beginFrame is not None else ff

    if end is not None:
        logging.info("End event detected")
        endFrame = end
    else:
        endFrame = endFrame if endFrame is not None else lf

    iff = initFrame - ff
    ilf = endFrame - ff

    #---motion side of the lower limb---
    if side is None:
        side = detectSide(acqFunc, "LANK", "RANK")
        logging.info("Detected motion side : %s" % (side))

    # --------------------------RESET OF THE STATIC File---------

    # load btkAcq from static file
    staticFilename = model.m_staticFilename
    acqStatic = btkTools.smartReader(str(DATA_PATH + staticFilename))
    btkTools.checkMultipleSubject(acqStatic)
    acqStatic = btkTools.applyTranslators(acqStatic, translators)

    # initial calibration ( i.e calibration from Calibration operation)
    leftFlatFoot = model.m_properties["CalibrationParameters"]["leftFlatFoot"]
    rightFlatFoot = model.m_properties["CalibrationParameters"][
        "rightFlatFoot"]
    markerDiameter = model.m_properties["CalibrationParameters"][
        "markerDiameter"]
    headFlat = model.m_properties["CalibrationParameters"]["headFlat"]

    if side == "Left":
        model.mp_computed["LeftKneeFuncCalibrationOffset"] = 0
    if side == "Right":
        model.mp_computed["RightKneeFuncCalibrationOffset"] = 0

    # initial calibration ( zero previous KneeFunc offset on considered side )
    scp = modelFilters.StaticCalibrationProcedure(model)
    modelFilters.ModelCalibrationFilter(
        scp,
        acqStatic,
        model,
        leftFlatFoot=leftFlatFoot,
        rightFlatFoot=rightFlatFoot,
        headFlat=headFlat,
        markerDiameter=markerDiameter).compute()

    if model.version in ["CGM2.3", "CGM2.4", "CGM2.5"]:
        if side == "Left":
            thigh_markers = model.getSegment("Left Thigh").m_tracking_markers
            shank_markers = model.getSegment("Left Shank").m_tracking_markers

        elif side == "Right":
            thigh_markers = model.getSegment("Right Thigh").m_tracking_markers
            shank_markers = model.getSegment("Right Shank").m_tracking_markers

        validFrames, vff, vlf = btkTools.findValidFrames(
            acqFunc, thigh_markers + shank_markers)

        proximalSegmentLabel = str(side + " Thigh")
        distalSegmentLabel = str(side + " Shank")

        # segment Motion
        modMotion = modelFilters.ModelMotionFilter(
            scp, acqFunc, model, enums.motionMethod.Sodervisk)
        modMotion.segmentalCompute([proximalSegmentLabel, distalSegmentLabel])

        # decorator

        modelDecorator.KneeCalibrationDecorator(model).sara(
            side, indexFirstFrame=iff, indexLastFrame=ilf)

        # --------------------------FINAL CALIBRATION OF THE STATIC File---------

        modelFilters.ModelCalibrationFilter(
            scp,
            acqStatic,
            model,
            leftFlatFoot=leftFlatFoot,
            rightFlatFoot=rightFlatFoot,
            headFlat=headFlat,
            markerDiameter=markerDiameter).compute()

    return model, acqFunc, side