コード例 #1
0
	def env_to_mask(self, env, size, stdev):

		"""
		desc:
			Converts an envelope name to a PsychoPy mask. Also returns the
			appropriate patch size and the smallest power-of-two size

			__Note:__

			Specific to the PsychoPy backend, primarily intended for internal
			use. Using this function directly will break your experiment when
			switching backends.

		arguments:
			env:	An envelope name.
			size:	A size value.

		returns:
			A (psychopy_mask, mask_size, power_of_two_size) tuple.
		"""

		env = canvas._match_env(env)

		# Get the smallest power-of-two size
		i = 2
		while size / (i) > 0:
			i = 2*i
		s = i

		# Create a PsychoPy mask
		if env == u"c":
			_env = u"circle"
			_size = size
		elif env == u"g":
			_env = u"gauss"
			_size = 6*stdev
		elif env == u"r":
			_env = u"None"
			_size = size
		elif env == u"l":
			_env = np.zeros([s,s])
			for x in range(s):
				for y in range(s):
					r = np.sqrt((x-s/2)**2+(y-s/2)**2)
					_env[x,y] = (max(0, (0.5*s-r) / (0.5*s))-0.5)*2
			_size = size
		return	(_env, _size, s)
コード例 #2
0
ファイル: psycho.py プロジェクト: JdenHartog/OpenSesame
	def env_to_mask(self, env, size, stdev):

		"""
		desc:
			Converts an envelope name to a PsychoPy mask. Also returns the
			appropriate patch size and the smallest power-of-two size

			__Note:__

			Specific to the PsychoPy backend, primarily intended for internal
			use. Using this function directly will break your experiment when
			switching backends.

		arguments:
			env:	An envelope name.
			size:	A size value.

		returns:
			A (psychopy_mask, mask_size, power_of_two_size) tuple.
		"""

		env = canvas._match_env(env)

		# Get the smallest power-of-two size
		i = 2
		while size / (i) > 0:
			i = 2*i
		s = i

		# Create a PsychoPy mask
		if env == u"c":
			_env = u"circle"
			_size = size
		elif env == u"g":
			_env = u"gauss"
			_size = 6*stdev
		elif env == u"r":
			_env = u"None"
			_size = size
		elif env == u"l":
			_env = np.zeros([s,s])
			for x in range(s):
				for y in range(s):
					r = np.sqrt((x-s/2)**2+(y-s/2)**2)
					_env[x,y] = (max(0, (0.5*s-r) / (0.5*s))-0.5)*2
			_size = size
		return	(_env, _size, s)
コード例 #3
0
	def _mask(self, env, size, stdev):

		"""
		visible: False

		desc:
			Generates a PsychoPy mask for Gabor and NoisePatch stimuli.

		arguments:
			env:
				desc:	The envelope.
				type:	str
			size:
				desc:	The stimulus size.
				type:	int
			stdev:
				desc:	The standard deviation of the mask if the envelope is
						gaussian.
				type:	int

		returns:
			desc:	A PsychoPy mask, which is a numpy array.
			type:	ndarray
		"""

		# Get the smallest power-of-two that is larger than or equal to the
		# given size
		size = int(np.ceil(np.sqrt(size))**2)
		# Create a PsychoPy mask
		env = canvas._match_env(env)
		if env == u'c':
			return u'circle', size
		if env == u'g':
			return u'gauss', 6 * stdev
		if env == u'r':
			return u'None', size
		if env == u'l':
			_env = np.zeros([size, size])
			for x in range(size):
				for y in range(size):
					r = np.sqrt((x-size/2)**2+(y-size/2)**2)
					_env[x, y] = (max(0, (0.5*size-r) / (0.5*size))-0.5)*2
			return _env, size
		raise ValueError('Invalid mask')