@@ -746,32 +746,46 @@ def detect_correct_order(rHS, rTO, lHS, lTO):
746
746
return True
747
747
748
748
# 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 = (
751
751
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 = (
754
755
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 ]
757
758
# Repeat for left.
758
- l_calc_rel_x = (
759
+ l_calc_rel = (
759
760
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 = (
762
763
self .markerDict ['markers' ]['L_toe_study' ] -
763
- self .markerDict ['markers' ]['L.PSIS_study' ])[:, 0 ]
764
+ self .markerDict ['markers' ]['L.PSIS_study' ])
764
765
765
766
# 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
775
789
776
790
# Detect peaks, check if they're in the right order, if not reduce prominence.
777
791
# the peaks can be less prominent with pathological or slower gait patterns
@@ -901,5 +915,4 @@ def detect_correct_order(rHS, rTO, lHS, lTO):
901
915
'eventNamesContralateral' :['TO' ,'HS' ],
902
916
'ipsilateralLeg' :leg }
903
917
904
- return gaitEvents
905
-
918
+ return gaitEvents
0 commit comments