def test_trial_metadata(): """Test metadata reading from c3d""" # 1-forceplate system c3dfile = _trial_path('girl6v', '2015_10_22_girl6v_IN02.c3d') tr = Trial(c3dfile) # default tolerance of assert_allclose is 1e-7 # could also use pytest.approx() assert_allclose(tr.analograte, 1000.0) assert_equal(tr.framerate, 100.0) assert_allclose(tr.subj_params['Bodymass'], 24.0) assert_equal(tr.name, 'Iiris') assert_equal(tr.n_forceplates, 1) assert_equal(tr.length, 794) assert_equal(tr.samplesperframe, 10.0) # 3-fp system c3dfile = _trial_path('adult_3fp', 'astrid_080515_02.c3d') tr = Trial(c3dfile) assert_equal(tr.analograte, 1000.0) assert_equal(tr.framerate, 200.0) assert_allclose(tr.subj_params['Bodymass'], 65.59999, rtol=1e-4) assert_equal(tr.name, 'Astrid') assert_equal(tr.n_forceplates, 3) assert_equal(tr.length, 639) assert_equal(tr.samplesperframe, 5) # 5-fp system c3dfile = _trial_path('runner', 'JL brooks 2,8 51.c3d') tr = Trial(c3dfile) assert_equal(tr.analograte, 1500.0) assert_equal(tr.framerate, 300.0) assert_allclose(tr.subj_params['Bodymass'], 74.0, rtol=1e-4) assert_equal(tr.name, 'JL') assert_equal(tr.n_forceplates, 5) assert_equal(tr.length, 391) assert_equal(tr.samplesperframe, 5)
def test_get_cycles(): """Test cycle getter""" c3dfile = _trial_path('girl6v', '2015_10_22_girl6v_IN02.c3d') tr = Trial(c3dfile) cycs = tr.get_cycles('forceplate') assert len(cycs) == 1 assert cycs[0].on_forceplate cycs = tr.get_cycles('all') assert len(cycs) == 4 cycs = tr.get_cycles('all', max_cycles_per_context=1) assert len(cycs) == 2
def test_nexus_plot(): """Test basic plot from Nexus""" start_nexus() vicon = nexus.viconnexus() trialname = '2015_10_22_girl6v_IN13' subject = 'girl6v' trialpath = _trial_path(subject, trialname) nexus._open_trial(trialpath) tr = Trial(vicon) pl = plots.plot_trials([tr], backend='matplotlib') assert isinstance(pl, Figure)
def test_trial_data_read(): """Test data read from normalized/unnormalized cycles""" c3dfile = _trial_path('girl6v', '2015_10_22_girl6v_IN02.c3d') tr = Trial(c3dfile) # read marker data pig = _pig_markerset(fullbody=True, sacr=True) for var in pig: t, data = tr.get_marker_data(var) # unnormalized assert t.shape == (794,) assert data.shape == (794, 3) t, data = tr.get_marker_data(var, 0) # 1st cycle assert t.shape == (101,) assert data.shape == (101, 3) # some known values for this cycle if var == 'SACR': data_truth = np.array( [ [225.61265564, -1224.5526123, 693.34594727], [223.94009735, -1216.89548584, 692.26601624], [222.29524506, -1209.13790283, 691.30033325], ] ) assert_allclose(data[:3, :], data_truth) # read model data for var in list(models.pig_lowerbody.varnames) + list( models.pig_upperbody.varnames ): t, data = tr.get_model_data(var) # unnormalized assert t.shape == (794,) assert data.shape == (794,) t, data = tr.get_model_data(var, 0) assert t.shape == (101,) assert data.shape == (101,) # some known values for this cycle if var == 'RHipAnglesX': data_truth = np.array( [ 5.12708759, 4.58470859, 4.0733108, 3.60522768, 3.1999483, 2.87095979, 2.62458159, 2.47358855, 2.44552759, 2.53485509, 2.75183632, 3.12467247, 3.65770569, 4.35132931, 5.21909947, ] ) assert_allclose(data[:15], data_truth)
def test_nexus_reader(): """Test basic data reading and Trial instance creation""" start_nexus() vicon = nexus.viconnexus() # from old Helsinki lab trialname = '2015_10_22_girl6v_IN13' subject = 'girl6v' trialpath = _trial_path(subject, trialname) nexus._open_trial(trialpath) tr = Trial(vicon) # XXX: probably with pytest, there is no benefit in using assert_equal assert_equal(tr.analograte, 1000.0) assert_equal(tr.framerate, 100.0) # assert_equal(tr.bodymass, 24.0) assert_equal(tr.subject_name, 'Iiris') assert_equal(tr.n_forceplates, 1) assert_equal(tr.samplesperframe, 10.0) assert_equal(tr.length, 488) assert_equal(tr.trialname, trialname) assert_equal(tr.ncycles, 5) assert_equal(tr.offset, 1) cycs = tr.get_cycles({'R': 'all'}) cyc = cycs[1] assert_equal(cyc.start, 230) assert_equal(cyc.end, 321) assert_equal(cyc.context, 'R') assert_equal(cyc.on_forceplate, True) assert_equal(cyc.toeoff, 282) cyc = cycs[0] assert_equal(cyc.start, 145) assert_equal(cyc.context, 'R') assert_equal(cyc.on_forceplate, False) # from Trondheim trialname = 'astrid_080515_02' subject = 'adult_3fp' trialpath = _trial_path(subject, trialname) nexus._open_trial(trialpath) tr = Trial(vicon) assert_equal(tr.analograte, 1000.0) assert_equal(tr.framerate, 200.0) # assert_equal(tr.bodymass, 70.0) assert_equal(tr.subject_name, 'Astrid') assert_equal(tr.n_forceplates, 3) assert_equal(tr.samplesperframe, 5.0) assert_equal(tr.length, 1986) assert_equal(tr.trialname, trialname) assert_equal(tr.ncycles, 4) assert_equal(tr.offset, 1) cycs = tr.get_cycles({'L': 'all'}) cyc = cycs[1] assert_equal(cyc.start, 1161) assert_equal(cyc.end, 1387) assert_equal(cyc.context, 'L') assert_equal(cyc.on_forceplate, True) assert_equal(cyc.toeoff, 1303)
def test_compare_to_c3d(): """Compare data reads from Nexus and corresponding Nexus written .c3d""" start_nexus() vicon = nexus.viconnexus() # set the correct EMG device name for the old data cfg.emg.devname = 'Myon' # can only get 3 decimals of agreement between Nexus/c3d model vars (??) NDEC = 3 # vars to test modelvars = models.pig_lowerbody.varlabels.keys() emg_chs = [ 'LGas', 'LGlut', 'LHam', 'LPer', 'LRec', 'LSol', 'LTibA', 'LVas', 'RGas', 'RGlut', 'RHam', 'RPer', 'RRec', 'RSol', 'RTibA', 'RVas', ] subj = 'girl6v' trialname = '2015_10_22_girl6v_IN03.c3d' trialpath = _trial_path(subj, trialname) nexus._open_trial(trialpath) tr_nexus = Trial(vicon) tr_c3d = Trial(trialpath) # metadata attrs = [ 'analograte', 'framerate', 'subject_name', 'n_forceplates', 'samplesperframe', 'length', 'trialname', 'ncycles', ] for attr in attrs: assert_equal(getattr(tr_nexus, attr), getattr(tr_c3d, attr)) # model data for var in modelvars: # read unnormalized model and compare xn, dn = tr_nexus.get_model_data(var) assert_array_equal(xn, range(tr_nexus.length)) xc, dc = tr_c3d.get_model_data(var) assert_array_equal(xc, range(tr_nexus.length)) assert_array_almost_equal(dn, dc, decimal=NDEC) # read normalized model and compare for j in range(4): for var in modelvars: xn, dn = tr_nexus.get_model_data(var, j) xc, dc = tr_c3d.get_model_data(var, j) assert_array_equal(xn, np.arange(101)) assert_array_equal(xc, np.arange(101)) assert_array_almost_equal(dn, dc, decimal=NDEC) # read unnormalized EMG and compare for ch in emg_chs: xn, dn = tr_nexus.get_emg_data(ch) xc, dc = tr_c3d.get_emg_data(ch) assert_array_equal( xn, np.arange(tr_nexus.length * tr_nexus.samplesperframe)) assert_array_equal(xn, xc) assert_array_almost_equal(dn, dc, decimal=NDEC) # read normalized EMG and compare for j in range(4): for ch in emg_chs: xn, dn = tr_nexus.get_emg_data(ch, j) xc, dc = tr_c3d.get_emg_data(ch, j) assert_array_equal(xn, xc) assert_array_almost_equal(dn, dc, decimal=NDEC)