Changeset 350

Show
Ignore:
Timestamp:
11/16/08 01:51:40 (2 months ago)
Author:
mschmucker
Message:

beautifying: adding more comments, adding more docstrings, adding axis labels
to the plots

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/examples/sfn2008/sfn_example_parameterspace.py

    r349 r350  
    44Example to show off some capabilities of the parameters module. 
    55 
    6 - creates a ParameterSpace of c and jitter for the example shown in sfn_example_stgen.py 
    7 - the parameters c and jitter are scanned and the cc and the corrcoef are calculated 
     6- creates a ParameterSpace of c and jitter for the example shown in  
     7  sfn_example_stgen.py 
     8- the parameters c and jitter are scanned and the cc and the corrcoef  
     9  are calculated 
    810- all the cc's are plotted 
    9 -  
    1011 
    1112Performed at the NeuroTools demo session, INCF booth,  
    1213SfN annual meeting 2008, Washington. DC. 
    1314""" 
     15import numpy, pylab 
     16 
    1417import NeuroTools.stgen as stgen 
    1518sg = stgen.StGen() 
    16 # function of the example in sfn_example_stgen.py 
     19 
     20from NeuroTools.parameters import ParameterSpace 
     21from NeuroTools.parameters import ParameterRange 
     22from NeuroTools.sandbox import make_name 
     23 
     24# creating a ParameterSpace 
     25p = ParameterSpace({}) 
     26 
     27# adding fixed parameters 
     28p.nu = 20. # rate [Hz] 
     29p.duration = 1000. 
     30 
     31# adding ParameterRanges 
     32p.c = ParameterRange([0.0,0.01,0.1,0.5]) 
     33p.jitter = ParameterRange([0.0,1.0,5.0,]) 
     34 
     35# calculation of the ParameterSpace dimension and the labels of the parameters 
     36# containing a range 
     37dims, labels = p.parameter_space_dimension_labels() 
     38print "dimensions: ", dims 
     39print ' labels: ', labels 
     40 
    1741def calc_cc(p): 
     42    """ 
     43    Generate correlated spike trains from the ParameterSet. 
     44     
     45    Parameter: 
     46    p - ParameterSet containing parameters nu (rate), c (correlation), 
     47        duration (in ms), jitter (in ms). 
     48         
     49    Returns: (cc, time_axis_cc, corrcoef) 
     50    cc - correlation coefficient 
     51    time_axis_cc - time axis for cross-correlation (for plotting) 
     52    corrcoef - correlation coefficient between the two SpikeTrains 
     53    """ 
    1854    rate_independent = (1-p.c)*p.nu 
    1955    rate_shared = p.c*p.nu 
     
    3470 
    3571 
    36 
    37 from NeuroTools.parameters import ParameterSpace 
    38 from NeuroTools.parameters import ParameterRange 
    39 from NeuroTools.sandbox import make_name 
    40 # creating a ParameterSpace 
    41 p = ParameterSpace({}) 
    42 # adding paramters 
    43 p.nu = 20. # Hz 
    44 # adding a ParameterRange 
    45 p.c = ParameterRange([0.0,0.01,0.1,0.5]) 
    46 p.jitter = ParameterRange([0.0,1.0,5.0,]) 
    47 p.duration = 1000. 
    48  
    49 # calculation of the ParameterSpace dimension and the labels of the parameters containing a range 
    50 dims, labels = p.parameter_space_dimension_labels() 
    51 # creating a results arry, with the dimensions of the ParameterSpace 
     72# creating a results array, with the dimensions of the ParameterSpace 
    5273corrcoef_results = numpy.empty(dims) 
    5374 
    54 # scanning the Space 
     75# scanning the ParameterSpace 
    5576for experiment in p.iter_inner(): 
    5677    # calculation of the index in the space 
     
    6586    pylab.title(make_name(experiment,p.range_keys())) 
    6687    pylab.xlim(-30,30.) 
    67     pylab.ylim(0,130.) 
     88    pylab.ylim(0,10.) 
    6889 
    6990 
    70  
     91# plot the results 
    7192pylab.matshow(corrcoef_results) 
    7293pylab.xticks(numpy.arange(0.5,dims[1]+0.5,1.0),[str(i) for i in p.jitter._values]) 
  • trunk/examples/sfn2008/sfn_example_simulated_data.py

    r349 r350  
    1 import NeuroTools.signals as signals 
    21""" 
    32Example to show off some capabilities of the signals module  
     
    1211SfN annual meeting 2008, Washington. DC. 
    1312""" 
     13import NeuroTools.signals as signals 
    1414 
    1515# loading spiking data 
     
    2929# isi distribution 
    3030hs = s.isi_hist() 
     31pylab.figure() 
    3132pylab.plot(hs[1],hs[0]) 
    3233 
  • trunk/examples/sfn2008/sfn_example_stgen.py

    r348 r350  
    4343                     st2.time_histogram(time_bin = 1.),  
    4444                     mode = 'same') 
     45time_axis = numpy.linspace(cc.shape[0]/-2., cc.shape[0]/2, cc.shape[0]) 
    4546 
    46 pylab.plot(cc, label = 'no correlation'
     47pylab.plot(time_axis, cc, label = 'no correlation', alpha = 0.5
    4748 
    4849# inject correlation into st1 and st2  
    49 st3 = sg.poisson_generator(rate=rate_shared, t_stop = duration)  
     50st3 = sg.poisson_generator(rate = rate_shared, t_stop = duration)  
    5051st1.merge(st3) 
    5152st2.merge(st3) 
     
    5556                      mode = 'same') 
    5657 
    57 pylab.plot(cc2, label = '10% correlation'
     58pylab.plot(time_axis, cc2, label = '10% correlation', alpha = 0.5
    5859pylab.legend() 
    5960pylab.show()