def generate_spike_windows(signal, sampling_freq, event_times,
            pre_padding=None,
            post_padding=None,
            min_num_channels=None,
            peak_drift=None,
            exclude_overlappers=None):

    # event times are in sec, peak_drift must be converted to sec (from ms).
    collapsed_event_times = collapse_event_times(event_times, 
            min_num_channels, peak_drift/1000.0)

    pre_padding_percent = pre_padding/float(pre_padding+post_padding)
    # from sampling frequency (in Hz) and pre/post_padding (in ms) determine
    #     window_size (in samples)
    window_duration = (pre_padding + post_padding) / 1000.0 # now in secs
    # +1 to account for the sample itself.
    window_size = int(window_duration * sampling_freq) + 1 

    if len(collapsed_event_times) == 0:
        # need to return something compatible in shape with what would have
        # been returned if there were event_times.
        return [numpy.empty((0, window_size)),numpy.empty(0),
                numpy.empty((0, window_size)),numpy.empty(0)]

    spike_index_list = numpy.array(collapsed_event_times, 
            dtype=numpy.float64)*sampling_freq
    spike_index_list = numpy.array(spike_index_list, dtype=numpy.int32)
    (spike_windows, spike_indexes, excluded_windows, excluded_indexes) =\
            window_spikes(signal, spike_index_list, 
                    window_size=window_size, 
                    pre_padding=pre_padding_percent, 
                    exclude_overlappers=exclude_overlappers)
        
    return [numpy.vstack(spike_windows), 
            numpy.array(spike_indexes)/float(sampling_freq), 
            excluded_windows, 
            numpy.array(excluded_indexes)/float(sampling_freq)]
示例#2
0
文件: isis.py 项目: jspobst/spikepy
    def _plot(self, trial, figure, invert_colors=False, large_bin_size=50, 
            small_bin_size=1, min_num_channels=3, peak_drift=0.3):
        bounds1 = (0.0, 3000.0) # 0 to 3 seconds
        bounds2 = (0.0, 20.0) # first 20 ms

        event_times = trial.event_times.data
        # event_times is in sec, so make peak_drift also in sec.
        collapsed_event_times = collapse_event_times(event_times, 
                min_num_channels, peak_drift/1000.0)

        isis = collapsed_event_times[1:] - collapsed_event_times[:-1]
        isis *= 1000.0 # to get it to ms

        def as_frac(x=None, y=None):
            f = figure
            canvas_size_in_pixels = (f.get_figwidth()*f.get_dpi(),
                                    f.get_figheight()*f.get_dpi())
            return as_fraction(x=x, y=y, 
                    canvas_size_in_pixels=canvas_size_in_pixels)

        figure.set_facecolor(background[invert_colors])
        figure.set_edgecolor(foreground[invert_colors])
        figure.subplots_adjust(left=as_frac(x=80), 
                right=1.0-as_frac(x=35), 
                bottom=as_frac(y=40), 
                top=1.0-as_frac(y=25),
                wspace=as_frac(x=80))

        a1 = figure.add_subplot(121)
        a2 = figure.add_subplot(122)

        a1.hist(isis, bins=int((bounds1[1]-bounds1[0])/large_bin_size),
                range=bounds1, fc=face_color[invert_colors], 
                ec=background[invert_colors])

        a2.hist(isis, bins=int((bounds2[1]-bounds2[0])/small_bin_size),
                range=bounds2, fc=face_color[invert_colors], 
                ec=background[invert_colors])

        a1.text(0.98, 0.95, '%d Spike Events Found' 
                % len(collapsed_event_times), 
                color=foreground[invert_colors],
                horizontalalignment='right', 
                verticalalignment='center', 
                transform=a1.transAxes)

        a1.set_ylabel('Count', color=foreground[invert_colors])
        a1.set_xlabel('Interspike Interval (ms)', 
                color=foreground[invert_colors])
        a2.set_xlabel('Interspike Interval (ms)', 
                color=foreground[invert_colors])

        # axes color fixing
        for axes in [a1, a2]:
            frame = axes.patch
            frame.set_facecolor(background[invert_colors])
            frame.set_edgecolor(foreground[invert_colors])
            for spine in axes.spines.values():
                spine.set_color(foreground[invert_colors])
            lines = axes.get_xticklines()
            lines.extend(axes.get_yticklines())
            for line in lines:
                line.set_color(foreground[invert_colors])
            labels = axes.get_xticklabels()
            labels.extend(axes.get_yticklabels())
            for label in labels:
                label.set_color(foreground[invert_colors])