Skip to content

Commit

Permalink
updates overground gait analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinefalisse committed Feb 15, 2024
1 parent 778640e commit 9a5a424
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 22 deletions.
55 changes: 34 additions & 21 deletions gait_analysis/function/gait_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,32 +746,46 @@ def detect_correct_order(rHS, rTO, lHS, lTO):
return True

# Subtract sacrum from foot.
# It looks like the position-based approach will be more robust.
r_calc_rel_x = (
# It looks like the position-based approach will be more robust.
r_calc_rel = (
self.markerDict['markers']['r_calc_study'] -
self.markerDict['markers']['r.PSIS_study'])[:,0]
r_toe_rel_x = (
self.markerDict['markers']['r.PSIS_study'])

r_toe_rel = (
self.markerDict['markers']['r_toe_study'] -
self.markerDict['markers']['r.PSIS_study'])[:,0]

self.markerDict['markers']['r.PSIS_study'])
r_toe_rel_x = r_toe_rel[:,0]
# Repeat for left.
l_calc_rel_x = (
l_calc_rel = (
self.markerDict['markers']['L_calc_study'] -
self.markerDict['markers']['L.PSIS_study'])[:,0]
l_toe_rel_x = (
self.markerDict['markers']['L.PSIS_study'])
l_toe_rel = (
self.markerDict['markers']['L_toe_study'] -
self.markerDict['markers']['L.PSIS_study'])[:,0]
self.markerDict['markers']['L.PSIS_study'])

# Identify which direction the subject is walking.
r_psis_x = self.markerDict['markers']['r.PSIS_study'][:,0]
r_asis_x = self.markerDict['markers']['r.ASIS_study'][:,0]
r_dir_x = r_asis_x-r_psis_x
position_approach_scaling = np.where(r_dir_x > 0, 1, -1)
# Adjust relative positions accordingly.
r_calc_rel_x *= position_approach_scaling
r_toe_rel_x *= position_approach_scaling
l_calc_rel_x *= position_approach_scaling
l_toe_rel_x *= position_approach_scaling
mid_psis = (self.markerDict['markers']['r.PSIS_study'] + self.markerDict['markers']['L.PSIS_study'])/2
mid_asis = (self.markerDict['markers']['r.ASIS_study'] + self.markerDict['markers']['L.ASIS_study'])/2
mid_dir = mid_asis - mid_psis
mid_dir_floor = np.copy(mid_dir)
mid_dir_floor[:,1] = 0
mid_dir_floor = mid_dir_floor / np.linalg.norm(mid_dir_floor,axis=1,keepdims=True)

# Dot product projections
r_calc_rel_x = np.einsum('ij,ij->i', mid_dir_floor,r_calc_rel)
l_calc_rel_x = np.einsum('ij,ij->i', mid_dir_floor,l_calc_rel)
r_toe_rel_x = np.einsum('ij,ij->i', mid_dir_floor,r_toe_rel)
l_toe_rel_x = np.einsum('ij,ij->i', mid_dir_floor,l_toe_rel)

# Old Approach that does not take the heading direction into account.
# r_psis_x = self.markerDict['markers']['r.PSIS_study'][:,0]
# r_asis_x = self.markerDict['markers']['r.ASIS_study'][:,0]
# r_dir_x = r_asis_x-r_psis_x
# position_approach_scaling = np.where(r_dir_x > 0, 1, -1)
# r_calc_rel_x = r_calc_rel[:,0] * position_approach_scaling
# r_toe_rel_x = r_toe_rel[:,0] * position_approach_scaling
# l_calc_rel_x = l_calc_rel[:,0] * position_approach_scaling
# l_toe_rel_x = l_toe_rel[:,0] * position_approach_scaling

# Detect peaks, check if they're in the right order, if not reduce prominence.
# the peaks can be less prominent with pathological or slower gait patterns
Expand Down Expand Up @@ -901,5 +915,4 @@ def detect_correct_order(rHS, rTO, lHS, lTO):
'eventNamesContralateral':['TO','HS'],
'ipsilateralLeg':leg}

return gaitEvents

return gaitEvents
3 changes: 2 additions & 1 deletion gait_analysis/function/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def handler(event, context):
gait[leg] = gait_analysis(
sessionDir, trial_name, leg=leg,
lowpass_cutoff_frequency_for_coordinate_values=filter_frequency,
n_gait_cycles=n_gait_cycles)
n_gait_cycles=n_gait_cycles, gait_style='overground',
trimming_start=0, trimming_end=0.5)
gait_events[leg] = gait[leg].get_gait_events()

# Select last leg.
Expand Down

0 comments on commit 9a5a424

Please sign in to comment.