コード例 #1
0
ファイル: psychopyIOHubRuntime.py プロジェクト: peircej/ioHub
    def __init__(self, configFilePath, configFile):
        """
        Initialize the ioHubExperimentRuntime Object, loading the experiment configuration file, initializing and launching
        the ioHub server process, and creating the client side device interface to the ioHub devices that have been created.

        Currently the ioHub timer uses a ctypes implementation of direct access to the Windows QPC functions in win32
        (so no python interpreter start time offset is applied between processes) and timeit.default_timer is used for
        all other platforms at this time. The advantage of not having a first read offset applied per python interpreter is that
        it means the both the psychopy process and the ioHub process are using the exact same timebase without a different
        offset that is hard to exactly determine due to the variablility in IPC request-reponses. By the two processes using
        the exact same time space, including offset, getTime() for the the ioHub client in psychopy == the current time of the ioHub server
        process, greatly simplifying some aspects of synconization. This only holds as long as both processes are running
        on the same PC of course.

        Note on timeit.default_timer: As of 2.7, timeit.default_timer correctly selects the best clock based on OS for high
        precision timing. < 2.7, you need to check the OS version yourself and select; or use the psychopy clocks since
        it does the work for you. ;)

        Args:
            configFilePath (str): The absolute path to the experiment configuration .yaml file, which is automatically assigned
            to the path the experiment script is running from by default.
            configFile (str): The name of the experiment configuration .yaml file, which has a default value of 'experiment_config.yaml'

            Return: None
        """
        self.hub=None
        self.configFilePath=configFilePath
        self.configFileName=configFile

        # load the experiment config settings from the experiment_config.yaml file.
        # The file must be in the same directory as the experiment script.
        self.configuration=load(file( os.path.join(self.configFilePath,self.configFileName),u'r'), Loader=Loader)

        import random
        random.seed(ioHub.highPrecisionTimer()*1000.123)
        randomInt=random.randint(1,1000)
        self.experimentConfig=dict()
        self._experimentConfigKeys=['title','code','version','description']
        self.experimentConfig.setdefault('title',self.experimentConfig.get('title','A Default Experiment Title'))
        self.experimentConfig.setdefault('code',self.experimentConfig.get('code','EXP_%d'%(randomInt,)))
        self.experimentConfig.setdefault('version',self.experimentConfig.get('version','1.0d'))
        self.experimentConfig.setdefault('description',self.experimentConfig.get('description','A Default Experiment Description'))
#        self.experimentConfig.setdefault('total_sessions_to_run',self.experimentConfig.get('total_sessions_to_run',0))

        for key in self._experimentConfigKeys:
            if key in self.configuration:
                self.experimentConfig[key]=self.configuration[key]
 
        self.experimentSessionDefaults=self.configuration['session_defaults']
        self.sessionUserVariables=self.experimentSessionDefaults.get('user_variables',None)
        if self.sessionUserVariables is not None:
            del self.experimentSessionDefaults['user_variables']
        else:
            self.sessionUserVariables={}

        # initialize the experiment object based on the configuration settings.
        self.hub=self._initalizeConfiguration()

        self.devices=self.hub.devices
        self.devices.computer=Computer
コード例 #2
0
ファイル: variableProvider.py プロジェクト: peircej/ioHub
    def __init__(self,fileNameWithPath,blockingVariableLabel,practiceBlockValues=None,randomizeBlocks=False,randomizeTrials=True,randSeed=None):
        self.fileNameWithPath=fileNameWithPath
        self.blockingVariableLabel=blockingVariableLabel
        self.practiceBlockValues=practiceBlockValues

        self.randomizeBlocks=randomizeBlocks
        self.randomizeTrials=randomizeTrials

        if ExperimentVariableProvider._randomGeneratorSeed is None:
            if randSeed is None:
                randSeed=int(ioHub.highPrecisionTimer()*1000.0)
            ExperimentVariableProvider._randomGeneratorSeed = randSeed
            np.random.seed(ExperimentVariableProvider._randomGeneratorSeed)

        self.variableNames=[]
        self.totalColumnCount=None
        self.totalRowCount=None
        self._numpyConditionVariableDescriptor=None
        self.data=None

        self.practiceBlocks=BlockSetProvider([TrialSetProvider([],self.randomizeTrials),],self.randomizeBlocks)
        self.experimentBlocks=BlockSetProvider([TrialSetProvider([],self.randomizeTrials),],self.randomizeBlocks)

        self._readConditionVariableFile()
コード例 #3
0
ファイル: __init__.py プロジェクト: awood3/ioHub
 def currentUsec():
     return int(highPrecisionTimer()*1000000.0)
コード例 #4
0
ファイル: __init__.py プロジェクト: awood3/ioHub
 def currentMsec():
     return highPrecisionTimer()*1000.0
コード例 #5
0
ファイル: __init__.py プロジェクト: awood3/ioHub
 def currentSec():
     return highPrecisionTimer()
コード例 #6
0
ファイル: server.py プロジェクト: peircej/ioHub
        ioHub.print2err("Error occurred during ioServer.start(): ",str(e))
        ioHub.printExceptionDetailsToStdErr()
        ioHub.print2err("------------------------------")

        sys.stdout.write("IOHUB_FAILED\n\r\n\r")
        sys.stdout.flush()
        
        try:
            s.shutdown()
        except:
            pass
    
    return -1
    
if __name__ == '__main__':
    import sys
    prog=sys.argv[0]
    if len(sys.argv)>=2:
        initial_offset=float(sys.argv[1])
    if len(sys.argv)>=3:
        rootScriptPathDir=sys.argv[2]
    if len(sys.argv)>=4:        
        configFileName=sys.argv[3]        
        #ioHub.print2err("ioServer initial_offset: ",initial_offset)
    if len(sys.argv)<2:
        configFileName=None
        rootScriptPathDir=None
        initial_offset=ioHub.highPrecisionTimer()
        
    run(initial_time_offset=initial_offset, rootScriptPathDir=rootScriptPathDir, configFilePath=configFileName)