Changeset 482 for trunk

Show
Ignore:
Timestamp:
02/24/11 00:42:40 (15 months ago)
Author:
mpereira
bzr:base-revision:
pereira@dantur-20110216181753-oju9on3c6n026j12
bzr:committer:
Michael Pereira michael.fsp@gmail.com
bzr:file-ids:

src/analysis.py 106@400bb3d0-8d2e-0410-a2c0-f692ac833539:trunk%2Fsrc%2Fanalysis.py
bzr:mapping-version:
v4
bzr:repository-uuid:
400bb3d0-8d2e-0410-a2c0-f692ac833539
bzr:revision-id:
michael.fsp@gmail.com-20110223232612-ddlqcvleyq48wqnn
bzr:revno:
426
bzr:revprop:branch-nick:
NeuroTools_branch
bzr:root:
trunk
bzr:timestamp:
2011-02-24 00:26:12.588999987 +0100
bzr:user-agent:
bzr2.2.4+bzr-svn1.0.3
svn:original-date:
2011-02-23T23:26:12.589000Z
Message:

analysis.crosscorrelate now handles empty correlograms more gracefuly

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/analysis.py

    r480 r482  
    174174            sua.append(x.ravel()) 
    175175        else: 
    176             raise TypeError("sua1 and sua2 must be either instances of the \ 
    177                             SpikeTrain class or column/row vectors") 
     176            raise TypeError("sua1 and sua2 must be either instances of the" \ 
     177                            "SpikeTrain class or column/row vectors") 
    178178    sua1 = sua[0] 
    179179    sua2 = sua[1] 
     
    194194        sua2_ = numpy.array([]) 
    195195        for ni in xrange(1,n_pred+1): 
    196             idx = numpy.random.permutation(isi.size-1) 
    197              
     196            idx = numpy.random.permutation(isi.size-1)             
    198197            sua2_ = numpy.append(sua2_, numpy.add(numpy.insert( 
    199198                (numpy.cumsum(isi[idx])), 0, 0), sua2.min() + ( 
     
    210209            int_ = numpy.append(int_, sua1[k] - sua2_[numpy.nonzero( 
    211210                (sua2_ > sua1[k] - lag) & (sua2_ < sua1[k] + lag))]) 
    212      
    213211    if reverse is True: 
    214212        int = -int 
     
    217215    norm = numpy.sqrt(sua1.size * sua2.size) 
    218216     
    219     # Plot the results if display=True 
     217    # Plot the results if display=True    
    220218    subplot = get_display(display) 
    221219    if not subplot or not HAVE_PYLAB: 
     
    223221    else: 
    224222        # Plot the cross-correlation 
    225         counts, bin_edges = numpy.histogram(int, **kwargs) 
    226         counts = counts / norm 
    227         xlabel = "Time" 
    228         ylabel = "Cross-correlation coefficient" 
    229         #NOTE: the x axis corresponds to the upper edge of each bin 
    230         subplot.plot(bin_edges[1:], counts, label='cross-correlation') 
    231         if predictor is None: 
    232             set_labels(subplot, xlabel, ylabel) 
    233             pylab.draw() 
    234         elif predictor is 'shuffle':             
    235             # Plot the predictor 
    236             norm_ = norm * n_pred 
    237             counts_, bin_edges_ = numpy.histogram(int_, **kwargs) 
    238             counts_ = counts_ / norm_ 
    239             subplot.plot(bin_edges_[1:], counts_, label='predictor') 
    240             subplot.legend() 
    241             pylab.draw() 
    242  
     223        try: 
     224            counts, bin_edges = numpy.histogram(int, **kwargs) 
     225            counts = counts / norm 
     226            xlabel = "Time" 
     227            ylabel = "Cross-correlation coefficient" 
     228            #NOTE: the x axis corresponds to the upper edge of each bin 
     229            subplot.plot(bin_edges[1:], counts, label='cross-correlation') 
     230            if predictor is None: 
     231                set_labels(subplot, xlabel, ylabel) 
     232                pylab.draw() 
     233            elif predictor is 'shuffle':             
     234                # Plot the predictor 
     235                norm_ = norm * n_pred 
     236                counts_, bin_edges_ = numpy.histogram(int_, **kwargs) 
     237                counts_ = counts_ / norm_ 
     238                subplot.plot(bin_edges_[1:], counts_, label='predictor') 
     239                subplot.legend() 
     240                pylab.draw() 
     241        except ValueError: 
     242            print "There are no correlated events within the selected lag"\ 
     243            " window of %s" % lag 
    243244def _dict_max(D): 
    244245    """