def map_angles(angles, period=None): """ maps angles into interval [-pi,pi] """ from numpy.oldnumeric import fmod, greater, logical_not if period is None: from numpy.oldnumeric import pi as period mask = greater(angles, 0.) return mask * (fmod(angles+period, 2*period)-period) + \ logical_not(mask) * (fmod(angles-period, 2*period)+period)
def map_angles(angles, period=None): """ maps angles into interval [-pi,pi] """ from numpy.oldnumeric import fmod, greater, logical_not if period is None: from numpy.oldnumeric import pi as period mask = greater(angles, 0.) return mask * (fmod(angles + period, 2 * period) - period) + \ logical_not(mask) * (fmod(angles - period, 2 * period) + period)
def concentricrings(x, y, white_thickness, gaussian_width, spacing): """ Concetric rings with the solid ring-shaped region, then Gaussian fall-off at the edges. """ # To have zero value in middle point this pattern calculates zero-value rings instead of # the one-value ones. But to be consistent with the rest of functions the parameters # are connected to one-value rings - like half_thickness is now recalculated for zero-value ring: half_thickness = ((spacing-white_thickness)/2.0)*greater_equal(spacing-white_thickness,0.0) distance_from_origin = sqrt(x**2+y**2) distance_from_ring_middle = fmod(distance_from_origin,spacing) distance_from_ring_middle = minimum(distance_from_ring_middle,spacing - distance_from_ring_middle) distance_from_ring = distance_from_ring_middle - half_thickness ring = 0.0 + greater_equal(distance_from_ring,0.0) sigmasq = gaussian_width*gaussian_width with float_error_ignore(): falloff = exp(divide(-distance_from_ring*distance_from_ring, 2.0*sigmasq)) return maximum(falloff,ring)
def function(self,params): """Archemidean spiral function.""" aspect_ratio = params['aspect_ratio'] x = self.pattern_x/aspect_ratio y = self.pattern_y thickness = params['thickness'] gaussian_width = params['smoothing'] size = params['size'] half_thickness = thickness/2.0 spacing = size*2*pi distance_from_origin = sqrt(x**2+y**2) distance_from_spiral_middle = fmod(spacing + distance_from_origin - size*arctan2(y,x),spacing) distance_from_spiral_middle = minimum(distance_from_spiral_middle,spacing - distance_from_spiral_middle) distance_from_spiral = distance_from_spiral_middle - half_thickness spiral = 1.0 - greater_equal(distance_from_spiral,0.0) sigmasq = gaussian_width*gaussian_width with float_error_ignore(): falloff = exp(divide(-distance_from_spiral*distance_from_spiral, 2.0*sigmasq)) return maximum(falloff, spiral)
def function(self,params): """Concentric rings.""" aspect_ratio = params['aspect_ratio'] x = self.pattern_x/aspect_ratio y = self.pattern_y thickness = params['thickness'] gaussian_width = params['smoothing'] size = params['size'] half_thickness = thickness / 2.0 distance_from_origin = sqrt(x**2+y**2) distance_from_ring_middle = fmod(distance_from_origin,size) distance_from_ring_middle = minimum(distance_from_ring_middle,size - distance_from_ring_middle) distance_from_ring = distance_from_ring_middle - half_thickness ring = 1.0 - greater_equal(distance_from_ring,0.0) sigmasq = gaussian_width*gaussian_width with float_error_ignore(): falloff = exp(divide(-distance_from_ring*distance_from_ring, 2.0*sigmasq)) return maximum(falloff, ring)
def function(self,params): """Hyperbolic function.""" aspect_ratio = params['aspect_ratio'] x = self.pattern_x/aspect_ratio y = self.pattern_y thickness = params['thickness'] gaussian_width = params['smoothing'] size = params['size'] half_thickness = thickness / 2.0 distance_from_vertex_middle = fmod(sqrt(absolute(x**2 - y**2)),size) distance_from_vertex_middle = minimum(distance_from_vertex_middle,size - distance_from_vertex_middle) distance_from_vertex = distance_from_vertex_middle - half_thickness hyperbola = 1.0 - greater_equal(distance_from_vertex,0.0) sigmasq = gaussian_width*gaussian_width with float_error_ignore(): falloff = exp(divide(-distance_from_vertex*distance_from_vertex, 2.0*sigmasq)) return maximum(falloff, hyperbola)
def spiral(x, y, thickness, gaussian_width, density): """ Archemidean spiral with Gaussian fall-off outside the spiral curve. """ half_thickness = thickness/2.0 spacing = density*2*pi distance_from_origin = sqrt(x**2+y**2) distance_from_spiral_middle = fmod(spacing + distance_from_origin - density*arctan2(y,x),spacing) distance_from_spiral_middle = minimum(distance_from_spiral_middle,spacing - distance_from_spiral_middle) distance_from_spiral = distance_from_spiral_middle - half_thickness spiral = 1.0 - greater_equal(distance_from_spiral,0.0) sigmasq = gaussian_width*gaussian_width with float_error_ignore(): falloff = exp(divide(-distance_from_spiral*distance_from_spiral, 2.0*sigmasq)) return maximum(falloff,spiral)
def draw(self): # XXX This method is not speed-optimized. I just wrote it to # get the job done. (Nonetheless, it seems faster than the C # version commented out above.) p = self.parameters # shorthand if p.center is not None: if not hasattr(VisionEgg.config, "_GAVE_CENTER_DEPRECATION"): logger = logging.getLogger('VisionEgg.Dots') logger.warning("Specifying DotArea2D by deprecated " "'center' parameter deprecated. Use " "'position' parameter instead. (Allows " "use of 'anchor' parameter to set to " "other values.)") VisionEgg.config._GAVE_CENTER_DEPRECATION = 1 p.anchor = 'center' p.position = p.center[0], p.center[ 1] # copy values (don't copy ref to tuple) if p.on: # calculate center center = VisionEgg._get_center(p.position, p.anchor, p.size) if p.anti_aliasing: if len(p.color) == 4 and not self._gave_alpha_warning: if p.color[3] != 1.0: logger = logging.getLogger('VisionEgg.Dots') logger.warning("The parameter anti_aliasing is " "set to true in the DotArea2D " "stimulus class, but the color " "parameter specifies an alpha " "value other than 1.0. To " "acheive the best anti-aliasing, " "ensure that the alpha value for " "the color parameter is 1.0.") self._gave_alpha_warning = 1 gl.glEnable(gl.GL_POINT_SMOOTH) # allow max_alpha value to control blending gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) else: gl.glDisable(gl.GL_BLEND) now_sec = VisionEgg.time_func() if self.start_times_sec is not None: # compute extinct dots and generate new positions replace_indices = Numeric.nonzero( Numeric.greater(now_sec - self.start_times_sec, p.dot_lifespan_sec)) Numeric.put(self.start_times_sec, replace_indices, now_sec) new_x_positions = RandomArray.uniform(0.0, 1.0, (len(replace_indices), )) Numeric.put(self.x_positions, replace_indices, new_x_positions) new_y_positions = RandomArray.uniform(0.0, 1.0, (len(replace_indices), )) Numeric.put(self.y_positions, replace_indices, new_y_positions) new_random_directions_radians = RandomArray.uniform( 0.0, 2 * math.pi, (len(replace_indices), )) Numeric.put(self.random_directions_radians, replace_indices, new_random_directions_radians) else: # initialize dot extinction values to random (uniform) distribution self.start_times_sec = RandomArray.uniform( now_sec - p.dot_lifespan_sec, now_sec, (self.constant_parameters.num_dots, )) signal_num_dots = int( round(p.signal_fraction * self.constant_parameters.num_dots)) time_delta_sec = now_sec - self.last_time_sec self.last_time_sec = now_sec # reset for next loop x_increment_normalized = math.cos( p.signal_direction_deg / 180.0 * math.pi ) * p.velocity_pixels_per_sec / p.size[0] * time_delta_sec y_increment_normalized = -math.sin( p.signal_direction_deg / 180.0 * math.pi ) * p.velocity_pixels_per_sec / p.size[1] * time_delta_sec self.x_positions[:signal_num_dots] += x_increment_normalized self.y_positions[:signal_num_dots] += y_increment_normalized num_random_dots = self.constant_parameters.num_dots - signal_num_dots random_x_increment_normalized = Numeric.cos( self.random_directions_radians[signal_num_dots:] ) * p.velocity_pixels_per_sec / p.size[0] * time_delta_sec random_y_increment_normalized = -Numeric.sin( self.random_directions_radians[signal_num_dots:] ) * p.velocity_pixels_per_sec / p.size[1] * time_delta_sec self.x_positions[signal_num_dots:] += random_x_increment_normalized self.y_positions[signal_num_dots:] += random_y_increment_normalized self.x_positions = Numeric.fmod(self.x_positions, 1.0) # wrap self.y_positions = Numeric.fmod(self.y_positions, 1.0) self.x_positions = Numeric.fmod(self.x_positions + 1, 1.0) # wrap again for values < 1 self.y_positions = Numeric.fmod(self.y_positions + 1, 1.0) xs = (self.x_positions - 0.5) * p.size[0] + center[0] ys = (self.y_positions - 0.5) * p.size[1] + center[1] if len(p.color) == 3: gl.glColor3f(*p.color) elif len(p.color) == 4: gl.glColor4f(*p.color) gl.glPointSize(p.dot_size) # Clear the modeview matrix gl.glMatrixMode(gl.GL_MODELVIEW) gl.glPushMatrix() gl.glDisable(gl.GL_TEXTURE_2D) if p.depth is None: depth = 0.0 else: gl.glEnable(gl.GL_DEPTH_TEST) depth = p.depth zs = (depth, ) * len(xs) # make N tuple with repeat value of depth draw_dots(xs, ys, zs) if p.anti_aliasing: gl.glDisable(gl.GL_POINT_SMOOTH) # turn off gl.glPopMatrix()
def draw(self): # XXX This method is not speed-optimized. I just wrote it to # get the job done. (Nonetheless, it seems faster than the C # version commented out above.) p = self.parameters # shorthand if p.center is not None: if not hasattr(VisionEgg.config,"_GAVE_CENTER_DEPRECATION"): logger = logging.getLogger('VisionEgg.Dots') logger.warning("Specifying DotArea2D by deprecated " "'center' parameter deprecated. Use " "'position' parameter instead. (Allows " "use of 'anchor' parameter to set to " "other values.)") VisionEgg.config._GAVE_CENTER_DEPRECATION = 1 p.anchor = 'center' p.position = p.center[0], p.center[1] # copy values (don't copy ref to tuple) if p.on: # calculate center center = VisionEgg._get_center(p.position,p.anchor,p.size) if p.anti_aliasing: if len(p.color) == 4 and not self._gave_alpha_warning: if p.color[3] != 1.0: logger = logging.getLogger('VisionEgg.Dots') logger.warning("The parameter anti_aliasing is " "set to true in the DotArea2D " "stimulus class, but the color " "parameter specifies an alpha " "value other than 1.0. To " "acheive the best anti-aliasing, " "ensure that the alpha value for " "the color parameter is 1.0.") self._gave_alpha_warning = 1 gl.glEnable( gl.GL_POINT_SMOOTH ) # allow max_alpha value to control blending gl.glEnable( gl.GL_BLEND ) gl.glBlendFunc( gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA ) else: gl.glDisable( gl.GL_BLEND ) now_sec = VisionEgg.time_func() if self.start_times_sec is not None: # compute extinct dots and generate new positions replace_indices = Numeric.nonzero( Numeric.greater( now_sec - self.start_times_sec, p.dot_lifespan_sec) ) Numeric.put( self.start_times_sec, replace_indices, now_sec ) new_x_positions = RandomArray.uniform(0.0,1.0, (len(replace_indices),)) Numeric.put( self.x_positions, replace_indices, new_x_positions ) new_y_positions = RandomArray.uniform(0.0,1.0, (len(replace_indices),)) Numeric.put( self.y_positions, replace_indices, new_y_positions ) new_random_directions_radians = RandomArray.uniform(0.0,2*math.pi, (len(replace_indices),)) Numeric.put( self.random_directions_radians, replace_indices, new_random_directions_radians ) else: # initialize dot extinction values to random (uniform) distribution self.start_times_sec = RandomArray.uniform( now_sec - p.dot_lifespan_sec, now_sec, (self.constant_parameters.num_dots,)) signal_num_dots = int(round(p.signal_fraction * self.constant_parameters.num_dots)) time_delta_sec = now_sec - self.last_time_sec self.last_time_sec = now_sec # reset for next loop x_increment_normalized = math.cos(p.signal_direction_deg/180.0*math.pi) * p.velocity_pixels_per_sec / p.size[0] * time_delta_sec y_increment_normalized = -math.sin(p.signal_direction_deg/180.0*math.pi) * p.velocity_pixels_per_sec / p.size[1] * time_delta_sec self.x_positions[:signal_num_dots] += x_increment_normalized self.y_positions[:signal_num_dots] += y_increment_normalized num_random_dots = self.constant_parameters.num_dots - signal_num_dots random_x_increment_normalized = Numeric.cos(self.random_directions_radians[signal_num_dots:]) * p.velocity_pixels_per_sec / p.size[0] * time_delta_sec random_y_increment_normalized = -Numeric.sin(self.random_directions_radians[signal_num_dots:]) * p.velocity_pixels_per_sec / p.size[1] * time_delta_sec self.x_positions[signal_num_dots:] += random_x_increment_normalized self.y_positions[signal_num_dots:] += random_y_increment_normalized self.x_positions = Numeric.fmod( self.x_positions, 1.0 ) # wrap self.y_positions = Numeric.fmod( self.y_positions, 1.0 ) self.x_positions = Numeric.fmod( self.x_positions+1, 1.0 ) # wrap again for values < 1 self.y_positions = Numeric.fmod( self.y_positions+1, 1.0 ) xs = (self.x_positions - 0.5) * p.size[0] + center[0] ys = (self.y_positions - 0.5) * p.size[1] + center[1] if len(p.color)==3: gl.glColor3f(*p.color) elif len(p.color)==4: gl.glColor4f(*p.color) gl.glPointSize(p.dot_size) # Clear the modeview matrix gl.glMatrixMode(gl.GL_MODELVIEW) gl.glPushMatrix() gl.glDisable(gl.GL_TEXTURE_2D) if p.depth is None: depth = 0.0 else: gl.glEnable(gl.GL_DEPTH_TEST) depth = p.depth zs = (depth,)*len(xs) # make N tuple with repeat value of depth draw_dots(xs,ys,zs) if p.anti_aliasing: gl.glDisable( gl.GL_POINT_SMOOTH ) # turn off gl.glPopMatrix()