本文整理汇总了Python中psychopy.tools.arraytools.val2array函数的典型用法代码示例。如果您正苦于以下问题:Python val2array函数的具体用法?Python val2array怎么用?Python val2array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了val2array函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: size
def size(self, value):
"""
:ref:`x,y-pair <attrib-xy>`, :ref:`scalar <attrib-scalar>` or None (resets to default). Supports :ref:`operations <attrib-operations>`.
Units are inherited from the stimulus.
Sizes can be negative and can extend beyond the window.
Example::
stim.size = 0.8 # Set size to (xsize, ysize) = (0.8, 0.8), quadratic.
print stim.size # Outputs array([0.8, 0.8])
stim.size += (0,5, -0.5) # make wider and flatter. Is now (1.3, 0.3)
Tip: if you can see the actual pixel range this corresponds to by
looking at stim._sizeRendered
"""
value = val2array(value) # Check correct user input
self._requestedSize = value #to track whether we're just using a default
# None --> set to default
if value == None:
"""Set the size to default (e.g. to the size of the loaded image etc)"""
#calculate new size
if self._origSize is None: #not an image from a file
value = numpy.array([0.5, 0.5]) #this was PsychoPy's original default
else:
#we have an image - calculate the size in `units` that matches original pixel size
if self.units == 'pix': value = numpy.array(self._origSize)
elif self.units == 'deg': value = pix2deg(numpy.array(self._origSize, float), self.win.monitor)
elif self.units == 'cm': value = pix2cm(numpy.array(self._origSize, float), self.win.monitor)
elif self.units == 'norm': value = 2 * numpy.array(self._origSize, float) / self.win.size
elif self.units == 'height': value = numpy.array(self._origSize, float) / self.win.size[1]
self.__dict__['size'] = value
self._calcSizeRendered()
if hasattr(self, '_calcCyclesPerStim'):
self._calcCyclesPerStim()
self._needUpdate = True
开发者ID:Gianluigi,项目名称:psychopy,代码行数:35,代码来源:basevisual.py
示例2: fieldPos
def fieldPos(self, value):
""":ref:`x,y-pair <attrib-xy>`.
Set the centre of the array of elements.
:ref:`Operations <attrib-operations>` are supported."""
self.__dict__['fieldPos'] = val2array(value, False, False)
self._needVertexUpdate = True
开发者ID:NSalem,项目名称:psychopy,代码行数:7,代码来源:elementarray.py
示例3: sf
def sf(self, value):
"""Spatial frequency of the grating texture
Should be a :ref:`x,y-pair <attrib-xy>` or
:ref:`scalar <attrib-scalar>` or None.
If `units` == 'deg' or 'cm' units are in
cycles per deg or cm as appropriate.
If `units` == 'norm' then sf units are in cycles per stimulus
(and so SF scales with stimulus size).
If texture is an image loaded from a file then sf=None
defaults to 1/stimSize to give one cycle of the image.
"""
# Recode phase to numpy array
if value is None:
# Set the sf to default (e.g. to the 1.0/size of the loaded image
if (self.units in ('pix', 'pixels') or
self._origSize is not None and
self.units in ('deg', 'cm')):
value = 1.0 / self.size # default to one cycle
else:
value = numpy.array([1.0, 1.0])
else:
value = val2array(value)
# Set value and update stuff
self.__dict__['sf'] = value
self._calcCyclesPerStim()
self._needUpdate = True
开发者ID:flipphillips,项目名称:psychopy,代码行数:29,代码来源:grating.py
示例4: sf
def sf(self, value):
"""
:ref:`x,y-pair <attrib-xy>` or :ref:`scalar <attrib-scalar>`
Where `units` == 'deg' or 'cm' units are in cycles per deg/cm.
If `units` == 'norm' then sf units are in cycles per stimulus (so scale with stimulus size).
If texture is an image loaded from a file then sf defaults to 1/stim size to give one cycle of the image.
Spatial frequency.
"""
# Recode phase to numpy array
if value == None:
"""Set the sf to default (e.g. to the 1.0/size of the loaded image etc)"""
if self.units in ['pix', 'pixels'] \
or self._origSize is not None and self.units in ['deg', 'cm']:
value = 1.0 / self.size #default to one cycle
else:
value = numpy.array([1.0, 1.0])
else:
value = val2array(value)
# Set value and update stuff
self.__dict__['sf'] = value
self._calcCyclesPerStim()
self._needUpdate = True
开发者ID:GentBinaku,项目名称:psychopy,代码行数:25,代码来源:grating.py
示例5: envsf
def envsf(self, value):
"""Spatial frequency of the envelope texture
Should be a :ref:`x,y-pair <attrib-xy>` or
:ref:`scalar <attrib-scalar>` or None.
If `units` == 'deg' or 'cm' units are in cycles per deg or cm
as appropriate.
If `units` == 'norm' then sf units are in cycles per stimulus
(and so envsf scales with stimulus size).
If texture is an image loaded from a file then envsf=None defaults
to 1/stimSize to give one cycle of the image.
Note sf is inhertited from GratingStim and controls the spatial frequency of the carrier
"""
# Recode phase to numpy array
if value is None:
# set the sf to default e.g. 1./size of the loaded image etc
if (self.units in ['pix', 'pixels'] or
self._origSize is not None and
self.units in ['deg', 'cm']):
value = 1.0/self.size # default to one cycle
else:
value = numpy.array([1.0, 1.0])
else:
value = val2array(value)
# Set value and update stuff
self.__dict__['envsf'] = value
self._calcEnvCyclesPerStim()
self._needUpdate = True
开发者ID:bergwiesel,项目名称:psychopy,代码行数:31,代码来源:secondorder.py
示例6: pos
def pos(self, value):
""":ref:`x,y-pair <attrib-xy>` specifying the he centre of the image
relative to the window center. Stimuli can be positioned off-screen,
beyond the window!
:ref:`operations <attrib-operations>` are supported."""
self.__dict__['pos'] = val2array(value, withNone=False)
self._calcPosRendered()
开发者ID:NSalem,项目名称:psychopy,代码行数:8,代码来源:simpleimage.py
示例7: fieldSize
def fieldSize(self, value):
"""Scalar or :ref:`x,y-pair <attrib-xy>`.
The size of the array of elements. This will be overridden by
setting explicit xy positions for the elements.
:ref:`Operations <attrib-operations>` are supported."""
self.__dict__['fieldSize'] = val2array(value, False)
self.setXYs(log=False) # to reflect new settings, overriding individual xys
开发者ID:NSalem,项目名称:psychopy,代码行数:8,代码来源:elementarray.py
示例8: phase
def phase(self, value):
"""Phase of the stimulus in each dimension of the texture.
Should be an :ref:`x,y-pair <attrib-xy>` or :ref:`scalar <attrib-scalar>`
**NB** phase has modulus 1 (rather than 360 or 2*pi)
This is a little unconventional but has the nice effect
that setting phase=t*n drifts a stimulus at n Hz
"""
# Recode phase to numpy array
value = val2array(value)
self.__dict__['phase'] = value
self._needUpdate = True
开发者ID:Dagiba,项目名称:psychopy,代码行数:13,代码来源:grating.py
示例9: vertices
def vertices(self, newVerts):
"""A list of lists or a numpy array (Nx2) specifying xy positions of
each vertex, relative to the center of the field.
Assigning to vertices can be slow if there are many vertices.
:ref:`Operations <attrib-operations>` supported with `.setVertices()`.
"""
# Check shape
self.__dict__['vertices'] = val2array(newVerts, withNone=True,
withScalar=True, length=2)
self._needVertexUpdate = True
self._tesselate(self.vertices)
开发者ID:flipphillips,项目名称:psychopy,代码行数:13,代码来源:shape.py
示例10: envphase
def envphase(self, value):
"""Phase of the modulation in each dimension of the envelope texture.
Should be an :ref:`x,y-pair <attrib-xy>` or
:ref:`scalar <attrib-scalar>`
**NB** phase has modulus 1 (rather than 360 or 2*pi)
This is a little unconventional but has the nice effect
that setting phase=t*n drifts a stimulus at n Hz
Note phase in inherited from GratingStim and controls the phase of the carrier
"""
# Recode phase to numpy array
value = val2array(value)
self.__dict__['envphase'] = value
self._needUpdate = True
开发者ID:bergwiesel,项目名称:psychopy,代码行数:15,代码来源:secondorder.py
示例11: size
def size(self, value):
"""The size (w,h) of the stimulus in the stimulus :ref:`units <units>`
Value should be :ref:`x,y-pair <attrib-xy>`, :ref:`scalar <attrib-scalar>` (applies to both dimensions)
or None (resets to default). :ref:`Operations <attrib-operations>` are supported.
Sizes can be negative (causing a mirror-image reversal) and can extend beyond the window.
Example::
stim.size = 0.8 # Set size to (xsize, ysize) = (0.8, 0.8), quadratic.
print stim.size # Outputs array([0.8, 0.8])
stim.size += (0.5, -0.5) # make wider and flatter. Is now (1.3, 0.3)
Tip: if you can see the actual pixel range this corresponds to by
looking at `stim._sizeRendered`
"""
value = val2array(value) # Check correct user input
self._requestedSize = value #to track whether we're just using a default
# None --> set to default
if value == None:
"""Set the size to default (e.g. to the size of the loaded image etc)"""
#calculate new size
if self._origSize is None: #not an image from a file
value = numpy.array([0.5, 0.5]) #this was PsychoPy's original default
else:
#we have an image - calculate the size in `units` that matches original pixel size
if self.units == 'pix':
value = numpy.array(self._origSize)
elif self.units in ['deg', 'degFlatPos', 'degFlat']:
#NB when no size has been set (assume to use orig size in pix) this should not
#be corrected for flat anyway, so degFlat==degFlatPos
value = pix2deg(numpy.array(self._origSize, float), self.win.monitor)
elif self.units == 'norm':
value = 2 * numpy.array(self._origSize, float) / self.win.size
elif self.units == 'height':
value = numpy.array(self._origSize, float) / self.win.size[1]
elif self.units == 'cm':
value = pix2cm(numpy.array(self._origSize, float), self.win.monitor)
else:
raise AttributeError, "Failed to create default size for ImageStim. Unsupported unit, %s" %(repr(self.units))
self.__dict__['size'] = value
self._needVertexUpdate=True
self._needUpdate = True
if hasattr(self, '_calcCyclesPerStim'):
self._calcCyclesPerStim()
开发者ID:larigaldie-n,项目名称:psychopy,代码行数:46,代码来源:basevisual.py
示例12: pos
def pos(self, value):
"""The position of the center of the stimulus in the stimulus :ref:`units <units>`
Value should be an :ref:`x,y-pair <attrib-xy>`. :ref:`Operations <attrib-operations>`
are also supported.
Example::
stim.pos = (0.5, 0) # Set slightly to the right of center
stim.pos += (0.5, -1) # Increment pos rightwards and upwards. Is now (1.0, -1.0)
stim.pos *= 0.2 # Move stim towards the center. Is now (0.2, -0.2)
Tip: if you can see the actual pixel range this corresponds to by
looking at `stim._posRendered`
"""
self.__dict__['pos'] = val2array(value, False, False)
self._calcPosRendered()
开发者ID:frankpapenmeier,项目名称:psychopy,代码行数:17,代码来源:basevisual.py
示例13: vertices
def vertices(self, newVerts):
"""A list of lists or a numpy array (Nx2) specifying xy positions of
each vertex, relative to the center of the field.
Assigning to vertices can be slow if there are many vertices.
:ref:`Operations <attrib-operations>` supported with `.setVertices()`.
"""
# check if this is a name of one of our known shapes
if isinstance(newVerts, basestring) and newVerts in knownShapes:
newVerts = knownShapes[newVerts]
# Check shape
self.__dict__['vertices'] = val2array(newVerts, withNone=True,
withScalar=True, length=2)
self._needVertexUpdate = True
self._tesselate(self.vertices)
开发者ID:ChenTzuYin,项目名称:psychopy,代码行数:17,代码来源:shape.py
示例14: pos
def pos(self, value):
"""
:ref:`x,y-pair <attrib-xy>`. :ref:`operations <attrib-operations>` supported.
Set the stimulus position in the `units` inherited from the stimulus.
Either list [x, y], tuple (x, y) or numpy.ndarray ([x, y]) with two elements.
Example::
stim.pos = (0.5, 0) # Slightly to the right
stim.pos += (0.5, -1) # Move right and up. Is now (1.0, -1.0)
stim.pos *= 0.2 # Move towards the center. Is now (0.2, -0.2)
Tip: if you can see the actual pixel range this corresponds to by
looking at stim._posRendered
"""
self.__dict__['pos'] = val2array(value, False, False)
self._calcPosRendered()
开发者ID:Gianluigi,项目名称:psychopy,代码行数:17,代码来源:basevisual.py
示例15: _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)
开发者ID:BrainTech,项目名称:psychopy,代码行数:18,代码来源:basevisual.py
示例16: _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, numpy.ndarray]:
val = val2array(val)
# Handle operations
setWithOperation(self, attrib, val, op)
logAttrib(self, log, attrib)
开发者ID:larigaldie-n,项目名称:psychopy,代码行数:21,代码来源:basevisual.py
示例17: _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, numpy.ndarray]:
val = val2array(val)
# Handle operations
setWithOperation(self, attrib, val, op)
if log and self.autoLog:
self.win.logOnFlip("Set %s %s=%s" %(self.name, attrib, getattr(self,attrib)),
level=logging.EXP,obj=self)
开发者ID:virtualtalks,项目名称:psychopy,代码行数:24,代码来源:basevisual.py
示例18: __init__
def __init__(self,
win,
tex="sin",
mask="none",
units="",
pos=(0.0, 0.0),
size=None,
sf=None,
ori=0.0,
phase=(0.0, 0.0),
texRes=128,
rgb=None,
dkl=None,
lms=None,
color=(1.0, 1.0, 1.0),
colorSpace='rgb',
contrast=1.0,
opacity=1.0,
depth=0,
rgbPedestal=(0.0, 0.0, 0.0),
interpolate=False,
blendmode='avg',
name=None,
autoLog=None,
autoDraw=False,
maskParams=None):
""" """ # Empty docstring. All doc is in attributes
# what local vars are defined (these are the init params) for use by
# __repr__
self._initParams = dir()
for unecess in ['self', 'rgb', 'dkl', 'lms']:
self._initParams.remove(unecess)
# initialise parent class
super(GratingStim, self).__init__(win, units=units, name=name,
autoLog=False)
# use shaders if available by default, this is a good thing
self.__dict__['useShaders'] = win._haveShaders
# UGLY HACK: Some parameters depend on each other for processing.
# They are set "superficially" here.
# TO DO: postpone calls to _createTexture, setColor and
# _calcCyclesPerStim whin initiating stimulus
self.__dict__['contrast'] = 1
self.__dict__['size'] = 1
self.__dict__['sf'] = 1
self.__dict__['tex'] = tex
self.__dict__['maskParams'] = maskParams
# initialise textures and masks for stimulus
self._texID = GL.GLuint()
GL.glGenTextures(1, ctypes.byref(self._texID))
self._maskID = GL.GLuint()
GL.glGenTextures(1, ctypes.byref(self._maskID))
self.__dict__['texRes'] = texRes # must be power of 2
self.interpolate = interpolate
# NB Pedestal isn't currently being used during rendering - this is a
# place-holder
self.rgbPedestal = val2array(rgbPedestal, False, length=3)
# No need to invoke decorator for color updating. It is done just
# below.
self.__dict__['colorSpace'] = colorSpace
if rgb != None:
logging.warning("Use of rgb arguments to stimuli are deprecated."
" Please use color and colorSpace args instead")
self.setColor(rgb, colorSpace='rgb', log=False)
elif dkl != None:
logging.warning("Use of dkl arguments to stimuli are deprecated."
" Please use color and colorSpace args instead")
self.setColor(dkl, colorSpace='dkl', log=False)
elif lms != None:
logging.warning("Use of lms arguments to stimuli are deprecated."
" Please use color and colorSpace args instead")
self.setColor(lms, colorSpace='lms', log=False)
else:
self.setColor(color, colorSpace=colorSpace, log=False)
# set other parameters
self.ori = float(ori)
self.phase = val2array(phase, False)
self._origSize = None # updated if an image texture is loaded
self._requestedSize = size
self.size = val2array(size)
self.sf = val2array(sf)
self.pos = val2array(pos, False, False)
self.depth = depth
self.tex = tex
self.mask = mask
self.contrast = float(contrast)
self.opacity = float(opacity)
self.autoLog = autoLog
self.autoDraw = autoDraw
self.blendmode=blendmode
# fix scaling to window coords
self._calcCyclesPerStim()
# generate a displaylist ID
self._listID = GL.glGenLists(1)
#.........这里部分代码省略.........
开发者ID:flipphillips,项目名称:psychopy,代码行数:101,代码来源:grating.py
示例19: __init__
def __init__(self, win,
filename="",
units='pix',
size=None,
pos=(0.0,0.0),
ori=0.0,
flipVert=False,
flipHoriz=False,
color=(1.0,1.0,1.0),
colorSpace='rgb',
opacity=1.0,
volume=1.0,
name='',
loop=False,
autoLog=True,
depth=0.0,
noAudio=False,
vframe_callback=None,
fps=None,
interpolate = True,
):
"""
:Parameters:
filename :
a string giving the relative or absolute path to the movie.
flipVert : True or *False*
If True then the movie will be top-bottom flipped
flipHoriz : True or *False*
If True then the movie will be right-left flipped
volume :
The nominal level is 100, and 0 is silence.
loop : bool, optional
Whether to start the movie over from the beginning if draw is
called and the movie is done.
"""
# what local vars are defined (these are the init params) for use
# by __repr__
self._initParams = dir()
self._initParams.remove('self')
super(MovieStim3, self).__init__(win, units=units, name=name,
autoLog=False)
retraceRate = win._monitorFrameRate
if retraceRate is None:
retraceRate = win.getActualFrameRate()
if retraceRate is None:
logging.warning("FrameRate could not be supplied by psychopy; defaulting to 60.0")
retraceRate = 60.0
self._retraceInterval = 1.0/retraceRate
self.filename = filename
self.loop = loop
self.flipVert = flipVert
self.flipHoriz = flipHoriz
self.pos = numpy.asarray(pos, float)
self.depth = depth
self.opacity = float(opacity)
self.interpolate = interpolate
self.noAudio = noAudio
self._audioStream = None
self.useTexSubImage2D = True
self._videoClock = Clock()
self.loadMovie(self.filename)
self.setVolume(volume)
self.nDroppedFrames = 0
#size
if size is None:
self.size = numpy.array([self._mov.w, self._mov.h],
float)
else:
self.size = val2array(size)
self.ori = ori
self._updateVertices()
#set autoLog (now that params have been initialised)
self.autoLog = autoLog
if autoLog:
logging.exp("Created %s = %s" %(self.name, str(self)))
开发者ID:papr,项目名称:psychopy,代码行数:80,代码来源:movie3.py
示例20: __init__
def __init__(self, win,
filename = "",
units = 'pix',
size = None,
pos =(0.0,0.0),
ori =0.0,
flipVert = False,
flipHoriz = False,
color=(1.0,1.0,1.0),
colorSpace='rgb',
opacity=1.0,
volume=1.0,
name=None,
loop=False,
autoLog=None,
depth=0.0,):
"""
:Parameters:
filename :
a string giving the relative or absolute path to the movie. Can be any movie that
AVbin can read (e.g. mpeg, DivX)
flipVert : True or *False*
If True then the movie will be top-bottom flipped
flipHoriz : True or *False*
If True then the movie will be right-left flipped
volume :
The nominal level is 1.0, and 0.0 is silence, see pyglet.media.Player
loop : bool, optional
Whether to start the movie over from the beginning if draw is
called and the movie is done.
"""
#what local vars are defined (these are the init params) for use by __repr__
self._initParams = dir()
self._initParams.remove('self')
super(MovieStim, self).__init__(win, units=units, name=name, autoLog=False)
self._verticesBase *= numpy.array([[-1,1]])#or the movie is flipped
if not havePygletMedia:
raise ImportError, """pyglet.media is needed for MovieStim and could not be imported.
This can occur for various reasons;
- psychopy.visual was imported too late (after a lib that uses scipy)
- no audio output is enabled (no audio card or no speakers attached)
- avbin is not installed
"""
self._movie=None # the actual pyglet media object
self._player=pyglet.media.ManagedSoundPlayer()
self._player.volume=volume
try:
self._player_default_on_eos = self._player.on_eos
except:
self._player_default_on_eos = self._player._on_eos #from pyglet 1.1.4?
self.filename=filename
self.duration=None
self.loop = loop
if loop and pyglet.version>='1.2':
logging.error("looping of movies is not currently supported for pyglet>=1.2 only for version 1.1.4")
self.loadMovie( self.filename )
self.format=self._movie.video_format
self.pos = numpy.asarray(pos, float)
self.depth=depth
self.flipVert = flipVert
self.flipHoriz = flipHoriz
self.opacity = float(opacity)
self.status=NOT_STARTED
#size
if size is None:
self.size= numpy.array([self.format.width,
self.format.height] , float)
else:
self.size = val2array(size)
self.ori = ori
self._updateVertices()
#check for pyglet
if win.winType!='pyglet':
logging.error('Movie stimuli can only be used with a pyglet window')
core.quit()
# set autoLog now that params have been initialised
self.__dict__['autoLog'] = autoLog or autoLog is None and self.win.autoLog
if self.autoLog:
logging.exp("Created %s = %s" %(self.name, str(self)))
开发者ID:Lx37,项目名称:psychopy,代码行数:88,代码来源:movie.py
注:本文中的psychopy.tools.arraytools.val2array函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论