本文整理汇总了Python中psychopy.tools.monitorunittools.deg2pix函数的典型用法代码示例。如果您正苦于以下问题:Python deg2pix函数的具体用法?Python deg2pix怎么用?Python deg2pix使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了deg2pix函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _calcFieldCoordsRendered
def _calcFieldCoordsRendered(self):
if self.units in ['norm', 'pix','height']:
self._fieldSizeRendered=self.fieldSize
self._fieldPosRendered=self.fieldPos
elif self.units in ['deg', 'degs']:
self._fieldSizeRendered=deg2pix(self.fieldSize, self.win.monitor)
self._fieldPosRendered=deg2pix(self.fieldPos, self.win.monitor)
elif self.units=='cm':
self._fieldSizeRendered=cm2pix(self.fieldSize, self.win.monitor)
self._fieldPosRendered=cm2pix(self.fieldPos, self.win.monitor)
示例2: _calcVerticesRendered
def _calcVerticesRendered(self):
self.needVertexUpdate=False
if self.units in ['norm', 'pix', 'height']:
self._verticesRendered=self.vertices
self._posRendered=self.pos
elif self.units in ['deg', 'degs']:
self._verticesRendered=deg2pix(self.vertices, self.win.monitor)
self._posRendered=deg2pix(self.pos, self.win.monitor)
elif self.units=='cm':
self._verticesRendered=cm2pix(self.vertices, self.win.monitor)
self._posRendered=cm2pix(self.pos, self.win.monitor)
self._verticesRendered = self._verticesRendered * self.size
示例3: setHeight
def setHeight(self,height, log=True):
"""Set the height of the letters (including the entire box that surrounds the letters
in the font). The width of the letters is then defined by the font.
"""
#height in pix (needs to be done after units)
if self.units=='cm':
if height==None: self.height = 1.0#default text height
else: self.height = height
self.heightPix = cm2pix(self.height, self.win.monitor)
elif self.units in ['deg', 'degs']:
if height==None: self.height = 1.0
else: self.height = height
self.heightPix = deg2pix(self.height, self.win.monitor)
elif self.units=='norm':
if height==None: self.height = 0.1
else: self.height = height
self.heightPix = self.height*self.win.size[1]/2
elif self.units=='height':
if height==None: self.height = 0.2
else: self.height = height
self.heightPix = self.height*self.win.size[1]
else: #treat units as pix
if height==None: self.height = 20
else: self.height = height
self.heightPix = self.height
#need to update the font to reflect the change
self.setFont(self.fontname, log=False)
if log and self.autoLog:
self.win.logOnFlip("Set %s height=%.2f" %(self.name, height),
level=logging.EXP,obj=self)
示例4: _calcSizeRendered
def _calcSizeRendered(self):
"""Calculate the size of the stimulus in coords of the :class:`~psychopy.visual.Window` (normalised or pixels)"""
if self.units in ['norm','pix', 'height']: self._sizeRendered=self.size
elif self.units in ['deg', 'degs']: self._sizeRendered=deg2pix(self.size, self.win.monitor)
elif self.units=='cm': self._sizeRendered=cm2pix(self.size, self.win.monitor)
else:
logging.ERROR("Stimulus units should be 'height', 'norm', 'deg', 'cm' or 'pix', not '%s'" %self.units)
示例5: contains
def contains(self, x, y=None):
"""Determines if a point x,y is inside the extent of the stimulus.
Can accept: a) two args, x and y; b) one arg, as a point (x,y) that is
list-like; or c) an object with a getPos() method that returns x,y, such
as a mouse. Returns True if the point is within the area defined by `vertices`.
This handles complex shapes, including concavities and self-crossings.
Note that, if your stimulus uses a mask (such as a Gaussian blob) then
this is not accounted for by the `contains` method; the extent of the
stmulus is determined purely by the size, pos and orientation settings
(and by the vertices for shape stimuli).
See coder demo, shapeContains.py
"""
if self.needVertexUpdate:
self._calcVerticesRendered()
if hasattr(x, 'getPos'):
x, y = x.getPos()
elif type(x) in [list, tuple, numpy.ndarray]:
x, y = x[0], x[1]
if self.units in ['deg','degs']:
x, y = deg2pix(numpy.array((x, y)), self.win.monitor)
elif self.units == 'cm':
x, y = cm2pix(numpy.array((x, y)), self.win.monitor)
if self.ori:
oriRadians = numpy.radians(self.ori)
sinOri = numpy.sin(oriRadians)
cosOri = numpy.cos(oriRadians)
x0, y0 = x-self._posRendered[0], y-self._posRendered[1]
x = x0 * cosOri - y0 * sinOri + self._posRendered[0]
y = x0 * sinOri + y0 * cosOri + self._posRendered[1]
return pointInPolygon(x, y, self)
示例6: _calcSizeRendered
def _calcSizeRendered(self):
"""DEPRECATED in 1.80.00. This funtionality is now handled by _updateVertices() and verticesPix"""
#raise DeprecationWarning, "_calcSizeRendered() was deprecated in 1.80.00. This funtionality is nowhanded by _updateVertices() and verticesPix"
if self.units in ['norm','pix', 'height']: self._sizeRendered=copy.copy(self.size)
elif self.units in ['deg', 'degs']: self._sizeRendered=deg2pix(self.size, self.win.monitor)
elif self.units=='cm': self._sizeRendered=cm2pix(self.size, self.win.monitor)
else:
logging.ERROR("Stimulus units should be 'height', 'norm', 'deg', 'cm' or 'pix', not '%s'" %self.units)
示例7: __init__
def __init__(self, win, actors, duration_frames, attn_video_size):
"""
Initialize class
:param win: window to use
:param actors: actors to show
:param duration_frames: how long to show (in frames)
"""
self.win = win
self.actors = actors
self.duration_frames = duration_frames
self.left_roi=visual.Rect(self.win, width=550, height=750, units='pix')
self.left_roi.pos=[deg2pix(-12,win.monitor),deg2pix(0,win.monitor)]
self.left_roi.lineColor = [1, -1, -1]
self.left_roi.lineWidth = 10
self.right_roi=visual.Rect(self.win, width=550, height=750, units='pix')
self.right_roi.pos=[deg2pix(12,win.monitor),deg2pix(0,win.monitor)]
self.right_roi.lineColor = [1, -1, -1]
self.right_roi.lineWidth = 10
self.attn_video=MovieStimulus(self.win, '', '', 'attn.mpg', attn_video_size)
示例8: _windowUnits2pix
def _windowUnits2pix(self, pos):
if self.win.units == "pix":
return pos
elif self.win.units == "norm":
return pos * self.win.size / 2.0
elif self.win.units == "cm":
return cm2pix(pos, self.win.monitor)
elif self.win.units == "deg":
return deg2pix(pos, self.win.monitor)
elif self.win.units == "height":
return pos * float(self.win.size[1])
示例9: _calcPosRendered
def _calcPosRendered(self):
"""Calculate the pos of the stimulus in pixels"""
if self.units == 'pix':
self._posRendered = self.pos
elif self.units == 'cm':
self._posRendered = cm2pix(self.pos, self.win.monitor)
elif self.units =='deg':
self._posRendered = deg2pix(self.pos, self.win.monitor)
elif self.units == 'norm':
self._posRendered = self.pos * self.win.size/2.0
elif self.units == 'height':
self._posRendered = self.pos * self.win.size[1]
示例10: _addRuntimeInfoToDisplayConfig
def _addRuntimeInfoToDisplayConfig(self):
if self not in Display._enabled_display_instances:
Display._enabled_display_instances.append(self)
display_config = self.getConfiguration()
runtime_info = display_config.get("runtime_info", None)
if runtime_info is None:
runtime_info = self._getRuntimeInfoByIndex(self.device_number)
display_config["runtime_info"] = runtime_info
self._createPsychopyCalibrationFile()
pixel_width = runtime_info["pixel_width"]
pixel_height = runtime_info["pixel_height"]
phys_width = display_config["physical_dimensions"]["width"]
phys_height = display_config["physical_dimensions"]["height"]
phys_unit_type = display_config["physical_dimensions"]["unit_type"]
# add pixels_per_degree to runtime info
ppd_x = deg2pix(
1.0, self._psychopy_monitor
) # math.tan(math.radians(0.5))*2.0*viewing_distance*pixel_width/phys_width
ppd_y = deg2pix(
1.0, self._psychopy_monitor
) # math.tan(math.radians(0.5))*2.0*viewing_distance*pixel_height/phys_height
runtime_info["pixels_per_degree"] = ppd_x, ppd_y
self._calculateCoordMappingFunctions(pixel_width, pixel_height, phys_unit_type, phys_width, phys_height)
left, top, right, bottom = runtime_info["bounds"]
coord_left, coord_top = self._pixel2DisplayCoord(left, top, self.device_number)
coord_right, coord_bottom = self._pixel2DisplayCoord(right, bottom, self.device_number)
runtime_info["coordinate_bounds"] = coord_left, coord_top, coord_right, coord_bottom
示例11: drawIA
def drawIA(self, x, y, size, index, color, name):
"""
Draws square interest area in EDF and a corresponding filled box on
eye-tracker display.
:param x: X coordinate in degrees visual angle for center of check area.
:type x: float or int
:param y: Y coordinate in degrees visual angle for center of check area.
:type y: float or int
:param size: length of one edge of square in degrees visual angle.
:type size: float or int
:param index: number to assign interest area in EDF
:type index: int
:param color: color of box drawn on eye-tracker display (0 - 15)
:type color: int
:param name: Name interest area in EDF
:type name: str
"""
# Convert units to eyelink space
elx = deg2pix(x, self.win.monitor) + (self.sres[0] / 2.0)
ely = -(deg2pix(y, self.win.monitor) - (self.sres[1] / 2.0))
elsz = deg2pix(size, self.win.monitor) / 2.0
# Make top left / bottom right coordinates for square
tplf = map(round, [elx - elsz, ely - elsz])
btrh = map(round, [elx + elsz, ely + elsz])
# Construct command strings
flist = [index, name, color] + tplf + btrh
iamsg = '!V IAREA RECTANGLE {0} {3} {4} {5} {6} {1}'.format(*flist)
bxmsg = 'draw_filled_box {3} {4} {5} {6} {2}'.format(*flist)
# Send commands
self.tracker.sendMessage(iamsg)
self.tracker.sendCommand(bxmsg)
示例12: __init__
def __init__(self, win, balloonID, color, maxPumps, gainpoints, initsize, gainsize, mon):
self.win = win
self.balloonID = balloonID
self.color = color
self.maxPumps = maxPumps
self.points = gainsize
self.initSize = initsize # units 'deg'
self.initSizeX = 3.5
self.initSizeY = 5
self.gainSize = gainsize # units 'deg'
self.mon = mon
self.pump = visual.ImageStim(win, image="assets/pump.png", pos=[0, 0], size=[10, 10])
self.explosionSound = sound.Sound(value='assets\explode.wav')
self.explosionSound.setVolume(1.0)
self.pumpSound = sound.Sound(value='assets\pump4.wav')
self.pumpSound.setVolume(1.0)
self.pump.pos = [0, pix2deg(-690 + (deg2pix(self.pump.size[1], mon) / 2), mon)]
self.stimuli = visual.ImageStim(win, image="assets/bal_blue.png", pos=[0,pix2deg(-400+(deg2pix(self.initSizeY,mon)/2),mon)],size=[self.initSizeX,self.initSizeY])
示例13: doCalibration
#.........这里部分代码省略.........
# Reset the radius of the large circle
self.calout.radius = caloutRadius
# After calibration, make sure the stimuli aren't drawn
self.calout.autoDraw = False
self.calout = None
# The following two will be set by the tobii SDK
self.computeCalibration_completed = False
self.computeCalibration_succeeded = False
# Do the computation
self.eyetracker.ComputeCalibration(self.on_calib_compute)
while not self.computeCalibration_completed:
psychopy.core.wait(0.1)
if psychopy.event.getKeys(keyList=['escape']):
raise KeyboardInterrupt("You interrupted the script.")
self.eyetracker.StopCalibration(None)
self.win.flip()
# Now we retrieve the calibration data
self.getcalibration_completed = False
self.calib = self.eyetracker.GetCalibration(self.on_calib_response)
while not self.getcalibration_completed:
psychopy.core.wait(0.1)
if psychopy.event.getKeys(keyList=['escape']):
raise KeyboardInterrupt("You interrupted the script.")
if not self.computeCalibration_succeeded:
# computeCalibration failed.
self.calmsg.text = ("Not enough data was collected "
"(Retry:[r] Abort:[ESC])")
elif self.calib is None:
# no calibration data
self.calmsg.text = ("No calibration data "
"(Retry:[r] Abort:[ESC])")
else:
# calibration seems to have worked out
points = {}
for data in self.calib.plot_data:
points[data.true_point] = {'left': data.left,
'right': data.right}
if len(points) == 0:
# no points in the calibration results
self.calmsg.text = ("No calibration data "
"(Retry:[r] Abort:[ESC])")
else:
# draw the calibration result
for p, d in points.iteritems():
psychopy.visual.Circle(self.win, radius=calinRadius,
fillColor=(1, 1, 1),
units='pix',
pos=(p.x - 0.5, 0.5 - p.y)).draw()
if d['left'].status == 1:
psychopy.visual.Line(self.win, units='pix',
lineColor='yellow',
start=(self.acsd2pix((p.x, p.y))),
end=(self.acsd2pix((d['left'].
map_point.x,
d['left'].
map_point.y)))
).draw()
if d['right'].status == 1:
psychopy.visual.Line(self.win, units='pix',
lineColor='blue',
start=(self.acsd2pix((p.x, p.y))),
end=(self.acsd2pix((d['right'].
map_point.x,
d['right'].
map_point.y)))
).draw()
for p in self.points:
psychopy.visual.Circle(self.win, radius=calinRadius,
fillColor=1,
units='pix',
pos=self.acsd2pix(p),
).draw()
psychopy.visual.Circle(self.win, units='pix',
lineColor=-0.5,
radius=deg2pix(0.9,
self.win.monitor),
pos=self.acsd2pix(p),
).draw()
self.calmsg.text = ("Accept calibration results\n"
"(Accept:[a] Retry:[r] Abort:[ESC])")
# Update the screen, then wait for response
self.calmsg.draw()
self.win.flip()
self.response = psychopy.event.waitKeys(keyList=['a', 'r', 'escape'])
if 'a' in self.response:
retval = 'accept'
elif 'r' in self.response:
retval = 'retry'
elif 'escape' in self.response:
retval = 'abort'
return retval
示例14: _calcPosRendered
def _calcPosRendered(self):
"""Calculate the pos of the stimulus in coords of the :class:`~psychopy.visual.Window` (normalised or pixels)"""
if self.units in ['pix', 'pixels', 'height', 'norm']: self._posRendered=self.pos
elif self.units in ['deg', 'degs']: self._posRendered=deg2pix(self.pos, self.win.monitor)
elif self.units=='cm': self._posRendered=cm2pix(self.pos, self.win.monitor)
示例15: _calcPosRendered
def _calcPosRendered(self):
"""DEPRECATED in 1.80.00. This funtionality is now handled by _updateVertices() and verticesPix"""
#raise DeprecationWarning, "_calcSizeRendered() was deprecated in 1.80.00. This funtionality is now handled by _updateVertices() and verticesPix"
if self.units in ['norm','pix', 'height']: self._posRendered= copy.copy(self.pos)
elif self.units in ['deg', 'degs']: self._posRendered=deg2pix(self.pos, self.win.monitor)
elif self.units=='cm': self._posRendered=cm2pix(self.pos, self.win.monitor)