Exemplo n.º 1
0
    def __init__(self, dataPath, filenameNoExt, subject):
        """
        """
        self.m_dataPath = dataPath
        self.m_filenameNoExt = filenameNoExt
        self.m_subject = subject

        self.m_framerate = NEXUS.GetFrameRate()
        #self.m_frames = NEXUS.GetTrialRange()[1]
        self.m_rangeROI = NEXUS.GetTrialRegionOfInterest()
        self.m_trialRange = NEXUS.GetTrialRange()
        self.m_trialFirstFrame = self.m_trialRange[0]

        self.m_firstFrame = self.m_rangeROI[0]
        self.m_lastFrame = self.m_rangeROI[1]
        self.m_frames = self.m_lastFrame - (self.m_firstFrame - 1)

        deviceIDs = NEXUS.GetDeviceIDs()
        self.m_analogFrameRate = NEXUS.GetDeviceDetails(1)[2] if (
            len(deviceIDs) > 0) else self.m_framerate

        self.m_numberAnalogSamplePerFrame = int(self.m_analogFrameRate /
                                                self.m_framerate)
        self.m_analogFrameNumber = self.m_frames * self.m_numberAnalogSamplePerFrame

        self.m_nexusForcePlates = list()
        self.m_nexusAnalogDevices = list()

        if (len(deviceIDs) > 0):
            for deviceID in deviceIDs:
                if NEXUS.GetDeviceDetails(deviceID)[1] == "ForcePlate":
                    self.m_nexusForcePlates.append(
                        Devices.ForcePlate(deviceID))
                else:
                    self.m_nexusAnalogDevices.append(
                        Devices.AnalogDevice(deviceID))

        self.m_root = ma.Node('root')
        self.m_trial = ma.Trial("NexusTrial", self.m_root)

        self.m_trial.setProperty("POINT:RATE", self.m_framerate)
        self.m_trial.setProperty("ANALOG:RATE", self.m_analogFrameRate)
Exemplo n.º 2
0
def convertBtkAcquisition(acq, returnType="Trial"):

    root = ma.Node('root')
    trial = ma.Trial("Trial", root)

    framerate = acq.GetPointFrequency()
    firstFrame = acq.GetFirstFrame()

    numberAnalogSamplePerFrame = acq.GetNumberAnalogSamplePerFrame()
    analogFramerate = acq.GetAnalogFrequency()

    if firstFrame == 1:
        time_init = 0.0
    else:
        time_init = firstFrame / framerate

    for it in btk.Iterate(acq.GetPoints()):

        label = it.GetLabel()
        values = it.GetValues()
        residuals = it.GetResiduals()
        desc = it.GetDescription()

        data = np.zeros((values.shape[0], 4))
        data[:, 0:3] = values
        data[:, 3] = residuals[:, 0]

        if it.GetType() == btk.btkPoint.Marker:
            ts = ma.TimeSequence(str(label), 4, data.shape[0], framerate,
                                 time_init, ma.TimeSequence.Type_Marker, "mm",
                                 trial.timeSequences())

        elif it.GetType() == btk.btkPoint.Angle:
            ts = ma.TimeSequence(str(label), 4, data.shape[0], framerate,
                                 time_init, ma.TimeSequence.Type_Angle, "Deg",
                                 trial.timeSequences())

        elif it.GetType() == btk.btkPoint.Force:
            ts = ma.TimeSequence(str(label), 4, data.shape[0], framerate,
                                 time_init, ma.TimeSequence.Type_Force,
                                 "N.Kg-1", trial.timeSequences())

        elif it.GetType() == btk.btkPoint.Moment:
            ts = ma.TimeSequence(str(label), 4, data.shape[0], framerate,
                                 time_init, ma.TimeSequence.Type_Moment,
                                 "Nmm.Kg-1", trial.timeSequences())

        elif it.GetType() == btk.btkPoint.Power:
            ts = ma.TimeSequence(str(label), 4, data.shape[0], framerate,
                                 time_init, ma.TimeSequence.Type_Power,
                                 "Watt.Kg-1", trial.timeSequences())

        else:
            logging.warning(
                "[pyCGM2] point [%s] not copied into openma trial" % (label))

        ts.setData(data)
        ts.setDescription(desc)

    for it in btk.Iterate(acq.GetAnalogs()):

        label = it.GetLabel()
        values = it.GetValues()
        desc = it.GetDescription()

        data = values

        ts = ma.TimeSequence(str(label), 1, data.shape[0], analogFramerate,
                             time_init, ma.TimeSequence.Type_Analog, "V", 1.0,
                             0.0, [-10.0, 10.0], trial.timeSequences())
        ts.setData(data)
        ts.setDescription(desc)

    for it in btk.Iterate(acq.GetEvents()):

        label = it.GetLabel()
        time = it.GetTime()
        context = it.GetContext()
        subject = it.GetSubject()

        ev = ma.Event(label, time, context, str(subject), trial.events())

    sortedEvents(trial)

    if returnType == "Trial":
        return trial
    else:
        return root
