Example #1
0
def test_markers(idx, names, expected_shape, expected_values, extension):
    """Assert markers shape."""
    if extension == "csv":
        arr = Markers3d.from_csv(
            MARKERS_CSV,
            first_row=5,
            first_column=2,
            header=2,
            prefix=":",
            idx=idx,
            names=names,
        )
    elif extension == "xlsx":
        arr = Markers3d.from_excel(
            MARKERS_XLSX,
            sheet_name=0,
            first_row=5,
            first_column=2,
            header=2,
            prefix=":",
            idx=idx,
            names=names,
        )
    elif extension == "c3d":
        arr = Markers3d.from_c3d(MARKERS_ANALOGS_C3D,
                                 prefix=":",
                                 idx=idx,
                                 names=names)

    else:
        raise ValueError(
            f'extension should be "csv", "c3d" or "xlsx". You provided {extension}'
        )
    # test shape
    np.testing.assert_equal(arr.shape, expected_shape)
    # test values
    d = arr[:, 0, int(arr.shape[2] / 2)]
    np.testing.assert_almost_equal(d, expected_values, decimal=2)
Example #2
0
ANALOGS_CSV = DATA_FOLDER / 'analogs.csv'

# read 11 first markers of a csv file
markers_1 = Markers3d.from_csv(MARKERS_CSV, first_row=5, first_column=2, header=2,
                               idx=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], prefix=':')

# mean of 1st and 4th markers of a csv file
markers_2 = Markers3d.from_csv(MARKERS_CSV, first_row=5, first_column=2, header=2,
                               idx=[[0, 1, 2], [0, 4, 2]], prefix=':')

# get markers by names in a csv file
markers_3 = Markers3d.from_csv(MARKERS_CSV, first_row=5, first_column=2, header=2,
                               names=['CLAV_post', 'PSISl', 'STERr', 'CLAV_post'], prefix=':')

# write a csv file from a Markers3d types
markers_3.to_csv('../Misc/mtest.csv', header=False)

# read 4 first markers of a c3d file
markers_4 = Markers3d.from_c3d(MARKERS_ANALOGS_C3D, idx=[0, 1, 2, 3])

# get 5 first analogs of a csv file
analogs_1 = Analogs3d.from_csv(ANALOGS_CSV, first_row=5, first_column=2, header=3,
                               idx=[[0, 1, 2], [0, 4, 2]])

# get analogs by names in a c3d file
analogs_2 = Analogs3d.from_c3d(MARKERS_ANALOGS_C3D, prefix=':',
                               names=['Delt_ant.EMG1', 'Subscap.EMG11', 'Triceps.EMG5', 'Gd_dors.IM EMG13'])

# write analogs to a csv file without header
analogs_2.to_csv('../Misc/atest.csv', header=True)
]
nTriPod = 6
nMarkOnInsole = 55
forceRetrainingModel = False
rtm = [
    6, 7, 8
]  # idx of the markers in training file of the Tripod at the back of the insole [left, top, right]
show_in_global = False
calculate_error = True
new_marker_tripod_names = False
show_animation = True
show_individual_plots = True

# load dataSet
dataSet = Markers3d.from_c3d(trainingFileName,
                             names=name_markers).low_pass(freq=100,
                                                          order=4,
                                                          cutoff=10)

# Get markers in a known reference frame
# rt = RotoTrans.define_axes(dataSet, [rtm[2], rtm[0]], [[rtm[0], rtm[1]], [rtm[2], rtm[1]]], "xz", "z", rtm)
rt = RotoTrans.define_axes(dataSet, [0, 4 * 3],
                           [[0, 5 * 3], [2 * 3 + 1, 2 * 3 + 1]], "xz", "z",
                           [0, 2 * 3 + 1, 5 * 3])
dataSet = dataSet.rotate(rt.transpose())

# split into input (X) and output (Y) variables
X = dataSet[:, 0:nTriPod * 3, :].to_2d()
Y = dataSet[:, nTriPod * 3:nTriPod * 3 + nMarkOnInsole, :].to_2d()
# X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.2, train_size=0.8)
X_train = X
y_train = Y
Example #4
0
# Load data
# all markers
d = Markers3d.from_csv(MARKERS_CSV, first_row=5, first_column=2, header=2,
                       idx=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], prefix=':')
# mean of 1st and 4th
d2 = Markers3d.from_csv(MARKERS_CSV, first_row=5, first_column=2, header=2,
                        idx=[[0, 1, 2], [0, 4, 2]], prefix=':')
# mean of first 3 markers
d3 = Markers3d.from_csv(MARKERS_CSV, first_row=5, first_column=2, header=2,
                        idx=[[0], [1], [2]], prefix=':')

