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)
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
def test_c3d_marker_data(): """Test marker data reads from c3d""" # lowerbody PiG marker set c3dfile = _c3d_path('double_contact.c3d') mkrset = list(utils._pig_markerset().keys()) mkrdata = read_data.get_marker_data(c3dfile, mkrset) assert utils.is_plugingait_set(mkrdata) assert len(mkrdata) == 5 * len(mkrset) # vars = P*2, V, A & gaps # check array dimensions for all markers (gap data has different dims) for mkr in mkrdata: if '_gaps' not in mkr: assert mkrdata[mkr].shape == (442, 3) # LHEE gaps from 360 to 388 assert_equal(mkrdata['LHEE_gaps'], np.arange(360, 389)) lhee_file = _file_path('lhee_data.npy') lhee_data = np.load(lhee_file) # allow some deviation from saved reference data (was read using btk) assert_allclose(mkrdata['LHEE'], lhee_data, rtol=1e-4)
def test_c3d_extended_chars(): """See if we can read filenames with extended chars""" c3dfile = _c3d_path('2020_11_10_postOp5v_säärituet_SSD06.c3d') read_data.get_analysis(c3dfile, 'c3dtest') mkrset = ['RASI', 'LASI'] read_data.get_marker_data(c3dfile, mkrset)