<commit_before>"""
Patterns based on patches of Sine Gratings as used in experiments.

$Id$
"""
__version__='$Revision$'

### JABALERT: These classes should not be necessary, if we can provide a way
### to control the parameters of subparts of Composite objects
### more easily (e.g. in the Test Pattern window, or when
### measuring tuning curves).

from math import pi, sin, cos, sqrt
import numpy
from numpy.oldnumeric import around,bitwise_and,sin,add,Float,bitwise_or
from numpy import alltrue

from .. import param
from ..param.parameterized import ParamOverrides

from topo.base.patterngenerator import PatternGenerator
# Imported here so that all PatternGenerators will be in the same package
from topo.base.patterngenerator import Constant
from topo.pattern.basic import SineGrating, Disk, Ring, Rectangle
from topo.misc.patternfn import gaussian,gabor,line,disk,ring
from topo.misc.numbergenerator import UniformRandom



class SineGratingDisk(PatternGenerator):
    """A sine grating masked by a circular disk so that only a round patch is visible."""
 
    aspect_ratio  = param.Number(default=1.0,bounds=(0.0,None),softbounds=(0.0,2.0),
        precedence=0.31,doc=
        "Ratio of width to height; size*aspect_ratio gives the width of the disk.")

    size  = param.Number(default=0.5,doc="Top to bottom height of the disk")
    
    smoothing = param.Number(default=0.0,bounds=(0.0,None),softbounds=(0.0,0.5),
                       precedence=0.61,doc="Width of the Gaussian fall-off")

    phase  = param.Number(default=1.0, doc="phase of the sine grating")

    frequency  = param.Number(default=2.4,doc="frequency of the sine grating")

       
    def __call__(self,**params_to_override):
        params = ParamOverrides(self,params_to_override)
      	bounds = params['bounds']
        xdensity=params['xdensity']
        ydensity=params['ydensity']
        x=params['x']
        y=params['y']
        scale=params['scale']
        offset=params['offset']
        orientation=params['orientation']
        size=params['size']
        phase=params['phase']
        frequency=params['frequency']
        aspect_ratio=params['aspect_ratio']
        smoothing=params['smoothing']
      
        input_1=SineGrating(phase=phase, frequency=frequency, orientation=orientation, scale=scale, offset=offset)
        input_2=Disk(aspect_ratio=aspect_ratio,smoothing=smoothing,x=x, y=y,size=size,scale=scale, offset=offset)
        
        patterns = [input_1(xdensity=xdensity,ydensity=ydensity,bounds=bounds),
                            input_2(xdensity=xdensity,ydensity=ydensity,bounds=bounds)]
                      
        image_array = numpy.minimum.reduce(patterns)
        return image_array


class SineGratingRectangle(PatternGenerator):
    """A sine grating masked by a rectangle so that only a rectangluar patch is visible"""
 
    aspect_ratio  = param.Number(default=1.0,bounds=(0.0,None),softbounds=(0.0,2.0),
        precedence=0.31,doc=
        "Ratio of width to height; size*aspect_ratio gives the width of the disk.")

    size  = param.Number(default=0.5,doc="Top to bottom height of the disk")
    
    phase  = param.Number(default=1.0, doc="phase of the sine grating")

    frequency  = param.Number(default=2.4,doc="frequency of the sine grating")

       
    def __call__(self,**params_to_override):
        params = ParamOverrides(self,params_to_override)
      	bounds = params['bounds']
        xdensity=params['xdensity']
        ydensity=params['ydensity']
        x=params['x']
        y=params['y']
        scale=params['scale']
        offset=params['offset']
        orientation=params['orientation']
        size=params['size']
        phase=params['phase']
        frequency=params['frequency']
        aspect_ratio=params['aspect_ratio']
              
        input_1=SineGrating(phase=phase, frequency=frequency, orientation=orientation, scale=scale, offset=offset)
        input_2=Rectangle(aspect_ratio=aspect_ratio,x=x, y=y,size=size,scale=scale, offset=offset)
        
        patterns = [input_1(xdensity=xdensity,ydensity=ydensity,bounds=bounds),<commit_msg>Cleaned up docstrings and comments.  Added commented-out example of using mask_shape to construct these patterns<commit_after>"""
Composite patterns such as patches of sine gratings as used in
psychophysical or physiological experiments.

$Id$
"""
__version__='$Revision$'

### JABALERT: These classes should not be necessary, if we can provide a way
### to control the parameters of subparts of Composite objects
### more easily (e.g. in the Test Pattern window, or when
### measuring tuning curves).

from math import pi, sin, cos, sqrt
import numpy
from numpy.oldnumeric import around,bitwise_and,sin,add,Float,bitwise_or
from numpy import alltrue

from .. import param
from ..param.parameterized import ParamOverrides

from topo.base.patterngenerator import PatternGenerator
# Imported here so that all PatternGenerators will be in the same package
from topo.base.patterngenerator import Constant
from topo.pattern.basic import SineGrating, Disk, Ring, Rectangle
from topo.misc.patternfn import gaussian,gabor,line,disk,ring
from topo.misc.numbergenerator import UniformRandom

# Simpler versions using the mask instead:
#class SineGratingDisk_m(SineGrating):
#    """2D sine grating pattern generator with a circular mask."""
#    mask_shape = param.Parameter(default=Disk(smoothing=0))
#
#class SineGratingRectangle_m(SineGrating):
#    """2D sine grating pattern generator with a rectangular mask."""
#    mask_shape = param.Parameter(default=Rectangle())
#
#class SineGratingRing_m(SineGrating):
#    """2D sine grating pattern generator with a ring-shaped mask."""
#    mask_shape = param.Parameter(default=Ring(smoothing=0))


class SineGratingDisk(PatternGenerator):
    """A sine grating masked by a circular disk so that only a round patch is visible."""
 
    aspect_ratio  = param.Number(default=1.0,bounds=(0.0,None),softbounds=(0.0,2.0),
        precedence=0.31,doc=
        "Ratio of width to height; size*aspect_ratio gives the width of the disk.")

    size  = param.Number(default=0.5,doc="Top to bottom height of the disk")
    
    smoothing = param.Number(default=0.0,bounds=(0.0,None),softbounds=(0.0,0.5),
                       precedence=0.61,doc="Width of the Gaussian fall-off")

    phase  = param.Number(default=1.0, doc="phase of the sine grating")

    frequency  = param.Number(default=2.4,doc="frequency of the sine grating")

       
    def __call__(self,**params_to_override):
        params = ParamOverrides(self,params_to_override)
      	bounds = params['bounds']
        xdensity=params['xdensity']
        ydensity=params['ydensity']
        x=params['x']
        y=params['y']
        scale=params['scale']
        offset=params['offset']
        orientation=params['orientation']
        size=params['size']
        phase=params['phase']
        frequency=params['frequency']
        aspect_ratio=params['aspect_ratio']
        smoothing=params['smoothing']
      
        input_1=SineGrating(phase=phase, frequency=frequency, orientation=orientation, scale=scale, offset=offset)
        input_2=Disk(aspect_ratio=aspect_ratio,smoothing=smoothing,x=x, y=y,size=size,scale=scale, offset=offset)
        
        patterns = [input_1(xdensity=xdensity,ydensity=ydensity,bounds=bounds),
                            input_2(xdensity=xdensity,ydensity=ydensity,bounds=bounds)]
                      
        image_array = numpy.minimum.reduce(patterns)
        return image_array


class SineGratingRectangle(PatternGenerator):
    """A sine grating masked by a rectangle so that only a rectangular patch is visible"""
 
    aspect_ratio  = param.Number(default=1.0,bounds=(0.0,None),softbounds=(0.0,2.0),
        precedence=0.31,doc="""Ratio of width to height
        size*aspect_ratio gives the width of the rectangle.""")

    size  = param.Number(default=0.5,doc="Top to bottom height of the rectangle")
    
    phase  = param.Number(default=1.0, doc="Phase of the sine grating")

    frequency  = param.Number(default=2.4,doc="Frequency of the sine grating")

       
    def __call__(self,**params_to_override):
        params = ParamOverrides(self,params_to_override)
      	bounds = params['bounds']
        xdensity=params['xdensity']
        ydensity=params['ydensity']
        x=params['x']
        y=params['y']
        scale=params['scale']
        offset=params['offset']
        orientation=params['orientation']
        size=params['size']
        phase=params['phase']
        frequency=params['frequency']
        aspect_ratio=params['aspect_ratio']
              
        input_1=SineGrating(phase=phase, frequency=frequency, orientation=orientation, scale=scale, offset=offset)
        input_2=Rectangle(aspect_ratio=aspect_ratio,x=x, y=y,size=size,scale=scale, offset=offset)
        
        patterns = [input_1(xdensity=xdensity,ydensity=ydensity,bounds=bounds),
{'fraction_non_alphanumeric': 0.11196781763325511, 'fraction_numerical': 0.01218013185830819, 'mean_word_length': 3.7480106100795756, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7560500', 'n_tokens_mistral': 2715, 'n_tokens_neox': 2602, 'n_words': 625}