d4 = Markers3d.from_csv(MARKERS_CSV, first_row=5, first_column=2, header=2,
                        names=['CLAV_post', 'PSISl', 'STERr', 'CLAV_post'], prefix=':')

# mean of first 3 markers in c3d file
d5 = Markers3d.from_c3d(MARKERS_ANALOGS_C3D, idx=[[0], [1], [2]], prefix=':')

# Create a windows with a nice gray background
vtkWindow = VtkWindow(background_color=(.5, .5, .5))

# Add marker holders to the window
vtkModelReal = VtkModel(vtkWindow, markers_color=(1, 0, 0), markers_size=10.0, markers_opacity=1)
vtkModelPred = VtkModel(vtkWindow, markers_color=(0, 0, 0), markers_size=10.0, markers_opacity=.5)
vtkModelMid = VtkModel(vtkWindow, markers_color=(0, 0, 1), markers_size=10.0, markers_opacity=.5)
vtkModelByNames = VtkModel(vtkWindow, markers_color=(0, 1, 1), markers_size=10.0, markers_opacity=.5)
vtkModelFromC3d = VtkModel(vtkWindow, markers_color=(0, 1, 0), markers_size=10.0, markers_opacity=.5)

# Create some RotoTrans attached to the first model
all_rt_real = RotoTransCollection()
all_rt_real.append(RotoTrans(angles=[0, 0, 0], angle_sequence="yxz", translations=d[:, 0, 0]))
all_rt_real.append(RotoTrans(angles=[0, 0, 0], angle_sequence="yxz", translations=d[:, 0, 0]))
Example #5
0
import numpy as np

from pyomeca import FrameDependentNpArray, Markers3d, RotoTrans, RotoTransCollection
from BiorbdViz.biorbd_vtk import VtkModel, VtkWindow, Mesh, MeshCollection

# Path to data
DATA_FOLDER = Path(
    '/home/pariterre/Programmation/biorbd-viz') / 'tests' / 'data'
MARKERS_CSV = DATA_FOLDER / 'markers.csv'
MARKERS_ANALOGS_C3D = DATA_FOLDER / 'markers_analogs.c3d'

# Load data
# all markers
d = Markers3d.from_c3d(MARKERS_ANALOGS_C3D,
                       idx=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
                       prefix=':')
# mean of 1st and 4th
d2 = Markers3d.from_c3d(MARKERS_ANALOGS_C3D,
                        idx=[[0, 1, 2], [0, 4, 2]],
                        prefix=':')
# mean of first 3 markers
d3 = Markers3d.from_c3d(MARKERS_ANALOGS_C3D, idx=[[0], [1], [2]], prefix=':')

d4 = Markers3d.from_c3d(MARKERS_ANALOGS_C3D,
                        names=['CLAV_post', 'PSISl', 'STERr', 'CLAV_post'],
                        prefix=':')

# mean of first 3 markers in c3d file
d5 = Markers3d.from_c3d(MARKERS_ANALOGS_C3D, idx=[[0], [1], [2]], prefix=':')
Example #6
0
from pathlib import Path

import numpy as np

from pyomeca import FrameDependentNpArray, Markers3d, RotoTrans, RotoTransCollection
from BiorbdViz.biorbd_vtk import VtkModel, VtkWindow, Mesh, MeshCollection

# Path to data
DATA_FOLDER = Path("/home/pariterre/Programmation/biorbd-viz") / "tests" / "data"
MARKERS_CSV = DATA_FOLDER / "markers.csv"
MARKERS_ANALOGS_C3D = DATA_FOLDER / "markers_analogs.c3d"

# Load data
# all markers
d = Markers3d.from_c3d(MARKERS_ANALOGS_C3D, idx=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], prefix=":")
# mean of 1st and 4th
d2 = Markers3d.from_c3d(MARKERS_ANALOGS_C3D, idx=[[0, 1, 2], [0, 4, 2]], prefix=":")
# mean of first 3 markers
d3 = Markers3d.from_c3d(MARKERS_ANALOGS_C3D, idx=[[0], [1], [2]], prefix=":")

d4 = Markers3d.from_c3d(MARKERS_ANALOGS_C3D, names=["CLAV_post", "PSISl", "STERr", "CLAV_post"], prefix=":")

# mean of first 3 markers in c3d file
d5 = Markers3d.from_c3d(MARKERS_ANALOGS_C3D, idx=[[0], [1], [2]], prefix=":")

# Create a windows with a nice gray background
vtkWindow = VtkWindow(background_color=(0.5, 0.5, 0.5))

# Add marker holders to the window
vtkModelReal = VtkModel(vtkWindow, markers_color=(1, 0, 0), markers_size=10.0, markers_opacity=1)