Changeset 411 for trunk

Show
Ignore:
Timestamp:
07/20/09 16:40:25 (3 years ago)
Author:
pierre
Message:

Change in the DistantDependentPairs? to ad a set_bounds function to fix d_min and d_max

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/signals/pairs.py

    r399 r411  
    66# of size NxN. Should then include a scaling parameter to allow 
    77# distances between distincts populations ? 
    8 def distance(pos_1, pos_2, N): 
    9     # Since we deal with a toroidal space, we have to take the min distance 
     8def distance(pos_1, pos_2, N=None): 
     9    # If N is not None, it means that we are dealing with a toroidal space,  
     10    # and we have to take the min distance 
    1011    # on the torus. 
    11     dx = numpy.minimum(abs(pos_1[0]-pos_2[0]), N-(abs(pos_1[0]-pos_2[0]))) 
    12     dy = numpy.minimum(abs(pos_1[1]-pos_2[1]), N-(abs(pos_1[1]-pos_2[1]))) 
     12    if N is None: 
     13        dx = pos_1[0]-pos_2[0] 
     14        dy = pos_1[1]-pos_2[1] 
     15    else: 
     16        dx = numpy.minimum(abs(pos_1[0]-pos_2[0]), N-(abs(pos_1[0]-pos_2[0]))) 
     17        dy = numpy.minimum(abs(pos_1[1]-pos_2[1]), N-(abs(pos_1[1]-pos_2[1]))) 
    1318    return numpy.sqrt(dx*dx + dy*dy) 
    1419 
     
    166171        length    - the lenght (in mm) covered by the extend of spk1 and spk2. Currently, spk1 
    167172                    and spk2 should cover the same surface. Default is spk1.length 
    168          
     173        d_min     - the minimal distance between cells 
     174        d_max     - the maximal distance between cells 
     175             
    169176    Examples: 
    170177        >> p = DistantDependentPairs(spk1, spk1, True, False) 
     
    178185    See also RandomPairs, CustomPairs, AutoPairs 
    179186    """ 
    180     def __init__(self, spk1, spk2, no_silent=False, no_auto=True, lenght=1.): 
     187    def __init__(self, spk1, spk2, no_silent=False, no_auto=True, lenght=1., d_min=0, dmax=1e6): 
    181188        PairsGenerator.__init__(self, spk1, spk2, no_silent) 
    182          
    183189        self.lenght  = lenght 
    184190        self.no_auto = no_auto 
    185      
    186     def get_pairs(self, nb_pairs, d_min, d_max): 
     191        self.d_min   = d_min 
     192        self.d_max   = d_max 
     193     
     194    def set_bounds(self, d_min, d_max): 
     195        self.d_min = d_min 
     196        self.d_max = d_max 
     197     
     198    def get_pairs(self, nb_pairs): 
    187199        """ 
    188200        Function to obtain a certain number of cells from the generator 
     
    190202        Inputs: 
    191203            nb_pairs - int to specify the number of pairs desired 
    192             d_min    - the minimal distance between cells 
    193             d_max    - the maximal distance between cells 
    194204             
    195205        The length parameter of the DistantDependentPairs should be defined correctly. It is the extent of the grid. 
     
    211221            pos_cell2 = numpy.array(self.spk2.id2position(cell2))*self.lenght/self.spk2.dimensions[0] 
    212222            dist      = distance(pos_cell1, pos_cell2, self.lenght) 
    213             idx       = numpy.where((dist >= d_min) & (dist < d_max))[0] 
     223            idx       = numpy.where((dist >= self.d_min) & (dist < self.d_max))[0] 
    214224            N         = len(idx) 
    215225            if N > 0: