Changeset 383
- Timestamp:
- 06/21/08 08:39:07 (5 months ago)
- Files:
-
- trunk/src/common.py (modified) (2 diffs)
- trunk/src/nest2/__init__.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/common.py
r375 r383 700 700 """ 701 701 702 def __init__(self, dims, cellclass, cellparams=None, label=None ):702 def __init__(self, dims, cellclass, cellparams=None, label=None, create_cells=True): 703 703 """ 704 704 dims should be a tuple containing the population dimensions, or a single … … 930 930 """ 931 931 return _abstract_method(self) 932 932 933 def getSubPopulation(self, cells): 934 """ 935 Returns a sub population from a population object. The shape of cells will 936 determine the dimensions of the sub population. cells should contains cells 937 member of the parent population. 938 Ex z = pop.getSubPopulation([pop[1],pop[3],pop[5]]) 939 """ 940 return _abstract_method(self) 941 933 942 # ============================================================================== 934 943 trunk/src/nest2/__init__.py
r382 r383 530 530 nPop = 0 531 531 532 def __init__(self, dims, cellclass, cellparams=None, label=None ):532 def __init__(self, dims, cellclass, cellparams=None, label=None, create_cells=True): 533 533 """ 534 534 dims should be a tuple containing the population dimensions, or a single … … 543 543 """ 544 544 545 common.Population.__init__(self, dims, cellclass, cellparams, label )545 common.Population.__init__(self, dims, cellclass, cellparams, label, create_cells) 546 546 547 547 # Should perhaps use "LayoutNetwork"? … … 549 549 if isinstance(cellclass, type): 550 550 self.celltype = cellclass(cellparams) 551 self.cell = nest.Create(self.celltype.nest_name, self.size) 551 if create_cells: 552 self.cell = nest.Create(self.celltype.nest_name, self.size) 553 else: 554 #A SubPopulation has been created, those fields will be filled later 555 self.cell = [] 552 556 self.cellparams = self.celltype.parameters 553 557 elif isinstance(cellclass, str): 554 self.cell = nest.Create(cellclass, self.size) 555 556 self.cell = numpy.array([ ID(GID) for GID in self.cell ], ID) 557 self.cell_local = self.cell[numpy.array(nest.GetStatus(self.cell.tolist(),'local'))] 558 self.first_id = self.cell.reshape(self.size,)[0] 559 560 for id in self.cell: 561 id.parent = self 558 if create_cells: 559 self.cell = nest.Create(cellclass, self.size) 560 else: 561 #A SubPopulation has been created, those fields will be filled later 562 self.cell = [] 563 ### Warning : not tested yet, quickly implemented in Okinawa. To allow the 564 ### construction of subpopulation without creating the cells 565 elif isinstance(cellclass,common.StandardCellType): 566 self.cell = [] 567 568 if create_cells: 569 self.cell = numpy.array([ ID(GID) for GID in self.cell ], ID) 570 self.cell_local = self.cell[numpy.array(nest.GetStatus(self.cell.tolist(),'local'))] 571 self.first_id = self.cell.reshape(self.size,)[0] 572 573 for id in self.cell: 574 id.parent = self 562 575 #id.setCellClass(cellclass) 563 576 #id.setPosition(self.locate(id)) 564 565 if self.cellparams: 566 nest.SetStatus(self.cell_local, [self.cellparams]) 567 568 self.cell = numpy.reshape(self.cell, self.dim) 577 self.cell = numpy.reshape(self.cell, self.dim) 578 if self.cellparams: 579 nest.SetStatus(self.cell_local, [self.cellparams]) 569 580 570 581 if not self.label: … … 899 910 self.recorders['conductance'].write(filename, gather, compatible_output) 900 911 912 def getSubPopulation(self, cell_list, label=None): 913 914 # We get the dimensions of the new population 915 dims = numpy.array(cell_list).shape 916 # We create an empty population 917 pop = Population(dims, cellclass=self.celltype, label=label, create_cells=False) 918 # And then copy parameters from its parent 919 pop.cellparams = self.cellparams 920 pop.cell = cell_list 921 pop.first_id = self.first_id 922 idx = pop.cell.flatten() -pop.first_id 923 pop.cell_local = self.cell_local[idx] 924 pop.position = self.positions[:,idx] 925 return pop 926 927 901 928 def describe(self): 902 929 """ … … 904 931 """ 905 932 print "\n------- Population description -------" 906 print "Population called %s is made of %d cells [%d being local]" %(self.label, len(self.cell ), len(self.cell_local))933 print "Population called %s is made of %d cells [%d being local]" %(self.label, len(self.cell.flatten()), len(self.cell_local)) 907 934 print "-> Cells are aranged on a %dD grid of size %s" %(len(self.dim), self.dim) 908 935 print "-> Celltype is %s" %self.celltype

