Merge pull request #64 from perfanalytics/draft

Merge draft to main
This commit is contained in:
David PAGNON 2024-01-19 20:15:01 +01:00 committed by GitHub
commit bbf5c425d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1738 changed files with 672804 additions and 230 deletions

View File

@ -26,13 +26,9 @@ frame_range = [] # For example [10,300], or [] for all frames
exclude_from_batch = [] # List of trials to be excluded from batch analysis, ['<participant_dir/trial_dir>', 'etc'].
# e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P00_Participant/S00_P00_T01_BalancingTrial']
## Only taken into account if pose_model is 'BODY_25_AUGMENTED' # Coming soon!
participant_height = 1.7 # m
participant_mass = 70 # kg
# Take heart, calibration is not that complicated once you get the hang of it!
[calibration]
calibration_type = 'convert' # 'convert' or 'calculate'
@ -94,8 +90,7 @@ calibration_type = 'convert' # 'convert' or 'calculate'
[pose]
pose_framework = 'openpose' # 'openpose', 'mediapipe', 'alphapose', 'deeplabcut'
pose_model = 'BODY_25B' #With openpose: BODY_25B, BODY_25, BODY_135, COCO, MPII,
# BODY_25_AUGMENTED # Coming soon!
pose_model = 'BODY_25B' #With openpose: BODY_25B, BODY_25, BODY_135, COCO, MPII
#With mediapipe: BLAZEPOSE.
#With alphapose: HALPE_26, HALPE_68, HALPE_136, COCO_133.
#With deeplabcut: CUSTOM. See example at the end of the file.
@ -141,7 +136,7 @@ make_c3d = false # save triangulated data in c3d format in addition to trc # Com
[filtering]
type = 'butterworth' # butterworth, kalman, gaussian, LOESS, median, butterworth_on_speed
display_figures = false # true or false (lowercase)
display_figures = true # true or false (lowercase)
[filtering.butterworth]
order = 4
@ -161,6 +156,12 @@ display_figures = false # true or false (lowercase)
kernel_size = 9
[markerAugmentation]
## Only works on BODY_25 and BODY_25B models
participant_height = 1.7 # m
participant_mass = 70 # kg
[opensim]
static_trial = ['S00_P00_Participant/S00_P00_T00_StaticTrial']
# # If this Config.toml file is at the Trial level, set to true or false (lowercase);

View File

@ -26,13 +26,9 @@
# exclude_from_batch = [] # List of trials to be excluded from batch analysis, ['<participant_dir/trial_dir>', 'etc'].
# e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P00_Participant/S00_P00_T01_BalancingTrial']
## Only taken into account if pose_model is 'BODY_25_AUGMENTED' # Coming soon!
# participant_height = 1.7 # m
# participant_mass = 70 # kg
## Take heart, calibration is not that complicated once you get the hang of it!
# [calibration]
# calibration_type = 'convert' # 'convert' or 'calculate'
@ -96,7 +92,6 @@
# [pose]
# pose_framework = 'openpose' # 'openpose', 'mediapipe', 'alphapose', 'deeplabcut'
# pose_model = 'BODY_25B' #With openpose: BODY_25B, BODY_25, BODY_135, COCO, MPII,
# BODY_25_AUGMENTED # Coming soon!
# #With mediapipe: BLAZEPOSE.
# #With alphapose: HALPE_26, HALPE_68, HALPE_136, COCO_133.
# #With deeplabcut: CUSTOM. See example at the end of the file.
@ -162,6 +157,12 @@
# kernel_size = 9
# [markerAugmentation]
# ## Only works on BODY_25 and BODY_25B models
# participant_height = 1.7 # m
# participant_mass = 70 # kg
# [opensim]
# static_trial = ['S00_P00_Participant/S00_P00_T00_StaticTrial']
# # If this Config.toml file is at the Trial level, set to true or false (lowercase);

View File

@ -27,10 +27,6 @@
# exclude_from_batch = [] # List of trials to be excluded from batch analysis, ['<participant_dir/trial_dir>', 'etc'].
# e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P00_Participant/S00_P00_T01_BalancingTrial']
## Only taken into account if pose_model is 'BODY_25_AUGMENTED' # Coming soon!
# participant_height = 1.7 # m
# participant_mass = 70 # kg
## Take heart, calibration is not that complicated once you get the hang of it!
# [calibration]
@ -96,7 +92,6 @@
# [pose]
# pose_framework = 'openpose' # 'openpose', 'mediapipe', 'alphapose', 'deeplabcut'
# pose_model = 'BODY_25B' #With openpose: BODY_25B, BODY_25, BODY_135, COCO, MPII,
# BODY_25_AUGMENTED # Coming soon!
# #With mediapipe: BLAZEPOSE.
# #With alphapose: HALPE_26, HALPE_68, HALPE_136, COCO_133.
# #With deeplabcut: CUSTOM. See example at the end of the file.
@ -140,9 +135,9 @@
# make_c3d = false # save triangulated data in c3d format in addition to trc # Coming soon!
# [filtering]
[filtering]
# type = 'butterworth' # butterworth, kalman, gaussian, LOESS, median, butterworth_on_speed
# display_figures = true # true or false (lowercase)
display_figures = false # true or false (lowercase)
# [filtering.butterworth]
# order = 4
@ -162,6 +157,12 @@
# kernel_size = 9
# [markerAugmentation]
# ## Only works on BODY_25 and BODY_25B models
# participant_height = 1.7 # m
# participant_mass = 70 # kg
# [opensim]
# static_trial = ['S00_P00_Participant/S00_P00_T00_StaticTrial']
# # If this Config.toml file is at the Trial level, set to true or false (lowercase);

View File

