本文整理汇总了Python中psychopy.iohub.launchHubServer函数的典型用法代码示例。如果您正苦于以下问题:Python launchHubServer函数的具体用法?Python launchHubServer怎么用?Python launchHubServer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了launchHubServer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testEnabledDataStore
def testEnabledDataStore():
"""
testEnabledDataStore is the same as testUsingPsychoPyMonitorConfig above,
but by adding an experiment_code parameter the ioHub DataStore will
be enabled, using a auto generated session_code each time it is run.
Experiment and session metadata is printed at the end of the demo.
Considerations:
* A Keyboard, Mouse, Monitor, and Experiment device are created by default.
* If the psychopy_monitor_name is valid, the ioHub Display is updated to
use the display size and viewing distance specified in the psychopy monitor config.
* ioHub DataStore is enabled because experiment_code is provided.
session_code will be auto generated using the current time.
"""
psychopy_mon_name='testMonitor'
exp_code='gap_endo_que'
io=launchHubServer(psychopy_monitor_name=psychopy_mon_name, experiment_code=exp_code)
display=io.devices.display
print('Display Psychopy Monitor Name: ', display.getPsychopyMonitorName())
print('Display Default Eye Distance: ', display.getDefaultEyeDistance())
print('Display Physical Dimensions: ', display.getPhysicalDimensions())
from pprint import pprint
print('Experiment Metadata: ')
pprint(io.getExperimentMetaData())
print('\nSession Metadata: ')
pprint(io.getSessionMetaData())
io.quit()
示例2: start_iohub
def start_iohub(sess_code=None):
import time, os
# Create initial default session code
if sess_code is None:
sess_code='S_{0}'.format(long(time.mktime(time.localtime())))
# Ask for session name / hdf5 file name
save_to = fileSaveDlg(initFilePath=os.path.dirname(__file__),initFileName=sess_code,
prompt="Set Session Output File",
allowed="ioHub Datastore Files (*.hdf5)|*.hdf5")
if save_to:
# session code should equal results file name
fdir, sess_code = os.path.split(save_to)
sess_code=sess_code[0:min(len(sess_code),24)]
if sess_code.endswith('.hdf5'):
sess_code = sess_code[:-5]
if save_to.endswith('.hdf5'):
save_to = save_to[:-5]
else:
save_to = sess_code
exp_code='wintab_evts_test'
kwargs={'experiment_code':exp_code,
'session_code':sess_code,
'datastore_name':save_to,
'wintab.WintabTablet':{'name':'tablet',
'mouse_simulation': {'enable':False,
'leave_region_timeout':2.0
}
}
}
return launchHubServer(**kwargs)
示例3: testWithNoKwargs
def testWithNoKwargs():
"""
testWithNoKwargs illustrates using the launchHubServer function with no
parameters at all. Considerations:
* A Keyboard, Mouse, Monitor, and Experiment device are created by default.
* All devices use their default parameter settings. Therefore, not very useful in real studies.
* ioHub DataStore is not enabled.
"""
io=launchHubServer()
# Get the default keyboard device created.
keyboard=io.devices.keyboard
print()
print("** PRESS A KEY TO CONTINUE.....")
# Check for new events every 1/4 second.
# By using the io.wait() fucntion, the ioHub Process is checked for
# events every 50 msec or so, and they are cached in the PsychoPy process
# until the next getEvents() call is made. On Windows, messagePump() is also
# called periodically so that any Window you have created does not lock up.
#
while not keyboard.getEvents():
io.wait(0.25)
print("A Keyboard Event was Detected; exiting Test.")
io.quit()
示例4: testUsingPsychoPyMonitorConfig
def testUsingPsychoPyMonitorConfig():
"""
testUsingPsychoPyMonitorConfig illustrates using the launchHubServer function
and providing a PsychoPy monitor configuration file name.
Considerations:
* A Keyboard, Mouse, Monitor, and Experiment device are created by default.
* If the psychopy_monitor_name is valid, the ioHub Display is updated to
use the display size and viewing distance specified in the psychopy monitor config.
* ioHub DataStore is not enabled.
"""
io=launchHubServer(psychopy_monitor_name='testMonitor')
# Get the default display device created.
#
display=io.devices.display
# print(the display's physical characteristics, showing they have
# been updated based on the settings in the PsychoPy monitor config.
#
print('Display Psychopy Monitor Name: ', display.getPsychopyMonitorName())
print('Display Default Eye Distance: ', display.getDefaultEyeDistance())
print('Display Physical Dimensions: ', display.getPhysicalDimensions())
# That's it, shut doqn the ioHub Proicess and exit. ;)
#
io.quit()
示例5: startHubProcess
def startHubProcess():
io = launchHubServer()
assert io != None
io_proc = Computer.getIoHubProcess()
io_proc_pid = io_proc.pid
assert io_proc != None and io_proc_pid > 0
return io
示例6: start_iohub
def start_iohub(sess_info):
'''
Starts the iohub server process, using data from the dict returned by
showSessionInfoDialog() to create the hdf5 file name. If the file
already exists, the existing file is renamed so that it is not
overwritten by the current sessions data.
iohub device configuration information is read from an
'iohub_config.yaml' file which must be in the same folder as this file.
The created ioHubConnection object is returned after the iohub
server has started and is ready for interaction with the experiment
runtime.
:param sess_info: dict returned from showSessionInfoDialog()
:return: ioHubConnection object
'''
import os, shutil
save_to = os.path.join(os.path.dirname(__file__),u'results',
sess_info['Session Code'])
save_to = os.path.normpath(save_to)
if not save_to.endswith('.hdf5'):
save_to = save_to+u'.hdf5'
fdir, sess_code = os.path.split(save_to)
if not os.path.exists(fdir):
os.mkdir(fdir)
#TODO: Ask if file should be overwritten, or new session code entered.
si = 1
save_dest = save_to
while os.path.exists(save_dest):
sname, sext = sess_code.rsplit(u'.',1)
save_dest = os.path.join(fdir, u"{}_{}.{}".format(sname,si,sext))
si+=1
if save_dest is not save_to:
shutil.move(save_to,save_dest)
sess_code=sess_code[0:min(len(sess_code),24)]
if sess_code.endswith(u'.hdf5'):
sess_code = sess_code[:-5]
if save_to.endswith(u'.hdf5'):
save_to = save_to[:-5]
kwargs={'experiment_code':EXP_NAME,
'session_code':sess_code,
'datastore_name':save_to,
'iohub_config_name': 'iohub_config.yaml'
}
return launchHubServer(**kwargs)
示例7: __init__
def __init__(self):
# Set up iohub and internal clock. Use existing ioHubServer if it exists.
from psychopy import iohub, core, sys
self._sys = sys
self._core = core
self._timeAtLastReset = core.getTime()
self._EventConstants = iohub.EventConstants
existing_iohub = iohub.ioHubConnection.ACTIVE_CONNECTION
self._io = existing_iohub if existing_iohub else iohub.launchHubServer()
import numpy
self._np = numpy
示例8: startIOHub
def startIOHub():
"""
Starts the ioHub process, saving events to events.hdf5, recording data from
all standard devices as well as the ioSync MCU device.
"""
global io
import time
psychopy_mon_name = 'testMonitor'
exp_code = 'events'
sess_code = 'S_{0}'.format(int(time.mktime(time.localtime())))
iohub_config = {
"psychopy_monitor_name": psychopy_mon_name,
"mcu.iosync.MCU": dict(serial_port='auto',
monitor_event_types=['AnalogInputEvent',
'DigitalInputEvent']),
"experiment_code": exp_code,
"session_code": sess_code
}
return launchHubServer(**iohub_config)
示例9: testEnabledDataStoreAutoSessionCode
def testEnabledDataStoreAutoSessionCode():
"""
testEnabledDataStoreAutoSessionCode is the same as testEnabledDataStore
above, but session_code is provided by the script instead of being
auto-generated. The ioHub DataStore will be enabled, using the
experiment and session_code provided each time it is run. Experiment
and session metadata is printed at the end of the demo.
Considerations:
* A Keyboard, Mouse, Monitor, and Experiment device are created by
default.
* If the psychopy_monitor_name is valid, the ioHub Display is
updated to use the display size and viewing distance specified
in the psychopy monitor config.
* ioHub DataStore is enabled because experiment_code and
session_code are provided.
"""
import time
from pprint import pprint
psychopy_mon_name = 'testMonitor'
exp_code = 'gap_endo_que'
sess_code = 'S_{0}'.format(int(time.mktime(time.localtime())))
print('Current Session Code will be: ', sess_code)
io = launchHubServer(psychopy_monitor_name=psychopy_mon_name,
experiment_code=exp_code,
session_code=sess_code)
display = io.devices.display
print('Display Psychopy Monitor Name: ', display.getPsychopyMonitorName())
print('Display Default Eye Distance: ', display.getDefaultEyeDistance())
print('Display Physical Dimensions: ', display.getPhysicalDimensions())
print('Experiment Metadata: ')
pprint(io.getExperimentMetaData())
print('\nSession Metadata: ')
pprint(io.getSessionMetaData())
io.quit()
示例10: normalizedValue2Coord
from psychopy import visual, core
from psychopy.iohub import launchHubServer, EventConstants
def normalizedValue2Coord(normed_position,normed_magnitude,display_coord_area):
x,y=normed_position[0]*normed_magnitude,normed_position[1]*normed_magnitude
w,h=display_coord_area
return x*(w/2.0),y*(h/2.0)
if __name__ == '__main__':
# Start the ioHub Event Server, requesting an XInput Gamepad Device to be
# created along with the default devices. Since the configuration dict
# for the Gamepad is empty, all default values will be used.
#
kwargs={'psychopy_monitor_name':'default','xinput.Gamepad':{}}
io=launchHubServer(**kwargs)
display = io.devices.display
mouse = io.devices.mouse
display = io.devices.display
keyboard = io.devices.keyboard
gamepad = io.devices.gamepad
display_resolution=display.getPixelResolution()
psychopy_monitor=display.getPsychopyMonitorName()
unit_type=display.getCoordinateType()
screen_index=display.getIndex()
dl,dt,dr,db=display.getCoordBounds()
coord_size=dr-dl,dt-db
myWin=visual.Window(display_resolution, monitor=psychopy_monitor,
示例11:
Displays event information from ioHub Keyboard Events.
Inital Version: May 6th, 2013, Sol Simpson
"""
from psychopy import visual
from psychopy.iohub import launchHubServer,EventConstants
# launchHubServer is a fucntion that can be used to create an instance of the
# ioHub Process within a procedural PsychoPy Script and without the need for
# external configuration files. It is useful when devices like the Keyboard,
# Mouse, Display, and Experiment are all that is needed. By default the
# Display device will use pixel units and display index 0 of a multimonitor setup.
# The returned 'io' variable gives access to the ioHub Process.
#
io=launchHubServer(experiment_code='key_evts',psychopy_monitor_name='default')
# Devices that have been created on the ioHub Process and will be monitored
# for events during the experiment can be accessed via the io.devices.* attribute.
#
# save some 'dots' during the trial loop
#
display = io.devices.display
keyboard = io.devices.keyboard
mouse=io.devices.mouse
# Hide the 'system mouse cursor'.
mouse.setSystemCursorVisibility(False)
# Get settings needed to create the PsychoPy full screen window.
# - display_resolution: the current resolution of diplsay specified by the screen_index.
示例12: launchHubServer
fetching and processing events from hardware; mice, keyboards, eyetrackers).
Inital Version: May 6th, 2013, Sol Simpson
Abbrieviated: May 2013, Jon Peirce
Updated July, 2013, Sol, Added timeouts
"""
from __future__ import division
import sys
from psychopy import visual, core
from psychopy.iohub import launchHubServer
# create the process that will run in the background polling devices
io = launchHubServer()
# some default devices have been created that can now be used
display = io.devices.display
keyboard = io.devices.keyboard
mouse = io.devices.mouse
# Hide the 'system mouse cursor'.
mouse.setSystemCursorVisibility(False)
# We can use display to find info for the Window creation, like the resolution
# (which means PsychoPy won't warn you that the fullscreen does not match your requested size)
display_resolution = display.getPixelResolution()
# ioHub currently supports the use of a single full-screen PsychoPy Window
win = visual.Window(display_resolution, units="pix", fullscr=True, allowGUI=False, screen=0)
示例13: dict
SERIAL_PORT = 'COM5'
BAUDRATE = 19200
# ioHub configuration.
psychopy_mon_name = 'Monitor_01'
exp_code = 'pstbox'
sess_code = 'S_{0}'.format(int(time.mktime(time.localtime())))
iohubkwargs = {
'psychopy_monitor_name': psychopy_mon_name,
'experiment_code': exp_code,
'session_code': sess_code,
'serial.Pstbox': dict(name='pstbox', port=SERIAL_PORT, baud=BAUDRATE)
}
# Start the iohub server and set up devices.
io = launchHubServer(**iohubkwargs)
computer = Computer
display = io.devices.display
pstbox = io.devices.pstbox
print('Switching on lamp #3...')
pstbox.setLampState([0, 0, 1, 0, 0])
print('...done.')
# Create a window.
win = visual.Window(
display.getPixelResolution(),
units='pix', fullscr=True, allowGUI=False,
screen=0
)
示例14: loggedFlip
"""
Created on Thu Oct 17 22:46:06 2013
@author: Sol
"""
from __future__ import print_function
from builtins import str
from psychopy import visual,core
from psychopy.data import TrialHandler,importConditions
from psychopy.iohub import launchHubServer,Computer,EventConstants
getTime=Computer.getTime
psychopy_mon_name='testMonitor'
exp_code='io_stroop'
io=launchHubServer(psychopy_monitor_name=psychopy_mon_name, experiment_code=exp_code)
io.sendMessageEvent(category='EXP',text='Experiment Started')
kb=io.devices.keyboard
mouse = io.devices.mouse
win = visual.Window(allowGUI=False,fullscr=True)
gabor = visual.GratingStim(win,tex="sin",mask="gauss",texRes=256,
size=[200.0,200.0], sf=[4,0], ori = 0, name='gabor1')
letter = visual.TextStim(win,pos=(0.0,0.0),text='X')
retrace_count=0
def loggedFlip(letter_char,letter_color):
global retrace_count
gabor.draw()
示例15:
logFile = logging.LogFile(filename+'.log', level=logging.DEBUG)
logging.console.setLevel(logging.WARNING) # this outputs to the screen, not a file
# An ExperimentHandler isn't essential but helps with data saving
thisExp = data.ExperimentHandler(name=expName, version='',
extraInfo=expInfo, runtimeInfo=None,
originPath=None,
savePickle=True, saveWideText=True,
dataFileName=filename)
#-------------------------------------------------------------------------------
# iohub stuff
#-------------------------------------------------------------------------------
# create the process that will run in the background polling devices
io=launchHubServer(experiment_code='target-sequences', psychopy_monitor_name='default')
# some default devices have been created that can now be used
display = io.devices.display
keyboard = io.devices.keyboard
mouse=io.devices.mouse
# Hide the 'system mouse cursor'.
mouse.setSystemCursorVisibility(False)
mouse.enableEventReporting(True)
# We can use display to find info for the Window creation, like the resolution
# (which means PsychoPy won't warn you that the fullscreen does not match your requested size)
display_resolution=display.getPixelResolution()
#-------------------------------------------------------------------------------