Changeset 54

Show
Ignore:
Timestamp:
05/11/07 16:00:49 (2 years ago)
Author:
apdavison
Message:

Merged trunk changes r48:53 into pyNN-0.3 branch

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/0.3/common.py

    r48 r54  
    186186# ============================================================================== 
    187187 
    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.""" 
     188def 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    """ 
    190194    dt = timestep 
    191195    pass 
     
    365369    def printSpikes(self,filename,gather=True, compatible_output=True): 
    366370        """ 
    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). 
    370375        This allows easy plotting of a `raster' plot of spiketimes, with one 
    371376        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        """         
    378387        pass 
    379388     
     
    381390        """ 
    382391        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. 
    383403        """ 
    384404        pass 
  • branches/0.3/facetsml.py

    r48 r54  
    3838    #if the <neuroml> markup is not yet created 
    3939    if(neuromlNodes.length == 0): 
    40         #seems createElementNS doesn't create the xmlns attribut
     40        #neuroml has no prefix, namespace http://morphml.org/neuroml/schema is the default on
    4141        neuromlNode = xmldoc.createElementNS('http://morphml.org/neuroml/schema','neuroml') 
    4242        xmldoc.appendChild(neuromlNode) 
     
    4444        neuromlNode = neuromlNodes[0] 
    4545    parentElementNodes = neuromlNode.getElementsByTagNameNS(parentElementNS,parentElementName) 
     46    #if the <parentElementName> markup is not yet created 
    4647    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  
    4750        if(prefix == ''): 
    4851            parentElementNode = xmldoc.createElementNS(parentElementNS,parentElementName) 
     
    5356        parentElementNode = parentElementNodes[0] 
    5457    return parentElementNode 
     58 
     59def 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     
    5567 
    5668 
     
    306318    </net:populations> 
    307319     
    308      
    309      
    310320        """ 
    311321         
     
    317327     
    318328     
    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.py 
    327     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): 
    328338            self.celltype = cellclass(cellparams) 
    329339            self.cellparams = self.celltype.parameters 
     
    332342            hoc_name = cellclass 
    333343        #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         
    388397        #raise "Not yet implemented." 
    389398         
    390399         
    391400        Population.nPop += 1 
    392     PrettyPrint(xmldoc) 
     401        PrettyPrint(xmldoc) 
    393402     
    394403         
     
    515524        than within methodParameters, particularly since some methods also use 
    516525        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> 
    517567        """ 
    518568        common.Projection.__init__(self,presynaptic_population,postsynaptic_population,method,methodParameters,source,target,label,rng) 
     
    520570        self._targets = [] 
    521571        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         
    524651         
    525652    # --- Connection methods --------------------------------------------------- 
  • branches/0.3/nest.py

    r48 r54  
    109109            'v_thresh'  : ('Theta'       , "parameters['v_thresh']"), 
    110110            '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']"), 
    112112            'e_rev_I'   : ('V_reversal_I', "parameters['e_rev_I']"), 
    113113            'v_init'    : ('u'           , "parameters['v_init']"), 
     
    154154# ============================================================================== 
    155155 
    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.""" 
     156def 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    """ 
    158162    if min_delay > max_delay: 
    159163        raise Exception("min_delay has to be less than or equal to max_delay.") 
     
    244248    both be individual cells or lists of cells, in which case all possible 
    245249    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.""" 
    247252    global dt 
    248253    if weight is None: 
     
    332337    pynest.sr('%s close' %tempfilename)  
    333338    if (compatible_output): 
    334        # Here we postprocess the file to have effectively the 
     339        # Here we postprocess the file to have effectively the 
    335340        # desired format : 
    336        # First line: # dimensions of the population 
    337        # 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) 
    338343        result = open(filename,'w',100) 
    339344        g = open(tempfilename,'r',100) 
     
    344349            neuron = int(single_line[0][1:len(single_line[0])]) 
    345350            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)) 
    347352        result.close() 
    348353    else: 
     
    364369    if (compatible_output): 
    365370        f = open(tempfilename.replace('/','_'),'r',100) 
    366        lines = f.readlines() 
     371        lines = f.readlines() 
    367372        f.close() 
    368373 
    369        # Here we postprocess the file to have effectively the 
     374        # Here we postprocess the file to have effectively the 
    370375        # desired format : 
    371        # First line: dimensions of the population 
    372        # Then spiketime cell_id-min(cell_id) 
     376        # First line: dimensions of the population 
     377        # Then spiketime cell_id-min(cell_id) 
    373378        for line in lines: 
    374379            line = line.rstrip() 
     
    376381            if (len(single_line) > 1) and (single_line[1] != '-'): 
    377382               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)) 
    379384    else: 
    380385        f = open(tempfilename.replace('/','_'),'r',100) 
    381        lines = f.readlines() 
     386        lines = f.readlines() 
    382387        f.close() 
    383388        for line in lines: 
     
    620625                                            'withpath':True}) # record which neuron spiked 
    621626         
    622        fixed_list = False 
     627        fixed_list = False 
    623628 
    624629        if record_from: 
    625630            if type(record_from) == types.ListType: 
    626                fixed_list = True 
    627                n_rec = len(record_from) 
     631                fixed_list = True 
     632                n_rec = len(record_from) 
    628633            elif type(record_from) == types.IntType: 
    629634                n_rec = record_from 
     
    634639        pynest.resCons(self.spike_detector[0],n_rec) 
    635640 
    636        if (fixed_list == True): 
    637            for neuron in record_from: 
     641        if (fixed_list == True): 
     642            for neuron in record_from: 
    638643                pynest.connect(pynest.getAddress(neuron),self.spike_detector[0]) 
    639644        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]: 
    641646                pynest.connect(pynest.getAddress(neuron),self.spike_detector[0]) 
    642                  
    643        # Open temporary output file & register file with detectors 
     647                 
     648        # Open temporary output file & register file with detectors 
    644649        # This should be redone now that Eilif has implemented the pythondatum datum type 
    645650        # pynest.sr('/tmpfile_%s (tmpfile_%s) (w) file def' % (self.label,self.label)) # old 
     
    658663        """ 
    659664        global hl_v_files 
    660          
    661        fixed_list = False 
    662          
    663        fixed_list = False 
     665         
     666        fixed_list = False 
     667         
     668        fixed_list = False 
    664669        if record_from: 
    665670            if type(record_from) == types.ListType: 
    666                fixed_list = True 
     671                fixed_list = True 
    667672                n_rec = len(record_from) 
    668673            elif type(record_from) == types.IntType: 
     
    673678            n_rec = self.size 
    674679 
    675        tmp_list = [] 
     680        tmp_list = [] 
    676681        filename    = '%s.v' % self.label 
    677682        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)) 
    683688        hl_v_files.append(filename) 
    684689        pynest.record_v(tmp_list, record_file.replace('/','_')) 
     
    687692    def printSpikes(self,filename,gather=True, compatible_output=True): 
    688693        """ 
    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). 
    695698        This allows easy plotting of a `raster' plot of spiketimes, with one 
    696699        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        """         
    706710        global hl_spike_files 
    707711        tempfilename = '%s.spikes' % self.label 
     
    710714            pynest.sr('%s close' % tempfilename) 
    711715            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) 
    717719            result = open(filename,'w',1) 
    718720            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) 
    726725            padding = numpy.reshape(self.cell,self.cell.size)[0] 
    727726            lines = g.readlines() 
     
    731730                neuron = int(single_line[0][1:len(single_line[0])]) - padding 
    732731                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)) 
    734733            result.close() 
    735734        else: 
    736735            shutil.move(tempdir+'/'+tempfilename,filename) 
    737          
     736         
    738737 
    739738    def meanSpikeCount(self,gather=True): 
     
    760759        """ 
    761760        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. 
    779772        """ 
    780773        global hl_v_files 
    781          
    782        tempfilename = tempdir+'/'+'%s.v' % self.label 
     774         
     775        tempfilename = tempdir+'/'+'%s.v' % self.label 
    783776        if hl_v_files.__contains__(tempfilename): 
    784777            pynest.sr('%s close' % tempfilename.replace('/','_')) 
    785778            hl_v_files.remove(tempfilename) 
    786                  
    787        result = open(filename,'w',1) 
     779                 
     780        result = open(filename,'w',1) 
    788781        dt = pynest.getNESTStatus()['resolution'] 
    789782        n = int(pynest.getNESTStatus()['time']/dt) 
    790783        result.write("# dt = %f\n# n = %d\n" % (dt,n)) 
    791784 
    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() 
    795788            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") 
    800790            padding = numpy.reshape(self.cell,self.cell.size)[0] 
    801791 
    802            # Here we postprocess the file to have effectively the 
     792            # Here we postprocess the file to have effectively the 
    803793            # desired format : 
    804            # First line: dimensions of the population 
    805            # Then spiketime cell_id-min(cell_id) 
     794            # First line: dimensions of the population 
     795            # Then spiketime cell_id-min(cell_id) 
    806796            for line in lines: 
    807797                line = line.rstrip() 
     
    809799                if (len(single_line) > 1) and (single_line[1] != '-'): 
    810800                    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: 
    813803            f = open(tempfilename.replace('/','_'),'r',1) 
    814            lines = f.readlines() 
     804            lines = f.readlines() 
    815805            f.close() 
    816806            for line in lines: 
  • branches/0.3/neuron.py

    r48 r54  
    6262    # creation of networks 
    6363    def setHocName(self, name): 
    64        self._hocname = name 
     64        self._hocname = name 
    6565 
    6666    def getHocName(self): 
    67        return self._hocname 
     67        return self._hocname 
    6868     
    6969 
     
    208208        errorstr = '"raise HocError(\'caused by HocToPy.get(%s,return_type=\\"%s\\")\')"' % (name,return_type) 
    209209        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 ] 
    211211        hoc_execute(hoc_commands) 
    212212        return HocToPy.hocvar 
     
    343343# ============================================================================== 
    344344 
    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.""" 
     345def 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    """ 
    347351    global dt, nhost, myid, _min_delay, logger 
    348352    dt = timestep 
     
    486490    both be individual cells or lists of cells, in which case all possible 
    487491    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.""" 
    489494    global ncid, gid, gidlist, _min_delay 
    490495    if type(source) != types.ListType: 
     
    960965            if gather: 
    961966                hoc_commands += ['objref gatheredvec'] 
    962            padding = self.fullgidlist[0] 
     967            padding = self.fullgidlist[0] 
    963968            for id in self.record_from[print_what]: 
    964969                addr = self.locate(id) 
    965970                #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)] 
    967972                if id in self.gidlist: 
    968973                    hoc_commands += ['tmp = %s.object(%d).%s.printf(fileobj,fmt)' % (self.label,self.gidlist.index(id),print_what)] 
     
    976981    def printSpikes(self,filename,gather=True, compatible_output=True): 
    977982        """ 
    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). 
    981987        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         
    984996        If gather is True, the file will only be created on the master node, 
    985997        otherwise, a file will be written on each node. 
    986         """ 
     998        """         
    987999        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) 
    9911003        self.__print('spiketimes',filename,"%.2f",gather, header) 
    9921004 
     
    9941006        """ 
    9951007        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. 
    9961019        """ 
    9971020        tstop = HocToPy.get('tstop','float') 
     
    9991022        header = "%s# %d" %(header,self.dim[0]) 
    10001023        for dimension in list(self.dim)[1:]: 
    1001                header = "%s\t%d" %(header,dimension) 
     1024                header = "%s\t%d" %(header,dimension) 
    10021025        hoc_comment("--- Population[%s].__print_v()__ ---" %self.label) 
    10031026        self.__print('vtrace',filename,"%.4g",gather,header) 
  • branches/0.3/oldneuron.py

    r48 r54  
    335335# ============================================================================== 
    336336 
    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.""" 
     337def 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    """ 
    339343    global logfile, dt, _min_delay 
    340344    dt = timestep 
     
    355359    return 0 
    356360 
    357 def end(): 
     361def end(compatible_output=True): 
    358362    """Do any necessary cleaning up before exiting.""" 
    359363    global logfile, vfilelist, spikefilelist 
     
    428432    both be individual cells or lists of cells, in which case all possible 
    429433    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.""" 
    431436    global hoc_netcons, _min_delay 
    432437    if type(source) != types.ListType: 
     
    741746        self.__record('_v',record_from,rng) 
    742747         
    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). 
    748754        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. 
    752768        hoc_commands = ['objref spikefile', 
    753769                        'spikefile = new File()', 
     
    776792        self._tcall('memb_init',rvals) 
    777793         
    778     def print_v(self,filename,gather=True): 
     794    def print_v(self,filename,gather=True,compatible_output=True): 
    779795        """ 
    780796        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. 
    781808        """ 
    782809        hoc_commands = ['objref vfile', 
     
    11601187     
    11611188# ============================================================================== 
    1162      
  • branches/0.3/pcsim.py

    r48 r54  
    1919import numpy 
    2020from pypcsim im