@ -27,10 +27,6 @@
# exclude_from_batch = [] # List of trials to be excluded from batch analysis, ['<participant_dir/trial_dir>', 'etc'].
# e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P00_Participant/S00_P00_T01_BalancingTrial']
## Only taken into account if pose_model is 'BODY_25_AUGMENTED' # Coming soon!
# participant_height = 1.7 # m
# participant_mass = 70 # kg
## Take heart, calibration is not that complicated once you get the hang of it!
# [calibration]
@ -96,7 +92,6 @@
# [pose]
# pose_framework = 'openpose' # 'openpose', 'mediapipe', 'alphapose', 'deeplabcut'
# pose_model = 'BODY_25B' #With openpose: BODY_25B, BODY_25, BODY_135, COCO, MPII,
# BODY_25_AUGMENTED # Coming soon!
# #With mediapipe: BLAZEPOSE.
# #With alphapose: HALPE_26, HALPE_68, HALPE_136, COCO_133.
# #With deeplabcut: CUSTOM. See example at the end of the file.
@ -140,9 +135,9 @@
# make_c3d = false # save triangulated data in c3d format in addition to trc # Coming soon!
[filtering]
# [filtering]
# type = 'butterworth' # butterworth, kalman, gaussian, LOESS, median, butterworth_on_speed
display_figures = true # true or false (lowercase)
# display_figures = true # true or false (lowercase)
# [filtering.butterworth]
# order = 4
@ -162,6 +157,12 @@ display_figures = true # true or false (lowercase)
# kernel_size = 9
# [markerAugmentation]
# ## Only works on BODY_25 and BODY_25B models
# participant_height = 1.7 # m
# participant_mass = 70 # kg
# [opensim]
# static_trial = ['S00_P00_Participant/S00_P00_T00_StaticTrial']
# # If this Config.toml file is at the Trial level, set to true or false (lowercase);

View File

@ -22,6 +22,7 @@ def test_workflow():
Pose2Sim.personAssociation(config_dict)
Pose2Sim.triangulation(config_dict)
Pose2Sim.filtering(config_dict)
Pose2Sim.markerAugmentation(config_dict)
# Pose2Sim.kinematics(config_dict)
@ -35,4 +36,5 @@ def test_workflow():
Pose2Sim.personAssociation(config_dict)
Pose2Sim.triangulation(config_dict)
Pose2Sim.filtering(config_dict)
Pose2Sim.markerAugmentation(config_dict)
# Pose2Sim.kinematics(config_dict)

View File

@ -26,13 +26,9 @@ frame_range = [] # For example [10,300], or [] for all frames
exclude_from_batch = [] # List of trials to be excluded from batch analysis, ['<participant_dir/trial_dir>', 'etc'].
# e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P00_Participant/S00_P00_T01_BalancingTrial']
## Only taken into account if pose_model is 'BODY_25_AUGMENTED' # Coming soon!
participant_height = 1.7 # m
participant_mass = 70 # kg
# Take heart, calibration is not that complicated once you get the hang of it!
[calibration]
calibration_type = 'convert' # 'convert' or 'calculate'
@ -94,8 +90,7 @@ calibration_type = 'convert' # 'convert' or 'calculate'
[pose]
pose_framework = 'openpose' # 'openpose', 'mediapipe', 'alphapose', 'deeplabcut'
pose_model = 'BODY_25B' #With openpose: BODY_25B, BODY_25, BODY_135, COCO, MPII,
# BODY_25_AUGMENTED # Coming soon!
pose_model = 'BODY_25B' #With openpose: BODY_25B, BODY_25, BODY_135, COCO, MPII
#With mediapipe: BLAZEPOSE.
#With alphapose: HALPE_26, HALPE_68, HALPE_136, COCO_133.
#With deeplabcut: CUSTOM. See example at the end of the file.
@ -123,7 +118,7 @@ single_person = true # false for multi-person analysis (not supported yet), true
tracked_keypoint = 'Neck' # If the neck is not detected by the pose_model, check skeleton.py
# and choose a stable point for tracking the person of interest (e.g., 'right_shoulder' with BLAZEPOSE)
reproj_error_threshold_association = 20 # px
likelihood_error_threshold_association = 0.2
likelihood_threshold_association = 0.2
[triangulation]
@ -131,17 +126,17 @@ reproj_error_threshold_triangulation = 15 # px
likelihood_threshold_triangulation = 0.3
min_cameras_for_triangulation = 2
interpolation = 'cubic' #linear, slinear, quadratic, cubic, or none
# 'none' if you don't want to interpolate missing points
# 'none' if you don't want to interpolate missing points
interp_if_gap_smaller_than = 10 # do not interpolate bigger gaps
show_interp_indices = true # true or false (lowercase). For each keypoint, return the frames that need to be interpolated
# handle_LR_swap = false # Better if few cameras (eg less than 4) with risk of limb swapping (eg camera facing sagittal plane), otherwise slightly less accurate and slower
# undistort_points = false # Better if distorted image (parallel lines curvy on the edge or at least one param > 10^-2), but unnecessary (and slightly slower) if distortions are low
# make_c3d = false # save triangulated data in c3d format in addition to trc # Coming soon!
handle_LR_swap = false # Better if few cameras (eg less than 4) with risk of limb swapping (eg camera facing sagittal plane), otherwise slightly less accurate and slower
undistort_points = false # Better if distorted image (parallel lines curvy on the edge or at least one param > 10^-2), but unnecessary (and slightly slower) if distortions are low
make_c3d = false # save triangulated data in c3d format in addition to trc # Coming soon!
[filtering]
type = 'butterworth' # butterworth, kalman, gaussian, LOESS, median, butterworth_on_speed
display_figures = false # true or false (lowercase)
display_figures = true # true or false (lowercase)
[filtering.butterworth]
order = 4
@ -161,8 +156,14 @@ display_figures = false # true or false (lowercase)
kernel_size = 9
[markerAugmentation]
## Only works on BODY_25 and BODY_25B models
participant_height = 1.7 # m
participant_mass = 70 # kg
[opensim]
static_trial = ['S01_P00_Participant0/S01_P00_T00_StaticTrial']
static_trial = ['S00_P00_Participant/S00_P00_T00_StaticTrial']
# # If this Config.toml file is at the Trial level, set to true or false (lowercase);
# # At the Participant level, specify the name of the static trial folder name, e.g. ['S00_P00_T00_StaticTrial'];
# # At the Session level, add participant subdirectory, e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P01_Participant/S00_P00_T00_StaticTrial']
@ -170,17 +171,17 @@ opensim_bin_path = 'C:\OpenSim 4.4\bin'
## CUSTOM skeleton, if you trained your own DeepLabCut model for example.
## Make sure the node ids correspond to the column numbers of the 2D pose file, starting from zero.
##
## If you want to perform inverse kinematics, you will also need to create an OpenSim model
## and add to its markerset the location where you expect the triangulated keypoints to be detected.
##
## In this example, CUSTOM reproduces the BODY_25B skeleton (default skeletons are stored in skeletons.py).
## You can create as many custom skeletons as you want, just add them further down and rename them.
##
## Check your model hierarchy with: for pre, _, node in RenderTree(model):
## print(f'{pre}{node.name} id={node.id}')
# CUSTOM skeleton, if you trained your own DeepLabCut model for example.
# Make sure the node ids correspond to the column numbers of the 2D pose file, starting from zero.
#
# If you want to perform inverse kinematics, you will also need to create an OpenSim model
# and add to its markerset the location where you expect the triangulated keypoints to be detected.
#
# In this example, CUSTOM reproduces the BODY_25B skeleton (default skeletons are stored in skeletons.py).
# You can create as many custom skeletons as you want, just add them further down and rename them.
#
# Check your model hierarchy with: for pre, _, node in RenderTree(model):
# print(f'{pre}{node.name} id={node.id}')
[pose.CUSTOM]
name = "CHip"
id = "None"

