Changeset 54
- Timestamp:
- 05/11/07 16:00:49 (2 years ago)
- Files:
-
- branches/0.3/common.py (modified) (3 diffs)
- branches/0.3/facetsml.py (modified) (8 diffs)
- branches/0.3/nest.py (modified) (16 diffs)
- branches/0.3/neuron.py (modified) (8 diffs)
- branches/0.3/oldneuron.py (modified) (6 diffs)
- branches/0.3/pcsim.py (modified) (15 diffs)
- branches/0.3/test/facetsmltest.py (copied) (copied from trunk/test/facetsmltest.py)
- branches/0.3/test/pyNNPcsimLowLevelTest.py (modified) (3 diffs)
- branches/0.3/test/pyNNPcsimPopulationTest.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/0.3/common.py
r48 r54 186 186 # ============================================================================== 187 187 188 def setup(timestep=0.1,min_delay=0.1,max_delay=0.1,debug=False): 189 """Should be called at the very beginning of a script.""" 188 def setup(timestep=0.1,min_delay=0.1,max_delay=0.1,debug=False,**extra_params): 189 """ 190 Should be called at the very beginning of a script. 191 extra_params contains any keyword arguments that are required by a given 192 simulator but not by others. 193 """ 190 194 dt = timestep 191 195 pass … … 365 369 def printSpikes(self,filename,gather=True, compatible_output=True): 366 370 """ 367 Prints spike times to file in the two-column format 368 "spiketime cell_id" where cell_id is the index of the cell counting 369 along rows and down columns (and the extension of that for 3-D). 371 Writes spike times to file. 372 If compatible_output is True, the format is "spiketime cell_id", 373 where cell_id is the index of the cell counting along rows and down 374 columns (and the extension of that for 3-D). 370 375 This allows easy plotting of a `raster' plot of spiketimes, with one 371 376 line for each cell. 372 On the first line, we have the dimension of the populations 373 By defaut, we should use a common format for that could be provided independent 374 of the simulator used to run the simulation. This will include post processing 375 of the raw file provided by the simulator, so for speed up increase one can 376 prefer to use avoid this step and use the format proposed by the different simulators 377 """ 377 The timestep and number of data points per cell is written as a header, 378 indicated by a '#' at the beginning of the line. 379 380 If compatible_output is False, the raw format produced by the simulator 381 is used. This may be faster, since it avoids any post-processing of the 382 spike files. 383 384 If gather is True, the file will only be created on the master node, 385 otherwise, a file will be written on each node. 386 """ 378 387 pass 379 388 … … 381 390 """ 382 391 Write membrane potential traces to file. 392 If compatible_output is True, the format is "v cell_id", 393 where cell_id is the index of the cell counting along rows and down 394 columns (and the extension of that for 3-D). 395 This allows easy plotting of a `raster' plot of spiketimes, with one 396 line for each cell. 397 The timestep and number of data points per cell is written as a header, 398 indicated by a '#' at the beginning of the line. 399 400 If compatible_output is False, the raw format produced by the simulator 401 is used. This may be faster, since it avoids any post-processing of the 402 voltage files. 383 403 """ 384 404 pass branches/0.3/facetsml.py
r48 r54 38 38 #if the <neuroml> markup is not yet created 39 39 if(neuromlNodes.length == 0): 40 # seems createElementNS doesn't create the xmlns attribute40 #neuroml has no prefix, namespace http://morphml.org/neuroml/schema is the default one 41 41 neuromlNode = xmldoc.createElementNS('http://morphml.org/neuroml/schema','neuroml') 42 42 xmldoc.appendChild(neuromlNode) … … 44 44 neuromlNode = neuromlNodes[0] 45 45 parentElementNodes = neuromlNode.getElementsByTagNameNS(parentElementNS,parentElementName) 46 #if the <parentElementName> markup is not yet created 46 47 if(parentElementNodes.length == 0): 48 #if no prefix has been defined and the namespace of the new parent element is not the default 49 # namespace, a new namespace is associated to null prefix, which is not good 47 50 if(prefix == ''): 48 51 parentElementNode = xmldoc.createElementNS(parentElementNS,parentElementName) … … 53 56 parentElementNode = parentElementNodes[0] 54 57 return parentElementNode 58 59 def writeDocument(url): 60 """ 61 write the xmldoc created to a file specified by the url 62 """ 63 file = open(url,'w') 64 PrettyPrint(xmldoc, file) 65 file.close() 66 55 67 56 68 … … 306 318 </net:populations> 307 319 308 309 310 320 """ 311 321 … … 317 327 318 328 319 populationsNode = initDocument('http://morphml.org/networkml/schema','populations','net')320 321 populationNode = xmldoc.createElementNS('http://morphml.org/networkml/schema','net:population')322 populationNode.setAttribute('name',label)323 populationsNode.appendChild(populationNode)324 325 cell_typeNode = xmldoc.createElementNS('http://morphml.org/networkml/schema','net:cell_type')326 #coming from neuron.py327 if isinstance(cellclass, type):329 populationsNode = initDocument('http://morphml.org/networkml/schema','populations','net') 330 331 populationNode = xmldoc.createElementNS('http://morphml.org/networkml/schema','net:population') 332 populationNode.setAttribute('name',label) 333 populationsNode.appendChild(populationNode) 334 335 cell_typeNode = xmldoc.createElementNS('http://morphml.org/networkml/schema','net:cell_type') 336 #coming from neuron.py 337 if isinstance(cellclass, type): 328 338 self.celltype = cellclass(cellparams) 329 339 self.cellparams = self.celltype.parameters … … 332 342 hoc_name = cellclass 333 343 #end of coming 334 335 cell_typeTextNode = xmldoc.createTextNode(hoc_name) 336 cell_typeNode.appendChild(cell_typeTextNode) 337 populationNode.appendChild(cell_typeNode) 338 """ 339 the minimal neuroml to add there is : 340 <net:pop_location reference="aReference"> 341 <net:grid_arrangement> 342 <net:rectangular_location name="aName"> 343 <meta:corner x="0" y="0" z="0"/> 344 <meta:size depth="10" height="100" width="100"/> 345 </net:rectangular_location> 346 <net:spacing x="10" y="10" z="10"/> 347 </net:grid_arrangement> 348 349 </net:pop_location> 350 """ 351 pop_locationNode = xmldoc.createElementNS('http://morphml.org/networkml/schema','net:pop_location') 352 pop_locationNode.setAttribute('reference','aReference') 353 populationNode.appendChild(pop_locationNode) 354 355 grid_arrangementNode = xmldoc.createElementNS('http://morphml.org/networkml/schema','net:grid_arrangement') 356 pop_locationNode.appendChild(grid_arrangementNode) 357 358 rectangular_locationNode = xmldoc.createElementNS('http://morphml.org/networkml/schema','net:rectangular_location') 359 rectangular_locationNode.setAttribute('name','aName') 360 grid_arrangementNode.appendChild(rectangular_locationNode) 361 362 cornerNode = xmldoc.createElementNS('http://morphml.org/metadata/schema','meta:corner') 363 cornerNode.setAttribute('x','0') 364 cornerNode.setAttribute('y','0') 365 cornerNode.setAttribute('z','0') 366 rectangular_locationNode.appendChild(cornerNode) 367 368 sizeNode = xmldoc.createElementNS('http://morphml.org/metadata/schema','meta:size') 369 #neuroml is always in 3D adding 0 for non covered dimensions 370 sizeNode.setAttribute('depth',str(10*dims[0])) 371 sizeNode.setAttribute('height',str(10*dims[1])) 372 if(dims.__len__() > 2): 373 sizeNode.setAttribute('width',str(10*dims[2])) 374 else: 375 sizeNode.setAttribute('width','0') 376 rectangular_locationNode.appendChild(sizeNode) 377 378 spacingNode = xmldoc.createElementNS('http://morphml.org/networkml/schema','net:spacing') 379 spacingNode.setAttribute('x','10') 380 spacingNode.setAttribute('y','10') 381 spacingNode.setAttribute('z','10') 382 grid_arrangementNode.appendChild(spacingNode) 383 384 385 #cellparams would be defined in a <cell> markup which would define precisely the neuron model 386 387 344 345 cell_typeTextNode = xmldoc.createTextNode(hoc_name) 346 cell_typeNode.appendChild(cell_typeTextNode) 347 populationNode.appendChild(cell_typeNode) 348 """ 349 the minimal neuroml to add there is : 350 <net:pop_location reference="aReference"> 351 <net:grid_arrangement> 352 <net:rectangular_location name="aName"> 353 <meta:corner x="0" y="0" z="0"/> 354 <meta:size depth="10" height="100" width="100"/> 355 </net:rectangular_location> 356 <net:spacing x="10" y="10" z="10"/> 357 </net:grid_arrangement> 358 </net:pop_location> 359 """ 360 pop_locationNode = xmldoc.createElementNS('http://morphml.org/networkml/schema','net:pop_location') 361 pop_locationNode.setAttribute('reference','aReference') 362 populationNode.appendChild(pop_locationNode) 363 364 grid_arrangementNode = xmldoc.createElementNS('http://morphml.org/networkml/schema','net:grid_arrangement') 365 pop_locationNode.appendChild(grid_arrangementNode) 366 367 rectangular_locationNode = xmldoc.createElementNS('http://morphml.org/networkml/schema','net:rectangular_location') 368 rectangular_locationNode.setAttribute('name','aName') 369 grid_arrangementNode.appendChild(rectangular_locationNode) 370 371 cornerNode = xmldoc.createElementNS('http://morphml.org/metadata/schema','meta:corner') 372 cornerNode.setAttribute('x','0') 373 cornerNode.setAttribute('y','0') 374 cornerNode.setAttribute('z','0') 375 rectangular_locationNode.appendChild(cornerNode) 376 377 sizeNode = xmldoc.createElementNS('http://morphml.org/metadata/schema','meta:size') 378 #neuroml is always in 3D, adding 0 for non covered dimensions 379 sizeNode.setAttribute('depth',str(10*dims[0])) 380 sizeNode.setAttribute('height',str(10*dims[1])) 381 if(dims.__len__() > 2): 382 sizeNode.setAttribute('width',str(10*dims[2])) 383 else: 384 sizeNode.setAttribute('width','0') 385 rectangular_locationNode.appendChild(sizeNode) 386 387 spacingNode = xmldoc.createElementNS('http://morphml.org/networkml/schema','net:spacing') 388 spacingNode.setAttribute('x','10') 389 spacingNode.setAttribute('y','10') 390 spacingNode.setAttribute('z','10') 391 grid_arrangementNode.appendChild(spacingNode) 392 393 394 #cellparams would be defined in a <cell> markup which would define precisely the neuron model 395 396 388 397 #raise "Not yet implemented." 389 398 390 399 391 400 Population.nPop += 1 392 PrettyPrint(xmldoc)401 PrettyPrint(xmldoc) 393 402 394 403 … … 515 524 than within methodParameters, particularly since some methods also use 516 525 random numbers to give variability in the number of connections per cell. 526 527 528 529 530 example of NeuroML for projections : 531 <projections units="Physiological Units" xmlns="http://morphml.org/networkml/schema"> 532 <projection name="NetworkConnection"> 533 <source>CellGroupA</source> 534 <target>CellGroupB</target> 535 <synapse_props> 536 <synapse_type>DoubExpSynA</synapse_type> 537 <default_values internal_delay="5" weight="1" threshold="-20"/> 538 </synapse_props> 539 <connections> 540 <connection id="0"> 541 <pre cell_id="0" segment_id = "0" fraction_along="0.5"/> 542 <post cell_id="1" segment_id = "1"/> 543 </connection> 544 <connection id="1"> 545 <pre cell_id="2" segment_id = "0"/> 546 <post cell_id="1" segment_id = "0"/> 547 </connection> 548 <connection id="1"> 549 <pre cell_id="3" segment_id = "0"/> 550 <post cell_id="1" segment_id = "1"/> 551 <properties internal_delay="10" weight="0.5"/> <!-- adjusted value --> 552 </connection> 553 </connections> 554 </projection> 555 <projection name="2"> 556 <source>CellGroupA</source> 557 <target>CellGroupB</target> 558 <synapse_props> 559 <synapse_type>DoubExpSynA</synapse_type> 560 <default_values/> 561 </synapse_props> 562 <connectivity_pattern> 563 <all_to_all/> 564 </connectivity_pattern> 565 </projection> 566 </projections> 517 567 """ 518 568 common.Projection.__init__(self,presynaptic_population,postsynaptic_population,method,methodParameters,source,target,label,rng) … … 520 570 self._targets = [] 521 571 self._sources = [] 522 connection_method = getattr(self,'_%s' % method) 523 self.nconn = connection_method(methodParameters) 572 #connection_method = getattr(self,'_%s' % method) 573 #self.nconn = connection_method(methodParameters) 574 575 576 577 578 579 580 projectionsNode = initDocument('http://morphml.org/networkml/schema','projections') 581 projectionsNode.setAttribute('units','Physiological Units') 582 583 projectionNode = xmldoc.createElementNS('http://morphml.org/networkml/schema','projection') 584 projectionNode.setAttribute('name',label) 585 projectionsNode.appendChild(projectionNode) 586 587 sourceNode = xmldoc.createElementNS('http://morphml.org/networkml/schema','source') 588 589 #evaluating presynaptic_populationName 590 if isinstance(presynaptic_population, Population): 591 presynaptic_populationName = presynaptic_population.label 592 elif isinstance(presynaptic_population, str): 593 presynaptic_populationName = presynaptic_population 594 595 596 sourceTextNode = xmldoc.createTextNode(presynaptic_populationName) 597 sourceNode.appendChild(sourceTextNode) 598 projectionNode.appendChild(sourceNode) 599 600 targetNode = xmldoc.createElementNS('http://morphml.org/networkml/schema','target') 601 602 #evaluating postsynaptic_populationName 603 if isinstance(postsynaptic_population, Population): 604 postsynaptic_populationName = postsynaptic_population.label 605 elif isinstance(postsynaptic_population, str): 606 postsynaptic_populationName = postsynaptic_population 607 608 609 targetTextNode = xmldoc.createTextNode(postsynaptic_populationName) 610 targetNode.appendChild(targetTextNode) 611 projectionNode.appendChild(targetNode) 612 613 synapse_propsNode = xmldoc.createElementNS('http://morphml.org/networkml/schema','synapse_props') 614 615 #I don't know how to deal with that 616 projectionNode.appendChild(synapse_propsNode) 617 618 synapse_typeNode = xmldoc.createElementNS('http://morphml.org/networkml/schema','synapse_type') 619 #false values to make it valid 620 synapse_typeTextNode = xmldoc.createTextNode("DoubExpSynA") 621 synapse_typeNode.appendChild(synapse_typeTextNode) 622 synapse_propsNode.appendChild(synapse_typeNode) 623 624 default_valuesNode = xmldoc.createElementNS('http://morphml.org/networkml/schema','default_values') 625 synapse_propsNode.appendChild(default_valuesNode) 626 627 """ 628 example of connectivity_pattern to add, must be generic 629 630 <connectivity_pattern> 631 <fixed_probability probability="0.5"></fixed_probability> 632 </connectivity_pattern> 633 634 635 """ 636 637 connectivity_patternNode = xmldoc.createElementNS('http://morphml.org/networkml/schema','connectivity_pattern') 638 projectionNode.appendChild(connectivity_patternNode) 639 640 methodNode = xmldoc.createElementNS('http://morphml.org/networkml/schema',method) 641 for key in methodParameters: 642 methodNode.setAttribute(key,methodParameters[key]) 643 644 connectivity_patternNode.appendChild(methodNode) 645 646 647 PrettyPrint(xmldoc) 648 649 650 524 651 525 652 # --- Connection methods --------------------------------------------------- branches/0.3/nest.py
r48 r54 109 109 'v_thresh' : ('Theta' , "parameters['v_thresh']"), 110 110 'i_offset' : ('I0' , "parameters['i_offset']*1000.0"), # I0 is in pA, i_offset in nA 111 'e_rev_E' : ('V_reversal_E', "parameters['e_rev_E']"),111 'e_rev_E' : ('V_reversal_E', "parameters['e_rev_E']"), 112 112 'e_rev_I' : ('V_reversal_I', "parameters['e_rev_I']"), 113 113 'v_init' : ('u' , "parameters['v_init']"), … … 154 154 # ============================================================================== 155 155 156 def setup(timestep=0.1,min_delay=0.1,max_delay=0.1,debug=False): 157 """Should be called at the very beginning of a script.""" 156 def setup(timestep=0.1,min_delay=0.1,max_delay=0.1,debug=False,**extra_params): 157 """ 158 Should be called at the very beginning of a script. 159 extra_params contains any keyword arguments that are required by a given 160 simulator but not by others. 161 """ 158 162 if min_delay > max_delay: 159 163 raise Exception("min_delay has to be less than or equal to max_delay.") … … 244 248 both be individual cells or lists of cells, in which case all possible 245 249 connections are made with probability p, using either the random number 246 generator supplied, or the default rng otherwise.""" 250 generator supplied, or the default rng otherwise. 251 Weights should be in nA or uS.""" 247 252 global dt 248 253 if weight is None: … … 332 337 pynest.sr('%s close' %tempfilename) 333 338 if (compatible_output): 334 # Here we postprocess the file to have effectively the339 # Here we postprocess the file to have effectively the 335 340 # desired format : 336 # First line: # dimensions of the population337 # Then spiketime (in ms) cell_id-min(cell_id)341 # First line: # dimensions of the population 342 # Then spiketime (in ms) cell_id-min(cell_id) 338 343 result = open(filename,'w',100) 339 344 g = open(tempfilename,'r',100) … … 344 349 neuron = int(single_line[0][1:len(single_line[0])]) 345 350 spike_time = dt*float(single_line[1]) 346 result.write("%g\t%d\n" %(spike_time, neuron))351 result.write("%g\t%d\n" %(spike_time, neuron)) 347 352 result.close() 348 353 else: … … 364 369 if (compatible_output): 365 370 f = open(tempfilename.replace('/','_'),'r',100) 366 lines = f.readlines()371 lines = f.readlines() 367 372 f.close() 368 373 369 # Here we postprocess the file to have effectively the374 # Here we postprocess the file to have effectively the 370 375 # desired format : 371 # First line: dimensions of the population372 # Then spiketime cell_id-min(cell_id)376 # First line: dimensions of the population 377 # Then spiketime cell_id-min(cell_id) 373 378 for line in lines: 374 379 line = line.rstrip() … … 376 381 if (len(single_line) > 1) and (single_line[1] != '-'): 377 382 neuron = int(single_line[0]) 378 result.write("%s\t%d\n" %(single_line[1], neuron))383 result.write("%s\t%d\n" %(single_line[1], neuron)) 379 384 else: 380 385 f = open(tempfilename.replace('/','_'),'r',100) 381 lines = f.readlines()386 lines = f.readlines() 382 387 f.close() 383 388 for line in lines: … … 620 625 'withpath':True}) # record which neuron spiked 621 626 622 fixed_list = False627 fixed_list = False 623 628 624 629 if record_from: 625 630 if type(record_from) == types.ListType: 626 fixed_list = True627 n_rec = len(record_from)631 fixed_list = True 632 n_rec = len(record_from) 628 633 elif type(record_from) == types.IntType: 629 634 n_rec = record_from … … 634 639 pynest.resCons(self.spike_detector[0],n_rec) 635 640 636 if (fixed_list == True):637 for neuron in record_from:641 if (fixed_list == True): 642 for neuron in record_from: 638 643 pynest.connect(pynest.getAddress(neuron),self.spike_detector[0]) 639 644 else: 640 for neuron in numpy.random.permutation(numpy.reshape(self.cell,(self.cell.size,)))[0:n_rec]:645 for neuron in numpy.random.permutation(numpy.reshape(self.cell,(self.cell.size,)))[0:n_rec]: 641 646 pynest.connect(pynest.getAddress(neuron),self.spike_detector[0]) 642 643 # Open temporary output file & register file with detectors647 648 # Open temporary output file & register file with detectors 644 649 # This should be redone now that Eilif has implemented the pythondatum datum type 645 650 # pynest.sr('/tmpfile_%s (tmpfile_%s) (w) file def' % (self.label,self.label)) # old … … 658 663 """ 659 664 global hl_v_files 660 661 fixed_list = False662 663 fixed_list = False665 666 fixed_list = False 667 668 fixed_list = False 664 669 if record_from: 665 670 if type(record_from) == types.ListType: 666 fixed_list = True671 fixed_list = True 667 672 n_rec = len(record_from) 668 673 elif type(record_from) == types.IntType: … … 673 678 n_rec = self.size 674 679 675 tmp_list = []680 tmp_list = [] 676 681 filename = '%s.v' % self.label 677 682 record_file = tempdir+'/'+filename 678 if (fixed_list == True):679 tmp_list = [pynest.getAddress(neuron) for neuron in record_from]680 else:681 for neuron in numpy.random.permutation(numpy.reshape(self.cell,(self.cell.size,)))[0:n_rec]:682 tmp_list.append(pynest.getAddress(neuron))683 if (fixed_list == True): 684 tmp_list = [pynest.getAddress(neuron) for neuron in record_from] 685 else: 686 for neuron in numpy.random.permutation(numpy.reshape(self.cell,(self.cell.size,)))[0:n_rec]: 687 tmp_list.append(pynest.getAddress(neuron)) 683 688 hl_v_files.append(filename) 684 689 pynest.record_v(tmp_list, record_file.replace('/','_')) … … 687 692 def printSpikes(self,filename,gather=True, compatible_output=True): 688 693 """ 689 Prints spike times to file in the two-column format 690 On the first line the dimensions of the population are saved as 691 # x y z 692 And then, we writes "spiketime cell_id" where cell_id is the relative gid 693 of the cell (starting from 0 to the number of cells in the population, 694 because we have substract the starting gid of the population) 694 Writes spike times to file. 695 If compatible_output is True, the format is "spiketime cell_id", 696 where cell_id is the index of the cell counting along rows and down 697 columns (and the extension of that for 3-D). 695 698 This allows easy plotting of a `raster' plot of spiketimes, with one 696 699 line for each cell. 697 This "compatible output" is the same than pyNN.neuron, and imply a 698 small postprocesing of the files produced by nest. To avoid that, the option 699 compatible_output can be set to False and then the results are the results given 700 by nest, i.e: 701 spikes_time (in dt unit) and gid (global gid) 702 703 TODO : return a numpy array? 704 705 """ 700 The timestep and number of data points per cell is written as a header, 701 indicated by a '#' at the beginning of the line. 702 703 If compatible_output is False, the raw format produced by the simulator 704 is used. This may be faster, since it avoids any post-processing of the 705 spike files. 706 707 If gather is True, the file will only be created on the master node, 708 otherwise, a file will be written on each node. 709 """ 706 710 global hl_spike_files 707 711 tempfilename = '%s.spikes' % self.label … … 710 714 pynest.sr('%s close' % tempfilename) 711 715 hl_spike_files.remove(tempfilename) 712 if (compatible_output): 713 # Here we postprocess the file to have effectively the 714 # desired format : 715 # First line: # dimensions of the population 716 # Then spiketime (in ms) cell_id-min(cell_id) 716 if (compatible_output): 717 # Here we postprocess the file to have effectively the 718 # desired format: spiketime (in ms) cell_id-min(cell_id) 717 719 result = open(filename,'w',1) 718 720 g = open("%s/%s" %(tempdir, tempfilename),'r',1) 719 # Writing dimensions of the population: 720 result.write("# ") 721 for dimension in self.dim: 722 result.write("%d\t" %dimension) 723 result.write("\n") 724 725 # Writing spiketimes, cell_id-min(cell_id) 721 # Writing dimensions of the population: 722 result.write("# " + "\t".join([str(d) for d in self.dim]) + "\n") 723 724 # Writing spiketimes, cell_id-min(cell_id) 726 725 padding = numpy.reshape(self.cell,self.cell.size)[0] 727 726 lines = g.readlines() … … 731 730 neuron = int(single_line[0][1:len(single_line[0])]) - padding 732 731 spike_time = dt*float(single_line[1]) 733 result.write("%g\t%d\n" %(spike_time, neuron))732 result.write("%g\t%d\n" %(spike_time, neuron)) 734 733 result.close() 735 734 else: 736 735 shutil.move(tempdir+'/'+tempfilename,filename) 737 736 738 737 739 738 def meanSpikeCount(self,gather=True): … … 760 759 """ 761 760 Write membrane potential traces to file. 762 On the first lines informations ar saved as 763 # dt = ... (dt in ms) 764 # n = ... (number of recorded values) 765 # x y z (dimensions of the population) 766 767 And then, we writes "Vm cell_id" where cell_id is the relative gid 768 of the cell (starting from 0 to the number of cells in the population, 769 because we have substract the starting gid of the population) 770 771 This "compatible output" is the same than pyNN.neuron, and imply a 772 small postprocesing of the files produced by nest. To avoid that, the option 773 compatible_output can be set to False and then the results are the results given 774 by nest, i.e: 775 # dt = ... 776 # n = ... 777 Vm and gid (global gid) 778 761 If compatible_output is True, the format is "v cell_id", 762 where cell_id is the index of the cell counting along rows and down 763 columns (and the extension of that for 3-D). 764 This allows easy plotting of a `raster' plot of spiketimes, with one 765 line for each cell. 766 The timestep and number of data points per cell is written as a header, 767 indicated by a '#' at the beginning of the line. 768 769 If compatible_output is False, the raw format produced by the simulator 770 is used. This may be faster, since it avoids any post-processing of the 771 voltage files. 779 772 """ 780 773 global hl_v_files 781 782 tempfilename = tempdir+'/'+'%s.v' % self.label774 775 tempfilename = tempdir+'/'+'%s.v' % self.label 783 776 if hl_v_files.__contains__(tempfilename): 784 777 pynest.sr('%s close' % tempfilename.replace('/','_')) 785 778 hl_v_files.remove(tempfilename) 786 787 result = open(filename,'w',1)779 780 result = open(filename,'w',1) 788 781 dt = pynest.getNESTStatus()['resolution'] 789 782 n = int(pynest.getNESTStatus()['time']/dt) 790 783 result.write("# dt = %f\n# n = %d\n" % (dt,n)) 791 784 792 if (compatible_output):793 f = open(tempfilename.replace('/','_'),'r',1)794 lines = f.readlines()785 if (compatible_output): 786 f = open(tempfilename.replace('/','_'),'r',1) 787 lines = f.readlines() 795 788 f.close() 796 result.write("# ") 797 for dimension in self.dim: 798 result.write("%d\t" %dimension) 799 result.write("\n") 789 result.write("# " + "\t".join([str(d) for d in self.dim]) + "\n") 800 790 padding = numpy.reshape(self.cell,self.cell.size)[0] 801 791 802 # Here we postprocess the file to have effectively the792 # Here we postprocess the file to have effectively the 803 793 # desired format : 804 # First line: dimensions of the population805 # Then spiketime cell_id-min(cell_id)794 # First line: dimensions of the population 795 # Then spiketime cell_id-min(cell_id) 806 796 for line in lines: 807 797 line = line.rstrip() … … 809 799 if (len(single_line) > 1) and (single_line[1] != '-'): 810 800 neuron = int(single_line[0]) - padding 811 result.write("%s\t%d\n" %(single_line[1], neuron))812 else:801 result.write("%s\t%d\n" %(single_line[1], neuron)) 802 else: 813 803 f = open(tempfilename.replace('/','_'),'r',1) 814 lines = f.readlines()804 lines = f.readlines() 815 805 f.close() 816 806 for line in lines: branches/0.3/neuron.py
r48 r54 62 62 # creation of networks 63 63 def setHocName(self, name): 64 self._hocname = name64 self._hocname = name 65 65 66 66 def getHocName(self): 67 return self._hocname67 return self._hocname 68 68 69 69 … … 208 208 errorstr = '"raise HocError(\'caused by HocToPy.get(%s,return_type=\\"%s\\")\')"' % (name,return_type) 209 209 hoc_commands = ['success = sprint(cmd,"HocToPy.hocvar = %s",%s)' % (HocToPy.fmt_dict[return_type],name), 210 'if (success) { nrnpython(cmd) } else { nrnpython(%s) }' % errorstr ]210 'if (success) { nrnpython(cmd) } else { nrnpython(%s) }' % errorstr ] 211 211 hoc_execute(hoc_commands) 212 212 return HocToPy.hocvar … … 343 343 # ============================================================================== 344 344 345 def setup(timestep=0.1,min_delay=0.1,max_delay=0.1,debug=False): 346 """Should be called at the very beginning of a script.""" 345 def setup(timestep=0.1,min_delay=0.1,max_delay=0.1,debug=False,**extra_params): 346 """ 347 Should be called at the very beginning of a script. 348 extra_params contains any keyword arguments that are required by a given 349 simulator but not by others. 350 """ 347 351 global dt, nhost, myid, _min_delay, logger 348 352 dt = timestep … … 486 490 both be individual cells or lists of cells, in which case all possible 487 491 connections are made with probability p, using either the random number 488 generator supplied, or the default rng otherwise.""" 492 generator supplied, or the default rng otherwise. 493 Weights should be in nA or uS.""" 489 494 global ncid, gid, gidlist, _min_delay 490 495 if type(source) != types.ListType: … … 960 965 if gather: 961 966 hoc_commands += ['objref gatheredvec'] 962 padding = self.fullgidlist[0]967 padding = self.fullgidlist[0] 963 968 for id in self.record_from[print_what]: 964 969 addr = self.locate(id) 965 970 #hoc_commands += ['fmt = "%s\\t%s\\n"' % (num_format, "\\t".join([str(j) for j in addr]))] 966 hoc_commands += ['fmt = "%s\\t%d\\n"' % (num_format, id-padding)]971 hoc_commands += ['fmt = "%s\\t%d\\n"' % (num_format, id-padding)] 967 972 if id in self.gidlist: 968 973 hoc_commands += ['tmp = %s.object(%d).%s.printf(fileobj,fmt)' % (self.label,self.gidlist.index(id),print_what)] … … 976 981 def printSpikes(self,filename,gather=True, compatible_output=True): 977 982 """ 978 Prints spike times to file in the two-column format 979 "spiketime cell_id" where cell_id is the index of the cell counting 980 along rows and down columns (and the extension of that for 3-D). 983 Writes spike times to file. 984 If compatible_output is True, the format is "spiketime cell_id", 985 where cell_id is the index of the cell counting along rows and down 986 columns (and the extension of that for 3-D). 981 987 This allows easy plotting of a `raster' plot of spiketimes, with one 982 line for each cell. This method requires that the cell class records 983 spikes in a vector spiketimes. 988 line for each cell. 989 The timestep and number of data points per cell is written as a header, 990 indicated by a '#' at the beginning of the line. 991 992 If compatible_output is False, the raw format produced by the simulator 993 is used. This may be faster, since it avoids any post-processing of the 994 spike files. 995 984 996 If gather is True, the file will only be created on the master node, 985 997 otherwise, a file will be written on each node. 986 """ 998 """ 987 999 hoc_comment("--- Population[%s].__printSpikes()__ ---" %self.label) 988 header = "# %d" %self.dim[0]989 for dimension in list(self.dim)[1:]:990 header = "%s\t%d" %(header,dimension)1000 header = "# %d" %self.dim[0] 1001 for dimension in list(self.dim)[1:]: 1002 header = "%s\t%d" %(header,dimension) 991 1003 self.__print('spiketimes',filename,"%.2f",gather, header) 992 1004 … … 994 1006 """ 995 1007 Write membrane potential traces to file. 1008 If compatible_output is True, the format is "v cell_id", 1009 where cell_id is the index of the cell counting along rows and down 1010 columns (and the extension of that for 3-D). 1011 This allows easy plotting of a `raster' plot of spiketimes, with one 1012 line for each cell. 1013 The timestep and number of data points per cell is written as a header, 1014 indicated by a '#' at the beginning of the line. 1015 1016 If compatible_output is False, the raw format produced by the simulator 1017 is used. This may be faster, since it avoids any post-processing of the 1018 voltage files. 996 1019 """ 997 1020 tstop = HocToPy.get('tstop','float') … … 999 1022 header = "%s# %d" %(header,self.dim[0]) 1000 1023 for dimension in list(self.dim)[1:]: 1001 header = "%s\t%d" %(header,dimension)1024 header = "%s\t%d" %(header,dimension) 1002 1025 hoc_comment("--- Population[%s].__print_v()__ ---" %self.label) 1003 1026 self.__print('vtrace',filename,"%.4g",gather,header) branches/0.3/oldneuron.py
r48 r54 335 335 # ============================================================================== 336 336 337 def setup(timestep=0.1,min_delay=0.1,max_delay=0.1,debug=False): 338 """Should be called at the very beginning of a script.""" 337 def setup(timestep=0.1,min_delay=0.1,max_delay=0.1,debug=False,**extra_params): 338 """ 339 Should be called at the very beginning of a script. 340 extra_params contains any keyword arguments that are required by a given 341 simulator but not by others. 342 """ 339 343 global logfile, dt, _min_delay 340 344 dt = timestep … … 355 359 return 0 356 360 357 def end( ):361 def end(compatible_output=True): 358 362 """Do any necessary cleaning up before exiting.""" 359 363 global logfile, vfilelist, spikefilelist … … 428 432 both be individual cells or lists of cells, in which case all possible 429 433 connections are made with probability p, using either the random number 430 generator supplied, or the default rng otherwise.""" 434 generator supplied, or the default rng otherwise. 435 Weights should be in nA or uS.""" 431 436 global hoc_netcons, _min_delay 432 437 if type(source) != types.ListType: … … 741 746 self.__record('_v',record_from,rng) 742 747 743 def printSpikes(self,filename,gather=True): 744 """ 745 Prints spike times to file in the two-column format 746 "spiketime cell_id" where cell_id is the index of the cell counting 747 along rows and down columns (and the extension of that for 3-D). 748 def printSpikes(self,filename,gather=True,compatible_output=True): 749 """ 750 Writes spike times to file. 751 If compatible_output is True, the format is "spiketime cell_id", 752 where cell_id is the index of the cell counting along rows and down 753 columns (and the extension of that for 3-D). 748 754 This allows easy plotting of a `raster' plot of spiketimes, with one 749 line for each cell. This method requires that the cell class records 750 spikes in a vector spiketimes. 751 """ 755 line for each cell. 756 The timestep and number of data points per cell is written as a header, 757 indicated by a '#' at the beginning of the line. 758 759 If compatible_output is False, the raw format produced by the simulator 760 is used. This may be faster, since it avoids any post-processing of the 761 spike files. 762 763 If gather is True, the file will only be created on the master node, 764 otherwise, a file will be written on each node. 765 """ 766 # Note that 'gather' has no effect, since this module is not 767 # parallelised. 752 768 hoc_commands = ['objref spikefile', 753 769 'spikefile = new File()', … … 776 792 self._tcall('memb_init',rvals) 777 793 778 def print_v(self,filename,gather=True ):794 def print_v(self,filename,gather=True,compatible_output=True): 779 795 """ 780 796 Write membrane potential traces to file. 797 If compatible_output is True, the format is "v cell_id", 798 where cell_id is the index of the cell counting along rows and down 799 columns (and the extension of that for 3-D). 800 This allows easy plotting of a `raster' plot of spiketimes, with one 801 line for each cell. 802 The timestep and number of data points per cell is written as a header, 803 indicated by a '#' at the beginning of the line. 804 805 If compatible_output is False, the raw format produced by the simulator 806 is used. This may be faster, since it avoids any post-processing of the 807 voltage files. 781 808 """ 782 809 hoc_commands = ['objref vfile', … … 1160 1187 1161 1188 # ============================================================================== 1162 branches/0.3/pcsim.py
r48 r54 19 19 import numpy 20 20 from pypcsim im
