コード例 #1
0
ファイル: not_test_nexus.py プロジェクト: Sanardi/gaitutils
def test_fp_detection():
    """Test autodetection of forceplate contact"""
    BOTH_OK = set(['L', 'R'])
    L_OK = set(['L'])
    R_OK = set(['R'])
    NOT_OK = set()
    _nexus_open_trial('girl6v', '2015_10_22_girl6v_IN02')
    valid = detect_forceplate_events(vicon)['valid']
    assert_equal(valid, R_OK)
    _nexus_open_trial('girl6v', '2015_10_22_girl6v_IN03')
    valid = detect_forceplate_events(vicon)['valid']
    assert_equal(valid, R_OK)
    _nexus_open_trial('girl6v', '2015_10_22_girl6v_IN06')
    valid = detect_forceplate_events(vicon)['valid']
    assert_equal(valid, NOT_OK)
コード例 #2
0
ファイル: test_nexus.py プロジェクト: jjnurminen/gaitutils
def test_event_marking():
    """Test automarking of events"""
    start_nexus()
    vicon = nexus.viconnexus()
    ev_tol = 4  # tolerance for event marking (frames)
    events_dict = dict()  # ground truth with forceplate info
    events_dict['Right'] = dict()
    events_dict['Right']['Foot Strike'] = [384, 505, 616]
    events_dict['Right']['Foot Off'] = [465, 570]
    events_dict['Left'] = dict()
    events_dict['Left']['Foot Strike'] = [311, 441, 562]
    events_dict['Left']['Foot Off'] = [402, 517]
    events_dict_nofp = dict()  # ground truth without forceplate info
    events_dict_nofp['Right'] = dict()
    events_dict_nofp['Right']['Foot Strike'] = [379, 501, 613]
    events_dict_nofp['Right']['Foot Off'] = [468, 572]
    events_dict_nofp['Left'] = dict()
    events_dict_nofp['Left']['Foot Strike'] = [310, 440, 561]
    events_dict_nofp['Left']['Foot Off'] = [401, 516]

    def _events_check(events_dict):
        """Helper to check whether Nexus events are close to ground truth"""
        for context, contextdict in events_dict.items():
            for event_type, events in contextdict.items():
                nexus_events = vicon.GetEvents(vicon.GetSubjectNames()[0],
                                               context, event_type)[0]
                assert_equal(len(events), len(nexus_events))
                for j, ev in enumerate(nexus_events):
                    assert abs(ev - events[j]) <= ev_tol

    subj = 'girl6v'
    trialname = '2015_10_22_girl6v_IN02.c3d'
    trialpath = _trial_path(subj, trialname)
    nexus._open_trial(trialpath)

    # automatic thresholding (do not respect fp events)
    vicon.ClearAllEvents()
    evs = utils.automark_events(vicon, events_range=[-1500, 1500])
    nexus._create_events(vicon, evs)
    _events_check(events_dict_nofp)

    # using forceplate-based velocity thresholds
    vicon.ClearAllEvents()
    fpe = utils.detect_forceplate_events(vicon)
    mkrdata = read_data.get_marker_data(
        vicon,
        cfg.autoproc.left_foot_markers + cfg.autoproc.right_foot_markers)
    vel = utils._get_foot_contact_vel(mkrdata, fpe)
    evs = utils.automark_events(
        vicon,
        vel_thresholds=vel,
        events_range=[-1500, 1500],
    )
    nexus._create_events(vicon, evs)
    _events_check(events_dict)