View File

@ -26,13 +26,9 @@
# exclude_from_batch = [] # List of trials to be excluded from batch analysis, ['<participant_dir/trial_dir>', 'etc'].
# e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P00_Participant/S00_P00_T01_BalancingTrial']
# participant_height = 1.7 # m
# participant_mass = 70 # kg
## Only taken into account if pose_model is 'BODY_25_AUGMENTED' # Coming soon!
## Take heart, calibration is not that complicated once you get the hang of it!
# [calibration]
# calibration_type = 'convert' # 'convert' or 'calculate'
@ -96,7 +92,6 @@
# [pose]
# pose_framework = 'openpose' # 'openpose', 'mediapipe', 'alphapose', 'deeplabcut'
# pose_model = 'BODY_25B' #With openpose: BODY_25B, BODY_25, BODY_135, COCO, MPII,
# BODY_25_AUGMENTED # Coming soon!
# #With mediapipe: BLAZEPOSE.
# #With alphapose: HALPE_26, HALPE_68, HALPE_136, COCO_133.
# #With deeplabcut: CUSTOM. See example at the end of the file.
@ -162,8 +157,14 @@
# kernel_size = 9
# [markerAugmentation]
# ## Only works on BODY_25 and BODY_25B models
# participant_height = 1.7 # m
# participant_mass = 70 # kg
# [opensim]
# static_trial = ['S01_P00_Participant0/S01_P00_T00_StaticTrial']
# static_trial = ['S00_P00_Participant/S00_P00_T00_StaticTrial']
# # If this Config.toml file is at the Trial level, set to true or false (lowercase);
# # At the Participant level, specify the name of the static trial folder name, e.g. ['S00_P00_T00_StaticTrial'];
# # At the Session level, add participant subdirectory, e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P01_Participant/S00_P00_T00_StaticTrial']

View File

@ -9,6 +9,7 @@
# If a parameter is not found here, Pose2Sim will look for its value in the
# Config.toml file of the level above. This way, you can set global
# instructions for the Session and alter them for specific Participants or Trials.
#
# If you wish to overwrite a parameter for a specific trial or participant,
# edit its Config.toml file by uncommenting its key (e.g., [project])
# and editing its value (e.g., frame_range = [10,300]). Or else, uncomment
@ -25,13 +26,9 @@
# exclude_from_batch = [] # List of trials to be excluded from batch analysis, ['<participant_dir/trial_dir>', 'etc'].
# e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P00_Participant/S00_P00_T01_BalancingTrial']
# participant_height = 1.7 # m
# participant_mass = 70 # kg
## Only taken into account if pose_model is 'BODY_25_AUGMENTED' # Coming soon!
## Take heart, calibration is not that complicated once you get the hang of it!
# [calibration]
# calibration_type = 'convert' # 'convert' or 'calculate'
@ -95,7 +92,6 @@
# [pose]
# pose_framework = 'openpose' # 'openpose', 'mediapipe', 'alphapose', 'deeplabcut'
# pose_model = 'BODY_25B' #With openpose: BODY_25B, BODY_25, BODY_135, COCO, MPII,
# BODY_25_AUGMENTED # Coming soon!
# #With mediapipe: BLAZEPOSE.
# #With alphapose: HALPE_26, HALPE_68, HALPE_136, COCO_133.
# #With deeplabcut: CUSTOM. See example at the end of the file.
@ -161,8 +157,14 @@
# kernel_size = 9
# [markerAugmentation]
# ## Only works on BODY_25 and BODY_25B models
# participant_height = 1.7 # m
# participant_mass = 70 # kg
# [opensim]
# static_trial = ['S01_P00_Participant0/S01_P00_T00_StaticTrial']
# static_trial = ['S00_P00_Participant/S00_P00_T00_StaticTrial']
# # If this Config.toml file is at the Trial level, set to true or false (lowercase);
# # At the Participant level, specify the name of the static trial folder name, e.g. ['S00_P00_T00_StaticTrial'];
# # At the Session level, add participant subdirectory, e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P01_Participant/S00_P00_T00_StaticTrial']

View File

@ -9,6 +9,7 @@
# If a parameter is not found here, Pose2Sim will look for its value in the
# Config.toml file of the level above. This way, you can set global
# instructions for the Session and alter them for specific Participants or Trials.
#
# If you wish to overwrite a parameter for a specific trial or participant,
# edit its Config.toml file by uncommenting its key (e.g., [project])
# and editing its value (e.g., frame_range = [10,300]). Or else, uncomment
@ -25,13 +26,9 @@
# exclude_from_batch = [] # List of trials to be excluded from batch analysis, ['<participant_dir/trial_dir>', 'etc'].
# e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P00_Participant/S00_P00_T01_BalancingTrial']
# participant_height = 1.7 # m
# participant_mass = 70 # kg
## Only taken into account if pose_model is 'BODY_25_AUGMENTED' # Coming soon!
## Take heart, calibration is not that complicated once you get the hang of it!
# [calibration]
# calibration_type = 'convert' # 'convert' or 'calculate'
@ -95,7 +92,6 @@
# [pose]
# pose_framework = 'openpose' # 'openpose', 'mediapipe', 'alphapose', 'deeplabcut'
# pose_model = 'BODY_25B' #With openpose: BODY_25B, BODY_25, BODY_135, COCO, MPII,
# BODY_25_AUGMENTED # Coming soon!
# #With mediapipe: BLAZEPOSE.
# #With alphapose: HALPE_26, HALPE_68, HALPE_136, COCO_133.
# #With deeplabcut: CUSTOM. See example at the end of the file.
@ -139,9 +135,9 @@
# make_c3d = false # save triangulated data in c3d format in addition to trc # Coming soon!
[filtering]
# [filtering]
# type = 'butterworth' # butterworth, kalman, gaussian, LOESS, median, butterworth_on_speed
display_figures = true # true or false (lowercase)
# display_figures = true # true or false (lowercase)
# [filtering.butterworth]
# order = 4
@ -161,8 +157,14 @@ display_figures = true # true or false (lowercase)
# kernel_size = 9
# [markerAugmentation]
# ## Only works on BODY_25 and BODY_25B models
# participant_height = 1.7 # m
# participant_mass = 70 # kg
# [opensim]
# static_trial = ['S01_P00_Participant/0S01_P00_T00_StaticTrial']
# static_trial = ['S00_P00_Participant/S00_P00_T00_StaticTrial']
# # If this Config.toml file is at the Trial level, set to true or false (lowercase);
# # At the Participant level, specify the name of the static trial folder name, e.g. ['S00_P00_T00_StaticTrial'];
# # At the Session level, add participant subdirectory, e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P01_Participant/S00_P00_T00_StaticTrial']

