Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
carmichaelong committed Jun 13, 2024
2 parents 2807b1f + e813f17 commit a1d7678
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
12 changes: 6 additions & 6 deletions gait_analysis/function/gait_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def __init__(self, session_dir, trial_name, leg='auto',
self.markerDict['markers'][marker] = self.markerDict['markers'][marker][:self.idx_trim_end,:]
self.coordinateValues = self.coordinateValues.iloc[:self.idx_trim_end]

# Rotate marker data so x is forward (not using for now, but could be useful for some analyses).
# self.rotation_about_y, self.markerDictRotated = self.rotate_x_forward()
# Rotate marker data so x is forward
self.rotation_about_y, self.markerDictRotated = self.rotate_x_forward()

# Segment gait cycles.
self.gaitEvents = self.segment_walking(n_gait_cycles=n_gait_cycles,leg=leg)
Expand Down Expand Up @@ -257,14 +257,14 @@ def compute_step_length(self,return_all=False):
step_lengths = {}

step_lengths[contLeg.lower()] = (
- self.markerDictRotatedPerGaitCycle['markers'][leg + '_calc_study'][self.gaitEvents['ipsilateralIdx'][:,:1],0] +
self.markerDictRotatedPerGaitCycle['markers'][contLeg + '_calc_study'][self.gaitEvents['contralateralIdx'][:,1:2],0] +
- self.markerDictRotated['markers'][leg + '_calc_study'][self.gaitEvents['ipsilateralIdx'][:,:1],0] +
self.markerDictRotated['markers'][contLeg + '_calc_study'][self.gaitEvents['contralateralIdx'][:,1:2],0] +
self.treadmillSpeed * (self.gaitEvents['contralateralTime'][:,1:2] -
self.gaitEvents['ipsilateralTime'][:,:1]))

step_lengths[leg.lower()] = (
self.markerDictRotatedPerGaitCycle['markers'][leg + '_calc_study'][self.gaitEvents['ipsilateralIdx'][:,2:],0] -
self.markerDictRotatedPerGaitCycle['markers'][contLeg + '_calc_study'][self.gaitEvents['contralateralIdx'][:,1:2],0] +
self.markerDictRotated['markers'][leg + '_calc_study'][self.gaitEvents['ipsilateralIdx'][:,2:],0] -
self.markerDictRotated['markers'][contLeg + '_calc_study'][self.gaitEvents['contralateralIdx'][:,1:2],0] +
self.treadmillSpeed * (-self.gaitEvents['contralateralTime'][:,1:2] +
self.gaitEvents['ipsilateralTime'][:,2:]))

Expand Down
22 changes: 16 additions & 6 deletions treadmill_gait_analysis/function/gait_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __init__(self, session_dir, trial_name, leg='auto',
self.coordinateValues = self.coordinateValues.iloc[:self.idx_trim_end]

# Rotate marker data so x is forward (not using for now, but could be useful for some analyses).
# self.rotation_about_y, self.markerDictRotated = self.rotate_x_forward()
self.rotation_about_y, self.markerDictRotated = self.rotate_x_forward()

# Segment gait cycles.
self.gaitEvents = self.segment_walking(n_gait_cycles=n_gait_cycles,leg=leg)
Expand Down Expand Up @@ -257,14 +257,14 @@ def compute_step_length(self,return_all=False):
step_lengths = {}

step_lengths[contLeg.lower()] = (
- self.markerDictRotatedPerGaitCycle['markers'][leg + '_calc_study'][self.gaitEvents['ipsilateralIdx'][:,:1],0] +
self.markerDictRotatedPerGaitCycle['markers'][contLeg + '_calc_study'][self.gaitEvents['contralateralIdx'][:,1:2],0] +
- self.markerDictRotated['markers'][leg + '_calc_study'][self.gaitEvents['ipsilateralIdx'][:,:1],0] +
self.markerDictRotated['markers'][contLeg + '_calc_study'][self.gaitEvents['contralateralIdx'][:,1:2],0] +
self.treadmillSpeed * (self.gaitEvents['contralateralTime'][:,1:2] -
self.gaitEvents['ipsilateralTime'][:,:1]))

step_lengths[leg.lower()] = (
self.markerDictRotatedPerGaitCycle['markers'][leg + '_calc_study'][self.gaitEvents['ipsilateralIdx'][:,2:],0] -
self.markerDictRotatedPerGaitCycle['markers'][contLeg + '_calc_study'][self.gaitEvents['contralateralIdx'][:,1:2],0] +
self.markerDictRotated['markers'][leg + '_calc_study'][self.gaitEvents['ipsilateralIdx'][:,2:],0] -
self.markerDictRotated['markers'][contLeg + '_calc_study'][self.gaitEvents['contralateralIdx'][:,1:2],0] +
self.treadmillSpeed * (-self.gaitEvents['contralateralTime'][:,1:2] +
self.gaitEvents['ipsilateralTime'][:,2:]))

Expand Down Expand Up @@ -812,7 +812,7 @@ def get_coordinates_normalized_time(self):

return coordinateValuesTimeNormalized

def segment_walking(self, n_gait_cycles=-1, leg='auto', visualize=False):
def segment_walking(self, n_gait_cycles=-1, leg='auto', delete_hand_sync_stride=True, visualize=False):

# n_gait_cycles = -1 finds all accessible gait cycles. Otherwise, it
# finds that many gait cycles, working backwards from end of trial.
Expand Down Expand Up @@ -989,6 +989,10 @@ def detect_correct_order(rHS, rTO, lHS, lTO):
gaitEvents_cont = np.zeros((n_gait_cycles, 2),dtype=int)
if n_gait_cycles <1:
raise Exception('Not enough gait cycles found.')

if delete_hand_sync_stride:
r_wrist_rel_y = self.markerDict['markers']['r_mwrist_study'][:,1] - self.markerDict['markers']['r_shoulder_study'][:,1]
l_wrist_rel_y = self.markerDict['markers']['L_mwrist_study'][:,1] - self.markerDict['markers']['L_shoulder_study'][:,1]

for i in range(n_gait_cycles):
# Ipsilateral HS, TO, HS.
Expand Down Expand Up @@ -1026,6 +1030,12 @@ def detect_correct_order(rHS, rTO, lHS, lTO):
' steps until the end. Skipping this step.')
gaitEvents_cont[i,:] = -1
gaitEvents_ips[i,:] = -1

elif delete_hand_sync_stride:
if (np.any(r_wrist_rel_y[gaitEvents_ips[i,0]:gaitEvents_ips[i,2]] > 0.1) or
np.any(l_wrist_rel_y[gaitEvents_ips[i,0]:gaitEvents_ips[i,2]] > 0.1)):
gaitEvents_cont[i,:] = -1
gaitEvents_ips[i,:] = -1

# Remove any nan rows
mask_ips = (gaitEvents_ips == -1).any(axis=1)
Expand Down

0 comments on commit a1d7678

Please sign in to comment.