本文整理汇总了Python中psychopy.tools.attributetools.setWithOperation函数的典型用法代码示例。如果您正苦于以下问题:Python setWithOperation函数的具体用法?Python setWithOperation怎么用?Python setWithOperation使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setWithOperation函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setOris
def setOris(self,value,operation='', log=True):
"""Set the orientation for each element.
Should either be a single value or an Nx1 array/list
"""
#make into an array
if type(value) in [int, float, list, tuple]:
value = numpy.array(value, dtype=float)
#check shape
if value.shape in [(),(1,)]:
value = value.repeat(self.nElements)
elif value.shape in [(self.nElements,), (self.nElements,1)]:
pass #is already Nx1
else:
raise ValueError("New value for setOris should be either Nx1 or a single value")
# flip orientation so, when drawn, it matches the convention of other
# visual stimuli
value = -value
#set value
setWithOperation(self, 'oris', value, operation)
self.needVertexUpdate=True
if log and self.autoLog:
self.win.logOnFlip("Set %s oris=%s" %(self.name, type(value)),
level=logging.EXP,obj=self)
示例2: setSizes
def setSizes(self,value,operation='', log=True):
"""Set the size for each element.
Should either be:
- a single value
- an Nx1 array/list
- an Nx2 array/list
"""
#make into an array
if type(value) in [int, float, list, tuple]:
value = numpy.array(value, dtype=float)
#check shape
if value.shape in [(),(1,),(2,)]:
value = numpy.resize(value, [self.nElements,2])
elif value.shape in [(self.nElements,), (self.nElements,1)]:
value.shape=(self.nElements,1)#set to be 2D
value = value.repeat(2,1) #repeat once on dim 1
elif value.shape == (self.nElements,2):
pass#all is good
else:
raise ValueError("New value for setSizes should be either Nx1, Nx2 or a single value")
#set value and log
setWithOperation(self, 'sizes', value, operation)
logAttrib(self, log, 'sizes', type(value))
self._needVertexUpdate=True
self._needTexCoordUpdate=True
示例3: setSfs
def setSfs(self, value,operation='', log=True):
"""Set the spatial frequency for each element.
Should either be:
- a single value
- an Nx1 array/list
- an Nx2 array/list (spatial frequency of the element in X and Y).
If the units for the stimulus are 'pix' or 'norm' then the units of sf
are cycles per stimulus width. For units of 'deg' or 'cm' the units
are c/cm or c/deg respectively.
"""
#make into an array
if type(value) in [int, float, list, tuple]:
value = numpy.array(value, dtype=float)
#check shape
if value.shape in [(),(1,),(2,)]:
value = numpy.resize(value, [self.nElements,2])
elif value.shape in [(self.nElements,), (self.nElements,1)]:
value.shape=(self.nElements,1)#set to be 2D
value = value.repeat(2,1) #repeat once on dim 1
elif value.shape == (self.nElements,2):
pass#all is good
else:
raise ValueError("New value for setSfs should be either Nx1, Nx2 or a single value")
# Set value and log
setWithOperation(self, 'sfs', value, operation)
if log and self.autoLog:
self.win.logOnFlip("Set %s sfs=%s" %(self.name, type(value)),
level=logging.EXP,obj=self)
示例4: setPhases
def setPhases(self,value,operation='', log=True):
"""Set the phase for each element.
Should either be:
- a single value
- an Nx1 array/list
- an Nx2 array/list (for separate X and Y phase)
"""
#make into an array
if type(value) in [int, float, list, tuple]:
value = numpy.array(value, dtype=float)
#check shape
if value.shape in [(),(1,),(2,)]:
value = numpy.resize(value, [self.nElements,2])
elif value.shape in [(self.nElements,), (self.nElements,1)]:
value.shape=(self.nElements,1)#set to be 2D
value = value.repeat(2,1) #repeat once on dim 1
elif value.shape == (self.nElements,2):
pass#all is good
else:
raise ValueError("New value for setPhases should be either Nx1, Nx2 or a single value")
#set value and log
setWithOperation(self, 'phases', value, operation)
self.needTexCoordUpdate=True
if log and self.autoLog:
self.win.logOnFlip("Set %s phases=%s" %(self.name, type(value)),
level=logging.EXP,obj=self)
示例5: setContrs
def setContrs(self,value,operation='', log=True):
"""Set the contrast for each element.
Should either be:
- a single value
- an Nx1 array/list
"""
#make into an array
if type(value) in [int, float, list, tuple]:
value = numpy.array(value, dtype=float)
#check shape
if value.shape in [(),(1,)]:
value = value.repeat(self.nElements)
elif value.shape in [(self.nElements,), (self.nElements,1)]:
pass #is already Nx1
else:
raise ValueError("New value for setContrs should be either Nx1 or a single value")
#set value and log
setWithOperation(self, 'contrs', value, operation)
self.needColorUpdate=True
if log and self.autoLog:
self.win.logOnFlip("Set %s contrs=%s" %(self.name, type(value)),
level=logging.EXP,obj=self)
示例6: setSfs
def setSfs(self, value, operation="", log=True):
"""Set the spatial frequency for each element.
Should either be:
- a single value
- an Nx1 array/list
- an Nx2 array/list (spatial frequency of the element in X and Y).
If the units for the stimulus are 'pix' or 'norm' then the units of sf
are cycles per stimulus width. For units of 'deg' or 'cm' the units
are c/cm or c/deg respectively.
"""
# make into an array
if type(value) in [int, float, list, tuple]:
value = numpy.array(value, dtype=float)
# check shape
if value.shape in [(), (1,), (2,)]:
value = numpy.resize(value, [self.nElements, 2])
elif value.shape in [(self.nElements,), (self.nElements, 1)]:
value.shape = (self.nElements, 1) # set to be 2D
value = value.repeat(2, 1) # repeat once on dim 1
elif value.shape == (self.nElements, 2):
pass # all is good
else:
raise ValueError("New value for setSfs should be either Nx1, Nx2 or a single value")
# Set value and log
setWithOperation(self, "sfs", value, operation)
logAttrib(self, log, "sfs", type(value))
self._needTexCoordUpdate = True
示例7: _set
def _set(self, attrib, val, op='', log=True):
"""Use this to set attributes of your stimulus after initialising it.
:Parameters:
attrib : a string naming any of the attributes of the stimulus (set during init)
val : the value to be used in the operation on the attrib
op : a string representing the operation to be performed (optional) most maths operators apply ('+','-','*'...)
examples::
myStim.set('rgb',0) #will simply set all guns to zero (black)
myStim.set('rgb',0.5,'+') #will increment all 3 guns by 0.5
myStim.set('rgb',(1.0,0.5,0.5),'*') # will keep the red gun the same and halve the others
"""
#format the input value as float vectors
if type(val) in [tuple,list]:
val=numpy.array(val,float)
#change the attribute as requested
setWithOperation(self, attrib, val, op)
#update the actual coherence for the requested coherence and nDots
if attrib in ['nDots','coherence']:
self.coherence=round(self.coherence*self.nDots)/self.nDots
if log and self.autoLog:
self.win.logOnFlip("Set %s %s=%s" %(self.name, attrib, getattr(self,attrib)),
level=logging.EXP)
示例8: setFieldPos
def setFieldPos(self,value,operation='', log=True):
"""Set the centre of the array (X,Y)
"""
#make into an array
if type(value) in [int, float, list, tuple]:
value = numpy.array(value, dtype=float)
#check shape
if value.shape != (2,):
raise ValueError("New value for setFieldPos should be [x,y]")
#set value and log
setWithOperation(self, 'fieldPos', value, operation)
logAttrib(self, log, 'fieldPos', type(value))
示例9: setFieldSize
def setFieldSize(self,value,operation='', log=True):
"""Set the size of the array on the screen (will override
current XY positions of the elements)
"""
#make into an array
if type(value) in [int, float, list, tuple]:
value = numpy.array(value, dtype=float)
#check shape
if value.shape not in [(2,),(1,)]:
raise ValueError("New value for setFieldSize should be [x,y] or a single value")
#set value and log
setWithOperation(self, 'fieldSize', value, operation)
logAttrib(self, log, 'fieldSize')
self.setXYs(log=False)#to reflect new settings, overriding individual xys
示例10: setFieldPos
def setFieldPos(self,value,operation='', log=True):
"""Set the centre of the array (X,Y)
"""
#make into an array
if type(value) in [int, float, list, tuple]:
value = numpy.array(value, dtype=float)
#check shape
if value.shape != (2,):
raise ValueError("New value for setFieldPos should be [x,y]")
#set value and log
setWithOperation(self, 'fieldPos', value, operation)
if log and self.autoLog:
self.win.logOnFlip("Set %s fieldPos=%s" %(self.name, type(value)),
level=logging.EXP,obj=self)
示例11: setVertices
def setVertices(self, value=None, operation="", log=True):
"""Set the xy values of the vertices (relative to the centre of the field).
Values should be:
- an array/list of Nx2 coordinates.
"""
# make into an array
if type(value) in [int, float, list, tuple]:
value = numpy.array(value, dtype=float)
# check shape
if not (value.shape == (2,) or (len(value.shape) == 2 and value.shape[1] == 2)):
raise ValueError("New value for setXYs should be 2x1 or Nx2")
# set value and log
setWithOperation(self, "vertices", value, operation)
logAttrib(self, log, "vertices", value)
self._needVertexUpdate = True
示例12: _set
def _set(self, attrib, val, op='', log=True):
"""
Use this method when you want to be able to suppress logging (e.g., in
tests). Typically better to use methods specific to the parameter, e.g. ::
stim.pos = [3,2.5]
stim.ori = 45
stim.phase += 0.5
NB this method does not flag the need for updates any more - that is
done by specific methods as described above.
"""
if op==None: op=''
#format the input value as float vectors
if type(val) in [tuple, list, numpy.ndarray]:
val = val2array(val)
# Handle operations
setWithOperation(self, attrib, val, op)
示例13: setXYs
def setXYs(self, value=None, operation="", log=True):
"""Set the xy values of the element centres (relative to the centre of the field).
Values should be:
- None
- an array/list of Nx2 coordinates.
If value is None then the xy positions will be generated automatically, based
on the fieldSize and fieldPos. In this case opacity will also be overridden
by this function (it is used to make elements outside the field invisible.
"""
if value == None:
if self.fieldShape in ["sqr", "square"]:
self.xys = (
numpy.random.rand(self.nElements, 2) * self.fieldSize - self.fieldSize / 2
) # initialise a random array of X,Y
# gone outside the square
self.xys[:, 0] = ((self.xys[:, 0] + self.fieldSize[0] / 2) % self.fieldSize[0]) - self.fieldSize[0] / 2
self.xys[:, 1] = ((self.xys[:, 1] + self.fieldSize[1] / 2) % self.fieldSize[1]) - self.fieldSize[1] / 2
elif self.fieldShape is "circle":
# take twice as many elements as we need (and cull the ones outside the circle)
xys = (
numpy.random.rand(self.nElements * 2, 2) * self.fieldSize - self.fieldSize / 2
) # initialise a random array of X,Y
# gone outside the square
xys[:, 0] = ((xys[:, 0] + self.fieldSize[0] / 2) % self.fieldSize[0]) - self.fieldSize[0] / 2
xys[:, 1] = ((xys[:, 1] + self.fieldSize[1] / 2) % self.fieldSize[1]) - self.fieldSize[1] / 2
# use a circular envelope and flips dot to opposite edge if they fall
# beyond radius.
# NB always circular - uses fieldSize in X only
normxy = xys / (self.fieldSize / 2.0)
dotDist = numpy.sqrt((normxy[:, 0] ** 2.0 + normxy[:, 1] ** 2.0))
self.xys = xys[dotDist < 1.0, :][0 : self.nElements]
else:
# make into an array
if type(value) in [int, float, list, tuple]:
value = numpy.array(value, dtype=float)
# check shape
if not (value.shape in [(), (2,), (self.nElements, 2)]):
raise ValueError("New value for setXYs should be either None or Nx2")
# set value
setWithOperation(self, "xys", value, operation)
self._needVertexUpdate = True
logAttrib(self, log, "XYs", type(value))
示例14: setOpacities
def setOpacities(self,value,operation='', log=True):
"""Set the opacity for each element.
Should either be a single value or an Nx1 array/list
"""
#make into an array
if type(value) in [int, float, list, tuple]:
value = numpy.array(value, dtype=float)
#check shape
if value.shape in [(),(1,)]:
value = value.repeat(self.nElements)
elif value.shape in [(self.nElements,), (self.nElements,1)]:
pass #is already Nx1
else:
raise ValueError("New value for setOpacities should be either Nx1 or a single value")
#set value and log
setWithOperation(self, 'opacities', value, operation)
logAttrib(self, log, 'opacities', type(value))
示例15: _set
def _set(self, attrib, val, op='', log=True):
"""
Deprecated. Use methods specific to the parameter you want to set
e.g. ::
stim.pos = [3,2.5]
stim.ori = 45
stim.phase += 0.5
NB this method does not flag the need for updates any more - that is
done by specific methods as described above.
"""
if op==None: op=''
#format the input value as float vectors
if type(val) in (tuple, list):
val=numpy.array(val, float)
setWithOperation(self, attrib, val, op)
logAttrib(self, log, attrib)