View File

@ -9,6 +9,7 @@
# If a parameter is not found here, Pose2Sim will look for its value in the
# Config.toml file of the level above. This way, you can set global
# instructions for the Session and alter them for specific Participants or Trials.
#
# If you wish to overwrite a parameter for a specific trial or participant,
# edit its Config.toml file by uncommenting its key (e.g., [project])
# and editing its value (e.g., frame_range = [10,300]). Or else, uncomment
@ -25,13 +26,9 @@
# exclude_from_batch = [] # List of trials to be excluded from batch analysis, ['<participant_dir/trial_dir>', 'etc'].
# e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P00_Participant/S00_P00_T01_BalancingTrial']
# participant_height = 1.7 # m
# participant_mass = 70 # kg
## Only taken into account if pose_model is 'BODY_25_AUGMENTED' # Coming soon!
## Take heart, calibration is not that complicated once you get the hang of it!
# [calibration]
# calibration_type = 'convert' # 'convert' or 'calculate'
@ -95,7 +92,6 @@
# [pose]
# pose_framework = 'openpose' # 'openpose', 'mediapipe', 'alphapose', 'deeplabcut'
# pose_model = 'BODY_25B' #With openpose: BODY_25B, BODY_25, BODY_135, COCO, MPII,
# BODY_25_AUGMENTED # Coming soon!
# #With mediapipe: BLAZEPOSE.
# #With alphapose: HALPE_26, HALPE_68, HALPE_136, COCO_133.
# #With deeplabcut: CUSTOM. See example at the end of the file.
@ -139,9 +135,9 @@
# make_c3d = false # save triangulated data in c3d format in addition to trc # Coming soon!
[filtering]
# [filtering]
# type = 'butterworth' # butterworth, kalman, gaussian, LOESS, median, butterworth_on_speed
display_figures = true # true or false (lowercase)
# display_figures = true # true or false (lowercase)
# [filtering.butterworth]
# order = 4
@ -161,8 +157,14 @@ display_figures = true # true or false (lowercase)
# kernel_size = 9
# [markerAugmentation]
# ## Only works on BODY_25 and BODY_25B models
# participant_height = 1.7 # m
# participant_mass = 70 # kg
# [opensim]
# static_trial = ['S01_P00_Participant0/S01_P00_T00_StaticTrial']
# static_trial = ['S00_P00_Participant/S00_P00_T00_StaticTrial']
# # If this Config.toml file is at the Trial level, set to true or false (lowercase);
# # At the Participant level, specify the name of the static trial folder name, e.g. ['S00_P00_T00_StaticTrial'];
# # At the Session level, add participant subdirectory, e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P01_Participant/S00_P00_T00_StaticTrial']

View File

@ -26,13 +26,9 @@
# exclude_from_batch = [] # List of trials to be excluded from batch analysis, ['<participant_dir/trial_dir>', 'etc'].
# e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P00_Participant/S00_P00_T01_BalancingTrial']
# participant_height = 1.7 # m
# participant_mass = 70 # kg
## Only taken into account if pose_model is 'BODY_25_AUGMENTED' # Coming soon!
## Take heart, calibration is not that complicated once you get the hang of it!
# [calibration]
# calibration_type = 'convert' # 'convert' or 'calculate'
@ -96,7 +92,6 @@
# [pose]
# pose_framework = 'openpose' # 'openpose', 'mediapipe', 'alphapose', 'deeplabcut'
# pose_model = 'BODY_25B' #With openpose: BODY_25B, BODY_25, BODY_135, COCO, MPII,
# BODY_25_AUGMENTED # Coming soon!
# #With mediapipe: BLAZEPOSE.
# #With alphapose: HALPE_26, HALPE_68, HALPE_136, COCO_133.
# #With deeplabcut: CUSTOM. See example at the end of the file.
@ -162,8 +157,14 @@
# kernel_size = 9
# [markerAugmentation]
# ## Only works on BODY_25 and BODY_25B models
# participant_height = 1.7 # m
# participant_mass = 70 # kg
# [opensim]
# static_trial = ['S01_P01_Participant1/S01_P01_T00_StaticTrial']
# static_trial = ['S00_P00_Participant/S00_P00_T00_StaticTrial']
# # If this Config.toml file is at the Trial level, set to true or false (lowercase);
# # At the Participant level, specify the name of the static trial folder name, e.g. ['S00_P00_T00_StaticTrial'];
# # At the Session level, add participant subdirectory, e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P01_Participant/S00_P00_T00_StaticTrial']

View File

@ -26,13 +26,9 @@
# exclude_from_batch = [] # List of trials to be excluded from batch analysis, ['<participant_dir/trial_dir>', 'etc'].
# e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P00_Participant/S00_P00_T01_BalancingTrial']
# participant_height = 1.7 # m
# participant_mass = 70 # kg
## Only taken into account if pose_model is 'BODY_25_AUGMENTED' # Coming soon!
## Take heart, calibration is not that complicated once you get the hang of it!
# [calibration]
# calibration_type = 'convert' # 'convert' or 'calculate'
@ -96,7 +92,6 @@
# [pose]
# pose_framework = 'openpose' # 'openpose', 'mediapipe', 'alphapose', 'deeplabcut'
# pose_model = 'BODY_25B' #With openpose: BODY_25B, BODY_25, BODY_135, COCO, MPII,
# BODY_25_AUGMENTED # Coming soon!
# #With mediapipe: BLAZEPOSE.
# #With alphapose: HALPE_26, HALPE_68, HALPE_136, COCO_133.
# #With deeplabcut: CUSTOM. See example at the end of the file.
@ -162,8 +157,14 @@
# kernel_size = 9
# [markerAugmentation]
# ## Only works on BODY_25 and BODY_25B models
# participant_height = 1.7 # m
# participant_mass = 70 # kg
# [opensim]
# static_trial = ['S01_P01_Participant1/S01_P01_T00_StaticTrial']
# static_trial = ['S00_P00_Participant/S00_P00_T00_StaticTrial']
# # If this Config.toml file is at the Trial level, set to true or false (lowercase);
# # At the Participant level, specify the name of the static trial folder name, e.g. ['S00_P00_T00_StaticTrial'];
# # At the Session level, add participant subdirectory, e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P01_Participant/S00_P00_T00_StaticTrial']

