Beispiel #1
0
"""
Create and update project
"""
import yaml
from pyoviz import FieldsAssignment
from pyosim import Conf, Project

aws_conf = yaml.safe_load(open("../conf.yml"))
local_or_distant = "distant" if aws_conf["distant_id"]["enable"] else "local"

# create Project object
project = Project(path=aws_conf["path"]["project"][local_or_distant])
project.update_participants()

# Create a Conf object
conf = Conf(project_path=aws_conf["path"]["project"][local_or_distant])

# Check if all participants have a configuration file and update it in the project_sample's configuration file
conf.check_confs()

# add some data path in participants' conf file
participants = conf.get_participants_to_process()
d = {}
for iparticipant in participants:
    pseudo_in_path = (
        iparticipant[0].upper() + iparticipant[1:-1] + iparticipant[-1].upper()
    )

    trials = (
        f"{aws_conf['path']['data'][local_or_distant]}/IRSST_{pseudo_in_path}d/trials"
    )
Beispiel #2
0
import os
from multiprocessing import Pool
from pathlib import Path

import numpy as np

from pyomeca.obj.analogs import MVC
from pyosim import Conf
from pyosim.obj import Analogs3dOsim

# path
PROJECT_PATH = Path('/home/romain/Dropbox/pyosim_irsst')
MULTIPROC = True

conf = Conf(project_path=PROJECT_PATH)

params = {
    'band_pass_cutoff': [10, 425],
    'low_pass_cutoff': 5,
    'order': 4,
    'outlier': 5,
    'emg_labels': conf.get_conf_field(participant='dapo', field=['emg', 'targets'])
}

participants = conf.get_participants_to_process()

for iparticipant in participants:
    print(f'\nparticipant: {iparticipant}')
    directories = conf.get_conf_field(participant=iparticipant, field=['emg', 'data'])
    assigned = conf.get_conf_field(participant=iparticipant, field=['emg', 'assigned'])
Beispiel #3
0
"""
Static optimization
"""
import yaml
from pyosim import Conf
from pyosim import StaticOptimization

import pandas as pd

aws_conf = yaml.safe_load(open("../conf.yml"))
local_or_distant = "distant" if aws_conf["distant_id"]["enable"] else "local"

conf = Conf(project_path=aws_conf["path"]["project"][local_or_distant])
participants = conf.get_participants_to_process()
conf.check_confs()

model_names = ["wu"]

blacklist = [
    "wu_AnnSF6H2_1",
    "wu_AnnSF6H2_3",
    "wu_SteBF6H2_2",
    "wu_JawRH12H4_1",
    "wu_JawRH12H3_3",
    "wu_JawRH12H3_2",
    "wu_JawRH12H2_1",
    "wu_JawRH12H1_3",
    "wu_NemKH6H2_3",
    "wu_NemKH6H1_3",
    "wu_NemKH6H1_2",
    "wu_NemKH6H1_1",
Beispiel #4
0
"""
Example: run joint reaction analysis and export sto
"""

from pathlib import Path

from pyosim import Conf
from pyosim import JointReaction

# path
PROJECT_PATH = Path('/home/romain/Dropbox/pyosim_irsst')
TEMPLATES_PATH = PROJECT_PATH / '_templates'

model_names = ['wu', 'das']

conf = Conf(project_path=PROJECT_PATH)
conf.check_confs()

participants = conf.get_participants_to_process()

for iparticipant in participants:
    print(f'\nparticipant: {iparticipant}')

    # ignore some trials
    blacklist_suffix = '0'

    trials = [
        ifile for ifile in (PROJECT_PATH / iparticipant /
                            '1_inverse_kinematic').glob('*.mot')
        if not ifile.stem.endswith(blacklist_suffix)
    ]
Beispiel #5
0
"""

from pathlib import Path

import matplotlib.pyplot as plt
import numpy as np

from pyosim import Conf
from pyosim.obj import Analogs3dOsim

# path
PROJECT_PATH = Path('/home/romain/Dropbox/pyosim_irsst')
# PROJECT_PATH = Path('/home/romain/Documents/codes/pyosim/Misc/project_sample')
CALIBRATION_MATRIX = Path('../tests/data/forces_calibration_matrix.csv')

conf = Conf(project_path=PROJECT_PATH)
conf.check_confs()

calibration_matrix = np.genfromtxt(CALIBRATION_MATRIX, delimiter=',')
params = {
    'low_pass_cutoff':
    30,
    'order':
    4,
    'forces_labels':
    conf.get_conf_field(participant='dapo', field=['analogs', 'targets'])
}

participants = conf.get_participants_to_process()

for iparticipant in participants:
Example: run inverse kinematic and export mot
"""

from pathlib import Path

from pyosim import Conf
from pyosim import InverseKinematics

# path
PROJECT_PATH = Path('/home/romain/Dropbox/pyosim_irsst')
TEMPLATES_PATH = PROJECT_PATH / '_templates'

model_names = ['wu', 'das']
offset = 0.05  # take 1 second before and after onsets

conf = Conf(project_path=PROJECT_PATH)
conf.check_confs()

participants = conf.get_participants_to_process()

for iparticipant in participants:
    print(f'\nparticipant: {iparticipant}')

    trials = [
        ifile
        for ifile in (PROJECT_PATH / iparticipant / '0_markers').glob('*.trc')
    ]
    onsets = conf.get_conf_field(iparticipant, ['onset'])
    onsets = {
        key: [values[0] - offset, values[1] + offset]
        for key, values in onsets.items()
Beispiel #7
0
"""
Example: export markers to trc
"""

from pathlib import Path

import numpy as np

from pyosim import Conf
from pyosim.obj import Markers3dOsim

# path
PROJECT_PATH = Path('/home/romain/Dropbox/pyosim_irsst')

conf = Conf(project_path=PROJECT_PATH)

markers_labels = conf.get_conf_field(participant='dapo',
                                     field=['markers', 'targets'])

participants = conf.get_participants_to_process()

for iparticipant in participants:
    print(f'\nparticipant: {iparticipant}')
    directories = conf.get_conf_field(participant=iparticipant,
                                      field=['markers', 'data'])
    assigned = conf.get_conf_field(participant=iparticipant,
                                   field=['markers', 'assigned'])

    for idir in directories:
        print(f'\n\tdirectory: {idir}')
Beispiel #8
0
from multiprocessing import Pool
from pathlib import Path

import numpy as np
import yaml
from pyomeca import MVC
from pyosim import Conf
from pyosim import Analogs3dOsim

# path
MULTIPROC = True

aws_conf = yaml.safe_load(open("../conf.yml"))
local_or_distant = "distant" if aws_conf["distant_id"]["enable"] else "local"

conf = Conf(project_path=aws_conf["path"]["project"][local_or_distant])
participants = conf.get_participants_to_process()

params = {
    "band_pass_cutoff": [10, 425],
    "low_pass_cutoff":
    5,
    "order":
    4,
    "outlier":
    5,
    "emg_labels":
    conf.get_conf_field(participant=participants[0], field=["emg", "targets"]),
}

for i, iparticipant in enumerate(participants):
Beispiel #9
0
"""

from pathlib import Path

from pyosim import Conf
from pyosim import Scale

# path
WU_MASS_FACTOR = 24.385 / 68.2
PROJECT_PATH = Path('/home/romain/Dropbox/pyosim_irsst')
MODELS_PATH = PROJECT_PATH / '_models'
TEMPLATES_PATH = PROJECT_PATH / '_templates'

model_names = ['wu', 'das']

conf = Conf(project_path=PROJECT_PATH)
conf.check_confs()

participants = conf.get_participants_to_process()

for iparticipant in participants:
    print(f'\nparticipant: {iparticipant}')
    pseudo_in_path = iparticipant[0].upper() + iparticipant[1:-1] + iparticipant[-1].upper()
    static_path = f"{PROJECT_PATH / iparticipant / '0_markers' / 'IRSST_'}{pseudo_in_path}d0.trc"
    mass = conf.get_conf_field(iparticipant, ['mass'])
    height = conf.get_conf_field(iparticipant, ['height'])

    for imodel in model_names:
        if imodel == 'wu':
            # mass of the upper limb + torso
            mass = mass * WU_MASS_FACTOR
Beispiel #10
0
"""
Scaling
"""
import yaml
from pyosim import Conf
from pyosim import Scale

aws_conf = yaml.safe_load(open("../conf.yml"))
local_or_distant = "distant" if aws_conf["distant_id"]["enable"] else "local"

conf = Conf(project_path=aws_conf["path"]["project"][local_or_distant])
conf.check_confs()
participants = conf.get_participants_to_process()

model_names = ["wu"]
WU_MASS_FACTOR = 24.385 / 68.2

for i, iparticipant in enumerate(participants):
    print(f"\nparticipant #{i}: {iparticipant}")
    pseudo_in_path = (iparticipant[0].upper() + iparticipant[1:-1] +
                      iparticipant[-1].upper())
    static_path = f"{conf.project_path / iparticipant / '0_markers' / 'IRSST_'}{pseudo_in_path}d0.trc"
    mass = conf.get_conf_field(iparticipant, ["mass"])
    height = conf.get_conf_field(iparticipant, ["height"])

    for imodel in model_names:
        if imodel[:2] == "wu":
            # mass of the upper limb + torso
            mass = mass * WU_MASS_FACTOR

        path_kwargs = {
Beispiel #11
0
"""
Export forces to sto
"""
from pathlib import Path
import matplotlib.pyplot as plt
import numpy as np
import yaml
from pyosim import Conf
from pyosim import Analogs3dOsim

aws_conf = yaml.safe_load(open("../conf.yml"))
local_or_distant = "distant" if aws_conf["distant_id"]["enable"] else "local"

conf = Conf(project_path=aws_conf["path"]["project"][local_or_distant])
participants = conf.get_participants_to_process()

calibration_matrix = np.genfromtxt(
    conf.project_path / "forces_calibration_matrix.csv", delimiter=","
)
params = {
    "low_pass_cutoff": 30,
    "order": 4,
    "forces_labels": conf.get_conf_field(
        participant=participants[0], field=["analogs", "targets"]
    ),
}

for i, iparticipant in enumerate(participants[:]):
    print(f"\nparticipant #{i}: {iparticipant}")
    directories = conf.get_conf_field(
        participant=iparticipant, field=["analogs", "data"]
Beispiel #12
0
"""
Export markers to trc
"""
from pathlib import Path
import yaml
import numpy as np
from pyosim import Conf, Markers3dOsim

aws_conf = yaml.safe_load(open("../conf.yml"))
local_or_distant = "distant" if aws_conf["distant_id"]["enable"] else "local"

conf = Conf(project_path=aws_conf["path"]["project"][local_or_distant])
participants = conf.get_participants_to_process()
conf.check_confs()

markers_labels = conf.get_conf_field(participant=participants[0],
                                     field=["markers", "targets"])

for i, iparticipant in enumerate(participants[:]):
    print(f"\nparticipant #{i}: {iparticipant}")
    directories = conf.get_conf_field(participant=iparticipant,
                                      field=["markers", "data"])
    assigned = conf.get_conf_field(participant=iparticipant,
                                   field=["markers", "assigned"])

    for idir in directories:
        print(f"\n\tdirectory: {idir}")

        for itrial in Path(idir).glob("*.c3d"):
            blacklist = False
            # try participant's channel assignment
Beispiel #13
0
# remove project if already exists (you don't need to do this)
if PROJECT_PATH.is_dir():
    shutil.rmtree(PROJECT_PATH)

# create Project object
project = Project(path=PROJECT_PATH)

# create project directory
project.create_project()

# add participants from the template conf file
shutil.copy(CONF_TEMPLATE, PROJECT_PATH)
project.update_participants()

# Create a Conf object
conf = Conf(project_path=PROJECT_PATH)

# Check if all participants have a configuration file and update it in the project's configuration file
conf.check_confs()

# add some data path in participants' conf file
participants = conf.get_participants_to_process()
d = {}
for iparticipant in participants:
    pseudo_in_path = iparticipant[0].upper(
    ) + iparticipant[1:-1] + iparticipant[-1].upper()
    trials = f'/media/romain/F/Data/Shoulder/RAW/IRSST_{pseudo_in_path}d/trials'
    score = f'/media/romain/F/Data/Shoulder/RAW/IRSST_{pseudo_in_path}d/MODEL2'
    mvc = f'/media/romain/E/Projet_MVC/data/C3D_original_files/irsst_hf/{pseudo_in_path}'

    d.update({