Changeset 5

Show
Ignore:
Timestamp:
05/02/07 10:41:50 (5 years ago)
Author:
JensKremkow
Message:
 
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/sandbox.py

    r4 r5  
    4949    return tmpdict 
    5050 
     51 
     52 
     53def get_connectivity(params): 
     54    """ 
     55     
     56    """ 
     57    a = params['a'] 
     58    radius = params['radius'] 
     59    radius_normalized = radius/a # when a is   
     60    population = params['population'] 
     61 
     62    center = (int(population.dim[0]/2.),int(population.dim[1]/2.)) 
     63    offset = (int(round(population.dim[0]*radius_normalized)),int(round(population.dim[1]*radius_normalized))) 
     64     
     65    targets={} 
     66    targets_gid={} 
     67    for n in range(center[0]-offset[0],center[0]+offset[0]+1): 
     68        for m in range(center[1]-offset[1],center[1]+offset[1]+1): 
     69            #print 'n: ',n, ' m: ',m 
     70            gid = population[n,m] 
     71            targets_tmp = pynest.getDict([gid])[0]['targets'] 
     72            targets_n_m = [] 
     73            for tgid in targets_tmp: 
     74                targets_n_m.append(population.locate(tgid)) 
     75             
     76            targets[(n,m)]=targets_n_m 
     77            targets_gid[gid]=targets_tmp 
     78    return targets, targets_n_m 
     79     
     80     
     81     
     82 
     83 
     84 
    5185""" 
    5286SpikeLists functions 
    5387 
    5488""" 
    55  
    5689def tmpfile2spikelist(filename,dt): 
    5790    """ 
     
    82115    return spike_list 
    83116 
     117# we need that for the hardware stuff, since printspike does not yet exist in the low-level api. and therefore the spiketrains are in the old format. 
     118def tmpfile2spikelist_old(filename): 
     119    """ returns a spike list from the tmp file saved by PyNN-NEST 
     120    the spike list is according to latest standards a list of tuples (relative time 
     121    of spike, neuron_id); both are integers the time is obtained""" 
     122    from numpy import * 
     123    from pylab import load 
     124    import os 
     125     
     126 
     127    spike_list = [] 
     128 
     129    if os.path.getsize(filename) > 0: # check that the size is not zero which raises an error in load 
     130        #DATA = load(filename) # TODO: replace with scipy function (fragile if spike list is empty) 
     131        neuron_id, spike_time = load(filename, usecols=(1,2), unpack=True) 
     132 
     133        spike_list=[] 
     134 
     135        if size(neuron_id) >1: 
     136            # TODO : does not work with one spike. therefore this stupid if 
     137            neuron_id = array([int(k) for k in neuron_id]) 
     138            spike_time = array([int(k) for k in spike_time]) 
     139            rel_spiketime = concatenate(([spike_time[0]] , spike_time[1:]-spike_time[:-1])) 
     140 
     141            for index in range(len(neuron_id)): 
     142                spike_list.append( (rel_spiketime[index], neuron_id[index]) ) 
     143 
     144        else: 
     145            spike_list.append( (spike_time, neuron_id) ) 
    84146 
    85147 
     148    return spike_list 
    86149 
    87150