View File

@ -26,13 +26,9 @@
# exclude_from_batch = [] # List of trials to be excluded from batch analysis, ['<participant_dir/trial_dir>', 'etc'].
# e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P00_Participant/S00_P00_T01_BalancingTrial']
# participant_height = 1.7 # m
# participant_mass = 70 # kg
## Only taken into account if pose_model is 'BODY_25_AUGMENTED' # Coming soon!
## Take heart, calibration is not that complicated once you get the hang of it!
# [calibration]
# calibration_type = 'convert' # 'convert' or 'calculate'
@ -96,7 +92,6 @@
# [pose]
# pose_framework = 'openpose' # 'openpose', 'mediapipe', 'alphapose', 'deeplabcut'
# pose_model = 'BODY_25B' #With openpose: BODY_25B, BODY_25, BODY_135, COCO, MPII,
# BODY_25_AUGMENTED # Coming soon!
# #With mediapipe: BLAZEPOSE.
# #With alphapose: HALPE_26, HALPE_68, HALPE_136, COCO_133.
# #With deeplabcut: CUSTOM. See example at the end of the file.
@ -140,9 +135,9 @@
# make_c3d = false # save triangulated data in c3d format in addition to trc # Coming soon!
[filtering]
# [filtering]
# type = 'butterworth' # butterworth, kalman, gaussian, LOESS, median, butterworth_on_speed
display_figures = true # true or false (lowercase)
# display_figures = true # true or false (lowercase)
# [filtering.butterworth]
# order = 4
@ -162,8 +157,14 @@ display_figures = true # true or false (lowercase)
# kernel_size = 9
# [markerAugmentation]
# ## Only works on BODY_25 and BODY_25B models
# participant_height = 1.7 # m
# participant_mass = 70 # kg
# [opensim]
# static_trial = ['S01_P01_Participant1/S01_P01_T00_StaticTrial']
# static_trial = ['S00_P00_Participant/S00_P00_T00_StaticTrial']
# # If this Config.toml file is at the Trial level, set to true or false (lowercase);
# # At the Participant level, specify the name of the static trial folder name, e.g. ['S00_P00_T00_StaticTrial'];
# # At the Session level, add participant subdirectory, e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P01_Participant/S00_P00_T00_StaticTrial']

View File

@ -26,13 +26,9 @@
# exclude_from_batch = [] # List of trials to be excluded from batch analysis, ['<participant_dir/trial_dir>', 'etc'].
# e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P00_Participant/S00_P00_T01_BalancingTrial']
# participant_height = 1.7 # m
# participant_mass = 70 # kg
## Only taken into account if pose_model is 'BODY_25_AUGMENTED' # Coming soon!
## Take heart, calibration is not that complicated once you get the hang of it!
# [calibration]
# calibration_type = 'convert' # 'convert' or 'calculate'
@ -96,7 +92,6 @@
# [pose]
# pose_framework = 'openpose' # 'openpose', 'mediapipe', 'alphapose', 'deeplabcut'
# pose_model = 'BODY_25B' #With openpose: BODY_25B, BODY_25, BODY_135, COCO, MPII,
# BODY_25_AUGMENTED # Coming soon!
# #With mediapipe: BLAZEPOSE.
# #With alphapose: HALPE_26, HALPE_68, HALPE_136, COCO_133.
# #With deeplabcut: CUSTOM. See example at the end of the file.
@ -140,9 +135,9 @@
# make_c3d = false # save triangulated data in c3d format in addition to trc # Coming soon!
[filtering]
# [filtering]
# type = 'butterworth' # butterworth, kalman, gaussian, LOESS, median, butterworth_on_speed
display_figures = true # true or false (lowercase)
# display_figures = true # true or false (lowercase)
# [filtering.butterworth]
# order = 4
@ -162,8 +157,14 @@ display_figures = true # true or false (lowercase)
# kernel_size = 9
# [markerAugmentation]
# ## Only works on BODY_25 and BODY_25B models
# participant_height = 1.7 # m
# participant_mass = 70 # kg
# [opensim]
# static_trial = ['S01_P01_Participant1/S01_P01_T00_StaticTrial']
# static_trial = ['S00_P00_Participant/S00_P00_T00_StaticTrial']
# # If this Config.toml file is at the Trial level, set to true or false (lowercase);
# # At the Participant level, specify the name of the static trial folder name, e.g. ['S00_P00_T00_StaticTrial'];
# # At the Session level, add participant subdirectory, e.g. ['S00_P00_Participant/S00_P00_T00_StaticTrial', 'S00_P01_Participant/S00_P00_T00_StaticTrial']

Binary file not shown.

View File

@ -0,0 +1 @@
{"reference_marker": "midHip"}

View File

