def quit(self, event=None): log.debug('PsychoPyApp: Quitting...') self.quitting = True #see whether any files need saving for frame in self.allFrames: try: #will fail if the frame has been shut somehow elsewhere ok = frame.checkSave() except: ok = False if not ok: log.debug('PsychoPyApp: User cancelled shutdown') return #user cancelled quit #save info about current frames for next run if self.coder and len(self.builderFrames) == 0: self.prefs.appData['lastFrame'] = 'coder' elif self.coder == None: self.prefs.appData['lastFrame'] = 'builder' else: self.prefs.appData['lastFrame'] = 'both' #update app data while closing each frame self.prefs.appData['builder']['prevFiles'] = [ ] #start with an empty list to be appended by each frame self.prefs.appData['coder']['prevFiles'] = [] for frame in copy.copy(self.allFrames): if frame == None: continue frame.closeFrame( checkSave=False) #should update (but not save) prefs.appData self.prefs.saveAppData( ) #must do this before destroying the frame? if sys.platform == 'darwin': self.menuFrame.Destroy() sys.exit() #really force a quit
def showAbout(self, event): log.debug('PsychoPyApp: Showing about dlg') licFile = open( os.path.join(self.prefs.paths['psychopy'], 'LICENSE.txt')) license = licFile.read() licFile.close() msg = """For stimulus generation and experimental control in python. PsychoPy depends on your feedback. If something doesn't work then let me/us know at [email protected]""" info = wx.AboutDialogInfo() info.SetName('PsychoPy') info.SetVersion('v' + psychopy.__version__) info.SetDescription(msg) info.SetCopyright('(C) 2002-2011 Jonathan Peirce') info.SetWebSite('http://www.psychopy.org') info.SetLicence(license) info.AddDeveloper('Jonathan Peirce') info.AddDeveloper('Yaroslav Halchenko') info.AddDeveloper('Jeremy Gray') info.AddDocWriter('Jonathan Peirce') wx.AboutBox(info)
def quit(self, event=None): log.debug('PsychoPyApp: Quitting...') self.quitting=True #see whether any files need saving for frame in self.allFrames: try:#will fail if the frame has been shut somehow elsewhere ok=frame.checkSave() except: ok=False if not ok: log.debug('PsychoPyApp: User cancelled shutdown') return#user cancelled quit #save info about current frames for next run if self.coder and len(self.builderFrames)==0: self.prefs.appData['lastFrame']='coder' elif self.coder==None: self.prefs.appData['lastFrame']='builder' else: self.prefs.appData['lastFrame']='both' #update app data while closing each frame self.prefs.appData['builder']['prevFiles']=[]#start with an empty list to be appended by each frame self.prefs.appData['coder']['prevFiles']=[] for frame in copy.copy(self.allFrames): if frame==None: continue frame.closeFrame(checkSave=False)#should update (but not save) prefs.appData self.prefs.saveAppData()#must do this before destroying the frame? if sys.platform=='darwin': self.menuFrame.Destroy() sys.exit()#really force a quit
def showAbout(self, event): log.debug('PsychoPyApp: Showing about dlg') licFile = open(os.path.join(self.prefs.paths['psychopy'],'LICENSE.txt')) license = licFile.read() licFile.close() msg = """For stimulus generation and experimental control in python. PsychoPy depends on your feedback. If something doesn't work then let me/us know at [email protected]""" info = wx.AboutDialogInfo() info.SetName('PsychoPy') info.SetVersion('v'+psychopy.__version__) info.SetDescription(msg) info.SetCopyright('(C) 2002-2011 Jonathan Peirce') info.SetWebSite('http://www.psychopy.org') info.SetLicence(license) info.AddDeveloper('Jonathan Peirce') info.AddDeveloper('Yaroslav Halchenko') info.AddDeveloper('Jeremy Gray') info.AddDocWriter('Jonathan Peirce') wx.AboutBox(info)
def __init__(self, win, contrast=1.0, gamma=[1.0,1.0,1.0], nEntries=256, bitsType='bits++',): self.win = win self.contrast=contrast self.nEntries=nEntries self.bitsType=bitsType self.method = 'fast' if len(gamma)>2: # [Lum,R,G,B] or [R,G,B] self.gamma=gamma[-3:] else: self.gamma = [gamma, gamma, gamma] if init(): setVideoMode(NOGAMMACORRECT|VIDEOENCODEDCOMMS) self.initialised=True log.debug('found and initialised bits++') else: self.initialised=False log.warning("couldn't initialise bits++") #do the processing self._HEADandLUT = numpy.zeros((524,1,3),numpy.uint8) self._HEADandLUT[:12,:,0] = numpy.asarray([ 36, 63, 8, 211, 3, 112, 56, 34,0,0,0,0]).reshape([12,1])#R self._HEADandLUT[:12,:,1] = numpy.asarray([ 106, 136, 19, 25, 115, 68, 41, 159,0,0,0,0]).reshape([12,1])#G self._HEADandLUT[:12,:,2] = numpy.asarray([ 133, 163, 138, 46, 164, 9, 49, 208,0,0,0,0]).reshape([12,1])#B self.LUT=numpy.zeros((256,3),'d') #just a place holder self.setLUT()#this will set self.LUT and update self._LUTandHEAD
def sendMessage(self, message, timeout=0.5, DEBUG=False): """Send a command to the photometer and wait an alloted timeout for a response (Timeout should be long for low light measurements) """ log.debug("Sending command '%s' to %s" % (message, self.portString)) #send complete message if message[-1] != '\n': message += '\n' #append a newline if necess #flush the read buffer first self.com.read( self.com.inWaiting()) #read as many chars as are in the buffer #send the message for letter in message: self.com.write( letter) #for PR655 have to send individual chars ! :-/ self.com.flush() time.sleep(0.2) #PR655 can get cranky if rushed #get feedback (within timeout) self.com.setTimeout(timeout) if message in ['d5\n', 'D5\n' ]: #we need a spectrum which will have multiple lines return self.com.readlines() else: return self.com.readline()
def compareScreenshot(fileName, win, crit=5.0): """Compare the current back buffer of the given window with the file Screenshots are stored and compared against the files under path kept in TESTS_DATA_PATH. Thus specify relative path to that directory """ #if we start this from a folder below run.py the data folder won't be found fileName = pjoin(TESTS_DATA_PATH, fileName) #get the frame from the window win.getMovieFrame(buffer='back') frame=win.movieFrames[-1] win.movieFrames=[] #if the file exists run a test, if not save the file if not isfile(fileName): frame.save(fileName, optimize=1) raise nose.plugins.skip.SkipTest("Created %s" % basename(fileName)) else: expected = Image.open(fileName) expDat = np.array(expected.getdata()) imgDat = np.array(frame.getdata()) rms = (((imgDat-expDat)**2).sum()/len(imgDat))**0.5 log.debug('PsychoPyTests: RMS=%.3g at threshold=%3.g' % (rms, crit)) if rms>=crit: filenameLocal = fileName.replace('.png','_local.png') frame.save(filenameLocal, optimize=1) log.debug('PsychoPyTests: Saving local copy into %s' % filenameLocal) raise AssertionError("RMS=%.3g at threshold=%.3g. Local copy in %s" % (rms, crit, filenameLocal)) assert rms<crit # must never fail here
def compareScreenshot(fileName, win, crit=5.0): """Compare the current back buffer of the given window with the file Screenshots are stored and compared against the files under path kept in TESTS_DATA_PATH. Thus specify relative path to that directory """ #if we start this from a folder below run.py the data folder won't be found fileName = pjoin(TESTS_DATA_PATH, fileName) #get the frame from the window win.getMovieFrame(buffer='back') frame = win.movieFrames[-1] win.movieFrames = [] #if the file exists run a test, if not save the file if not isfile(fileName): frame.save(fileName, optimize=1) raise nose.plugins.skip.SkipTest("Created %s" % basename(fileName)) else: expected = Image.open(fileName) expDat = np.array(expected.getdata()) imgDat = np.array(frame.getdata()) rms = (((imgDat - expDat)**2).sum() / len(imgDat))**0.5 log.debug('PsychoPyTests: RMS=%.3g at threshold=%3.g' % (rms, crit)) if rms >= crit: filenameLocal = fileName.replace('.png', '_local.png') frame.save(filenameLocal, optimize=1) log.debug('PsychoPyTests: Saving local copy into %s' % filenameLocal) raise AssertionError( "RMS=%.3g at threshold=%.3g. Local copy in %s" % (rms, crit, filenameLocal)) assert rms < crit # must never fail here
def MacOpenFile(self, fileName): log.debug('PsychoPyApp: Received Mac file dropped event') if fileName.endswith('.py'): if self.coder == None: self.showCoder() self.coder.setCurrentDoc(fileName) elif fileName.endswith('.psyexp'): self.newBuilderFrame(fileName=fileName)
def __del__(self): try: self.endRemoteMode() time.sleep(0.1) self.com.close() log.debug('Closed PR655 port') except: pass
def MacOpenFile(self,fileName): log.debug('PsychoPyApp: Received Mac file dropped event') if fileName.endswith('.py'): if self.coder==None: self.showCoder() self.coder.setCurrentDoc(fileName) elif fileName.endswith('.psyexp'): self.newBuilderFrame(fileName=fileName)
def show(self): """Presents the dialog and waits for the user to press either OK or CANCEL. This function returns nothing. When they do, dlg.OK will be set to True or False (according to which button they pressed. If OK==True then dlg.data will be populated with a list of values coming from each of the input fields created. """ #add buttons for OK and Cancel buttons = wx.BoxSizer(wx.HORIZONTAL) OK = wx.Button(self, wx.ID_OK, " OK ") OK.SetDefault() buttons.Add(OK) CANCEL = wx.Button(self, wx.ID_CANCEL, " Cancel ") buttons.Add(CANCEL) self.sizer.Add(buttons, 1, flag=wx.ALIGN_RIGHT | wx.ALIGN_BOTTOM, border=5) self.SetSizerAndFit(self.sizer) if self.ShowModal() == wx.ID_OK: self.data = [] #get data from input fields for n in range(len(self.inputFields)): thisName = self.inputFieldNames[n] thisVal = self.inputFields[n].GetValue() thisType = self.inputFieldTypes[n] #try to handle different types of input from strings log.debug("%s: %s" % (self.inputFieldNames[n], unicode(thisVal))) if thisType in [tuple, list, float, int]: #probably a tuple or list exec("self.data.append(" + thisVal + ")") #evaluate it elif thisType == numpy.ndarray: exec("self.data.append(numpy.array(" + thisVal + "))") elif thisType in [str, unicode, bool]: self.data.append(thisVal) else: log.warning('unknown type:' + self.inputFieldNames[n]) self.data.append(thisVal) self.OK = True else: self.OK = False self.Destroy()
def show(self): """Presents the dialog and waits for the user to press either OK or CANCEL. This function returns nothing. When they do, dlg.OK will be set to True or False (according to which button they pressed. If OK==True then dlg.data will be populated with a list of values coming from each of the input fields created. """ #add buttons for OK and Cancel buttons = wx.BoxSizer(wx.HORIZONTAL) OK = wx.Button(self, wx.ID_OK, " OK ") OK.SetDefault() buttons.Add(OK) CANCEL = wx.Button(self, wx.ID_CANCEL, " Cancel ") buttons.Add(CANCEL) self.sizer.Add(buttons,1,flag=wx.ALIGN_RIGHT|wx.ALIGN_BOTTOM,border=5) self.SetSizerAndFit(self.sizer) if self.ShowModal() == wx.ID_OK: self.data=[] #get data from input fields for n in range(len(self.inputFields)): thisName = self.inputFieldNames[n] thisVal = self.inputFields[n].GetValue() thisType= self.inputFieldTypes[n] #try to handle different types of input from strings log.debug("%s: %s" %(self.inputFieldNames[n], unicode(thisVal))) if thisType in [tuple,list,float,int]: #probably a tuple or list exec("self.data.append("+thisVal+")")#evaluate it elif thisType==numpy.ndarray: exec("self.data.append(numpy.array("+thisVal+"))") elif thisType in [str,unicode,bool]: self.data.append(thisVal) else: log.warning('unknown type:'+self.inputFieldNames[n]) self.data.append(thisVal) self.OK=True else: self.OK=False self.Destroy()
def sendMessage(self, message, timeout=5.0): """Send a command to the photometer and wait an alloted timeout for a response. """ if message[-2:]!='\r\n': message+='\r\n' #append a newline if necess #flush the read buffer first self.com.read(self.com.inWaiting())#read as many chars as are in the buffer for attemptN in range(self.maxAttempts): #send the message time.sleep(0.1) self.com.write(message) self.com.flush() time.sleep(0.1) #get reply (within timeout limit) self.com.setTimeout(timeout) log.debug('Sent command:'+message[:-2])#send complete message retVal= self.com.readline() if len(retVal)>0:break#we got a reply so can stop trying return retVal
def sendMessage(self, message, timeout=0.5, DEBUG=False): """Send a command to the photometer and wait an alloted timeout for a response (Timeout should be long for low light measurements) """ if message[-1]!='\n': message+='\n' #append a newline if necess #flush the read buffer first self.com.read(self.com.inWaiting())#read as many chars as are in the buffer #send the message self.com.write(message) self.com.flush() #time.sleep(0.1) #PR650 gets upset if hurried! #get feedback (within timeout limit) self.com.setTimeout(timeout) log.debug(message)#send complete message if message in ['d5', 'd5\n']: #we need a spectrum which will have multiple lines return self.com.readlines() else: return self.com.readline()
def __init__( self, win, contrast=1.0, gamma=[1.0, 1.0, 1.0], nEntries=256, bitsType='bits++', ): self.win = win self.contrast = contrast self.nEntries = nEntries self.bitsType = bitsType self.method = 'fast' if len(gamma) > 2: # [Lum,R,G,B] or [R,G,B] self.gamma = gamma[-3:] else: self.gamma = [gamma, gamma, gamma] if init(): setVideoMode(NOGAMMACORRECT | VIDEOENCODEDCOMMS) self.initialised = True log.debug('found and initialised bits++') else: self.initialised = False log.warning("couldn't initialise bits++") #do the processing self._HEADandLUT = numpy.zeros((524, 1, 3), numpy.uint8) self._HEADandLUT[:12, :, 0] = numpy.asarray( [36, 63, 8, 211, 3, 112, 56, 34, 0, 0, 0, 0]).reshape([12, 1]) #R self._HEADandLUT[:12, :, 1] = numpy.asarray( [106, 136, 19, 25, 115, 68, 41, 159, 0, 0, 0, 0]).reshape([12, 1]) #G self._HEADandLUT[:12, :, 2] = numpy.asarray( [133, 163, 138, 46, 164, 9, 49, 208, 0, 0, 0, 0]).reshape([12, 1]) #B self.LUT = numpy.zeros((256, 3), 'd') #just a place holder self.setLUT() #this will set self.LUT and update self._LUTandHEAD
def sendMessage(self, message, timeout=0.5, DEBUG=False): """Send a command to the photometer and wait an alloted timeout for a response (Timeout should be long for low light measurements) """ log.debug("Sending command '%s' to %s" %(message, self.portString))#send complete message if message[-1]!='\n': message+='\n' #append a newline if necess #flush the read buffer first self.com.read(self.com.inWaiting())#read as many chars as are in the buffer #send the message for letter in message: self.com.write(letter)#for PR655 have to send individual chars ! :-/ self.com.flush() time.sleep(0.2)#PR655 can get cranky if rushed #get feedback (within timeout) self.com.setTimeout(timeout) if message in ['d5\n', 'D5\n']: #we need a spectrum which will have multiple lines return self.com.readlines() else: return self.com.readline()
def sendMessage(self, message, timeout=0.5, DEBUG=False): """Send a command to the photometer and wait an alloted timeout for a response (Timeout should be long for low light measurements) """ if message[-1] != '\n': message += '\n' #append a newline if necess #flush the read buffer first self.com.read( self.com.inWaiting()) #read as many chars as are in the buffer #send the message self.com.write(message) self.com.flush() #time.sleep(0.1) #PR650 gets upset if hurried! #get feedback (within timeout limit) self.com.setTimeout(timeout) log.debug(message) #send complete message if message in ['d5', 'd5\n' ]: #we need a spectrum which will have multiple lines return self.com.readlines() else: return self.com.readline()
def showPrefs(self, event): log.debug('PsychoPyApp: Showing prefs dlg') prefsDlg = preferences.PreferencesDlg(app=self) prefsDlg.Show()
# Part of the PsychoPy library # Copyright (C) 2011 Jonathan Peirce # Distributed under the terms of the GNU General Public License (GPL). import sys, time from psychopy import log try: import ctypes, ctypes.util importCtypesFailed = False except: importCtypesFailed = True log.debug("rush() not available because import ctypes failed in contrib/darwin.py") #constants KERN_SUCCESS=0; kCGLCPSwapInterval= ctypes.c_int(222) #these defined in thread_policy.h from apple (googleable) THREAD_STANDARD_POLICY=ctypes.c_int(1) THREAD_STANDARD_POLICY_COUNT=ctypes.c_int(0 ) THREAD_EXTENDED_POLICY=ctypes.c_int(1) THREAD_EXTENDED_POLICY_COUNT=ctypes.c_int(1) THREAD_TIME_CONSTRAINT_POLICY=ctypes.c_int(2) THREAD_TIME_CONSTRAINT_POLICY_COUNT=ctypes.c_int(4) #these were found in pyglet/window/carbon/constants thanks to Alex Holkner kCFStringEncodingASCII = 0x0600 kCFStringEncodingUnicode = 0x0100 kCFStringEncodingUTF8 = 0x08000100 kCFNumberLongType = 10 #some data types these can be found in various *.defs CGDirectDisplayID = ctypes.c_void_p CGDisplayCount = ctypes.c_uint32
# Part of the PsychoPy library # Copyright (C) 2011 Jonathan Peirce # Distributed under the terms of the GNU General Public License (GPL). import sys, time from psychopy import log try: import ctypes, ctypes.util importCtypesFailed = False except: importCtypesFailed = True log.debug( "rush() not available because import ctypes failed in contrib/darwin.py" ) #constants KERN_SUCCESS = 0 kCGLCPSwapInterval = ctypes.c_int(222) #these defined in thread_policy.h from apple (googleable) THREAD_STANDARD_POLICY = ctypes.c_int(1) THREAD_STANDARD_POLICY_COUNT = ctypes.c_int(0) THREAD_EXTENDED_POLICY = ctypes.c_int(1) THREAD_EXTENDED_POLICY_COUNT = ctypes.c_int(1) THREAD_TIME_CONSTRAINT_POLICY = ctypes.c_int(2) THREAD_TIME_CONSTRAINT_POLICY_COUNT = ctypes.c_int(4) #these were found in pyglet/window/carbon/constants thanks to Alex Holkner kCFStringEncodingASCII = 0x0600 kCFStringEncodingUnicode = 0x0100 kCFStringEncodingUTF8 = 0x08000100 kCFNumberLongType = 10 #some data types these can be found in various *.defs
def showPrefs(self, event): from psychopy.app.preferencesDlg import PreferencesDlg log.debug('PsychoPyApp: Showing prefs dlg') prefsDlg = PreferencesDlg(app=self) prefsDlg.Show()
# Part of the PsychoPy library # Copyright (C) 2010 Jonathan Peirce # Distributed under the terms of the GNU General Public License (GPL). """ placeholder for adding c (or ctypes) extensions to the linux PsychoPy """ from psychopy import log import sys try: import ctypes, ctypes.util c = ctypes.cdll.LoadLibrary(ctypes.util.find_library('c')) importCtypesFailed = False except: importCtypesFailed = True log.debug("rush() not available because import ctypes, ctypes.util failed in ext/linux.py") #FIFO and RR(round-robin) allow highest priority for realtime SCHED_NORMAL=0 SCHED_FIFO =1 SCHED_RR =2 SCHED_BATCH =3 if not importCtypesFailed: class _SchedParams(ctypes.Structure): _fields_ = [('sched_priority', ctypes.c_int)]# def rush(value=True): """Raise the priority of the current thread/process using - sched_setscheduler NB for rush() to work on (debian-based?) linux requires that the script is run using a copy of python that
def lineariseLums(self, desiredLums, newInterpolators=False, overrideGamma=None): """lums should be uncalibrated luminance values (e.g. a linear ramp) ranging 0:1""" linMethod = self.getLineariseMethod() desiredLums = numpy.asarray(desiredLums) output = desiredLums*0.0 #needs same size as input #gamma interpolation if linMethod==3: lumsPre = copy(self.getLumsPre()) if self._gammaInterpolator!=None and not newInterpolators: pass #we already have an interpolator elif lumsPre != None: log.info('Creating linear interpolation for gamma') #we can make an interpolator self._gammaInterpolator, self._gammaInterpolator2 =[],[] #each of these interpolators is a function! levelsPre = self.getLevelsPre()/255.0 for gun in range(4): lumsPre[gun,:] = (lumsPre[gun,:]-lumsPre[gun,0])/(lumsPre[gun,-1]-lumsPre[gun,0])#scale to 0:1 self._gammaInterpolator.append(interp1d(lumsPre[gun,:], levelsPre,kind='linear')) #interpFunc = Interpolation.InterpolatingFunction((lumsPre[gun,:],), levelsPre) #polyFunc = interpFunc.fitPolynomial(3) #print polyFunc.coeff #print polyFunc.derivative(0) #print polyFunc.derivative(0.5) #print polyFunc.derivative(1.0) #self._gammaInterpolator2.append( [polyFunc.coeff]) else: #no way to do this! Calibrate the monitor log.error("Can't do a gamma interpolation on your monitor without calibrating!") return desiredLums #then do the actual interpolations if len(desiredLums.shape)>1: for gun in range(3): output[:,gun] = self._gammaInterpolator[gun+1](desiredLums[:,gun])#gun+1 because we don't want luminance interpolator else:#just luminance output = self._gammaInterpolator[0](desiredLums) #use a fitted gamma equation (1 or 2) elif linMethod in [1,2]: #get the min,max lums gammaGrid = self.getGammaGrid() if gammaGrid!=None: #if we have info about min and max luminance then use it minLum = gammaGrid[1,0] maxLum = gammaGrid[1:4,1] if overrideGamma is not None: gamma=overrideGamma else: gamma = gammaGrid[1:4,2] maxLumWhite = gammaGrid[0,1] gammaWhite = gammaGrid[0,2] log.debug('using gamma grid'+str(gammaGrid)) else: #just do the calculation using gamma minLum=0 maxLumR, maxLumG, maxLumB, maxLumWhite= 1,1,1, 1 gamma = self.gamma gammaWhite = num.average(self.gamma) #get the inverse gamma if len(desiredLums.shape)>1: for gun in range(3): output[:,gun] = gammaInvFun(desiredLums[:,gun], minLum, maxLum[gun], gamma[gun],eq=linMethod) #print gamma else: output = gammaInvFun(desiredLums, minLum, maxLumWhite, gammaWhite,eq=linMethod) else: log.error("Don't know how to linearise with method %i" %linMethod) output = desiredLums #if DEBUG: print 'LUT:', output[0:10,1], '...' return output
def lineariseLums(self, desiredLums, newInterpolators=False, overrideGamma=None): """lums should be uncalibrated luminance values (e.g. a linear ramp) ranging 0:1""" linMethod = self.getLineariseMethod() desiredLums = numpy.asarray(desiredLums) output = desiredLums*0.0 #needs same size as input #gamma interpolation if linMethod==3: lumsPre = copy(self.getLumsPre()) if self._gammaInterpolator!=None and not newInterpolators: pass #we already have an interpolator elif lumsPre != None: log.info('Creating linear interpolation for gamma') #we can make an interpolator self._gammaInterpolator, self._gammaInterpolator2 =[],[] #each of these interpolators is a function! levelsPre = self.getLevelsPre()/255.0 for gun in range(4): lumsPre[gun,:] = (lumsPre[gun,:]-lumsPre[gun,0])/(lumsPre[gun,-1]-lumsPre[gun,0])#scale to 0:1 self._gammaInterpolator.append(interp1d(lumsPre[gun,:], levelsPre,kind='linear')) #interpFunc = Interpolation.InterpolatingFunction((lumsPre[gun,:],), levelsPre) #polyFunc = interpFunc.fitPolynomial(3) #print polyFunc.coeff #print polyFunc.derivative(0) #print polyFunc.derivative(0.5) #print polyFunc.derivative(1.0) #self._gammaInterpolator2.append( [polyFunc.coeff]) else: #no way to do this! Calibrate the monitor log.error("Can't do a gamma interpolation on your monitor without calibrating!") return desiredLums #then do the actual interpolations if len(desiredLums.shape)>1: for gun in range(3): output[:,gun] = self._gammaInterpolator[gun+1](desiredLums[:,gun])#gun+1 because we don't want luminance interpolator else:#just luminance output = self._gammaInterpolator[0](desiredLums) #use a fitted gamma equation (1 or 2) elif linMethod in [1,2,4]: #get the min,max lums gammaGrid = self.getGammaGrid() if gammaGrid!=None: #if we have info about min and max luminance then use it minLum = gammaGrid[1,0] maxLum = gammaGrid[1:4,1] b = gammaGrid[1:4,4] if overrideGamma is not None: gamma=overrideGamma else: gamma = gammaGrid[1:4,2] maxLumWhite = gammaGrid[0,1] gammaWhite = gammaGrid[0,2] log.debug('using gamma grid'+str(gammaGrid)) else: #just do the calculation using gamma minLum=0 maxLumR, maxLumG, maxLumB, maxLumWhite= 1,1,1, 1 gamma = self.gamma gammaWhite = num.average(self.gamma) #get the inverse gamma if len(desiredLums.shape)>1: for gun in range(3): output[:,gun] = gammaInvFun(desiredLums[:,gun], minLum, maxLum[gun], gamma[gun],eq=linMethod, b=b[gun]) #print gamma else: output = gammaInvFun(desiredLums, minLum, maxLumWhite, gammaWhite,eq=linMethod) else: log.error("Don't know how to linearise with method %i" %linMethod) output = desiredLums #if DEBUG: print 'LUT:', output[0:10,1], '...' return output
# Part of the PsychoPy library # Copyright (C) 2011 Jonathan Peirce # Distributed under the terms of the GNU General Public License (GPL). """ placeholder for adding c (or ctypes) extensions to the linux PsychoPy """ from psychopy import log import sys try: import ctypes, ctypes.util c = ctypes.cdll.LoadLibrary(ctypes.util.find_library('c')) importCtypesFailed = False except: importCtypesFailed = True log.debug( "rush() not available because import ctypes, ctypes.util failed in ext/linux.py" ) #FIFO and RR(round-robin) allow highest priority for realtime SCHED_NORMAL = 0 SCHED_FIFO = 1 SCHED_RR = 2 SCHED_BATCH = 3 if not importCtypesFailed: class _SchedParams(ctypes.Structure): _fields_ = [('sched_priority', ctypes.c_int)] # def rush(value=True):