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) with pytest.raises(ValueError): # nonexistent cycle tr.set_norm_cycle(10) # read marker data pig = _pig_markerset(fullbody=True, sacr=True) for var in pig: tr.set_norm_cycle(None) # unnormalized t, data = tr.get_marker_data(var) assert t.shape == (794, ) assert data.shape == (794, 3) tr.set_norm_cycle(0) # unnormalized t, data = tr.get_marker_data(var) 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): tr.set_norm_cycle(None) # unnormalized t, data = tr.get_model_data(var) assert t.shape == (794, ) assert data.shape == (794, ) tr.set_norm_cycle(0) # unnormalized t, data = tr.get_model_data(var) 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_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)