@ -0,0 +1 @@
{"class_name": "Sequential", "config": {"name": "sequential_2", "layers": [{"class_name": "InputLayer", "config": {"batch_input_shape": [null, null, 47], "dtype": "float32", "sparse": false, "ragged": false, "name": "lstm_8_input"}}, {"class_name": "LSTM", "config": {"name": "lstm_8", "trainable": true, "dtype": "float32", "batch_input_shape": [null, null, 47], "return_sequences": true, "return_state": false, "go_backwards": false, "stateful": false, "unroll": false, "time_major": false, "units": 128, "activation": "tanh", "recurrent_activation": "sigmoid", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "recurrent_initializer": {"class_name": "Orthogonal", "config": {"gain": 1.0, "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "unit_forget_bias": true, "kernel_regularizer": null, "recurrent_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "recurrent_constraint": null, "bias_constraint": null, "dropout": 0.0, "recurrent_dropout": 0.0, "implementation": 2}}, {"class_name": "LSTM", "config": {"name": "lstm_9", "trainable": true, "dtype": "float32", "return_sequences": true, "return_state": false, "go_backwards": false, "stateful": false, "unroll": false, "time_major": false, "units": 128, "activation": "tanh", "recurrent_activation": "sigmoid", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "recurrent_initializer": {"class_name": "Orthogonal", "config": {"gain": 1.0, "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "unit_forget_bias": true, "kernel_regularizer": null, "recurrent_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "recurrent_constraint": null, "bias_constraint": null, "dropout": 0.0, "recurrent_dropout": 0.0, "implementation": 2}}, {"class_name": "LSTM", "config": {"name": "lstm_10", "trainable": true, "dtype": "float32", "return_sequences": true, "return_state": false, "go_backwards": false, "stateful": false, "unroll": false, "time_major": false, "units": 128, "activation": "tanh", "recurrent_activation": "sigmoid", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "recurrent_initializer": {"class_name": "Orthogonal", "config": {"gain": 1.0, "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "unit_forget_bias": true, "kernel_regularizer": null, "recurrent_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "recurrent_constraint": null, "bias_constraint": null, "dropout": 0.0, "recurrent_dropout": 0.0, "implementation": 2}}, {"class_name": "LSTM", "config": {"name": "lstm_11", "trainable": true, "dtype": "float32", "return_sequences": true, "return_state": false, "go_backwards": false, "stateful": false, "unroll": false, "time_major": false, "units": 128, "activation": "tanh", "recurrent_activation": "sigmoid", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "recurrent_initializer": {"class_name": "Orthogonal", "config": {"gain": 1.0, "seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "unit_forget_bias": true, "kernel_regularizer": null, "recurrent_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "recurrent_constraint": null, "bias_constraint": null, "dropout": 0.0, "recurrent_dropout": 0.0, "implementation": 2}}, {"class_name": "TimeDistributed", "config": {"name": "time_distributed_2", "trainable": true, "dtype": "float32", "layer": {"class_name": "Dense", "config": {"name": "dense_2", "trainable": true, "dtype": "float32", "units": 105, "activation": "linear", "use_bias": true, "kernel_initializer": {"class_name": "GlorotUniform", "config": {"seed": null}}, "bias_initializer": {"class_name": "Zeros", "config": {}}, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "bias_constraint": null}}}}]}, "keras_version": "2.12.0", "backend": "tensorflow"}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1 @@
{"reference_marker": "midHip"}

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,191 @@
from . import utilsDataman
import numpy as np
import os
def TRC2numpy(pathFile, markers,rotation=None):
# rotation is a dict, eg. {'y':90} with axis, angle for rotation
trc_file = utilsDataman.TRCFile(pathFile)
time = trc_file.time
num_frames = time.shape[0]
data = np.zeros((num_frames, len(markers)*3))
if rotation != None:
for axis,angle in rotation.items():
trc_file.rotate(axis,angle)
for count, marker in enumerate(markers):
data[:,3*count:3*count+3] = trc_file.marker(marker)
this_dat = np.empty((num_frames, 1))
this_dat[:, 0] = time
data_out = np.concatenate((this_dat, data), axis=1)
return data_out
def numpy2TRC(f, data, headers, fc=50.0, t_start=0.0, units="m"):
header_mapping = {}
for count, header in enumerate(headers):
header_mapping[count+1] = header
# Line 1.
f.write('PathFileType 4\t(X/Y/Z) %s\n' % os.getcwd())
# Line 2.
f.write('DataRate\tCameraRate\tNumFrames\tNumMarkers\t'
'Units\tOrigDataRate\tOrigDataStartFrame\tOrigNumFrames\n')
num_frames=data.shape[0]
num_markers=len(header_mapping.keys())
# Line 3.
f.write('%.1f\t%.1f\t%i\t%i\t%s\t%.1f\t%i\t%i\n' % (
fc, fc, num_frames,
num_markers, units, fc,
1, num_frames))
# Line 4.
f.write("Frame#\tTime\t")
for key in sorted(header_mapping.keys()):
f.write("%s\t\t\t" % format(header_mapping[key]))
# Line 5.
f.write("\n\t\t")
for imark in np.arange(num_markers) + 1:
f.write('X%i\tY%s\tZ%s\t' % (imark, imark, imark))
f.write('\n')
# Line 6.
f.write('\n')
for frame in range(data.shape[0]):
f.write("{}\t{:.8f}\t".format(frame+1,(frame)/fc+t_start)) # opensim frame labeling is 1 indexed
for key in sorted(header_mapping.keys()):
f.write("{:.5f}\t{:.5f}\t{:.5f}\t".format(data[frame,0+(key-1)*3], data[frame,1+(key-1)*3], data[frame,2+(key-1)*3]))
f.write("\n")
def getOpenPoseMarkerNames():
markerNames = ["Nose", "Neck", "RShoulder", "RElbow", "RWrist",
"LShoulder", "LElbow", "LWrist", "midHip", "RHip",
"RKnee", "RAnkle", "LHip", "LKnee", "LAnkle", "REye",
"LEye", "REar", "LEar", "LBigToe", "LSmallToe",
"LHeel", "RBigToe", "RSmallToe", "RHeel"]
return markerNames
def getOpenPoseFaceMarkers():
faceMarkerNames = ['Nose', 'REye', 'LEye', 'REar', 'LEar']
markerNames = getOpenPoseMarkerNames()
idxFaceMarkers = [markerNames.index(i) for i in faceMarkerNames]
return faceMarkerNames, idxFaceMarkers
def getOpenPoseMarkers_fullBody():
feature_markers = [
"Neck", "RShoulder", "LShoulder", "RHip", "LHip", "RKnee", "LKnee",
"RAnkle", "LAnkle", "RHeel", "LHeel", "RSmallToe", "LSmallToe",
"RBigToe", "LBigToe", "RElbow", "LElbow", "RWrist", "LWrist"]
response_markers = ["C7_study", "r_shoulder_study", "L_shoulder_study",
"r.ASIS_study", "L.ASIS_study", "r.PSIS_study",
"L.PSIS_study", "r_knee_study", "L_knee_study",
"r_mknee_study", "L_mknee_study", "r_ankle_study",
"L_ankle_study", "r_mankle_study", "L_mankle_study",
"r_calc_study", "L_calc_study", "r_toe_study",
"L_toe_study", "r_5meta_study", "L_5meta_study",
"r_lelbow_study", "L_lelbow_study", "r_melbow_study",
"L_melbow_study", "r_lwrist_study", "L_lwrist_study",
"r_mwrist_study", "L_mwrist_study",
"r_thigh1_study", "r_thigh2_study", "r_thigh3_study",
"L_thigh1_study", "L_thigh2_study", "L_thigh3_study",
"r_sh1_study", "r_sh2_study", "r_sh3_study",
"L_sh1_study", "L_sh2_study", "L_sh3_study",
"RHJC_study", "LHJC_study"]
return feature_markers, response_markers
def getOpenPoseMarkers_lowerExtremity():
feature_markers = [
"Neck", "RShoulder", "LShoulder", "RHip", "LHip", "RKnee", "LKnee",
"RAnkle", "LAnkle", "RHeel", "LHeel", "RSmallToe", "LSmallToe",
"RBigToe", "LBigToe"]
response_markers = ["C7_study", "r_shoulder_study", "L_shoulder_study",
"r.ASIS_study", "L.ASIS_study", "r.PSIS_study",
"L.PSIS_study", "r_knee_study", "L_knee_study",
"r_mknee_study", "L_mknee_study", "r_ankle_study",
"L_ankle_study", "r_mankle_study", "L_mankle_study",
"r_calc_study", "L_calc_study", "r_toe_study",
"L_toe_study", "r_5meta_study", "L_5meta_study",
"r_thigh1_study", "r_thigh2_study", "r_thigh3_study",
"L_thigh1_study", "L_thigh2_study", "L_thigh3_study",
"r_sh1_study", "r_sh2_study", "r_sh3_study",
"L_sh1_study", "L_sh2_study", "L_sh3_study",
"RHJC_study", "LHJC_study"]
return feature_markers, response_markers
# Different order of markers compared to getOpenPoseMarkers_lowerExtremity
def getOpenPoseMarkers_lowerExtremity2():
feature_markers = [
"Neck", "RShoulder", "LShoulder", "RHip", "LHip", "RKnee", "LKnee",
"RAnkle", "LAnkle", "RHeel", "LHeel", "RSmallToe", "LSmallToe",
"RBigToe", "LBigToe"]
response_markers = [
'r.ASIS_study', 'L.ASIS_study', 'r.PSIS_study',
'L.PSIS_study', 'r_knee_study', 'r_mknee_study',
'r_ankle_study', 'r_mankle_study', 'r_toe_study',
'r_5meta_study', 'r_calc_study', 'L_knee_study',
'L_mknee_study', 'L_ankle_study', 'L_mankle_study',
'L_toe_study', 'L_calc_study', 'L_5meta_study',
'r_shoulder_study', 'L_shoulder_study', 'C7_study',
'r_thigh1_study', 'r_thigh2_study', 'r_thigh3_study',
'L_thigh1_study', 'L_thigh2_study', 'L_thigh3_study',
'r_sh1_study', 'r_sh2_study', 'r_sh3_study', 'L_sh1_study',
'L_sh2_study', 'L_sh3_study', 'RHJC_study', 'LHJC_study']
return feature_markers, response_markers
def getMarkers_upperExtremity_pelvis():
feature_markers = [
"Neck", "RShoulder", "LShoulder", "RHip", "LHip", "RElbow", "LElbow",
"RWrist", "LWrist"]
response_markers = ["r_lelbow_study", "L_lelbow_study", "r_melbow_study",
"L_melbow_study", "r_lwrist_study", "L_lwrist_study",
"r_mwrist_study", "L_mwrist_study"]
return feature_markers, response_markers
def getMarkers_upperExtremity_noPelvis():
feature_markers = [
"Neck", "RShoulder", "LShoulder", "RElbow", "LElbow", "RWrist",
"LWrist"]
response_markers = ["r_lelbow_study", "L_lelbow_study", "r_melbow_study",
"L_melbow_study", "r_lwrist_study", "L_lwrist_study",
"r_mwrist_study", "L_mwrist_study"]
return feature_markers, response_markers
# Different order of markers compared to getMarkers_upperExtremity_noPelvis.
def getMarkers_upperExtremity_noPelvis2():
feature_markers = [
"Neck", "RShoulder", "LShoulder", "RElbow", "LElbow", "RWrist",
"LWrist"]
response_markers = ["r_lelbow_study", "r_melbow_study", "r_lwrist_study",
"r_mwrist_study", "L_lelbow_study", "L_melbow_study",
"L_lwrist_study", "L_mwrist_study"]
return feature_markers, response_markers

View File

@ -0,0 +1,282 @@
"""Manages the movement and use of data files."""
import os
import warnings
from scipy.spatial.transform import Rotation as R
import numpy as np
from numpy.lib.recfunctions import append_fields
class TRCFile(object):
"""A plain-text file format for storing motion capture marker trajectories.
TRC stands for Track Row Column.
The metadata for the file is stored in attributes of this object.
See
http://simtk-confluence.stanford.edu:8080/display/OpenSim/Marker+(.trc)+Files
for more information.
"""
def __init__(self, fpath=None, **kwargs):
#path=None,
#data_rate=None,
#camera_rate=None,
#num_frames=None,
#num_markers=None,
#units=None,
#orig_data_rate=None,
#orig_data_start_frame=None,
#orig_num_frames=None,
#marker_names=None,
#time=None,
#):
"""
Parameters
----------
fpath : str
Valid file path to a TRC (.trc) file.
"""
self.marker_names = []
if fpath != None:
self.read_from_file(fpath)
else:
for k, v in kwargs.items():
setattr(self, k, v)
def read_from_file(self, fpath):
# Read the header lines / metadata.
# ---------------------------------
# Split by any whitespace.
# TODO may cause issues with paths that have spaces in them.
f = open(fpath)
# These are lists of each entry on the first few lines.
first_line = f.readline().split()
# Skip the 2nd line.
f.readline()
third_line = f.readline().split()
fourth_line = f.readline().split()
f.close()
# First line.
if len(first_line) > 3:
self.path = first_line[3]
else:
self.path = ''
# Third line.
self.data_rate = float(third_line[0])
self.camera_rate = float(third_line[1])
self.num_frames = int(third_line[2])
self.num_markers = int(third_line[3])
self.units = third_line[4]
self.orig_data_rate = float(third_line[5])
self.orig_data_start_frame = int(third_line[6])
self.orig_num_frames = int(third_line[7])
# Marker names.
# The first and second column names are 'Frame#' and 'Time'.
self.marker_names = fourth_line[2:]
len_marker_names = len(self.marker_names)
if len_marker_names != self.num_markers:
warnings.warn('Header entry NumMarkers, %i, does not '
'match actual number of markers, %i. Changing '
'NumMarkers to match actual number.' % (
self.num_markers, len_marker_names))
self.num_markers = len_marker_names
# Load the actual data.
# ---------------------
col_names = ['frame_num', 'time']
# This naming convention comes from OpenSim's Inverse Kinematics tool,
# when it writes model marker locations.
for mark in self.marker_names:
col_names += [mark + '_tx', mark + '_ty', mark + '_tz']
dtype = {'names': col_names,
'formats': ['int'] + ['float64'] * (3 * self.num_markers + 1)}
usecols = [i for i in range(3 * self.num_markers + 1 + 1)]
self.data = np.loadtxt(fpath, delimiter='\t', skiprows=5, dtype=dtype,
usecols=usecols)
self.time = self.data['time']
# Check the number of rows.
n_rows = self.time.shape[0]
if n_rows != self.num_frames:
warnings.warn('%s: Header entry NumFrames, %i, does not '
'match actual number of frames, %i, Changing '
'NumFrames to match actual number.' % (fpath,
self.num_frames, n_rows))
self.num_frames = n_rows
def __getitem__(self, key):
"""See `marker()`.
"""
return self.marker(key)
def units(self):
return self.units
def time(self):
this_dat = np.empty((self.num_frames, 1))
this_dat[:, 0] = self.time
return this_dat
def marker(self, name):
"""The trajectory of marker `name`, given as a `self.num_frames` x 3
array. The order of the columns is x, y, z.
"""
this_dat = np.empty((self.num_frames, 3))
this_dat[:, 0] = self.data[name + '_tx']
this_dat[:, 1] = self.data[name + '_ty']
this_dat[:, 2] = self.data[name + '_tz']
return this_dat
def add_marker(self, name, x, y, z):
"""Add a marker, with name `name` to the TRCFile.
Parameters
----------
name : str
Name of the marker; e.g., 'R.Hip'.
x, y, z: array_like
Coordinates of the marker trajectory. All 3 must have the same
length.
"""
if (len(x) != self.num_frames or len(y) != self.num_frames or len(z) !=
self.num_frames):
raise Exception('Length of data (%i, %i, %i) is not '
'NumFrames (%i).', len(x), len(y), len(z), self.num_frames)
self.marker_names += [name]
self.num_markers += 1
if not hasattr(self, 'data'):
self.data = np.array(x, dtype=[('%s_tx' % name, 'float64')])
self.data = append_fields(self.data,
['%s_t%s' % (name, s) for s in 'yz'],
[y, z], usemask=False)
else:
self.data = append_fields(self.data,
['%s_t%s' % (name, s) for s in 'xyz'],
[x, y, z], usemask=False)
def marker_at(self, name, time):
x = np.interp(time, self.time, self.data[name + '_tx'])
y = np.interp(time, self.time, self.data[name + '_ty'])
z = np.interp(time, self.time, self.data[name + '_tz'])
return [x, y, z]
def marker_exists(self, name):
"""
Returns
-------
exists : bool
Is the marker in the TRCFile?
"""
return name in self.marker_names
def write(self, fpath):
"""Write this TRCFile object to a TRC file.
Parameters
----------
fpath : str
Valid file path to which this TRCFile is saved.
"""
f = open(fpath, 'w')
# Line 1.
f.write('PathFileType 4\t(X/Y/Z) %s\n' % os.path.split(fpath)[0])
# Line 2.
f.write('DataRate\tCameraRate\tNumFrames\tNumMarkers\t'
'Units\tOrigDataRate\tOrigDataStartFrame\tOrigNumFrames\n')
# Line 3.
f.write('%.1f\t%.1f\t%i\t%i\t%s\t%.1f\t%i\t%i\n' % (
self.data_rate, self.camera_rate, self.num_frames,
self.num_markers, self.units, self.orig_data_rate,
self.orig_data_start_frame, self.orig_num_frames))
# Line 4.
f.write('Frame#\tTime\t')
for imark in range(self.num_markers):
f.write('%s\t\t\t' % self.marker_names[imark])
f.write('\n')
# Line 5.
f.write('\t\t')
for imark in np.arange(self.num_markers) + 1:
f.write('X%i\tY%s\tZ%s\t' % (imark, imark, imark))
f.write('\n')
# Line 6.
f.write('\n')
# Data.
for iframe in range(self.num_frames):
f.write('%i' % (iframe + 1))
f.write('\t%.7f' % self.time[iframe])
for mark in self.marker_names:
idxs = [mark + '_tx', mark + '_ty', mark + '_tz']
f.write('\t%.7f\t%.7f\t%.7f' % tuple(
self.data[coln][iframe] for coln in idxs))
f.write('\n')
f.close()
def add_noise(self, noise_width):
""" add random noise to each component of the marker trajectory
The noise mean will be zero, with the noise_width being the
standard deviation.
noise_width : int
"""
for imarker in range(self.num_markers):
components = ['_tx', '_ty', '_tz']
for iComponent in range(3):
# generate noise
noise = np.random.normal(0, noise_width, self.num_frames)
# add noise to each component of marker data.
self.data[self.marker_names[imarker] + components[iComponent]] += noise
def rotate(self, axis, value):
""" rotate the data.
axis : rotation axis
value : angle in degree
"""
for imarker in range(self.num_markers):
temp = np.zeros((self.num_frames, 3))
temp[:,0] = self.data[self.marker_names[imarker] + '_tx']
temp[:,1] = self.data[self.marker_names[imarker] + '_ty']
temp[:,2] = self.data[self.marker_names[imarker] + '_tz']
r = R.from_euler(axis, value, degrees=True)
temp_rot = r.apply(temp)
self.data[self.marker_names[imarker] + '_tx'] = temp_rot[:,0]
self.data[self.marker_names[imarker] + '_ty'] = temp_rot[:,1]
self.data[self.marker_names[imarker] + '_tz'] = temp_rot[:,2]
def offset(self, axis, value):
""" offset the data.
axis : rotation axis
value : offset in m
"""
for imarker in range(self.num_markers):
if axis.lower() == 'x':
self.data[self.marker_names[imarker] + '_tx'] += value
elif axis.lower() == 'y':
self.data[self.marker_names[imarker] + '_ty'] += value
elif axis.lower() == 'z':
self.data[self.marker_names[imarker] + '_tz'] += value
else:
raise ValueError("Axis not recognized")

Some files were not shown because too many files have changed in this diff Show More