Changeset 385

Show
Ignore:
Timestamp:
06/22/08 16:34:33 (5 months ago)
Author:
pierre
Message:

Sounds more nice to have a parent attribute for the subpopulation that have been created. We can therefore know from which population a subpopulation is related to. Nevertheless, still have to think about how changing positions in the children population will have an impact on positions in the parent one. Therefore, getSubPopulation is still experimental

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/common.py

    r383 r385  
    700700    """ 
    701701     
    702     def __init__(self, dims, cellclass, cellparams=None, label=None, create_cells=True): 
     702    def __init__(self, dims, cellclass, cellparams=None, label=None, parent=None): 
    703703        """ 
    704704        dims should be a tuple containing the population dimensions, or a single 
     
    723723        self.cellparams = cellparams 
    724724        self.size = self.dim[0] 
     725        self.parent = parent 
    725726        for i in range(1, self.ndim): 
    726727            self.size *= self.dim[i] 
  • trunk/src/nest2/__init__.py

    r384 r385  
    530530    nPop = 0 
    531531 
    532     def __init__(self, dims, cellclass, cellparams=None, label=None, create_cells=True): 
     532    def __init__(self, dims, cellclass, cellparams=None, label=None, parent=None): 
    533533        """ 
    534534        dims should be a tuple containing the population dimensions, or a single 
     
    543543        """ 
    544544 
    545         common.Population.__init__(self, dims, cellclass, cellparams, label, create_cells
     545        common.Population.__init__(self, dims, cellclass, cellparams, label, parent
    546546 
    547547        # Should perhaps use "LayoutNetwork"? 
     
    549549        if isinstance(cellclass, type): 
    550550            self.celltype = cellclass(cellparams) 
    551             if create_cells
     551            if not parent
    552552                self.cell = nest.Create(self.celltype.nest_name, self.size) 
    553553            else: 
     
    556556            self.cellparams = self.celltype.parameters 
    557557        elif isinstance(cellclass, str): 
    558             if create_cells
     558            if not parent
    559559                self.cell = nest.Create(cellclass, self.size) 
    560560            else: 
     
    566566            self.cell = [] 
    567567 
    568         if create_cells
     568        if not parent
    569569            self.cell = numpy.array([ ID(GID) for GID in self.cell ], ID) 
    570570            self.cell_local = self.cell[numpy.array(nest.GetStatus(self.cell.tolist(),'local'))] 
     
    915915        dims = numpy.array(cell_list).shape 
    916916        # We create an empty population 
    917         pop = Population(dims, cellclass=self.celltype, label=label, create_cells=False
     917        pop = Population(dims, cellclass=self.celltype, label=label, parent=self
    918918        # And then copy parameters from its parent 
    919         pop.cellparams  = self.cellparams 
    920         pop.first_id    = self.first_id 
    921         idx             = numpy.array(cell_list).flatten() - pop.first_id 
    922         pop.cell        = self.cell.flatten()[idx].reshape(dims) 
    923         pop.cell_local  = self.cell_local[idx] 
    924         pop.positions   = self.positions[:,idx] 
     919        pop.cellparams  = pop.parent.cellparams 
     920        pop.first_id    = pop.parent.first_id 
     921        idx             = numpy.array(cell_list,int).flatten() - pop.first_id 
     922        pop.cell        = pop.parent.cell.flatten()[idx].reshape(dims) 
     923        pop.cell_local  = pop.parent.cell_local[idx] 
     924        pop.positions   = pop.parent.positions[:,idx] 
    925925        return pop 
    926  
    927  
    928  
    929926 
    930927    def describe(self): 
     
    934931        print "\n------- Population description -------" 
    935932        print "Population called %s is made of %d cells [%d being local]" %(self.label, len(self.cell.flatten()), len(self.cell_local)) 
     933        if self.parent: 
     934            print "This population is a subpopulation of population %s" %self.parent.label 
    936935        print "-> Cells are aranged on a %dD grid of size %s" %(len(self.dim), self.dim) 
    937936        print "-> Celltype is %s" %self.celltype 
     
    13781377        idx = numpy.where(numpy.array(dict['targets']) == self._targets[0])[0] 
    13791378        for key, value in dict.items(): 
    1380           print "\t| ", key, ": ", value[idx
     1379          print "\t| ", key, ": ", value[idx[0]
    13811380 
    13821381        print "---- End of Projection description -----"