removed logging errors to make sure tests don't pass in case of problems
This commit is contained in:
parent
65e675ab64
commit
3e31eaf50f
@ -191,11 +191,7 @@ def calibration(config=None):
|
|||||||
logging.info("---------------------------------------------------------------------\n")
|
logging.info("---------------------------------------------------------------------\n")
|
||||||
start = time.time()
|
start = time.time()
|
||||||
|
|
||||||
try:
|
calibrate_cams_all(config_dict)
|
||||||
calibrate_cams_all(config_dict)
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"Error during calibration: {e}")
|
|
||||||
return
|
|
||||||
|
|
||||||
end = time.time()
|
end = time.time()
|
||||||
logging.info(f'\nCalibration took {end-start:.2f} s.\n')
|
logging.info(f'\nCalibration took {end-start:.2f} s.\n')
|
||||||
@ -239,12 +235,8 @@ def poseEstimation(config=None):
|
|||||||
logging.info(f"Project directory: {project_dir}")
|
logging.info(f"Project directory: {project_dir}")
|
||||||
logging.info("---------------------------------------------------------------------\n")
|
logging.info("---------------------------------------------------------------------\n")
|
||||||
|
|
||||||
try:
|
rtm_estimator(config_dict)
|
||||||
rtm_estimator(config_dict)
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"Error during pose estimation: {e}")
|
|
||||||
continue
|
|
||||||
|
|
||||||
end = time.time()
|
end = time.time()
|
||||||
elapsed = end - start
|
elapsed = end - start
|
||||||
logging.info(f'\nPose estimation took {time.strftime("%Hh%Mm%Ss", time.gmtime(elapsed))}.\n')
|
logging.info(f'\nPose estimation took {time.strftime("%Hh%Mm%Ss", time.gmtime(elapsed))}.\n')
|
||||||
@ -287,12 +279,8 @@ def synchronization(config=None):
|
|||||||
logging.info(f"Project directory: {project_dir}")
|
logging.info(f"Project directory: {project_dir}")
|
||||||
logging.info("---------------------------------------------------------------------\n")
|
logging.info("---------------------------------------------------------------------\n")
|
||||||
|
|
||||||
try:
|
synchronize_cams_all(config_dict)
|
||||||
synchronize_cams_all(config_dict)
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"Error during synchronization: {e}")
|
|
||||||
continue
|
|
||||||
|
|
||||||
end = time.time()
|
end = time.time()
|
||||||
elapsed = end-start
|
elapsed = end-start
|
||||||
logging.info(f'\nSynchronization took {time.strftime("%Hh%Mm%Ss", time.gmtime(elapsed))}.\n')
|
logging.info(f'\nSynchronization took {time.strftime("%Hh%Mm%Ss", time.gmtime(elapsed))}.\n')
|
||||||
@ -338,12 +326,8 @@ def personAssociation(config=None):
|
|||||||
logging.info(f"Project directory: {project_dir}")
|
logging.info(f"Project directory: {project_dir}")
|
||||||
logging.info("---------------------------------------------------------------------\n")
|
logging.info("---------------------------------------------------------------------\n")
|
||||||
|
|
||||||
try:
|
track_2d_all(config_dict)
|
||||||
track_2d_all(config_dict)
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"Error during person association: {e}")
|
|
||||||
continue
|
|
||||||
|
|
||||||
end = time.time()
|
end = time.time()
|
||||||
elapsed = end-start
|
elapsed = end-start
|
||||||
logging.info(f'\nAssociating persons took {time.strftime("%Hh%Mm%Ss", time.gmtime(elapsed))}.\n')
|
logging.info(f'\nAssociating persons took {time.strftime("%Hh%Mm%Ss", time.gmtime(elapsed))}.\n')
|
||||||
@ -388,12 +372,8 @@ def triangulation(config=None):
|
|||||||
logging.info(f"Project directory: {project_dir}")
|
logging.info(f"Project directory: {project_dir}")
|
||||||
logging.info("---------------------------------------------------------------------\n")
|
logging.info("---------------------------------------------------------------------\n")
|
||||||
|
|
||||||
try:
|
triangulate_all(config_dict)
|
||||||
triangulate_all(config_dict)
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"Error during triangulation: {e}")
|
|
||||||
continue
|
|
||||||
|
|
||||||
end = time.time()
|
end = time.time()
|
||||||
elapsed = end-start
|
elapsed = end-start
|
||||||
logging.info(f'\nTriangulation took {time.strftime("%Hh%Mm%Ss", time.gmtime(elapsed))}.\n')
|
logging.info(f'\nTriangulation took {time.strftime("%Hh%Mm%Ss", time.gmtime(elapsed))}.\n')
|
||||||
@ -437,12 +417,8 @@ def filtering(config=None):
|
|||||||
logging.info(f"Project directory: {project_dir}\n")
|
logging.info(f"Project directory: {project_dir}\n")
|
||||||
logging.info("---------------------------------------------------------------------\n")
|
logging.info("---------------------------------------------------------------------\n")
|
||||||
|
|
||||||
try:
|
filter_all(config_dict)
|
||||||
filter_all(config_dict)
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"Error during filtering: {e}")
|
|
||||||
continue
|
|
||||||
|
|
||||||
logging.info('\n')
|
logging.info('\n')
|
||||||
|
|
||||||
|
|
||||||
@ -482,12 +458,8 @@ def markerAugmentation(config=None):
|
|||||||
logging.info(f"Project directory: {project_dir}")
|
logging.info(f"Project directory: {project_dir}")
|
||||||
logging.info("---------------------------------------------------------------------\n")
|
logging.info("---------------------------------------------------------------------\n")
|
||||||
|
|
||||||
try:
|
augmentTRC(config_dict)
|
||||||
augmentTRC(config_dict)
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"Error during marker augmentation: {e}")
|
|
||||||
continue
|
|
||||||
|
|
||||||
end = time.time()
|
end = time.time()
|
||||||
elapsed = end-start
|
elapsed = end-start
|
||||||
logging.info(f'\nMarker augmentation took {time.strftime("%Hh%Mm%Ss", time.gmtime(elapsed))}.\n')
|
logging.info(f'\nMarker augmentation took {time.strftime("%Hh%Mm%Ss", time.gmtime(elapsed))}.\n')
|
||||||
@ -531,12 +503,8 @@ def kinematics(config=None):
|
|||||||
logging.info(f"Project directory: {project_dir}")
|
logging.info(f"Project directory: {project_dir}")
|
||||||
logging.info("---------------------------------------------------------------------\n")
|
logging.info("---------------------------------------------------------------------\n")
|
||||||
|
|
||||||
try:
|
kinematics(config_dict)
|
||||||
kinematics(config_dict)
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"Error during OpenSim processing: {e}")
|
|
||||||
continue
|
|
||||||
|
|
||||||
end = time.time()
|
end = time.time()
|
||||||
elapsed = end - start
|
elapsed = end - start
|
||||||
logging.info(f'OpenSim scaling and inverse kinematics took {time.strftime("%Hh%Mm%Ss", time.gmtime(elapsed))}.\n')
|
logging.info(f'OpenSim scaling and inverse kinematics took {time.strftime("%Hh%Mm%Ss", time.gmtime(elapsed))}.\n')
|
||||||
|
@ -489,79 +489,76 @@ def kinematics(config_dict):
|
|||||||
- Joint angle data files (.mot) for each person.
|
- Joint angle data files (.mot) for each person.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
try:
|
# Read config_dict
|
||||||
# Read config_dict
|
project_dir = config_dict.get('project').get('project_dir')
|
||||||
project_dir = config_dict.get('project').get('project_dir')
|
# if batch
|
||||||
# if batch
|
session_dir = Path(project_dir) / '..'
|
||||||
session_dir = Path(project_dir) / '..'
|
# if single trial
|
||||||
# if single trial
|
session_dir = session_dir if 'Config.toml' in os.listdir(session_dir) else os.getcwd()
|
||||||
session_dir = session_dir if 'Config.toml' in os.listdir(session_dir) else os.getcwd()
|
use_augmentation = config_dict.get('kinematics').get('use_augmentation')
|
||||||
use_augmentation = config_dict.get('kinematics').get('use_augmentation')
|
if use_augmentation: model_name = 'LSTM'
|
||||||
if use_augmentation: model_name = 'LSTM'
|
else: model_name = config_dict.get('pose').get('pose_model').upper()
|
||||||
else: model_name = config_dict.get('pose').get('pose_model').upper()
|
right_left_symmetry = config_dict.get('kinematics').get('right_left_symmetry')
|
||||||
right_left_symmetry = config_dict.get('kinematics').get('right_left_symmetry')
|
remove_scaling_setup = config_dict.get('kinematics').get('remove_individual_scaling_setup')
|
||||||
remove_scaling_setup = config_dict.get('kinematics').get('remove_individual_scaling_setup')
|
remove_IK_setup = config_dict.get('kinematics').get('remove_individual_IK_setup')
|
||||||
remove_IK_setup = config_dict.get('kinematics').get('remove_individual_IK_setup')
|
subject_height = config_dict.get('project').get('participant_height')
|
||||||
subject_height = config_dict.get('project').get('participant_height')
|
subject_mass = config_dict.get('project').get('participant_mass')
|
||||||
subject_mass = config_dict.get('project').get('participant_mass')
|
|
||||||
|
|
||||||
pose3d_dir = Path(project_dir) / 'pose-3d'
|
pose3d_dir = Path(project_dir) / 'pose-3d'
|
||||||
kinematics_dir = Path(project_dir) / 'kinematics'
|
kinematics_dir = Path(project_dir) / 'kinematics'
|
||||||
kinematics_dir.mkdir(parents=True, exist_ok=True)
|
kinematics_dir.mkdir(parents=True, exist_ok=True)
|
||||||
osim_setup_dir = get_opensim_setup_dir()
|
osim_setup_dir = get_opensim_setup_dir()
|
||||||
|
|
||||||
# OpenSim logs saved to a different file
|
# OpenSim logs saved to a different file
|
||||||
opensim_logs_file = kinematics_dir / 'opensim_logs.txt'
|
opensim_logs_file = kinematics_dir / 'opensim_logs.txt'
|
||||||
opensim.Logger.setLevelString('Info')
|
opensim.Logger.setLevelString('Info')
|
||||||
opensim.Logger.removeFileSink()
|
opensim.Logger.removeFileSink()
|
||||||
opensim.Logger.addFileSink(str(opensim_logs_file))
|
opensim.Logger.addFileSink(str(opensim_logs_file))
|
||||||
|
|
||||||
# Find all trc files
|
# Find all trc files
|
||||||
trc_files = []
|
trc_files = []
|
||||||
if use_augmentation:
|
if use_augmentation:
|
||||||
trc_files = [f for f in pose3d_dir.glob('*.trc') if '_LSTM' in f.name]
|
trc_files = [f for f in pose3d_dir.glob('*.trc') if '_LSTM' in f.name]
|
||||||
if len(trc_files) == 0:
|
|
||||||
model_name = config_dict.get('pose').get('pose_model').upper()
|
|
||||||
logging.warning("No LSTM trc files found. Using non augmented trc files instead.")
|
|
||||||
if len(trc_files) == 0: # filtered files by default
|
|
||||||
trc_files = [f for f in pose3d_dir.glob('*.trc') if '_LSTM' not in f.name and '_filt' in f.name and '_scaling' not in f.name]
|
|
||||||
if len(trc_files) == 0:
|
|
||||||
trc_files = [f for f in pose3d_dir.glob('*.trc') if '_LSTM' not in f.name and '_scaling' not in f.name]
|
|
||||||
if len(trc_files) == 0:
|
if len(trc_files) == 0:
|
||||||
raise ValueError(f'No trc files found in {pose3d_dir}.')
|
model_name = config_dict.get('pose').get('pose_model').upper()
|
||||||
sorted(trc_files, key=natural_sort_key)
|
logging.warning("No LSTM trc files found. Using non augmented trc files instead.")
|
||||||
|
if len(trc_files) == 0: # filtered files by default
|
||||||
|
trc_files = [f for f in pose3d_dir.glob('*.trc') if '_LSTM' not in f.name and '_filt' in f.name and '_scaling' not in f.name]
|
||||||
|
if len(trc_files) == 0:
|
||||||
|
trc_files = [f for f in pose3d_dir.glob('*.trc') if '_LSTM' not in f.name and '_scaling' not in f.name]
|
||||||
|
if len(trc_files) == 0:
|
||||||
|
raise ValueError(f'No trc files found in {pose3d_dir}.')
|
||||||
|
sorted(trc_files, key=natural_sort_key)
|
||||||
|
|
||||||
# Get subject heights and masses
|
# Get subject heights and masses
|
||||||
if subject_height is None or subject_height == 0:
|
if subject_height is None or subject_height == 0:
|
||||||
subject_height = [1.75] * len(trc_files)
|
subject_height = [1.75] * len(trc_files)
|
||||||
logging.warning("No subject height found in Config.toml. Using default height of 1.75m.")
|
logging.warning("No subject height found in Config.toml. Using default height of 1.75m.")
|
||||||
elif not type(subject_height) == list: # int or float
|
elif not type(subject_height) == list: # int or float
|
||||||
subject_height = [subject_height]
|
subject_height = [subject_height]
|
||||||
elif len(subject_height) < len(trc_files):
|
elif len(subject_height) < len(trc_files):
|
||||||
logging.warning("Number of subject heights does not match number of TRC files. Missing heights are set to 1.75m.")
|
logging.warning("Number of subject heights does not match number of TRC files. Missing heights are set to 1.75m.")
|
||||||
subject_height += [1.75] * (len(trc_files) - len(subject_height))
|
subject_height += [1.75] * (len(trc_files) - len(subject_height))
|
||||||
|
|
||||||
if subject_mass is None or subject_mass == 0:
|
if subject_mass is None or subject_mass == 0:
|
||||||
subject_mass = [70] * len(trc_files)
|
subject_mass = [70] * len(trc_files)
|
||||||
logging.warning("No subject mass found in Config.toml. Using default mass of 70kg.")
|
logging.warning("No subject mass found in Config.toml. Using default mass of 70kg.")
|
||||||
elif not type(subject_mass) == list:
|
elif not type(subject_mass) == list:
|
||||||
subject_mass = [subject_mass]
|
subject_mass = [subject_mass]
|
||||||
elif len(subject_mass) < len(trc_files):
|
elif len(subject_mass) < len(trc_files):
|
||||||
logging.warning("Number of subject masses does not match number of TRC files. Missing masses are set to 70kg.")
|
logging.warning("Number of subject masses does not match number of TRC files. Missing masses are set to 70kg.")
|
||||||
subject_mass += [70] * (len(trc_files) - len(subject_mass))
|
subject_mass += [70] * (len(trc_files) - len(subject_mass))
|
||||||
|
|
||||||
# Perform scaling and IK for each trc file
|
# Perform scaling and IK for each trc file
|
||||||
for p, trc_file in enumerate(trc_files):
|
for p, trc_file in enumerate(trc_files):
|
||||||
logging.info(f"Processing TRC file: {trc_file.resolve()}")
|
logging.info(f"Processing TRC file: {trc_file.resolve()}")
|
||||||
|
|
||||||
logging.info("Scaling...")
|
logging.info("Scaling...")
|
||||||
perform_scaling(trc_file, kinematics_dir, osim_setup_dir, model_name, right_left_symmetry=right_left_symmetry, subject_height=subject_height[p], subject_mass=subject_mass[p], remove_scaling_setup=remove_scaling_setup)
|
perform_scaling(trc_file, kinematics_dir, osim_setup_dir, model_name, right_left_symmetry=right_left_symmetry, subject_height=subject_height[p], subject_mass=subject_mass[p], remove_scaling_setup=remove_scaling_setup)
|
||||||
logging.info(f"\tDone. OpenSim logs saved to {opensim_logs_file.resolve()}.")
|
logging.info(f"\tDone. OpenSim logs saved to {opensim_logs_file.resolve()}.")
|
||||||
logging.info(f"\tScaled model saved to {(kinematics_dir / (trc_file.stem + '_scaled.osim')).resolve()}")
|
logging.info(f"\tScaled model saved to {(kinematics_dir / (trc_file.stem + '_scaled.osim')).resolve()}")
|
||||||
|
|
||||||
logging.info("\nInverse Kinematics...")
|
logging.info("\nInverse Kinematics...")
|
||||||
perform_IK(trc_file, kinematics_dir, osim_setup_dir, model_name, remove_IK_setup=remove_IK_setup)
|
perform_IK(trc_file, kinematics_dir, osim_setup_dir, model_name, remove_IK_setup=remove_IK_setup)
|
||||||
logging.info(f"\tDone. OpenSim logs saved to {opensim_logs_file.resolve()}.")
|
logging.info(f"\tDone. OpenSim logs saved to {opensim_logs_file.resolve()}.")
|
||||||
logging.info(f"\tJoint angle data saved to {(kinematics_dir / (trc_file.stem + '.mot')).resolve()}\n")
|
logging.info(f"\tJoint angle data saved to {(kinematics_dir / (trc_file.stem + '.mot')).resolve()}\n")
|
||||||
except RuntimeError as e:
|
|
||||||
logging.error(f"Error occurred: {e}")
|
|
||||||
|
Loading…
Reference in New Issue
Block a user