Exemplo n.º 3
0
    def export(self, outputName, path=None):

        root = ma.Node('root')
        trial = ma.Trial("AnalysisC3d", root)

        # metadata
        #-------------

        # subject infos
        if self.analysis.subjectInfo is not None:
            subjInfo = self.analysis.subjectInfo
            for item in subjInfo.items():
                trial.setProperty("SUBJECT_INFO:" + str(item[0]), item[1])

        # model infos
        if self.analysis.modelInfo is not None:
            modelInfo = self.analysis.modelInfo
            for item in modelInfo.items():
                trial.setProperty("MODEL_INFO:" + str(item[0]), item[1])

        # model infos
        if self.analysis.experimentalInfo is not None:
            experimentalConditionInfo = self.analysis.experimentalInfo
            for item in experimentalConditionInfo.items():
                trial.setProperty("EXPERIMENTAL_INFO:" + str(item[0]), item[1])

        #trial.setProperty('MY_GROUP:MY_PARAMETER',10.0)

        # kinematic cycles
        #------------------

        # metadata
        # for key in self.analysis.kinematicStats.data.keys():
        #     if key[1]=="Left":
        #         n_left_cycle = len(self.analysis.kinematicStats.data[key[0],key[1]]["values"])
        #         trial.setProperty('PROCESSING:LeftKinematicCycleNumber',n_left_cycle)
        #         break
        #
        # for key in self.analysis.kinematicStats.data.keys():
        #     if key[1]=="Right":
        #         n_right_cycle = len(self.analysis.kinematicStats.data[key[0],key[1]]["values"])
        #         trial.setProperty('PROCESSING:RightKinematicCycleNumber',n_right_cycle)
        #         break

        # cycles
        for key in self.analysis.kinematicStats.data.keys():
            label = key[0]
            context = key[1]
            if not np.all(
                    self.analysis.kinematicStats.data[label,
                                                      context]["mean"] == 0):
                cycle = 0
                values = np.zeros((101, 4))
                values2 = np.zeros((101, 1))
                for val in self.analysis.kinematicStats.data[
                        label, context]["values"]:
                    angle = ma.TimeSequence(
                        str(label + "." + context + "." + str(cycle)), 4, 101,
                        1.0, 0.0, ma.TimeSequence.Type_Angle, "deg",
                        trial.timeSequences())
                    values[:, 0:3] = val
                    angle.setData(values)
                    cycle += 1

        # kinetic cycles
        #------------------

        # # metadata
        # for key in self.analysis.kineticStats.data.keys():
        #     if key[1]=="Left":
        #         n_left_cycle = len(self.analysis.kineticStats.data[key[0],key[1]]["values"])
        #         trial.setProperty('PROCESSING:LeftKineticCycleNumber',n_left_cycle)
        #         break
        #
        # for key in self.analysis.kineticStats.data.keys():
        #     if key[1]=="Right":
        #         n_right_cycle = len(self.analysis.kineticStats.data[key[0],key[1]]["values"])
        #         trial.setProperty('PROCESSING:RightKineticCycleNumber',n_right_cycle)
        #         break

        # cycles
        for key in self.analysis.kineticStats.data.keys():
            label = key[0]
            context = key[1]
            if not np.all(
                    self.analysis.kineticStats.data[label,
                                                    context]["mean"] == 0):
                cycle = 0
                values = np.zeros((101, 4))
                for val in self.analysis.kineticStats.data[label,
                                                           context]["values"]:
                    moment = ma.TimeSequence(
                        str(label + "." + context + "." + str(cycle)), 4, 101,
                        1.0, 0.0, ma.TimeSequence.Type_Moment, "N.mm",
                        trial.timeSequences())
                    values[:, 0:3] = val
                    moment.setData(values)
                    cycle += 1

        # for key in self.analysis.emgStats.data.keys():
        #     label = key[0]
        #     context = key[1]
        #     if not np.all( self.analysis.emgStats.data[label,context]["mean"]==0):
        #         cycle = 0
        #         for val in self.analysis.emgStats.data[label,context]["values"]:
        #             analog = ma.TimeSequence(str(label+"."+context+"."+str(cycle)),1,101,1.0,0.0,ma.TimeSequence.Type_Analog,"V", 1.0,0.0,[-10.0,10.0], trial.timeSequences())
        #             analog.setData(val)
        #             cycle+=1

        try:
            if path == None:
                ma.io.write(root, str(outputName + ".c3d"))
            else:
                ma.io.write(root, str(path + outputName + ".c3d"))
            logging.info("Analysis c3d  [%s.c3d] Exported" %
                         (str(outputName + ".c3d")))
        except:
            raise Exception("[pyCGM2] : analysis c3d doesn t export")