def detect(self): """ Run the motion filter """ pf = self.m_aqui.GetPointFrequency() eventDescriptor = self.m_procedure.description indexes_fs_left, indexes_fo_left, indexes_fs_right, indexes_fo_right = self.m_procedure.detect( self.m_aqui) for ind in indexes_fs_left: ev = btk.btkEvent('Foot Strike', (ind - 1) / pf, 'Left', btk.btkEvent.Automatic, '', eventDescriptor) ev.SetId(1) self.m_aqui.AppendEvent(ev) for ind in indexes_fo_left: ev = btk.btkEvent('Foot Off', (ind - 1) / pf, 'Left', btk.btkEvent.Automatic, '', eventDescriptor) ev.SetId(2) self.m_aqui.AppendEvent(ev) for ind in indexes_fs_right: ev = btk.btkEvent('Foot Strike', (ind - 1) / pf, 'Right', btk.btkEvent.Manual, '', eventDescriptor) ev.SetId(1) self.m_aqui.AppendEvent(ev) for ind in indexes_fo_right: ev = btk.btkEvent('Foot Off', (ind - 1) / pf, 'Right', btk.btkEvent.Manual, '', eventDescriptor) ev.SetId(2) self.m_aqui.AppendEvent(ev)
def addForcePlateGeneralEvents(btkAcq, mappedForcePlate): """ Add General events from force plate assignmenet """ ff = btkAcq.GetFirstFrame() lf = btkAcq.GetLastFrame() pf = btkAcq.GetPointFrequency() appf = btkAcq.GetNumberAnalogSamplePerFrame() # --- ground reaction force wrench --- pfe = btk.btkForcePlatformsExtractor() grwf = btk.btkGroundReactionWrenchFilter() pfe.SetInput(btkAcq) pfc = pfe.GetOutput() grwf.SetInput(pfc) grwc = grwf.GetOutput() grwc.Update() # remove force plates events btkTools.clearEvents(btkAcq, ["Left-FP", "Right-FP"]) # add general events indexFP = 0 for letter in mappedForcePlate: force = grwc.GetItem(indexFP).GetForce().GetValues() force_downsample = force[0:(lf - ff + 1) * appf:appf] # downsample Rz = np.abs(force_downsample[:, 2]) frameMax = ff + np.argmax(Rz) if letter == "L": ev = btk.btkEvent('Left-FP', (frameMax - 1) / pf, 'General', btk.btkEvent.Automatic, '', 'event from Force plate assignment') btkAcq.AppendEvent(ev) elif letter == "R": ev = btk.btkEvent('Right-FP', (frameMax - 1) / pf, 'General', btk.btkEvent.Automatic, '', 'event from Force plate assignment') btkAcq.AppendEvent(ev) indexFP += 1
def appendEvents(self): eventType = "Foot Strike" eventContext = "Left" if NEXUS.GetEvents(self.m_subject, eventContext, eventType)[0] != []: for frame in NEXUS.GetEvents(self.m_subject, eventContext, eventType)[0]: if frame >= self.m_firstFrame and frame <= self.m_lastFrame: time = (frame - 1) / self.m_framerate ev = btk.btkEvent(eventType, time, int(frame), eventContext, btk.btkEvent.Automatic) ev.SetSubject(utils.str(self.m_subject)) self.m_acq.AppendEvent(ev) eventType = "Foot Off" eventContext = "Left" if NEXUS.GetEvents(self.m_subject, eventContext, eventType)[0] != []: for frame in NEXUS.GetEvents(self.m_subject, eventContext, eventType)[0]: if frame >= self.m_firstFrame and frame <= self.m_lastFrame: time = (frame - 1) / self.m_framerate ev = btk.btkEvent(eventType, time, int(frame), eventContext, btk.btkEvent.Automatic) ev.SetSubject(utils.str(self.m_subject)) self.m_acq.AppendEvent(ev) eventType = "Foot Strike" eventContext = "Right" if NEXUS.GetEvents(self.m_subject, eventContext, eventType)[0] != []: for frame in NEXUS.GetEvents(self.m_subject, eventContext, eventType)[0]: if frame >= self.m_firstFrame and frame <= self.m_lastFrame: time = (frame - 1) / self.m_framerate ev = btk.btkEvent(eventType, time, int(frame), eventContext, btk.btkEvent.Automatic) ev.SetSubject(utils.str(self.m_subject)) self.m_acq.AppendEvent(ev) eventType = "Foot Off" eventContext = "Right" if NEXUS.GetEvents(self.m_subject, eventContext, eventType)[0] != []: for frame in NEXUS.GetEvents(self.m_subject, eventContext, eventType)[0]: if frame >= self.m_firstFrame and frame <= self.m_lastFrame: time = (frame - 1) / self.m_framerate ev = btk.btkEvent(eventType, time, int(frame), eventContext, btk.btkEvent.Automatic) ev.SetSubject(utils.str(self.m_subject)) self.m_acq.AppendEvent(ev) eventType = "Event" eventContext = "General" if NEXUS.GetEvents(self.m_subject, eventContext, eventType)[0] != []: for frame in NEXUS.GetEvents(self.m_subject, eventContext, eventType)[0]: if frame >= self.m_firstFrame and frame <= self.m_lastFrame: time = (frame - 1) / self.m_framerate ev = btk.btkEvent(eventType, time, int(frame), eventContext, btk.btkEvent.Manual) ev.SetSubject(utils.str(self.m_subject)) self.m_acq.AppendEvent(ev) eventType = "Left-FP" eventContext = "General" if NEXUS.GetEvents(self.m_subject, eventContext, eventType)[0] != []: for frame in NEXUS.GetEvents(self.m_subject, eventContext, eventType)[0]: if frame >= self.m_firstFrame and frame <= self.m_lastFrame: time = (frame - 1) / self.m_framerate ev = btk.btkEvent(eventType, time, int(frame), eventContext, btk.btkEvent.Manual) ev.SetSubject(utils.str(self.m_subject)) self.m_acq.AppendEvent(ev) eventType = "Right-FP" eventContext = "General" if NEXUS.GetEvents(self.m_subject, eventContext, eventType)[0] != []: for frame in NEXUS.GetEvents(self.m_subject, eventContext, eventType)[0]: if frame >= self.m_firstFrame and frame <= self.m_lastFrame: time = (frame - 1) / self.m_framerate ev = btk.btkEvent(eventType, time, int(frame), eventContext, btk.btkEvent.Manual) ev.SetSubject(utils.str(self.m_subject)) self.m_acq.AppendEvent(ev) eventType = "Start" eventContext = "Left" if NEXUS.GetEvents(self.m_subject, eventContext, eventType)[0] != []: for frame in NEXUS.GetEvents(self.m_subject, eventContext, eventType)[0]: if frame >= self.m_firstFrame and frame <= self.m_lastFrame: time = (frame - 1) / self.m_framerate ev = btk.btkEvent(eventType, time, int(frame), eventContext, btk.btkEvent.Manual) ev.SetSubject(utils.str(self.m_subject)) self.m_acq.AppendEvent(ev) eventType = "End" eventContext = "Left" if NEXUS.GetEvents(self.m_subject, eventContext, eventType)[0] != []: for frame in NEXUS.GetEvents(self.m_subject, eventContext, eventType)[0]: if frame >= self.m_firstFrame and frame <= self.m_lastFrame: time = (frame - 1) / self.m_framerate ev = btk.btkEvent(eventType, time, int(frame), eventContext, btk.btkEvent.Manual) ev.SetSubject(utils.str(self.m_subject)) self.m_acq.AppendEvent(ev)