Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,15 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/


*.env
*.vtp
*.trc
*.osim
*.csv
*.json
*.xml
*.yaml
*.yml
*.mot
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# opencap-analysis
This repository contains analyses to be deployed on OpenCap web application.
This repository contains analyses to be deployed on OpenCap web application.
39 changes: 32 additions & 7 deletions gait_analysis/function/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,24 @@ def handler(event, context):
To invoke the function do POST request on the following url
http://localhost:8080/2015-03-31/functions/function/invocations
"""
# temporary placeholder
kwargs = json.loads(event['body'])
try:
return _handler(event, context)
except Exception as e:
return {
'statusCode': 500,
'headers': {'Content-Type': 'application/json'},
'body': {'error': str(e)}
}


def _handler(event, context):
body = event.get('body', None)
if isinstance(body, dict):
kwargs = body
elif isinstance(body, str) and body:
kwargs = json.loads(body)
else:
kwargs = event

for field in ('session_id', 'specific_trial_names'):
if field not in kwargs:
Expand Down Expand Up @@ -79,14 +95,23 @@ def handler(event, context):

# %% Process data.
# Init gait analysis and get gait events.
# Try with end trimming first (removes HRNet artifacts when subject leaves
# frame); fall back to no trimming if not enough gait cycles are found.
legs = ['r']
gait, gait_events = {}, {}
for leg in legs:
gait[leg] = gait_analysis(
sessionDir, trial_name, leg=leg,
lowpass_cutoff_frequency_for_coordinate_values=filter_frequency,
n_gait_cycles=n_gait_cycles, gait_style='overground',
trimming_start=0, trimming_end=0.5)
try:
gait[leg] = gait_analysis(
sessionDir, trial_name, leg=leg,
lowpass_cutoff_frequency_for_coordinate_values=filter_frequency,
n_gait_cycles=n_gait_cycles, gait_style='overground',
trimming_start=0, trimming_end=0.5)
except Exception:
gait[leg] = gait_analysis(
sessionDir, trial_name, leg=leg,
lowpass_cutoff_frequency_for_coordinate_values=filter_frequency,
n_gait_cycles=n_gait_cycles, gait_style='overground',
trimming_start=0, trimming_end=0)
gait_events[leg] = gait[leg].get_gait_events()

# Select last leg.
Expand Down
56 changes: 56 additions & 0 deletions gait_analysis/function/marker_name_mapping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
Marker name mapping dictionary for converting from expected format (with '_study' suffix)
to actual format (without '_study' suffix, lowercase).

This mapping is used to rename markers in TRC files to match the expected format
used by the gait_analysis class.

Expected format: markers end with '_study' (e.g., 'r_calc_study', 'r.ASIS_study')
Actual format: markers without '_study' suffix, lowercase (e.g., 'r_calc', 'r_ASIS')
"""

MARKER_NAME_MAPPING = {
# Pelvis markers
'r.ASIS_study': 'r_ASIS',
'L.ASIS_study': 'l_ASIS',
'r.PSIS_study': 'r_PSIS',
'L.PSIS_study': 'l_PSIS',

# Right leg markers
'r_knee_study': 'r_knee',
'r_mknee_study': 'r_mknee',
'r_ankle_study': 'r_ankle',
'r_mankle_study': 'r_mankle',
'r_toe_study': 'r_toe',
'r_5meta_study': 'r_5meta',
'r_calc_study': 'r_calc',

# Left leg markers
'L_knee_study': 'l_knee',
'L_mknee_study': 'l_mknee',
'L_ankle_study': 'l_ankle',
'L_mankle_study': 'l_mankle',
'L_toe_study': 'l_toe',
'L_calc_study': 'l_calc',
'L_5meta_study': 'l_5meta',

# Shoulder markers
'r_shoulder_study': 'r_shoulder',
'L_shoulder_study': 'l_shoulder',

# Spine markers
'C7_study': 'C7',

# Hip joint centers
'RHJC_study': 'RHJC', # Check if exists in actual file
'LHJC_study': 'LHJC', # Check if exists in actual file

# Elbow markers
'r_melbow_study': 'r_melbow',
'L_melbow_study': 'l_melbow',

}

# Reverse mapping (actual -> expected) for renaming markers in TRC files
REVERSE_MARKER_NAME_MAPPING = {v: k for k, v in MARKER_NAME_MAPPING.items()}

Loading
Loading