Changeset 485 for trunk

Show
Ignore:
Timestamp:
06/08/11 16:44:37 (12 months ago)
Author:
pierre
Message:

Add a binary flag to the spike_histogram function, and minor changes.

Location:
trunk/src/signals
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/signals/analogs.py

    r468 r485  
    398398 
    399399    Inputs: 
    400         signals - a list of the AnalogSignals objects 
     400        signals - a list of tuples (id, value) with all the values sorted in time of the analog signals 
    401401        id_list - the list of the ids of all recorded cells (needed for silent cells) 
    402402        dt      - if dt is specified, time values should be floats 
     
    423423         
    424424        signals = numpy.array(signals) 
    425          
    426425        for id in id_list: 
    427426            signal = numpy.transpose(signals[signals[:,0] == id, 1:])[0] 
     
    821820                if v_thresh is not None: 
    822821                    to_be_plot = pylab.where(to_be_plot>=v_thresh-0.02, v_thresh+0.5, to_be_plot) 
     822                if len(time_axis) > len(to_be_plot): 
     823                    time_axis = time_axis[:-1] 
     824                if len(to_be_plot) > len(time_axis): 
     825                    to_be_plot = to_be_plot[:-1] 
    823826                subplot.plot(time_axis, to_be_plot, **kwargs) 
    824827                subplot.hold(1) 
  • trunk/src/signals/spikes.py

    r484 r485  
    148148 
    149149    def __del__(self): 
    150         pass 
     150        del self.spike_times 
    151151 
    152152    def __len__(self): 
     
    534534         
    535535 
    536     def time_histogram(self, time_bin=10, normalized=True): 
     536    def time_histogram(self, time_bin=10, normalized=True, binary=False): 
    537537        """ 
    538538        Bin the spikes with the specified bin width. The first and last bins 
     
    544544                         in spikes/second, otherwise otherwise it's the number of spikes  
    545545                         per bin. 
     546            binary     - if True, a binary matrix of 0/1 is returned 
    546547         
    547548        Examples: 
     
    566567        if normalized: # what about normalization if time_bin is a sequence? 
    567568            hist *= 1000.0/float(time_bin) 
     569        if binary: 
     570            hist = hist.astype(bool).astype(int) 
    568571        return hist 
    569572 
     
    867870 
    868871    def __del__(self): 
    869         pass 
     872        for id in self.id_list: 
     873            del self.spiketrains[id] 
    870874 
    871875    @property 
     
    10711075                    spiketrain.relative_times() 
    10721076                self.append(id, spiketrain) 
    1073                  
     1077        self.__calc_startstop()     
    10741078     
    10751079    def complete(self, id_list): 
     
    16171621 
    16181622 
    1619     def spike_histogram(self, time_bin, normalized=False, display=False, kwargs={}): 
     1623    def spike_histogram(self, time_bin, normalized=False, binary=False, display=False, kwargs={}): 
    16201624        """ 
    16211625        Generate an array with all the spike_histograms of all the SpikeTrains 
     
    16281632            display    - if True, a new figure is created. Could also be a subplot. The averaged 
    16291633                         spike_histogram over the whole population is then plotted 
     1634            binary     - if True, a binary matrix of 0/1 is returned 
    16301635            kwargs     - dictionary contening extra parameters that will be sent to the plot  
    16311636                         function 
     
    16391644        if newnum: 
    16401645            M -= 1 
    1641         spike_hist = numpy.zeros((N, M), numpy.float32) 
     1646        if binary: 
     1647            spike_hist = numpy.zeros((N, M), numpy.int) 
     1648        else: 
     1649            spike_hist = numpy.zeros((N, M), numpy.float32) 
    16421650        subplot    = get_display(display) 
     1651 
    16431652        for idx,id in enumerate(self.id_list): 
    1644             spike_hist[idx,:] = self.spiketrains[id].time_histogram(time_bin, normalized) 
     1653            if newnum: 
     1654                if not hist_new: 
     1655                    hist, edges = numpy.histogram(self.spiketrains[id].spike_times, nbins) 
     1656                else: 
     1657                    hist, edges = numpy.histogram(self.spiketrains[id].spike_times, nbins, new=newnum) 
     1658            else: 
     1659                hist, edges = numpy.histogram(self.spike_times, bins) 
     1660            hist = hist.astype(float) 
     1661            if normalized: # what about normalization if time_bin is a sequence? 
     1662                hist *= 1000.0/float(time_bin) 
     1663            if binary: 
     1664                hist = hist.astype(bool) 
     1665            spike_hist[idx,:] = hist 
    16451666        if not subplot or not HAVE_PYLAB: 
    16461667            return spike_hist 
     
    16591680             
    16601681 
    1661     def firing_rate(self, time_bin, display=False, average=False, kwargs={}): 
     1682    def firing_rate(self, time_bin, display=False, average=False, binary=False, kwargs={}): 
    16621683        """ 
    16631684        Generate an array with all the instantaneous firing rates along time (in Hz)  
     
    16701691            display    - if True, a new figure is created. Could also be a subplot. The averaged 
    16711692                         spike_histogram over the whole population is then plotted 
     1693            binary     - If True, a binary matrix with 0/1 is returned.  
    16721694            kwargs     - dictionary contening extra parameters that will be sent to the plot  
    16731695                         function 
     
    16761698            spike_histogram, time_axis 
    16771699        """ 
    1678         result = self.spike_histogram(time_bin, normalized=True, display=display, kwargs=kwargs) 
     1700        result = self.spike_histogram(time_bin, normalized=True, binary=False, display=display, kwargs=kwargs) 
    16791701        if average: 
    16801702            return numpy.mean(result, axis=0)