else: frameDur = 1.0 / 60.0 # could not measure, so guess # Initialize components for Routine "preflight" #preflightClock = core.Clock() #frameRate=win.getActualFrameRate() #print(expInfo['frameRate']) mon = monitors.Monitor(expInfo['Monitor'], distance=56) #=======================================================================================# #Opening the appropriate a CRS class of the desired / necessary type print("open CRS") if expInfo['Device'] == 'Bits++': bits = crs.BitsPlusPlus(win, mode='bits++', rampType=1) if expInfo['Device'] == 'Bits#': bits = crs.BitsSharp(win, mode='bits++', checkConfigLevel=1) if expInfo['Device'] == 'Display++' or expInfo['Device'] == 'None': if expInfo['Touch screen'] == "Yes": if expInfo['Device'] == 'Display++': bits = crs.DisplayPlusPlusTouch(win, mode='bits++', checkConfigLevel=1) else: bits = crs.DisplayPlusPlusTouch(win, mode='bits++', checkConfigLevel=1, noComms=True) else: if expInfo['Device'] == 'Display++':
def getLumSeries(lumLevels=8, winSize=(800, 600), monitor=None, gamma=1.0, allGuns=True, useBits=False, autoMode='auto', stimSize=0.3, photometer=None): """Automatically measures a series of gun values and measures the luminance with a photometer. :Parameters: photometer : a photometer object e.g. a :class:`~psychopy.hardware.pr.PR65` or :class:`~psychopy.hardware.minolta.LS100` from hardware.findPhotometer() lumLevels : (default=8) array of values to test or single value for n evenly spaced test values gamma : (default=1.0) the gamma value at which to test autoMode : 'auto' or 'semi'(='auto') If 'auto' the program will present the screen and automatically take a measurement before moving on. If set to 'semi' the program will wait for a keypress before moving on but will not attempt to make a measurement (use this to make a measurement with your own device). Any other value will simply move on without pausing on each screen (use this to see that the display is performing as expected). """ import psychopy.event import psychopy.visual from psychopy import core if photometer is None: havePhotom = False elif not hasattr(photometer, 'getLum'): msg = ("photometer argument to monitors.getLumSeries should be a " "type of photometer object, not a %s") logging.error(msg % type(photometer)) return None else: havePhotom = True if gamma == 1: initRGB = 0.5**(1 / 2.0) * 2 - 1 else: initRGB = 0.8 # setup screen and "stimuli" myWin = psychopy.visual.Window(fullscr=0, size=winSize, gamma=gamma, units='norm', monitor=monitor, allowGUI=True, winType='pyglet') if useBits == 'Bits++': from psychopy.hardware import crs bits = crs.BitsPlusPlus(myWin, gamma=[1, 1, 1]) instructions = ("Point the photometer at the central bar. " "Hit a key when ready (or wait 30s)") message = psychopy.visual.TextStim(myWin, text=instructions, height=0.1, pos=(0, -0.85), rgb=[1, -1, -1]) noise = numpy.random.rand(512, 512).round() * 2 - 1 backPatch = psychopy.visual.PatchStim(myWin, tex=noise, size=2, units='norm', sf=[winSize[0] / 512.0, winSize[1] / 512.0]) testPatch = psychopy.visual.PatchStim(myWin, tex='sqr', size=stimSize, rgb=initRGB, units='norm') # stay like this until key press (or 30secs has passed) waitClock = core.Clock() tRemain = 30 msg = ("Point the photometer at the central white bar. " "Hit a key when ready (or wait %iss)") while tRemain > 0: tRemain = 30 - waitClock.getTime() instructions = msg % tRemain backPatch.draw() testPatch.draw() message.setText(instructions) message.draw() myWin.flip() if len(psychopy.event.getKeys()): break # we got a keypress so move on if autoMode != 'semi': message.setText('Q to quit at any time') else: message.setText('Spacebar for next patch') # LS100 likes to take at least one bright measurement if havePhotom and photometer.type == 'LS100': junk = photometer.getLum() # what are the test values of luminance if (type(lumLevels) is int) or (type(lumLevels) is float): toTest = DACrange(lumLevels) else: toTest = numpy.asarray(lumLevels) if allGuns: guns = [0, 1, 2, 3] # gun=0 is the white luminance measure else: allGuns = [0] # this will hold the measured luminance values lumsList = numpy.zeros((len(guns), len(toTest)), 'd') # for each gun, for each value run test for gun in guns: for valN, DACval in enumerate(toTest): lum = DACval / 127.5 - 1 # get into range -1:1 # only do luminanc=-1 once if lum == -1 and gun > 0: continue # set hte patch color if gun > 0: rgb = [-1, -1, -1] rgb[gun - 1] = lum else: rgb = [lum, lum, lum] backPatch.draw() testPatch.setColor(rgb) testPatch.draw() message.draw() myWin.flip() time.sleep(0.2) # allowing the screen to settle (no good reason!) # take measurement if havePhotom and autoMode == 'auto': actualLum = photometer.getLum() print("At DAC value %i\t: %.2fcd/m^2" % (DACval, actualLum)) if lum == -1 or not allGuns: # if the screen is black set all guns to this lum value! lumsList[:, valN] = actualLum else: # otherwise just this gun lumsList[gun, valN] = actualLum # check for quit request for thisKey in psychopy.event.getKeys(): if thisKey in ('q', 'Q', 'escape'): myWin.close() return numpy.array([]) elif autoMode == 'semi': print("At DAC value %i" % DACval) done = False while not done: # check for quit request for thisKey in psychopy.event.getKeys(): if thisKey in ('q', 'Q', 'escape'): myWin.close() return numpy.array([]) elif thisKey in (' ', 'space'): done = True myWin.close() # we're done with the visual stimuli if havePhotom: return lumsList else: return numpy.array([])
""" from __future__ import division from psychopy import visual, core, event, logging from psychopy.hardware import crs import numpy # This is the new way to use the Bits++ box (or a Bits# device) with PsychoPy. # The BitsSharp device under PsychoPy has some issues right now: # - the shaders aren't working for mono++and color++modes # - for BitsSharp, the device will try to deduce the identity LUT of the screen # but to do that it needs to be in fullscreen mode # logging.console.setLevel(logging.INFO) win = visual.Window([1024, 768], useFBO=True, fullscr=True, screen = 0) bitsBox = crs.BitsPlusPlus(win, mode='bits++', rampType='configFile') # change this to an integer to use a specific identityLUT # BitsSharp can check identity LUT automatically: # bitsBox = crs.BitsSharp(win, mode='bits++', checkConfigLevel=1) # if not bitsBox.OK: # print('failed to connect to Bits box') # else: # print('found %s on %s' %(bitsBox.type, bitsBox.com.port)) grating = visual.GratingStim(win, mask = 'gauss', ori=45, sf=2) # Using bits++ with one stimulus globalClock = core.Clock() while True: # get new contrast t = globalClock.getTime()
# win = visual.Window([1024,768]) # bitsBox = crs.BitsSharp(win, mode='bits++') # bitsBox.setContrast(0.5) # # Check your experiment still works as expected! # # This is the new way to use the Bits++ box (or a Bits# device) with a PsychoPy window. # The BitsSharp device under PsychoPy has some issues right now: # - the shaders aren't working for mono++ and color++ modes # - for BitsSharp, the device will try to deduce the identity LUT of the screen # but to do that it needs to be in fullscreen mode win = visual.Window([1280,1024], useFBO=True, fullscr=True, screen = 0) win.setGamma(1) #make sure that the window is set to identity LUT bitsBox = crs.BitsPlusPlus(win, mode='bits++') #BitsSharp can check identity LUT automatically: #bitsBox = crs.BitsSharp(win, mode='bits++', checkConfig=1) grating = visual.PatchStim(win,mask = 'gauss',sf=2) #---using bits++ with one stimulus globalClock = core.Clock() while True: #get new contrast t=globalClock.getTime() newContr = numpy.sin(t*numpy.pi*2)#sinusoidally modulate contrast #set whole screen to this contrast bitsBox.setContrast(newContr)
else: frameDur = 1.0 / 60.0 # could not measure, so guess # Initialize components for Routine "preflight" preflightClock = core.Clock() import sys from psychopy import monitors, filters, gamma, visual from psychopy.visual import gamma from psychopy.hardware import crs from scipy import misc mon=monitors.Monitor(expInfo['Monitor'],distance=56) print("open CRS") if expInfo['Device']=='Bits++': bits = crs.BitsPlusPlus(win, mode='bits++',rampType=1, frameRate=120) if expInfo['Device']=='Bits#': bits = crs.BitsSharp(win, mode='bits++',checkConfigLevel=1) if expInfo['Device']=='Display++': if expInfo['Touch screen']=="Yes": bits = crs.DisplayPlusPlusTouch(win, mode='bits++',checkConfigLevel=1) else: bits = crs.DisplayPlusPlus(win, mode='bits++',checkConfigLevel=1) if expInfo['Device'] != 'Bits++': if bits.noComms: sys.exit #bits = crs.BitsSharp(win, mode='bits++') #gamma.setGamma(win.winHandle._dc, 1.0, 1) bits.sendMessage('$TemporalDithering=[ON]\r') bits.read(timeout=0.1)