Skip to content

Commit 9a5a424

Browse files
updates overground gait analysis
1 parent 778640e commit 9a5a424

File tree

2 files changed

+36
-22
lines changed

2 files changed

+36
-22
lines changed

gait_analysis/function/gait_analysis.py

+34-21
Original file line numberDiff line numberDiff line change
@@ -746,32 +746,46 @@ def detect_correct_order(rHS, rTO, lHS, lTO):
746746
return True
747747

748748
# Subtract sacrum from foot.
749-
# It looks like the position-based approach will be more robust.
750-
r_calc_rel_x = (
749+
# It looks like the position-based approach will be more robust.
750+
r_calc_rel = (
751751
self.markerDict['markers']['r_calc_study'] -
752-
self.markerDict['markers']['r.PSIS_study'])[:,0]
753-
r_toe_rel_x = (
752+
self.markerDict['markers']['r.PSIS_study'])
753+
754+
r_toe_rel = (
754755
self.markerDict['markers']['r_toe_study'] -
755-
self.markerDict['markers']['r.PSIS_study'])[:,0]
756-
756+
self.markerDict['markers']['r.PSIS_study'])
757+
r_toe_rel_x = r_toe_rel[:,0]
757758
# Repeat for left.
758-
l_calc_rel_x = (
759+
l_calc_rel = (
759760
self.markerDict['markers']['L_calc_study'] -
760-
self.markerDict['markers']['L.PSIS_study'])[:,0]
761-
l_toe_rel_x = (
761+
self.markerDict['markers']['L.PSIS_study'])
762+
l_toe_rel = (
762763
self.markerDict['markers']['L_toe_study'] -
763-
self.markerDict['markers']['L.PSIS_study'])[:,0]
764+
self.markerDict['markers']['L.PSIS_study'])
764765

765766
# Identify which direction the subject is walking.
766-
r_psis_x = self.markerDict['markers']['r.PSIS_study'][:,0]
767-
r_asis_x = self.markerDict['markers']['r.ASIS_study'][:,0]
768-
r_dir_x = r_asis_x-r_psis_x
769-
position_approach_scaling = np.where(r_dir_x > 0, 1, -1)
770-
# Adjust relative positions accordingly.
771-
r_calc_rel_x *= position_approach_scaling
772-
r_toe_rel_x *= position_approach_scaling
773-
l_calc_rel_x *= position_approach_scaling
774-
l_toe_rel_x *= position_approach_scaling
767+
mid_psis = (self.markerDict['markers']['r.PSIS_study'] + self.markerDict['markers']['L.PSIS_study'])/2
768+
mid_asis = (self.markerDict['markers']['r.ASIS_study'] + self.markerDict['markers']['L.ASIS_study'])/2
769+
mid_dir = mid_asis - mid_psis
770+
mid_dir_floor = np.copy(mid_dir)
771+
mid_dir_floor[:,1] = 0
772+
mid_dir_floor = mid_dir_floor / np.linalg.norm(mid_dir_floor,axis=1,keepdims=True)
773+
774+
# Dot product projections
775+
r_calc_rel_x = np.einsum('ij,ij->i', mid_dir_floor,r_calc_rel)
776+
l_calc_rel_x = np.einsum('ij,ij->i', mid_dir_floor,l_calc_rel)
777+
r_toe_rel_x = np.einsum('ij,ij->i', mid_dir_floor,r_toe_rel)
778+
l_toe_rel_x = np.einsum('ij,ij->i', mid_dir_floor,l_toe_rel)
779+
780+
# Old Approach that does not take the heading direction into account.
781+
# r_psis_x = self.markerDict['markers']['r.PSIS_study'][:,0]
782+
# r_asis_x = self.markerDict['markers']['r.ASIS_study'][:,0]
783+
# r_dir_x = r_asis_x-r_psis_x
784+
# position_approach_scaling = np.where(r_dir_x > 0, 1, -1)
785+
# r_calc_rel_x = r_calc_rel[:,0] * position_approach_scaling
786+
# r_toe_rel_x = r_toe_rel[:,0] * position_approach_scaling
787+
# l_calc_rel_x = l_calc_rel[:,0] * position_approach_scaling
788+
# l_toe_rel_x = l_toe_rel[:,0] * position_approach_scaling
775789

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

904-
return gaitEvents
905-
918+
return gaitEvents

gait_analysis/function/handler.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ def handler(event, context):
8888
gait[leg] = gait_analysis(
8989
sessionDir, trial_name, leg=leg,
9090
lowpass_cutoff_frequency_for_coordinate_values=filter_frequency,
91-
n_gait_cycles=n_gait_cycles)
91+
n_gait_cycles=n_gait_cycles, gait_style='overground',
92+
trimming_start=0, trimming_end=0.5)
9293
gait_events[leg] = gait[leg].get_gait_events()
9394

9495
# Select last leg.

0 commit comments

Comments
 (0)