コード例 #3
0
ファイル: not_test_nexus.py プロジェクト: Sanardi/gaitutils
def test_event_marking():
    """Test automarking of events"""
    ev_tol = 4  # tolerance for event marking (frames)
    events_dict = dict()  # ground truth with forceplate info
    events_dict['Right'] = dict()
    events_dict['Right']['Foot Strike'] = [384, 505, 616]
    events_dict['Right']['Foot Off'] = [465, 570]
    events_dict['Left'] = dict()
    events_dict['Left']['Foot Strike'] = [311, 441, 562]
    events_dict['Left']['Foot Off'] = [402, 517]
    events_dict_nofp = dict()  # ground truth without forceplate info
    events_dict_nofp['Right'] = dict()
    events_dict_nofp['Right']['Foot Strike'] = [379, 501, 613]
    events_dict_nofp['Right']['Foot Off'] = [468, 572]
    events_dict_nofp['Left'] = dict()
    events_dict_nofp['Left']['Foot Strike'] = [310, 440, 561]
    events_dict_nofp['Left']['Foot Off'] = [401, 516]

    def _events_check(events_dict):
        """Helper to check whether Nexus events are close to ground truth"""
        for side, sidedict in events_dict.items():
            for event_type, events in sidedict.items():
                nexus_events = vicon.GetEvents(vicon.GetSubjectNames()[0],
                                               side, event_type)[0]
                assert_equal(len(events), len(nexus_events))
                for j, ev in enumerate(nexus_events):
                    assert_less_equal(abs(ev - events[j]), ev_tol)

    _nexus_open_trial('girl6v', '2015_10_22_girl6v_IN02')

    # automatic thresholding (do not respect fp events)
    vicon.ClearAllEvents()
    nexus.automark_events(vicon, events_range=[-1500, 1500])
    _events_check(events_dict_nofp)

    # using forceplate thresholds
    vicon.ClearAllEvents()
    fpe = utils.detect_forceplate_events(vicon)
    mkrdata = read_data.get_marker_data(
        vicon,
        cfg.autoproc.left_foot_markers + cfg.autoproc.right_foot_markers)
    vel = utils.get_foot_contact_velocity(mkrdata, fpe)
    nexus.automark_events(vicon,
                          vel_thresholds=vel,
                          events_range=[-1500, 1500],
                          fp_events=fpe)
    _events_check(events_dict)
    vicon.SaveTrial(60)  # to prevent 'Save trial?' dialog on subsequent loads
コード例 #4
0
ファイル: test_c3d.py プロジェクト: Sanardi/gaitutils
def test_c3d_fp_detection():
    """Test forceplate contact detection on c3d files"""
    c3dfile = _trial_path('adult_3fp', 'astrid_080515_02.c3d')
    res = detect_forceplate_events(c3dfile)['coded']
    assert res == 'LRL'
    c3dfile = _trial_path('runner', 'JL brooks 2,8 51.c3d')
    res = detect_forceplate_events(c3dfile)['coded']
    assert res == 'XRLXX'
    c3dfile = _trial_path('girl6v', '2015_10_22_girl6v_IN02.c3d')
    res = detect_forceplate_events(c3dfile)['coded']
    assert res == 'R'
    # detect slight overstep (toeoff not on plate)
    c3dfile = _c3d_path('slight_overstep.c3d')
    res = detect_forceplate_events(c3dfile)['coded']
    assert res == 'X'
    # detect double contact (both feet on plate)
    c3dfile = _c3d_path('double_contact.c3d')
    res = detect_forceplate_events(c3dfile)['coded']
    assert res == 'X'
    # almost overstepped but should be flagged as ok
    # too hard - disabled for now
    # c3d3 = 'testdata/test_c3ds/barely_ok.c3d'
    # res = detect_forceplate_events(c3d3)['coded']
    # assert res == 'R'
    # inside but on the edge
    c3dfile = _c3d_path('side_edge.c3d')
    res = detect_forceplate_events(c3dfile)['coded']
    assert res == 'L'
    c3dfile = _c3d_path('adult_barely_overstepped.c3d')
    res = detect_forceplate_events(c3dfile)['coded']
    assert res == 'X'
    c3dfile = _c3d_path('adult_almost_overstepped.c3d')
    res = detect_forceplate_events(c3dfile)['coded']
    assert res == 'L'
    c3dfile = _c3d_path('adult_overstep.c3d')
    res = detect_forceplate_events(c3dfile)['coded']
    assert res == 'X'
    c3dfile = _c3d_path('adult_ok.c3d')
    res = detect_forceplate_events(c3dfile)['coded']
    assert res == 'L'
    # walker device disturbs forceplate data, but we should
    # still be able to detect foot contacts
    c3dfile = _c3d_path('walker_on_forceplate.c3d')
    res = detect_forceplate_events(c3dfile)['coded']
    assert res == 'RLXX'