Changeset 712
- Timestamp:
- 02/16/10 12:33:37 (2 years ago)
- Location:
- trunk/src
- Files:
-
- 1 added
- 8 modified
-
__init__.py (modified) (1 diff)
-
brian/__init__.py (modified) (2 diffs)
-
common.py (modified) (1 diff)
-
connectors.py (modified) (5 diffs)
-
connectors2.py (modified) (3 diffs)
-
nest/__init__.py (modified) (2 diffs)
-
neuron/__init__.py (modified) (2 diffs)
-
pcsim/__init__.py (modified) (2 diffs)
-
space.py (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/__init__.py
r711 r712 67 67 68 68 __version__ = '0.7pre ( $Rev$)'.replace(' $','') 69 __all__ = ["common", "random", "nest", "neuron", "pcsim", "brian", "recording", "errors" ]69 __all__ = ["common", "random", "nest", "neuron", "pcsim", "brian", "recording", "errors", "space"] 70 70 -
trunk/src/brian/__init__.py
r705 r712 9 9 #import brian_no_units_no_warnings 10 10 from pyNN.brian import simulator 11 from pyNN import common, recording, __doc__11 from pyNN import common, recording, space, __doc__ 12 12 common.simulator = simulator 13 13 recording.simulator = simulator … … 172 172 173 173 174 Space = common.Space174 Space = space.Space -
trunk/src/common.py
r711 r712 133 133 raise errors.ConnectionError("delay (%s) is out of range [%s,%s]" % (delay, get_min_delay(), get_max_delay())) 134 134 return delay 135 136 def distance(src, tgt, mask=None, scale_factor=1.0, offset=0.0,137 periodic_boundaries=None): # may need to add an offset parameter138 """139 Return the Euclidian distance between two cells.140 `mask` allows only certain dimensions to be considered, e.g.::141 * to ignore the z-dimension, use `mask=array([0,1])`142 * to ignore y, `mask=array([0,2])`143 * to just consider z-distance, `mask=array([2])`144 `scale_factor` allows for different units in the pre- and post- position145 (the post-synaptic position is multipied by this quantity).146 """147 d = src.position - scale_factor*(tgt.position + offset)148 149 if not periodic_boundaries == None:150 d = numpy.minimum(abs(d), periodic_boundaries-abs(d))151 if mask is not None:152 d = d[mask]153 return numpy.sqrt(numpy.dot(d, d))154 155 156 class Space(object):157 158 AXES = {'x' : [0], 'y': [1], 'z': [2],159 'xy': [0,1], 'yz': [1,2], 'xz': [0,2], 'xyz': range(3), None: range(3)}160 161 def __init__(self, axes=None, scale_factor=1.0, offset=0.0,162 periodic_boundaries=None):163 """164 axes -- if not supplied, then the 3D distance is calculated. If supplied,165 axes should be a string containing the axes to be used, e.g. 'x', or166 'yz'. axes='xyz' is the same as axes=None.167 scale_factor -- it may be that the pre and post populations use168 different units for position, e.g. degrees and µm. In this case,169 `scale_factor` can be specified, which is applied to the positions170 in the post-synaptic population.171 offset -- if the origins of the coordinate systems of the pre- and post-172 synaptic populations are different, `offset` can be used to adjust173 for this difference. The offset is applied before any scaling.174 periodic_boundaries -- either `None`, or a tuple giving the boundaries175 for each dimension, e.g. `((x_min, x_max), None, (z_min, z_max))`.176 """177 self.periodic_boundaries = periodic_boundaries178 self.axes = numpy.array(Space.AXES[axes])179 self.scale_factor = scale_factor180 self.offset = offset181 182 def distances(self, A, B):183 """184 Calculate the distance matrix between two sets of coordinates, given185 the topology of the current space.186 From http://projects.scipy.org/pipermail/numpy-discussion/2007-April/027203.html187 """188 if len(A.shape) == 1:189 A = A.reshape(3, 1)190 if len(B.shape) == 1:191 B = B.reshape(3, 1)192 B = self.scale_factor*(B + self.offset)193 d = numpy.zeros((A.shape[1], B.shape[1]), dtype=A.dtype)194 for axis in self.axes:195 diff2 = A[axis,:,None] - B[axis,:]196 if self.periodic_boundaries is not None:197 boundaries = self.periodic_boundaries[axis]198 if boundaries is not None:199 range = boundaries[1]-boundaries[0]200 ad2 = abs(diff2)201 diff2 = numpy.minimum(ad2, range-ad2)202 diff2 **= 2203 d += diff2204 numpy.sqrt(d, d)205 return d206 135 207 136 -
trunk/src/connectors.py
r711 r712 21 21 sin, sinh, sqrt, tan, tanh 22 22 from pyNN import random, common, errors 23 from pyNN.space import Space 23 24 24 25 logger = logging.getLogger("PyNN") … … 147 148 """ 148 149 149 def __init__(self, allow_self_connections=True, weights=0.0, delays=None, space= common.Space()):150 def __init__(self, allow_self_connections=True, weights=0.0, delays=None, space=Space()): 150 151 """ 151 152 Create a new connector. … … 455 456 """ 456 457 457 def __init__(self, p_connect, allow_self_connections=True, weights=0.0, delays=None, space= common.Space()):458 def __init__(self, p_connect, allow_self_connections=True, weights=0.0, delays=None, space=Space()): 458 459 """ 459 460 Create a new connector. … … 500 501 501 502 def __init__(self, d_expression, allow_self_connections=True, 502 weights=0.0, delays=None, space= common.Space()):503 weights=0.0, delays=None, space=Space()): 503 504 """ 504 505 Create a new connector. … … 524 525 assert isinstance(allow_self_connections, bool) 525 526 self.allow_self_connections = allow_self_connections 526 assert isinstance(space, common.Space)527 assert isinstance(space, Space) 527 528 self.space = space 528 529 -
trunk/src/connectors2.py
r701 r712 1 1 import numpy 2 2 from pyNN import common 3 from pyNN.space import Space 3 4 from pyNN.random import RandomDistribution 4 5 from numpy import exp … … 87 88 88 89 def __init__(self, allow_self_connections=True, 89 weights=0.0, delays=None, space= common.Space()):90 weights=0.0, delays=None, space=Space()): 90 91 """ 91 92 Create a new connector. … … 133 134 134 135 def __init__(self, p_connect, allow_self_connections=True, 135 weights=0.0, delays=None, space= common.Space()):136 weights=0.0, delays=None, space=Space()): 136 137 """ 137 138 Create a new connector. -
trunk/src/nest/__init__.py
r711 r712 7 7 import nest 8 8 from pyNN.nest import simulator 9 from pyNN import common, recording, errors, __doc__9 from pyNN import common, recording, errors, space, __doc__ 10 10 common.simulator = simulator 11 11 recording.simulator = simulator … … 433 433 434 434 435 Space = common.Space436 437 # ============================================================================== 435 Space = space.Space 436 437 # ============================================================================== -
trunk/src/neuron/__init__.py
r701 r712 9 9 from pyNN.random import * 10 10 from pyNN.neuron import simulator 11 from pyNN import common, recording, __doc__11 from pyNN import common, recording, space, __doc__ 12 12 common.simulator = simulator 13 13 recording.simulator = simulator … … 285 285 286 286 287 Space = common.Space288 289 # ============================================================================== 287 Space = space.Space 288 289 # ============================================================================== -
trunk/src/pcsim/__init__.py
r711 r712 15 15 16 16 import pyNN.random 17 from pyNN import common, recording, errors, __doc__17 from pyNN import common, recording, errors, space, __doc__ 18 18 from pyNN.pcsim import simulator 19 19 common.simulator = simulator … … 822 822 823 823 824 Space = common.Space824 Space = space.Space 825 825 826 826 # ==============================================================================
