def ProfileTestRun(ProfilingTime=10):

    t0 = getTime()
    while getTime() - t0 < ProfilingTime:
        PrintTest("Profiling t-" +
                  str(round(ProfilingTime - (getTime() - t0), 2)) + " s")
        Wait(0.1)
    def Accelerometer_log_data(self, timestamp, data, logconf):
        """Callback from the log API when data arrives"""
        
        if self.a_DataTimer==0:
            self.a_DataTimer = getTime()
        dt = getTime()-self.a_DataTimer
        self.a_DataTimer = getTime()

        self.aRaw = np.array([\
        data['acc.x'],\
        data['acc.y'],\
        data['acc.z']\
        ]).astype(float)*10#/1000

    #     self.EvaluateAccelerometerData()

    # def EvaluateAccelerometerData(self):
        self.aRel = copy(self.aRaw)
        #print self.aRel
        Gravity = 9.81
        relative_Gravity = [0,0,-Gravity]
        relative_Gravity = EulerRotation(relative_Gravity,[1,0,0],self.roll_Real)
        relative_Gravity = EulerRotation(relative_Gravity,[0,1,0],self.pitch_Real)
        self.aRel+=relative_Gravity


        # Body_to_Earth = rotation_matrix([1,0,0],self.att[0],matrix=True)*rotation_matrix([0,1,0],self.att[1],matrix=True)*rotation_matrix([0,0,1],self.att[2],matrix=True)
        self.a=self.aRel#self.a = np.dot(Body_to_Earth,self.aRel)

        self.velRel += self.aRel*dt
        self.pos    += self.velRel*dt
Beispiel #3
0
def ExecuteCommands(cmds,
                    sudo=False,
                    PrintCmd=False,
                    PrintOutput=False,
                    TimeIt=False):

    if TimeIt:
        Times = []
        t00 = getTime()

    for cmd in cmds:
        if sudo:
            cmd = "sudo " + cmd

        if TimeIt:
            t0 = getTime()
        ExeCmd(cmd, PrintCmd=PrintCmd, PrintOutput=PrintOutput)
        if TimeIt:
            t = getTime() - t0
            Times.append(t)
            print ">/> Time passed: " + str(round(t, 2)) + " s"

    if TimeIt:
        print "=" * 50
        print "Total Runtime: " + str(round(getTime() - t00, 2)) + " s:"
        for i in range(len(cmds)):
            print " " * 3 + str(round(Times[i],
                                      2)) + " s: " + '"' + cmds[i] + '"'
Beispiel #4
0
    def _readRequestReply(cls, t3, request_id):
        request = t3.getActiveRequests().pop(request_id, None)
        if request is None:
            return None

        request.rx_time = getTime()
        rx_data = [request_id, ord(t3.getSerialPort().read(1))]
        if rx_data[1] > 0:
            rx_data.extend(
                [ord(c) for c in t3.getSerialPort().read(rx_data[1] - 2)])
        request.setRxByteArray(rx_data)

        syncstate = cls.sync_state
        #request.drift=syncstate.getDrift()
        #request.offset=syncstate.getOffset()
        #request.sync_accuracy=syncstate.getAccuracy()

        request.iohub_time = None
        if syncstate.getOffset() is not None:
            request.iohub_time = float(
                syncstate.remote2LocalTime(request.device_time))

            #request.last_rtt=float(syncstate.RTTs[-1])
            #request.last_local_dt=float(syncstate.L_times[-1])
            #request.last_remote_dt=float(syncstate.R_times[-1])

            #request.mean_rtt=float(syncstate.RTTs.mean())
            #request.mean_local_dt=float(syncstate.L_times.mean())
            #request.mean_remote_dt=float(syncstate.R_times.mean())

            #request.stdev_rtt=float(syncstate.RTTs.std(ddof=1))
            #request.stdev_local_dt=float(syncstate.L_times.std(ddof=1))
            #request.stdev_remote_dt=float(syncstate.R_times.std(ddof=1))

        return request
Beispiel #5
0
    def _readRequestReply(cls,t3,request_id):
        request=t3.getActiveRequests().pop(request_id,None)
        if request is None:
            return None

        request.rx_time=getTime()
        rx_data=[request_id,ord(t3.getSerialPort().read(1))]
        if rx_data[1]>0:
            rx_data.extend([ord(c) for c in t3.getSerialPort().read(rx_data[1]-2)] )
        request.setRxByteArray(rx_data)
        
        syncstate=cls.sync_state
        #request.drift=syncstate.getDrift()
        #request.offset=syncstate.getOffset()
        #request.sync_accuracy=syncstate.getAccuracy()
                        
        request.iohub_time=None
        if syncstate.getOffset() is not None:
            request.iohub_time=float(syncstate.remote2LocalTime(request.device_time))

            #request.last_rtt=float(syncstate.RTTs[-1])    
            #request.last_local_dt=float(syncstate.L_times[-1])    
            #request.last_remote_dt=float(syncstate.R_times[-1]) 

            #request.mean_rtt=float(syncstate.RTTs.mean())   
            #request.mean_local_dt=float(syncstate.L_times.mean())    
            #request.mean_remote_dt=float(syncstate.R_times.mean())  

            #request.stdev_rtt=float(syncstate.RTTs.std(ddof=1))   
            #request.stdev_local_dt=float(syncstate.L_times.std(ddof=1))    
            #request.stdev_remote_dt=float(syncstate.R_times.std(ddof=1))  
            
        return request
Beispiel #6
0
 def _sendT3Request(self,request):
     try:
         request.tx_time=getTime()
         tx_count=self._serial_port.write(request.getTxByteArray())
         self._serial_port.flush()
         self._active_requests[request.getID()]=request
         return tx_count
     except Exception as e:
         print2err("ERROR During sendT3Request: ",e,". Has ioSync been disconnected?")
         self.close()
Beispiel #7
0
 def _sendT3Request(self, request):
     try:
         request.tx_time = getTime()
         tx_count = self._serial_port.write(request.getTxByteArray())
         self._serial_port.flush()
         self._active_requests[request.getID()] = request
         return tx_count
     except Exception, e:
         print2err("ERROR During sendT3Request: ", e,
                   ". Has ioSync been disconnected?")
         self.close()
Beispiel #8
0
 def local2RemoteTime(self, local_time=None):
     """
     Converts a local time (sec.msec format) to the corresponding remote
     computer time, using the current offset and drift measures.
     """
     #drift=self.getDrift()
     offset = self.getOffset()
     if offset is None:
         return None
     if local_time is None:
         local_time = getTime()
     #local_dt=0.0#local_time-self.L_times[-1]
     return (local_time + offset)  #+local_dt#drift*local_time+offset
Beispiel #9
0
 def local2RemoteTime(self,local_time=None):
     """
     Converts a local time (sec.msec format) to the corresponding remote
     computer time, using the current offset and drift measures.
     """        
     #drift=self.getDrift()
     offset=self.getOffset()
     if offset is None:
         return None
     if local_time is None:
         local_time=getTime()
     #local_dt=0.0#local_time-self.L_times[-1]
     return (local_time+offset)#+local_dt#drift*local_time+offset
Beispiel #10
0
 def _readRequestReply(cls,t3,request_id):
     request=t3.getActiveRequests().pop(request_id,None)
     if request is None:
         return None
     request.rx_time=getTime()
     rx_data=[request_id,ord(t3.getSerialPort().read(1))]
     if rx_data[1]>0:
         rx_data.extend([ord(c) for c in t3.getSerialPort().read(rx_data[1]-2)] )
     request.setRxByteArray(rx_data)
     syncstate=cls.sync_state
     request.iohub_time=None
     if syncstate.getOffset() is not None:
         request.iohub_time=float(syncstate.remote2LocalTime(request.device_time))
     return request
    def EvaluateData(self):
        self.att = np.array([self.roll_Real,-self.pitch_Real,-self.yaw_Real])
        # Update CS
        self.CS.setCS(self.att)

        if Plotting:
            if self.t0==0:
                self.t0=getTime()
            # print "Timestamp: ",timestamp
            t = getTime()-self.t0
            self.Stabilizer_Plot.UpdateGraph(graphname="Roll" ,pos=[t,np.degrees(self.roll_Real)])
            self.Stabilizer_Plot.UpdateGraph(graphname="Pitch",pos=[t,np.degrees(self.pitch_Real)])
            self.Stabilizer_Plot.UpdateGraph(graphname="Yaw"  ,pos=[t,np.degrees(self.yaw_Real)])

            self.Velocity_Plot.UpdateGraph(graphname="X"    ,pos=[t,self.vel[0]])
            self.Velocity_Plot.UpdateGraph(graphname="Y"    ,pos=[t,self.vel[1]])
            self.Velocity_Plot.UpdateGraph(graphname="Z"    ,pos=[t,self.vel[2]])
            #print self.aRaw[2],VectorAbs(self.aRaw)#self.a
            self.Acceleration_Plot.UpdateGraph(graphname="X_Earth",pos=[t,self.a[0]])
            self.Acceleration_Plot.UpdateGraph(graphname="Y_Earth",pos=[t,self.a[1]])
            self.Acceleration_Plot.UpdateGraph(graphname="Z_Earth",pos=[t,self.a[2]])
            self.Acceleration_Plot.UpdateGraph(graphname="X_Raw",pos=[t,self.aRaw[0]])
            self.Acceleration_Plot.UpdateGraph(graphname="Y_Raw",pos=[t,self.aRaw[1]])
            self.Acceleration_Plot.UpdateGraph(graphname="Z_Raw",pos=[t,self.aRaw[2]])
Beispiel #12
0
 def _readRequestReply(cls, t3, request_id):
     request = t3.getPendingRequests().pop(request_id, None)
     if request is None:
         return None
     request.rx_time = getTime()
     rx_data = [request_id, ord(t3.getSerialPort().read(1))]
     if rx_data[1] > 0:
         rx_data.extend(
             [ord(c) for c in t3.getSerialPort().read(rx_data[1] - 2)])
     request.setRxByteArray(rx_data)
     syncstate = cls.sync_state
     request.iohub_time = None
     if syncstate.getOffset() is not None:
         request.iohub_time = float(
             syncstate.remote2LocalTime(request.device_time))
     return request
    def Profile(self,
                ProfilingCommand=None,
                FileName="ProfilingResults.pstats",
                ctx=False,
                delay=0,
                AutoVisualize=True,
                PrintInfo=True,
                PrintStats=True,
                PrintTime=True,
                ShowFullGraph=False):

        #========================================================================================
        # Initialization
        #========================================================================================

        #+++++++++++++++++++++++++++++++++++++++++++
        # Check Results Folder
        #+++++++++++++++++++++++++++++++++++++++++++

        if (not ("/" in FileName)) and (not ("\\" in FileName)):
            if not os.path.exists(DefaultProfilingFolder):
                os.makedirs(DefaultProfilingFolder)
            FileName = DefaultProfilingFolder + FileName

        #-------------------------------------------
        # Fix Filename
        #-------------------------------------------

        ForbiddenChars = []
        ForbiddenChars.append([" ", "_"])  # Remove Spaces!
        ForbiddenChars.append(["=", "_"])  # Equal signs are not allowed!
        if 1:  # These are guesses! (Not sure whether they cause problems...)
            ForbiddenChars.append(["#", "Nr"])
            # ForbiddenChars.append(["-","_"])
            #ForbiddenChars.append([".",","])

        for ForbiddenCharPair in ForbiddenChars:
            B, G = ForbiddenCharPair
            if B in FileName:
                #if PrintInfo: print("CAUTION: '"+B+"' in FileName (not allowed) will be replaced by '"+G+"'")
                FileName = FileName.replace(B, G)

        if " " in FileName:
            print("WARNING: The profiling Filename contains spaces! '" +
                  str(FileName) + "' causes issues when calling cmd commands!")

        #+++++++++++++++++++++++++++++++++++++++++++
        # Default TestRun
        #+++++++++++++++++++++++++++++++++++++++++++

        if ProfilingCommand == None:
            DefaultProfilingTime = 10
            ProfilingCommand = "ProfileTestRun(" + str(
                DefaultProfilingTime) + ")"

        #+++++++++++++++++++++++++++++++++++++++++++
        # MasterClass
        #+++++++++++++++++++++++++++++++++++++++++++

        if self.MasterClass != None and type(ProfilingCommand) == str:
            ProfilingCommand = ProfilingCommand.replace(
                "self.", "self.MasterClass.")

        #========================================================================================
        # Start Profiling
        #========================================================================================

        if PrintInfo:
            print("=" * 50)
            print(">>>!!!Starting Profiling!!!<<<")
            ProfCMD = str(ProfilingCommand)
            if len(ProfCMD) < 100:
                print(">>>'" + ProfCMD + "'<<<")
            else:
                print(">>>'" + ProfCMD[:100] + "[...]" + "'<<<")
            print("=" * 50)

        t0 = getTime()

        if type(ProfilingCommand) == str:
            if ctx:
                Result = cProfile.runctx(ProfilingCommand, globals(), locals(),
                                         FileName)
            else:
                Result = cProfile.run(ProfilingCommand, FileName)
        else:
            Result = self.Profile_Function(ProfilingCommand, FileName)

        t_Profiling = getTime() - t0

        if PrintInfo:
            print("=" * 50)
            print(">>>!!!Profiling Finished (in " +
                  str(round(t_Profiling, 1)) + "s" + ")!!!<<<")
            print(">>>Writing Results to: " + FileName)
            print("=" * 50)
        elif PrintTime:
            print(">>>!!!Profiling of '" + str(ProfilingCommand) +
                  "' Finished (in " + str(round(t_Profiling, 1)) + "s" +
                  ")!!!<<<")

        #--- Delay ---
        if delay > 0:
            Wait(delay)

        #========================================================================================
        # Print Stats
        #========================================================================================

        if PrintStats:
            if 1:  #Threaded:
                PrintCurrentThreads()
            if 0:
                raw_input("View Profiling Results?")

            self.PrintStats(FileName)

        #+++++++++++++++++++++++++++++++++++++++++++
        # Visualize
        #+++++++++++++++++++++++++++++++++++++++++++

        if AutoVisualize:  #and os.name!="nt":
            self.Visualize(FileName, ShowFullGraph=ShowFullGraph)

        # print("ProfilingResult:",Result)
        return Result
Beispiel #14
0
 def _sendT3Request(self, request):
     request.tx_time = getTime()
     tx_count = self._serial_port.write(request.getTxByteArray())
     self._serial_port.flush()
     self._active_requests[request.getID()] = request
     return tx_count
        SESSION_FOLDER = os.path.normpath(os.path.abspath(os.path.join(RESULT_DIR_ROOT,experiment_folder,session_folder)))
        print "SESSION_FOLDER: ", SESSION_FOLDER

        APP_CONF = readAppSettingParameters(SESSION_FOLDER)
        sync_conf = APP_CONF.get('video_event_sync')

        SYNC_TIME_BOX = sync_conf.get('region')
        SYNC_TRANSITION_COUNT = sync_conf.get('cycle_count')
        SYNC_COLORS = sync_conf.get('colors')
        # extra 50 msec / flash is just padding.
        SYNC_FLASH_INTERVAL = sync_conf.get('phase_duration') +0.05
        MAX_SEARCH_FRAMES = int(SYNC_TRANSITION_COUNT * len(
            SYNC_COLORS) * SYNC_FLASH_INTERVAL * FPS) + 90  # extra 3 seconds of frames to handle sleep time at runtime.

        proc_start_time = getTime()
        session_folder = SESSION_FOLDER
        _, session_name = session_folder.rsplit(os.sep, 1)

        # A list of lists. list len = # of recording blocks (videos) in session,
        # Each element of the list is a list of exp message sync frame times.
        flash_msg_times_per_video = getVideoEventSyncMessages(session_folder)


        # Returns a list of str's, each being the abs path to a video file
        # in the given session folder.
        session_video_paths = getVideoFilesFromSessionPath(session_folder)

        session_rec_block_frame_events = []
        mean_offsets_per_video=[]
        for rec_video_index, vpath in enumerate(session_video_paths):
