Changeset 730

Show
Ignore:
Timestamp:
03/12/10 10:14:48 (2 years ago)
Author:
pierre
Message:

Add a method to save Positions into a file. Polish and test the new Connector2 module, by adding a connectors_benchmark script in the unittest that allow to plot graphs of the connections for all the connectors and according to all the parameters. Need to play a bit with, but everything seems to be OK. Andrew, maybe please have a small look, and as soon as you consider that the progress bar, the connections are ok for you, you can commit the new connectors2 module and erase the old one.

Location:
trunk/src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/common.py

    r720 r730  
    898898        raise NotImplementedError() 
    899899     
     900    def savePositions(self, filename, gather=True, compatible_output=True): 
     901        """ 
     902        Save positions to file. The output format is id x y z 
     903        """ 
     904        fmt = "%s\t%s\t%s\t%s\n" % ("%d", "%g", "%g", "%g") 
     905        lines = [] 
     906        for cell in self.all():   
     907            x,y,z = cell.position 
     908            line = fmt  % (cell, x, y, z) 
     909            lines.append(line) 
     910        if rank() == 0: 
     911            f = open(filename, 'w') 
     912            f.writelines(lines) 
     913            f.close() 
     914     
    900915# ============================================================================== 
    901916 
  • trunk/src/connectors2.py

    r729 r730  
    2424         
    2525    def extract(self, N, distance_matrix=None, sub_mask=None): 
     26        #local_mask is supposed to be a mask of booleans, while  
     27        #sub_mask is a list of cells ids. 
    2628        if isinstance(self.source, basestring): 
    2729            assert distance_matrix is not None 
     
    198200        self.distance_matrix.set_source(src.position)         
    199201        targets = self.projection.post.local_cells[create] 
     202        if not self.allow_self_connections and self.projection.pre == self.projection.post and src in targets: 
     203            i       = numpy.where(targets == src)[0] 
     204            targets = numpy.delete(targets, i) 
     205            create  = numpy.delete(create, i) 
     206         
    200207        weights = self.weights_generator.get(self.N, self.distance_matrix, create) 
    201208        delays  = self.delays_generator.get(self.N, self.distance_matrix, create) 
    202209             
    203         if not self.allow_self_connections and self.projection.pre == self.projection.post and src in targets: 
    204             i       = numpy.where(targets == src)[0] 
    205             weights = numpy.delete(weights, i) 
    206             delays  = numpy.delete(delays, i) 
    207             targets = numpy.delete(targets, i) 
    208          
    209210        if len(targets) > 0: 
    210211            self.projection.connection_manager.connect(src, targets.tolist(), weights, delays)