- Timestamp:
- 07/20/09 16:40:25 (3 years ago)
- Files:
-
- 1 modified
-
trunk/src/signals/pairs.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/signals/pairs.py
r399 r411 6 6 # of size NxN. Should then include a scaling parameter to allow 7 7 # 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 8 def 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 10 11 # 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]))) 13 18 return numpy.sqrt(dx*dx + dy*dy) 14 19 … … 166 171 length - the lenght (in mm) covered by the extend of spk1 and spk2. Currently, spk1 167 172 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 169 176 Examples: 170 177 >> p = DistantDependentPairs(spk1, spk1, True, False) … … 178 185 See also RandomPairs, CustomPairs, AutoPairs 179 186 """ 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): 181 188 PairsGenerator.__init__(self, spk1, spk2, no_silent) 182 183 189 self.lenght = lenght 184 190 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): 187 199 """ 188 200 Function to obtain a certain number of cells from the generator … … 190 202 Inputs: 191 203 nb_pairs - int to specify the number of pairs desired 192 d_min - the minimal distance between cells193 d_max - the maximal distance between cells194 204 195 205 The length parameter of the DistantDependentPairs should be defined correctly. It is the extent of the grid. … … 211 221 pos_cell2 = numpy.array(self.spk2.id2position(cell2))*self.lenght/self.spk2.dimensions[0] 212 222 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] 214 224 N = len(idx) 215 225 if N > 0:
