def smartAppendAnalog(acq,label,values,desc="" ): if isAnalogExist(acq,label): acq.GetAnalog(utils.str(label)).SetValues(values) acq.GetAnalog(utils.str(label)).SetDescription(utils.str(desc)) #acq.GetAnalog(label).SetType(PointType) else: newAnalog=btk.btkAnalog(acq.GetAnalogFrameNumber()) newAnalog.SetValues(values) newAnalog.SetLabel(utils.str(label)) acq.AppendAnalog(newAnalog)
def appendAnalogs(self): ftr = NEXUS.GetTrialRange()[0] for nexusAnalogDevice in self.m_nexusAnalogDevices: start = self.m_firstFrame - 1 #self.m_trialFirstFrame end = self.m_lastFrame - 1 #self.m_trialFirstFrame channels = nexusAnalogDevice.getChannels() for channel in channels: analog = btk.btkAnalog() analog.SetLabel(channel.getLabel()) analog.SetUnit(channel.getUnit()) analog.SetFrameNumber(self.m_analogFrameNumber) analog.SetValues(channel.getValues() [start * self.m_numberAnalogSamplePerFrame:(end + 1) * self.m_numberAnalogSamplePerFrame]) analog.SetDescription(channel.getDescription()) self.m_acq.AppendAnalog(analog)
def appendForcePlates(self): forcePlateNumber = len(self.m_nexusForcePlates) fp_count = 0 for nexusForcePlate in self.m_nexusForcePlates: forceLocal = nexusForcePlate.getLocalReactionForce( ) # row number = NEXUS.getTrialRange[1] not FrameCount momentLocal = nexusForcePlate.getLocalReactionMoment() start = self.m_firstFrame - 1 #-1 because Nexus frame start at 1 end = self.m_lastFrame - 1 #- self.m_trialFirstFrame forceLabels = [ "Force.Fx" + str(fp_count + 1), "Force.Fy" + str(fp_count + 1), "Force.Fz" + str(fp_count + 1) ] for j in range(0, 3): analog = btk.btkAnalog() analog.SetLabel(forceLabels[j]) analog.SetUnit("N") #nexusForcePlate.getForceUnit()) analog.SetFrameNumber(self.m_analogFrameNumber) analog.SetValues( forceLocal[(start) * self.m_numberAnalogSamplePerFrame:(end + 1) * self.m_numberAnalogSamplePerFrame, j]) analog.SetDescription(nexusForcePlate.getDescription()) #analog.SetGain(btk.btkAnalog.PlusMinus10) self.m_acq.AppendAnalog(analog) momentLabels = [ "Moment.Mx" + str(fp_count + 1), "Moment.My" + str(fp_count + 1), "Moment.Mz" + str(fp_count + 1) ] for j in range(0, 3): analog = btk.btkAnalog() analog.SetLabel(momentLabels[j]) analog.SetUnit("Nmm") #nexusForcePlate.getMomentUnit()) analog.SetFrameNumber(self.m_analogFrameNumber) analog.SetValues( momentLocal[(start) * self.m_numberAnalogSamplePerFrame:(end + 1) * self.m_numberAnalogSamplePerFrame, j]) analog.SetDescription(nexusForcePlate.getDescription()) #analog.GetGain(btk.btkAnalog.PlusMinus10) self.m_acq.AppendAnalog(analog) fp_count += 1 # metadata for platform type2 md_force_platform = btk.btkMetaData('FORCE_PLATFORM') btk.btkMetaDataCreateChild(md_force_platform, "USED", int(forcePlateNumber)) # a btk.btkMetaDataCreateChild(md_force_platform, "ZERO", [1, 0]) # btk.btkMetaDataCreateChild( md_force_platform, "TYPE", btk.btkDoubleArray( forcePlateNumber, 2)) #btk.btkDoubleArray(forcePlateNumber, 2))# add a child self.m_acq.GetMetaData().AppendChild(md_force_platform) origins = [] for nexusForcePlate in self.m_nexusForcePlates: origins.append(-1.0 * nexusForcePlate.getLocalOrigin()) md_origin = btk.btkMetaData('ORIGIN') md_origin.SetInfo( btk.btkMetaDataInfo([3, int(forcePlateNumber)], np.concatenate(origins))) md_force_platform.AppendChild(md_origin) corners = [] for nexusForcePlate in self.m_nexusForcePlates: corners.append(nexusForcePlate.getCorners().T.flatten()) md_corners = btk.btkMetaData('CORNERS') md_corners.SetInfo( btk.btkMetaDataInfo([3, 4, int(forcePlateNumber)], np.concatenate(corners))) md_force_platform.AppendChild(md_corners) md_channel = btk.btkMetaData('CHANNEL') md_channel.SetInfo( btk.btkMetaDataInfo([6, int(forcePlateNumber)], np.arange(1, int(forcePlateNumber) * 6 + 1))) md_force_platform.AppendChild(md_channel)