Beispiel #16
0
 def _sendT3Request(self,request):
     request.tx_time=getTime()
     tx_count=self._serial_port.write(request.getTxByteArray())
     self._serial_port.flush()
     self._active_requests[request.getID()]=request
     return tx_count
Beispiel #17
0
        return False

    return True

############### MAIN RUNTIME SCRIPT ########################
#
# Below is the actual script that is run when this file is run through
# the python interpreter. The code above defines functions used by the below
# runtime script.
#
if __name__ == '__main__':
    try:
        et_model_display_configs = dict()
        scount = 0

        start_time = getTime()

        if not os.path.exists(OUTPUT_FOLDER):
            os.mkdir(OUTPUT_FOLDER)

        col_count = len(wide_row_dtype.names)
        format_str = "{}\t" * col_count
        format_str = format_str[:-1] + "\n"
        row_names = wide_row_dtype.names
        header_line = '\t'.join(row_names) + '\n'
        file_proc_count = 0
        total_file_count = len(DATA_FILES)
        hub_file = None
        for file_path in DATA_FILES:
            dpath, dfile = os.path.split(file_path)
            print "Processing file %d / %d. \r" % (
Beispiel #18
0
        print "SESSION_FOLDER: ", SESSION_FOLDER

        APP_CONF = readAppSettingParameters(SESSION_FOLDER)
        sync_conf = APP_CONF.get('video_event_sync')

        SYNC_TIME_BOX = sync_conf.get('region')
        SYNC_TRANSITION_COUNT = sync_conf.get('cycle_count')
        SYNC_COLORS = sync_conf.get('colors')
        # extra 50 msec / flash is just padding.
        SYNC_FLASH_INTERVAL = sync_conf.get('phase_duration') + 0.05
        MAX_SEARCH_FRAMES = int(
            SYNC_TRANSITION_COUNT * len(SYNC_COLORS) * SYNC_FLASH_INTERVAL *
            FPS
        ) + 90  # extra 3 seconds of frames to handle sleep time at runtime.

        proc_start_time = getTime()
        session_folder = SESSION_FOLDER
        _, session_name = session_folder.rsplit(os.sep, 1)

        # A list of lists. list len = # of recording blocks (videos) in session,
        # Each element of the list is a list of exp message sync frame times.
        flash_msg_times_per_video = getVideoEventSyncMessages(session_folder)

        # Returns a list of str's, each being the abs path to a video file
        # in the given session folder.
        session_video_paths = getVideoFilesFromSessionPath(session_folder)

        session_rec_block_frame_events = []
        mean_offsets_per_video = []
        for rec_video_index, vpath in enumerate(session_video_paths):
            t1 = getTime()
Beispiel #19
0
        print 'Dublicate subject ids in %s:'%et_model, \
        unique_ids[np.argwhere(unique_counts > 1).flatten()]
        sys.exit()

############### MAIN RUNTIME SCRIPT ########################
#
# Below is the actual script that is run when this file is run through
# the python interpreter. The code above defines functions used by the below
# runtime script.
#

if __name__ == '__main__':
    et_model_display_configs = dict()
    scount = 0

    start_time = getTime()

    if not os.path.exists(OUTPUT_FOLDER):
        os.mkdir(OUTPUT_FOLDER)

    col_count = len(wide_row_dtype.names)
    format_str = "{}\t" * col_count
    format_str = format_str[:-1] + "\n"
    row_names = wide_row_dtype.names
    header_line = '\t'.join(row_names) + '\n'
    file_proc_count = 0
    total_file_count = len(DATA_FILES)
    hub_file = None
    file_log = None
    
    for file_path in DATA_FILES: