Changeset 48

Show
Ignore:
Timestamp:
05/11/07 11:35:19 (2 years ago)
Author:
apdavison
Message:

Merged trunk changes r37:47 into pyNN-0.3 branch

Files:

Legend:

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

    r36 r48  
    149149 
    150150class IF_cond_alpha(StandardCellType): 
    151 #    """Leaky integrate and fire model with fixed threshold and alpha-function- 
    152 #    shaped post-synaptic conductance.""" 
    153 #     
     151    """Leaky integrate and fire model with fixed threshold and alpha-function- 
     152    shaped post-synaptic conductance.""" 
     153     
    154154    default_parameters = { 
    155155        'v_rest'     : -65.0,   # Resting membrane potential in mV.  
     
    218218    both be individual cells or lists of cells, in which case all possible 
    219219    connections are made with probability p, using either the random number 
    220     generator supplied, or the default rng otherwise.""" 
     220    generator supplied, or the default rng otherwise. 
     221    Weights should be in nA or uS.""" 
    221222    pass 
    222223 
  • branches/0.3/doc/lowlevelapi.txt

    r29 r48  
    22Neurons and Connections 
    33======================= 
     4 
     5Initialising the simulator 
     6========================== 
     7 
     8Before using any other functions or classes from PyNN, the user must call the ``setup()`` function:: 
     9 
     10    >>> setup() 
     11     
     12``setup()`` takes various optional arguments: setting the simulation timestep (there is currently no support in the API for variable timestep methods although native simulator code can be used to select this option where the simulator supports it), setting the minimum and maximum synaptic delays, and turning debugging output on and off, e.g.:: 
     13 
     14    >>> setup(timestep=0.1, min_delay=0.1, max_delay=0.1, debug=False) 
     15     
     16Debugging information is written to a log file in the working directory. 
    417 
    518Creating neurons 
     
    5568    >>> connect(spike_source, cells) 
    5669     
    57 In this case we connect a spike-generating mechanism (``SpikeSourceArray`` is a 'standard cell' model that emits spikes at times specified by the ``spiketimes`` parameter) to each cell in the list ``cells`, i.e. we create 10 connections at once. 
     70In this case we connect a spike-generating mechanism (``SpikeSourceArray`` is a 'standard cell' model that emits spikes at times specified by the ``spiketimes`` parameter) to each cell in the list ``cells``, i.e. we create 10 connections at once. 
    5871For clarity, we could also have specified the argument names:: 
    5972 
     
    110123Recording spikes and membrane potential 
    111124======================================= 
     125 
     126To record action potentials use the ``record()`` function and to record membrane potential use the ``record_v()`` function. 
     127The arguments for both functions are a cell id or list of ids, and a filename, e.g.:: 
     128 
     129    >>> record(cell, "spikes.dat") 
     130    >>> record_v(cell_list, "allspikes.dat") 
     131     
     132By default, all simulators write data files in the same format. 
     133 
     134The beginning of a typical spike file looks like:: 
     135 
     136    # dt = 0.1 
     137    # n = 1000 
     138    0.0     2 
     139    0.3     5 
     140    0.4     3 
     141    0.9     2 
     142    1.0     1 
     143    . . . 
     144     
     145The beginning of a typical membrane potential file looks like:: 
     146 
     147    # dt = 0.1 
     148    # n = 1000 
     149    -65.0   0 
     150    -64.9   0 
     151    -64.7   0 
     152    -64.5   0 
     153    . . . 
     154 
     155Both file types begin with header lines giving the timestep (there is currently no support for variable-time step recording) and the number of data points [per cell or total?] in the file. 
     156Each line of the spike file then gives the occurence time of a spike (in ms) and the id of the neuron in which it was recorded. 
     157Each line of the membrane potential file gives the membrane potential (in mV) followed by the id of the neuron in which it was recorded. 
     158In both cases, whether the file is sorted by cell id or by time depends on the simulator: it is not standardised. 
     159 
     160In some cases it is more efficient to write files in the simulator's native format, rather than the standard PyNN format. 
     161In this case, use the ``compatible_output=False`` argument to the ``end()`` function. 
     162 
     163Considerable enhancements to file formats are planned for future releases of PyNN, including recording to binary (HDF5) rather than text files, support for variable time-step recording, and user-specified output formats. 
     164 
     165Running a simulation 
     166==================== 
     167 
     168The ``run()`` function runs the simulation for a given number of milliseconds, e.g.:: 
     169 
     170    >>> run(1000.0) 
     171     
     172Finishing up 
     173============ 
     174 
     175Just as a simulation must be begun with a call to ``setup()``, it must be ended with a call to ``end()``. 
     176 
     177Example 
     178======= 
     179 
     180We now give a full example of a PyNN simulation script:: 
     181 
     182    from pyNN.nest import * 
     183     
     184    <insert IF_curr_alpha.py here (with line numbers?)> 
     185     
     186To run the script with NEURON, replace the first line with:: 
     187 
     188    from pyNN.neuron import * 
     189     
     190and to run the script with PCSIM:: 
     191 
     192    from pyNN.pcsim import * 
     193     
  • branches/0.3/doc/standardmodels.txt

    r28 r48  
    22Standard models 
    33=============== 
     4 
     5Standard models are neuron models that are available in at least two of the simulation engines supported by PyNN. 
     6PyNN performs automatic translation of parameter names, types and units. 
     7Only a handful of models are currently available, but the list will be expanded in future releases. 
     8 
     9Integrate-and-fire neurons 
     10========================== 
     11 
     12IF_curr_alpha 
     13------------- 
     14 
     15Leaky integrate and fire model with fixed threshold and alpha-function-shaped post-synaptic current. 
     16 
     17Availability: NEST, NEURON, PCSIM 
     18 
     19==============  =============  =====  ======================================== 
     20Name            Default value  Units  Description 
     21==============  =============  =====  ======================================== 
     22``v_rest``      -65.0          mV     Resting membrane potential  
     23``cm``            1.0          nF     Capacity of the membrane 
     24``tau_m``        20.0          ms     Membrane time constant 
     25``tau_refrac``    0.0          ms     Duration of refractory period 
     26``tau_syn``       5.0          ms     Rise time of the synaptic alpha function 
     27``i_offset``      0.0          nA     Offset current 
     28``v_reset``     -65.0          mV     Reset potential after a spike 
     29``v_thresh``    -50.0          mV     Spike threshold 
     30``v_init``      -65.0          mV     Membrane potential at ``t`` = 0 
     31==============  =============  =====  ======================================== 
     32 
     33 
     34IF_curr_exp 
     35----------- 
     36 
     37Leaky integrate and fire model with fixed threshold and decaying-exponential post-synaptic current. 
     38(Separate synaptic currents for excitatory and inhibitory synapses. 
     39     
     40Availability: NEST, NEURON, PCSIM 
     41     
     42==============  =============  =====  ========================================= 
     43Name            Default value  Units  Description 
     44==============  =============  =====  ========================================= 
     45``v_rest``      -65.0          mV     Resting membrane potential 
     46``cm``            1.0          nF     Capacity of the membrane 
     47``tau_m``        20.0          ms     Membrane time constant 
     48``tau_refrac``    0.0          ms     Duration of refractory period 
     49``tau_syn_E``     5.0          ms     Decay time of excitatory synaptic current 
     50``tau_syn_I``     5.0          ms     Decay time of inhibitory synaptic current 
     51``i_offset``      0.0          nA     Offset current 
     52``v_reset``     -65.0          mV     Reset potential after a spike 
     53``v_thresh``    -50.0          mV     Spike threshold 
     54``v_init``      -65.0          mV     Membrane potential ``t`` = 0 
     55==============  =============  =====  ========================================= 
     56 
     57 
     58IF_cond_alpha 
     59_____________ 
     60 
     61Leaky integrate and fire model with fixed threshold and alpha-function-shaped post-synaptic conductance. 
     62 
     63Availability: NEST, NEURON, PCSIM 
     64 
     65==============  =============  =====  =================================================== 
     66Name            Default value  Units  Description 
     67==============  =============  =====  =================================================== 
     68``v_rest``      -65.0          mV     Resting membrane potential  
     69``cm``            1.0          nF     Capacity of the membrane 
     70``tau_m``        20.0          ms     Membrane time constant 
     71``tau_refrac``    0.0          ms     Duration of refractory period 
     72``tau_syn_E``     5.0          ms     Rise time of the excitatory synaptic alpha function 
     73``tau_syn_I``     5.0          ms     Rise time of the inhibitory synaptic alpha function 
     74``e_rev_E``       0.0          mV     Reversal potential for excitatory input 
     75``e_rev_I``     -70.0          mV     Reversal potential for inhibitory input 
     76``v_thresh``    -50.0          mV     Spike threshold 
     77``v_reset``     -65.0          mV     Reset potential after a spike 
     78``i_offset``      0.0          nA     Offset current 
     79``v_init``      -65.0          mV     Membrane potential at ``t`` = 0 
     80==============  =============  =====  =================================================== 
     81 
     82 
     83 
     84Spike sources 
     85============= 
     86 
     87SpikeSourcePoisson 
     88------------------ 
     89 
     90Spike source, generating spikes according to a Poisson process. 
     91 
     92Availability: NEST, NEURON, PCSIM 
     93[note problems with this in NEST] 
     94 
     95============  =============  ======  ========================== 
     96Name          Default value  Units   Description 
     97============  =============  ======  ========================== 
     98``rate`       0.0            s^`-1`  Mean spike frequency 
     99``start``     0.0            ms      Start time 
     100``duration``  10^9           ms      Duration of spike sequence 
     101============  =============  ======  ========================== 
     102 
     103 
     104SpikeSourceArray 
     105---------------- 
     106Spike source generating spikes at the times given in the ``spike_times`` array. 
     107 
     108Availability: NEST, NEURON, PCSIM 
     109 
     110===============  =============  ======  ========================== 
     111Name             Default value  Units   Description 
     112===============  =============  ======  ========================== 
     113``spike_times``  ``[]``         ms      list or numpy array containing spike times 
     114===============  =============  ======  ========================== 
  • branches/0.3/facetsml.py

    r5 r48  
    55 
    66import common 
    7 import numpy, types, sys, shutil 
     7#import numpy, types, sys, shutil 
    88import RandomArray 
     9from xml.dom import * 
     10from xml.dom.minidom import * 
     11from xml.dom.ext import * 
     12 
    913         
    1014open_files = [] 
    1115 
    1216dt = 0.1 
     17xmldoc = Document() 
     18 
     19""" 
     20warning : 
     21    in order to write xml in a format which respects the namespaces, you must use xml.dom.ext.PrettyPrint 
     22namespaces allowed are : 
     23        neuromlNode.setAttribute('xmlns:net','http://morphml.org/networkml/schema') 
     24        neuromlNode.setAttribute('xmlns:mml','http://morphml.org/morphml/schema') 
     25        neuromlNode.setAttribute('xmlns:meta','http://morphml.org/metadata/schema') 
     26        neuromlNode.setAttribute('xmlns:bio','http://morphml.org/biophysics/schema') 
     27        neuromlNode.setAttribute('xmlns:cml','http://morphml.org/channelml/schema') 
     28 
     29""" 
     30 
     31def initDocument(parentElementNS,parentElementName,prefix=''): 
     32    """ 
     33    create the root element <neuroml> if doesn't exist 
     34    and the specified parentElement just below <neuroml> if doesn't exist 
     35    returns the parentElement node 
     36    """ 
     37    neuromlNodes = xmldoc.getElementsByTagNameNS('http://morphml.org/neuroml/schema','neuroml') 
     38    #if the <neuroml> markup is not yet created 
     39    if(neuromlNodes.length == 0): 
     40        #seems createElementNS doesn't create the xmlns attribute 
     41        neuromlNode = xmldoc.createElementNS('http://morphml.org/neuroml/schema','neuroml') 
     42        xmldoc.appendChild(neuromlNode) 
     43    else: 
     44        neuromlNode = neuromlNodes[0] 
     45    parentElementNodes = neuromlNode.getElementsByTagNameNS(parentElementNS,parentElementName) 
     46    if(parentElementNodes.length == 0): 
     47        if(prefix == ''): 
     48            parentElementNode = xmldoc.createElementNS(parentElementNS,parentElementName) 
     49        else: 
     50            parentElementNode = xmldoc.createElementNS(parentElementNS,prefix + ":" + parentElementName) 
     51        neuromlNode.appendChild(parentElementNode) 
     52    else: 
     53        parentElementNode = parentElementNodes[0] 
     54    return parentElementNode 
    1355 
    1456 
     
    222264    nPop = 0 
    223265     
    224     def __init__(self,dims,celltype,cellparams=None,label=None): 
     266    def __init__(self,dims,cellclass,cellparams=None,label=None): 
    225267        """ 
    226268        dims should be a tuple containing the population dimensions, or a single 
     
    232274          constructor 
    233275        label is an optional name for the population. 
    234         """ 
    235          
    236         common.Population.__init__(self,dims,celltype,cellparams,label) 
     276     
     277    example of NeuroML (completeNetwork.xml with CellGroupC example added) : 
     278    <net:populations> 
     279        <net:population name="CellGroupA"> 
     280            <net:cell_type>CellA</net:cell_type> 
     281            <net:instances> 
     282                <net:instance id="0"><net:location x="0" y="0" z="0"/></net:instance> 
     283                <net:instance id="1"><net:location x="0" y="10" z="0"/></net:instance> 
     284                <net:instance id="2"><net:location x="0" y="20" z="0"/></net:instance> 
     285            </net:instances> 
     286        </net:population> 
     287        <net:population name="CellGroupB"> 
     288            <net:cell_type>CellA</net:cell_type> 
     289            <net:instances> 
     290                <net:instance id="0"><net:location x="0" y="100" z="0"/></net:instance> 
     291                <net:instance id="1"><net:location x="20" y="100" z="0"/></net:instance> 
     292            </net:instances> 
     293        </net:population> 
     294        <net:population name="CellGroupC"> 
     295            <net:cell_type>CellC</net:cell_type> 
     296            <net:pop_location reference="aeag"> 
     297                <net:grid_arrangement> 
     298                    <net:rectangular_location name="aefku"> 
     299                        <meta:corner x="0" y="0" z="0"/> 
     300                        <meta:size depth="10" height="100" width="100"/> 
     301                    </net:rectangular_location> 
     302                    <net:spacing x="10" y="10" z="10"/> 
     303                </net:grid_arrangement> 
     304            </net:pop_location> 
     305        </net:population> 
     306    </net:populations> 
     307     
     308     
     309     
     310        """ 
     311         
     312        common.Population.__init__(self,dims,cellclass,cellparams,label) 
    237313                      
    238         self.translate = getattr(StandardCells,self.celltype) # move this to common.Population.__init__()? 
    239314         
    240315        if not self.label: 
    241316            self.label = 'population%d' % Population.nPop 
    242              
    243         raise "Not yet implemented." 
     317     
     318     
     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): 
     328            self.celltype = cellclass(cellparams) 
     329            self.cellparams = self.celltype.parameters 
     330            hoc_name = self.celltype.hoc_name 
     331        elif isinstance(cellclass, str): # not a standard model 
     332            hoc_name = cellclass 
     333        #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     
     388        #raise "Not yet implemented." 
    244389         
    245390         
    246391        Population.nPop += 1 
     392    PrettyPrint(xmldoc) 
     393     
    247394         
    248395    def set(self,param,val): 
  • branches/0.3/hoc/standardCells.hoc

    r20 r48  
    3232  if ($o1.has_key("t_refrac")) { t_refrac = $o1.get("t_refrac") } else { t_refrac = 2 }      // (ms) 
    3333  if ($o1.has_key("i_offset")) { i_offset = $o1.get("i_offset") } else { i_offset = 0 }      // (nA) 
     34  if ($o1.has_key("v_init"))   { v_init   = $o1.get("v_init") }   else { v_init   = v_rest } // (mV) 
    3435  if ($o1.has_key("tau_syn"))  { 
    3536    tau_e = $o1.get("tau_syn") 
     
    4647    if ($o1.has_key("e_i"))    { e_i      = $o1.get("e_i") }      else { e_i      = -70 }    // (mV) 
    4748  } 
    48   v_init   = v_rest 
    4949  fih = new FInitializeHandler("memb_init()",this) 
    5050  fih2 = new FInitializeHandler("param_update()", this) 
  • branches/0.3/nest.py

    r34 r48  
    9797class IF_cond_alpha(common.IF_cond_alpha): 
    9898    """Leaky integrate and fire model with fixed threshold and alpha-function- 
    99     shaped post-synaptic current.""" 
     99    shaped post-synaptic conductance.""" 
    100100     
    101101    translations = { 
     
    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             'v_init'    : ('u'           , "parameters['v_init']"), 
    112111            'e_rev_E'   : ('V_reversal_E', "parameters['e_rev_E']"), 
    113112            'e_rev_I'   : ('V_reversal_I', "parameters['e_rev_I']"), 
     113            'v_init'    : ('u'           , "parameters['v_init']"), 
    114114    } 
    115115    nest_name = "iaf_cond_neuron" 
     
    265265                if p < 1: 
    266266                    if rng: # use the supplied RNG 
    267                         rarr = self.rng.uniform(0,1,len(target)) 
     267                        rarr = rng.rng.uniform(0,1,len(target)) 
    268268                    else:   # use the default RNG 
    269269                        rarr = numpy.random.uniform(0,1,len(target)) 
     
    376376            if (len(single_line) > 1) and (single_line[1] != '-'): 
    377377               neuron = int(single_line[0]) 
    378                result.write("%g\t%d\n" %(float(single_line[1]), neuron)) 
     378               result.write("%s\t%d\n" %(single_line[1], neuron)) 
    379379    else: 
    380380        f = open(tempfilename.replace('/','_'),'r',100) 
     
    456456            raise IndexError, 'Invalid cell address %s' % str(addr) 
    457457        return id 
     458     
     459    def __getitems__(self,addrs): 
     460        """Returns the ids of neurons. Input should have format: 
     461        n = number of synapses; nd = number of dimensions 
     462        shape(addrs) == (n,nd) 
     463        """ 
     464        #if isinstance(addr,int): 
     465        #    addr = (addr,) 
     466        ids = [] 
     467        if len(addrs[0]) == self.ndim: 
     468            for addr in range(len(addrs)): 
     469                try: 
     470                    ids.append(self.cell[tuple(addrs[addr,:])]) 
     471                except IndexError: 
     472                    pass                 
     473        else: 
     474            raise common.InvalidDimensionsError, "Population has %d dimensions. Address was %s" % (self.ndim,str(len(addrs))) 
     475        return ids 
     476 
     477         #   for syn_nr in range(len(target_position_x)): 
     478         #       try: 
     479         #           target_id.append(self.post[(target_position_x[syn_nr],target_position_y[syn_nr],target_position_z[syn_nr])]) 
     480         #       except IndexError: 
     481         #           target_id.append(False) 
     482 
    458483     
    459484    def __len__(self): 
     
    726751        random values. 
    727752        """ 
    728         cells = numpy.reshape(self.cell,self.cell.size) 
    729         rvals = rand_distr.next(n=self.cell.size) 
    730         for node, v_init in zip(cells,rvals): 
    731             pynest.setDict([node],{'u': v_init}) 
     753        self.rset('v_init',rand_distr) 
     754        #cells = numpy.reshape(self.cell,self.cell.size) 
     755        #rvals = rand_distr.next(n=self.cell.size) 
     756        #for node, v_init in zip(cells,rvals): 
     757        #    pynest.setDict([node],{'u': v_init}) 
    732758     
    733759    def print_v(self,filename,gather=True, compatible_output=True): 
     
    781807                line = line.rstrip() 
    782808                single_line = line.split("\t", 2) 
    783                 neuron = int(single_line[0]) - padding 
    784                 result.write("%s\t%d\n" %(single_line[1], neuron)) 
     809                if (len(single_line) > 1) and (single_line[1] != '-'): 
     810                    neuron = int(single_line[0]) - padding 
     811                    result.write("%s\t%d\n" %(single_line[1], neuron)) 
    785812        else: 
    786813            f = open(tempfilename.replace('/','_'),'r',1) 
     
    11661193        sigma: sigma of the Gauss 
    11671194        """ 
     1195 
     1196        #def get_ids(self,parameters): 
     1197            #ids = [] 
     1198            #if len(addrs) == self.ndim: 
     1199        # 
     1200        #for addr in range(len(parameters['x'])): 
     1201        #    try: 
     1202        #        ids = numpy.append(ids,post.cell[addr]) 
     1203        #    except IndexError: 
     1204        #        pass 
     1205        #else: 
     1206        #    raise common.InvalidDimensionsError, "Population has %d dimensions. Address was %s" % (self.ndim,str(addrs)) 
     1207        #return ids.astype('int') 
     1208 
    11681209         
    11691210        def rcf_3D(parameters): 
     
    11801221            r = rng.normal(scale=sigma,size=n) 
    11811222            # for z  
    1182             h = rng.uniform(size=n)*post_dim[2] 
    1183              
    1184             target_position_x = numpy.floor(pre_position[1]+r*numpy.cos(phi)) 
    1185             target_position_y = numpy.floor(pre_position[0]+r*numpy.sin(phi)) 
     1223            h = rng.uniform(size=n)*post_dim[2] # here post dim because it does not metter where it comes from in pre dim 
     1224             
     1225            target_position_x = numpy.floor(pre_position[1]+r*numpy.cos(phi)).astype('int') 
     1226            target_position_y = numpy.floor(pre_position[0]+r*numpy.sin(phi)).astype('int') 
    11861227            target_position_z = numpy.floor(h).astype('int') 
    11871228             
    11881229            target_id = [] 
     1230            # __getitems__ version 
     1231             
     1232             
    11891233            for syn_nr in range(len(target_position_x)): 
    11901234                try: 
    1191                     target_id.append(self.post[(target_position_x[syn_nr],target_position_y[syn_nr],target_position_z[syn_nr])]) 
     1235                    target_id.append(self.post.cell[(target_position_x[syn_nr],target_position_y[syn_nr],target_position_z[syn_nr])]) 
    11921236                except IndexError: 
    1193                     target_id.append(False) 
     1237                    pass 
     1238                    #target_id.append(False) 
    11941239             
    11951240            pynest.divConnect(pre_id,target_id,[weight],[delay]) 
  • branches/0.3/neuron.py

    r34 r48  
    149149    return hoc_commands, argstr.strip().strip(',') 
    150150 
    151 def _translate_synapse_type(synapse_type): 
     151def _translate_synapse_type(synapse_type,weight=None): 
     152    """ 
     153    If synapse_type is given (not None), it is used to determine whether the 
     154    synapse is excitatory or inhibitory. 
     155    Otherwise, the synapse type is inferred from the sign of the weight. 
     156    Much testing needed to check if this behaviour matches nest and pcsim. 
     157    """ 
     158     
    152159    if synapse_type: 
    153160        if synapse_type == 'excitatory': 
     
    161168            syn_objref = synapse_type 
    162169    else: 
    163         syn_objref = "esyn" 
     170        if weight is None or weight >= 0.0: 
     171            syn_objref = "esyn" 
     172        else: 
     173            syn_objref = "isyn" 
    164174    return syn_objref 
    165175 
     
    268278class IF_cond_alpha(common.IF_cond_alpha): 
    269279    """Leaky integrate and fire model with fixed threshold and alpha-function- 
    270     shaped post-synaptic current.""" 
     280    shaped post-synaptic conductance.""" 
    271281     
    272282    translations = { 
     
    484494    if weight is None:  weight = 0.0 
    485495    if delay  is None:  delay = _min_delay 
    486     syn_objref = _translate_synapse_type(synapse_type
     496    syn_objref = _translate_synapse_type(synapse_type,weight
    487497    nc_start = ncid 
    488498    hoc_commands = [] 
     
    562572    hoc_execute(hoc_commands, "--- set() ---") 
    563573 
    564 def record(source,filename, compatible_output=True): 
     574def record(source,filename): 
    565575    """Record spikes to a file. source can be an individual cell or a list of 
    566576    cells.""" 
     
    579589    hoc_execute(hoc_commands, "---record() ---") 
    580590 
    581 def record_v(source,filename, compatible_output=True): 
     591def record_v(source,filename): 
    582592    """ 
    583593    Record membrane potential to a file. source can be an individual cell or 
  • branches/0.3/oldneuron.py

    r34 r48  
    136136    return hoc_commands, argstr.strip().strip(',') 
    137137 
    138 def _translate_synapse_type(synapse_type): 
     138def _translate_synapse_type(synapse_type,weight=None): 
     139    """ 
     140    If synapse_type is given (not None), it is used to determine whether the 
     141    synapse is excitatory or inhibitory. 
     142    Otherwise, the synapse type is inferred from the sign of the weight. 
     143    Much testing needed to check if this behaviour matches nest and pcsim. 
     144    """ 
     145     
    139146    if synapse_type: 
    140147        if synapse_type == 'excitatory': 
     
    145152            # More sophisticated treatment needed once we have more sophisticated synapse 
    146153            # models, e.g. NMDA... 
    147             raise common.InvalidParameterValueError, synapse_type, "valid types are 'excitatory' or 'inhibitory'" 
     154            #raise common.InvalidParameterValueError, synapse_type, "valid types are 'excitatory' or 'inhibitory'" 
     155            syn_objref = synapse_type 
    148156    else: 
    149         syn_objref = "esyn" 
     157        if weight is None or weight >= 0.0: 
     158            syn_objref = "esyn" 
     159        else: 
     160            syn_objref = "isyn" 
    150161    return syn_objref 
    151162 
     
    259270class IF_cond_alpha(common.IF_cond_alpha): 
    260271    """Leaky integrate and fire model with fixed threshold and alpha-function- 
    261     shaped post-synaptic current.""" 
     272    shaped post-synaptic conductance.""" 
    262273     
    263274    translations = { 
     
    425436    if weight is None:  weight = 0.0 
    426437    if delay  is None:  delay = _min_delay 
    427     syn_objref = _translate_synapse_type(synapse_type
     438    syn_objref = _translate_synapse_type(synapse_type, weight
    428439    nc_start = hoc_netcons 
    429440    hoc_commands = [] 
  • branches/0.3/pcsim.py

    r36 r48  
    8585         
    8686class SpikesMultiChannelRecorder(object): 
    87     recordings = []   
     87    #recordings = []   
    8888     
    8989    def __init__(self, source, filename = None, source_indices = None, gather = False):         
     
    9898            Add celllist list to the list of the cells for which spikes  
    9999            are recorded by this spikes multi recorder 
    100         """         
     100        """ 
     101        if type(sources) != types.ListType: 
     102            sources = [sources] 
    101103        if not src_indices: 
    102104            src_indices = range(len(self.recordings), len(self.recordings) + len(sources)) 
     
    149151 
    150152class FieldMultiChannelRecorder: 
    151     recordings = []   
     153    #recordings = []   
    152154     
    153155    def __init__(self,sources,filename = None,src_indices = None, gather = False, fieldname = "Vm"):         
    154156        self.filename = filename 
    155157        self.fieldname = fieldname 
    156         self.gather = gather         
     158        self.gather = gather 
     159        self.recordings = [] 
    157160        self.record(sources, src_indices) 
    158161         
     
    162165            Add celllist to the list of the cells for which field values 
    163166            are recorded by this field multi recorder 
    164         """         
     167        """ 
     168        if type(sources) != types.ListType: 
     169            sources = [sources] 
    165170        if not src_indices: 
    166171            src_indices = range(len(self.recordings), len(self.recordings) + len(sources)) 
    167172        global pcsim_globals 
    168         if type(sources) != types.ListType: 
    169             sources = [sources]         
    170173        for i,src in zip(src_indices, sources): 
    171174            src_id = SimObject.ID(src) 
     
    174177            if (src_id.node == pcsim_globals.net.mpi_rank()): 
    175178                self.recordings += [ (i, rec, src) ] 
    176          
    177179                 
    178180    def saveValuesH5(self, filename = None): 
     
    188190        h5file.close() 
    189191         
    190     def saveValuesText(self, filename = None): 
     192    def saveValuesText(self, filename = None, compatible_output=True): 
    191193        if filename: 
    192194            self.filename = filename 
     
    195197        f = file(self.filename, "w") 
    196198        all_spikes = [] 
    197         for i, rec, src in self.recordings: 
    198             analog_values =  [i] +  pcsim_globals.net.object(rec).getRecordedValues()             
    199             for v in analog_values: 
    200                 f.write("%s " % v)                 
    201             f.write("\n") 
     199        if compatible_output: 
     200            f.write("# dt = %g\n" % pcsim_globals.dt) 
     201            f.write("# n = %d\n" % len(pcsim_globals.net.object(self.recordings[0][1]).getRecordedValues())) 
     202            for i, rec, src in self.recordings: 
     203                analog_values =  pcsim_globals.net.object(rec).getRecordedValues() 
     204                for v in analog_values: 
     205                    f.write("%g %d\n" % (float(v)*1000.0,i)) # convert from mV to V 
     206             
     207        else: 
     208            for i, rec, src in self.recordings: 
     209                analog_values =  [i] +  pcsim_globals.net.object(rec).getRecordedValues() 
     210                for v in analog_values: 
     211                    f.write("%s " % v)                 
     212                f.write("\n") 
    202213        f.close() 
    203214 
     
    211222     
    212223    translations = {         
    213         'tau_m'     : ('taum'    , "parameters['tau_m']" ) , 
    214         'cm'        : ('Cm'      , "parameters['cm']"),  
    215         'v_rest'    : ('Vresting', "parameters['v_rest']"),  
    216         'v_thresh'  : ('Vthresh' , "parameters['v_thresh']"),  
    217         'v_reset'   : ('Vreset'  , "parameters['v_reset']"),  
    218         'tau_refrac': ('Trefract', "parameters['tau_refrac']"),  
    219         'i_offset'  : ('Iinject' , "parameters['i_offset']"),          
    220         'tau_syn'   : ('TauSyn'  , "parameters['tau_syn']"),  
    221         'v_init'    : ('Vinit'   , "parameters['v_init']")  
     224        'tau_m'     : ('taum'    , "parameters['tau_m']*1e-3" ) , 
     225        'cm'        : ('Cm'      , "parameters['cm']*1e-9"),  
     226        'v_rest'    : ('Vresting', "parameters['v_rest']*1e-3"),  
     227        'v_thresh'  : ('Vthresh' , "parameters['v_thresh']*1e-3"),  
     228        'v_reset'   : ('Vreset'  , "parameters['v_reset']*1e-3"),  
     229        'tau_refrac': ('Trefract', "parameters['tau_refrac']*1e-3"),  
     230        'i_offset'  : ('Iinject' , "parameters['i_offset']*1e-9"),          
     231        'tau_syn'   : ('TauSyn'  , "parameters['tau_syn']*1e-3"),  
     232        'v_init'    : ('Vinit'   , "parameters['v_init']*1e-3")  
    222233    } 
    223234    pcsim_name = "LIFCurrAlphaNeuron"     
     
    232243                                                Cm       = self.parameters['Cm'],  
    233244                                                Vresting = self.parameters['Vresting'],  
    234                                                 Vthresh  = self.parameters['Vthresh'],  
     245                                                Vthresh  = self.parameters['Vthresh'], 
     246                                                Vreset   = self.parameters['Vreset'], 
    235247                                                Trefract = self.parameters['Trefract'],  
    236248                                                Iinject  = self.parameters['Iinject'],  
     
    247259     
    248260    translations = { 
    249         'tau_m'     : ('taum'   , "parameters['tau_m']"),  
    250         'cm'        : ('Cm'      , "parameters['cm']"), 
    251         'v_rest'    : ('Vresting', "parameters['v_rest']"),  
    252         'v_thresh'  : ('Vthresh' , "parameters['v_thresh']"),  
    253         'v_reset'   : ('Vreset'  , "parameters['v_reset']"),  
    254         'tau_refrac': ('Trefract', "parameters['tau_refrac']"),  
    255         'i_offset'  : ('Iinject' , "parameters['i_offset']"),  
    256         'v_init'    : ('Vinit'   , "parameters['v_init']"),  
    257         'tau_syn_E' : ('TauSynExc', "parameters['tau_syn_E']"),  
    258         'tau_syn_I' : ('TauSynInh', "parameters['tau_syn_I']"),  
     261        'tau_m'     : ('taum'   , "parameters['tau_m']*1e-3"),  
     262        'cm'        : ('Cm'      , "parameters['cm']*1e-9"), 
     263        'v_rest'    : ('Vresting', "parameters['v_rest']*1e-3"),  
     264        'v_thresh'  : ('Vthresh' , "parameters['v_thresh']*1e-3"),  
     265        'v_reset'   : ('Vreset'  , "parameters['v_reset']*1e-3"),  
     266        'tau_refrac': ('Trefract', "parameters['tau_refrac']*1e-3"),  
     267        'i_offset'  : ('Iinject' , "parameters['i_offset']*1e-9"), # i_offset in nA, Iinject in A  
     268        'v_init'    : ('Vinit'   , "parameters['v_init']*1e-3"),  
     269        'tau_syn_E' : ('TauSynExc', "parameters['tau_syn_E']*1e-3"),  
     270        'tau_syn_I' : ('TauSynInh', "parameters['tau_syn_I']*1e-3"),  
    259271    } 
    260272     
     
    269281        self.simObjFactory = LIFCurrExpNeuron(taum     = self.parameters['taum'],  
    270282                                              Cm       = self.parameters['Cm'],  
    271                                               Vresting = self.parameters['Vresting'],  
     283                                              Vresting = self.parameters['Vresting'], 
     284                                              Vreset   = self.parameters['Vreset'], 
    272285                                              Vthresh  = self.parameters['Vthresh'],  
    273286                                              Trefract = self.parameters['Trefract'],  
     
    278291                                              TauSynInh = self.parameters['TauSynInh']) 
    279292 
     293 
     294#class IF_cond_alpha(common.IF_cond_alpha): 
     295#    """Leaky integrate and fire model with fixed threshold and alpha-function- 
     296#    shaped post-synaptic conductance.""" 
     297#     
     298#    translations = {         
     299#        'tau_m'     : ('taum',      "parameters['tau_m']*1e-3" ) , 
     300#        'cm'        : ('Cm',        "parameters['cm']*1e-9"),  
     301#        'v_rest'    : ('Vresting',  "parameters['v_rest']*1e-3"),  
     302#        'v_thresh'  : ('Vthresh',   "parameters['v_thresh']*1e-3"),  
     303#        'v_reset'   : ('Vreset',    "parameters['v_reset']*1e-3"),  
     304#        'tau_refrac': ('Trefract',  "parameters['tau_refrac']*1e-3"),  
     305#        'i_offset'  : ('Iinject',   "parameters['i_offset']*1e-9"),          
     306#        'tau_syn_E' : ('TauSynExc', "parameters['tau_syn_E']*1e-3"), 
     307#        'tau_syn_I' : ('TauSynInh', "parameters['tau_syn_I']*1e-3"), 
     308#        'e_rev_E'   : ('ErevExc',   "parameters['e_rev_E']*1e-3"), 
     309#        'e_rev_I'   : ('ErevInh',   "parameters['e_rev_I']*1e-3"), 
     310#        'v_init'    : ('Vinit',     "parameters['v_init']*1e-3"),  
     311#    } 
     312#     
     313#    pcsim_name = "LIFCondAlphaNeuron"     
     314#    simObjFactory = None 
     315#     
     316#         
     317#    def __init__(self, parameters): 
     318#        common.IF_cond_alpha.__init__(self, parameters) # checks supplied parameters and adds default                                               # values for not-specified parameters. 
     319#        self.parameters = self.translate(self.parameters)                 
     320#        self.parameters['Inoise'] = 0.0 
     321#        self.simObjFactory = LIFCondAlphaNeuron(taum      = self.parameters['taum'],  
     322#                                                Cm        = self.parameters['Cm'],  
     323#                                                Vresting  = self.parameters['Vresting'],  
     324#                                                Vthresh   = self.parameters['Vthresh'], 
     325#                                                Vreset    = self.parameters['Vreset'], 
     326#                                                Trefract  = self.parameters['Trefract'],  
     327#