9
9
import gaitalytics .mapping as mapping
10
10
import gaitalytics .model as model
11
11
import gaitalytics .utils .linalg as linalg
12
- import gaitalytics .utils .mocap as mocap
13
12
import gaitalytics .utils .math as math
13
+ import gaitalytics .utils .mocap as mocap
14
14
15
15
16
16
class FeatureCalculation (ABC ):
@@ -545,7 +545,7 @@ def _calculate(self, trial: model.Trial) -> xr.DataArray:
545
545
)
546
546
if marker_dict ["xcom" ] is not None :
547
547
results_dict .update (
548
- self ._calculate_AP_margin_of_stability (
548
+ self ._calculate_ap_margin_of_stability (
549
549
trial ,
550
550
marker_dict ["ipsi_toe_2" ],
551
551
marker_dict ["contra_toe_2" ],
@@ -577,7 +577,7 @@ def select_markers_for_spatial_features(
577
577
Returns:
578
578
A dictionary of markers based on context
579
579
"""
580
- if trial .events .attrs ["context" ] == "Right" :
580
+ if trial .events is not None and trial . events .attrs ["context" ] == "Right" :
581
581
ipsi_heel_marker = mapping .MappedMarkers .R_HEEL
582
582
ipsi_toe_2_marker = mapping .MappedMarkers .R_TOE
583
583
ipsi_toe_5_marker = self .get_optional_marker ("R_TOE_5" )
@@ -704,28 +704,32 @@ def _calculate_stride_length(
704
704
progress_axis = self ._get_progression_vector (trial )
705
705
progress_axis = linalg .normalize_vector (progress_axis )
706
706
707
- total_distance = 0
707
+ total_distance = None
708
708
709
+ # Add the distance of the ipsi and contra heel step length
709
710
for event_time in [event_times [2 ], event_times [- 1 ]]:
710
711
ipsi_heel = self ._get_marker_data (trial , ipsi_marker ).sel (
711
712
time = event_time , method = "nearest"
712
713
)
713
714
contra_heel = self ._get_marker_data (trial , contra_marker ).sel (
714
715
time = event_time , method = "nearest"
715
716
)
716
- print (f"ipsi heel: { ipsi_heel } " )
717
717
718
718
projected_ipsi = linalg .project_point_on_vector (ipsi_heel , progress_axis )
719
719
projected_contra = linalg .project_point_on_vector (
720
720
contra_heel , progress_axis
721
721
)
722
- print (f"projected ipsi: { projected_ipsi } " )
723
722
724
723
distance = linalg .calculate_distance (
725
724
projected_ipsi , projected_contra
726
725
).values
727
- print (f"distance: { distance } " )
728
- total_distance += distance
726
+ if total_distance is None :
727
+ total_distance = distance
728
+ else :
729
+ total_distance += distance
730
+
731
+ if total_distance is None :
732
+ total_distance = np .empty (1 )
729
733
730
734
return {"stride_length" : total_distance }
731
735
@@ -782,23 +786,21 @@ def _calculate_minimal_toe_clearance(
782
786
mtc_values .append (meta_data .sel (axis = "z" )[i ])
783
787
784
788
if not mtc_values :
785
- return {"minimal_toe_clearance" : np .NaN }
789
+ return {"minimal_toe_clearance" : np .empty ( 1 ) }
786
790
787
791
return {"minimal_toe_clearance" : min (mtc_values )}
788
792
793
+ @staticmethod
789
794
def _find_mtc_index (
790
- self ,
791
- toe_position : xr .DataArray ,
792
- heel_position : xr .DataArray ,
793
- toes_vel : xr .DataArray ,
795
+ toe_position : xr .DataArray , heel_position : xr .DataArray , toes_vel : xr .DataArray
794
796
):
795
797
"""Find the time corresponding to minimal toe clearance of a specific toe.
796
- Valid minimal toe clearance point must validates conditions
798
+ Valid minimal toe clearance point must pass conditions
797
799
defined in Schulz 2017 (doi: 10.1016/j.jbiomech.2017.02.024)
798
800
Args:
799
801
toe_position: A DataArray containing positions of the toe
800
802
heel_position: A DataArray containing positions of the heel
801
- toes_vel: A DataArray containing the mean toes velocity at each timepoint
803
+ toes_vel: A DataArray containing the mean toes velocity at each point in time
802
804
Returns:
803
805
The time corresponding to minimal toe clearance for the input toe.
804
806
"""
@@ -811,24 +813,24 @@ def _find_mtc_index(
811
813
mtc_i = [i for i in mtc_i if toes_vel [i ] >= toes_vel_up_quant ]
812
814
mtc_i = [i for i in mtc_i if toe_z [i ] <= heel_z [i ]]
813
815
814
- return np . NaN if not mtc_i else min (mtc_i , key = lambda i : toe_z [i ])
816
+ return None if not mtc_i else min (mtc_i , key = lambda i : toe_z [i ])
815
817
816
- def _calculate_AP_margin_of_stability (
818
+ def _calculate_ap_margin_of_stability (
817
819
self ,
818
820
trial : model .Trial ,
819
821
ipsi_toe_marker : mapping .MappedMarkers ,
820
822
contra_toe_marker : mapping .MappedMarkers ,
821
823
xcom_marker : mapping .MappedMarkers ,
822
824
) -> dict [str , np .ndarray ]:
823
- """Calculate the anterio -posterior margin of stability at heel strike
825
+ """Calculate the anterior -posterior margin of stability at heel strike
824
826
Args:
825
827
trial: The trial for which to calculate the AP margin of stability
826
828
ipsi_toe_marker: The ipsi-lateral toe marker
827
- contra_marker : The contra-lateral toe marker
829
+ contra_toe_marker : The contra-lateral toe marker
828
830
xcom_marker: The extrapolated center of mass marker
829
831
830
832
Returns:
831
- The calculated anterio -posterior margin of stability in a dict
833
+ The calculated anterior -posterior margin of stability in a dict
832
834
"""
833
835
event_times = self .get_event_times (trial .events )
834
836
@@ -866,8 +868,8 @@ def _calculate_ML_margin_of_stability(
866
868
"""Calculate the medio-lateral margin of stability at heel strike
867
869
Args:
868
870
trial: The trial for which to calculate the AP margin of stability
869
- ipsi_toe_marker : The ipsi-lateral lateral ankle marker
870
- contra_marker : The contra-lateral lateral ankle marker
871
+ ipsi_ankle_marker : The ipsi-lateral lateral ankle marker
872
+ contra_ankle_marker : The contra-lateral lateral ankle marker
871
873
xcom_marker: The extrapolated center of mass marker
872
874
873
875
Returns:
0 commit comments