コード例 #1
0
ファイル: traces.py プロジェクト: jspobst/spikepy
    def _plot(self, trial, figure, channel_separation_std=8.0, 
            invert_colors=False):
        pf_traces = getattr(trial, self.requires[0]).data
        pf_sf = getattr(trial, self.requires[1]).data

        f_traces, f_sf = self._get_auxiliary_results(trial)
        have_filtered_results = (f_traces is not None)

        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=75), 
                right=1.0-as_frac(x=10), 
                bottom=as_frac(y=30), 
                top=1.0-as_frac(y=10))

        pf_times = create_times_array(pf_traces, pf_sf)
        if have_filtered_results:
            f_times = create_times_array(f_traces, f_sf)
            channel_separation = (numpy.std(pf_traces[0]) + 
                    numpy.std(f_traces[0]))*(channel_separation_std/2.0)
        else:
            channel_separation = (numpy.std(pf_traces[0]))*channel_separation_std

        axes = figure.add_subplot(111)
        axes.set_axis_bgcolor(background[invert_colors])
        make_into_publication_axes(axes, base_unit_prefix=('', 'm'), 
                scale_bar_origin_frac=as_frac(-25, -5),
                target_size_frac=as_frac(150, 80),
                y_label_rotation='vertical',
                color=foreground[invert_colors])
        axes.lock_axes()

        offsets = []
        y_mins = []
        y_maxs = []
        for i, pf_trace in enumerate(pf_traces):
            offset = -i*channel_separation
            offsets.append(offset)
            y_values = pf_trace+offset
            y_mins.append(numpy.min(y_values))
            y_maxs.append(numpy.max(y_values))
            axes.signal_plot(pf_times, pf_trace+offset, 
                    color=foreground[invert_colors],
                    alpha=0.5,
                    label='Pre-Filtered')

        if have_filtered_results:
            for i, f_trace in enumerate(f_traces):
                color = colors[invert_colors][i%len(colors[invert_colors])]
                offset = offsets[i]
                y_values = f_trace+offset
                y_mins.append(numpy.min(y_values))
                y_maxs.append(numpy.max(y_values))
                axes.signal_plot(f_times, y_values, color=color, 
                        label='Filtered')

        axes.set_ylabel('Channel', color=foreground[invert_colors])
        axes.set_yticks(offsets)
        axes.set_yticklabels([str((i+1)) for i in range(len(offsets))],
                color=foreground[invert_colors])

        y_min = min(y_mins)
        y_max = max(y_maxs)
        y_range = y_max - y_min

        axes.unlock_axes()
        axes.set_xlim(pf_times[0], pf_times[-1])
        axes.set_ylim((y_min - 0.03*y_range, y_max + 0.20*y_range))
コード例 #2
0
ファイル: rasters.py プロジェクト: jspobst/spikepy
    def _plot(self, trial, figure, channel_separation_std=8.0, 
            invert_colors=False, 
            raster_position='center', 
            raster_size=20,
            trace_opacity=0.25):
        f_traces = trial.df_traces.data
        f_sf = trial.df_sampling_freq.data
        f_times = create_times_array(f_traces, f_sf)

        if hasattr(trial, 'event_times'):
            event_times = trial.event_times.data
        else:
            event_times = None
        have_event_times = (event_times is not None)

        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=75), 
                right=1.0-as_frac(x=10), 
                bottom=as_frac(y=30), 
                top=1.0-as_frac(y=10))

        channel_separation = numpy.std(f_traces[0]) * channel_separation_std

        axes = figure.add_subplot(111)
        axes.set_axis_bgcolor(background[invert_colors])
        make_into_publication_axes(axes, base_unit_prefix=('', 'm'), 
                scale_bar_origin_frac=as_frac(-25, -5),
                target_size_frac=as_frac(150, 80),
                y_label_rotation='vertical',
                color=foreground[invert_colors])

        axes.lock_axes()

        # plot traces
        offsets = []
        y_mins = []
        y_maxs = []
        for i, f_trace in enumerate(f_traces):
            offset = -i*channel_separation
            offsets.append(offset)
            y_values = f_trace+offset
            y_mins.append(numpy.min(y_values))
            y_maxs.append(numpy.max(y_values))
            axes.signal_plot(f_times, y_values, color=foreground[invert_colors],
                    alpha=trace_opacity)

        axes.set_ylabel('Channel', color=foreground[invert_colors])
        axes.set_yticks(offsets)
        axes.set_yticklabels([str((i+1)) for i in range(len(offsets))],
                color=foreground[invert_colors])

        y_min = min(y_mins)
        y_max = max(y_maxs)
        y_range = y_max - y_min

        if have_event_times:
            for i, event_sequence in enumerate(event_times):
                if len(event_sequence) > 0:
                    color = colors[invert_colors][i%len(colors[invert_colors])]
                    e_xs = event_sequence
                    if raster_position == 'center':
                        e_ys = [offsets[i] for e in e_xs]
                    else:
                        # 0.1 corrects for roundoff error
                        event_indexes = [int(f_sf*e+0.1) for e in e_xs] 
                        e_ys = [f_traces[i][ei]+offsets[i] 
                                for ei in event_indexes]

                    axes.plot(numpy.array(e_xs), numpy.array(e_ys), 
                            linewidth=0, marker='|', 
                            markersize=raster_size, color=color,
                            markeredgewidth=2)

        axes.unlock_axes()
        axes.set_xlim(f_times[0], f_times[-1])
        axes.set_ylim((y_min - 0.03*y_range, y_max + 0.20*y_range))
        self.axes = axes
コード例 #3
0
ファイル: clustered_rasters.py プロジェクト: jspobst/spikepy
    def _plot(self, trial, figure, channel_separation_std=8.0, 
            invert_colors=False, 
            raster_size=20,
            trace_opacity=0.25,
            traces_shown='Extraction Filtered'):

        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=75), 
                right=1.0-as_frac(x=40), 
                bottom=as_frac(y=30), 
                top=1.0-as_frac(y=10))

        if traces_shown != 'None':
            tn = {
                    'Detection Filtered':('df_traces', 'df_sampling_freq'),
                    'Extraction Filtered':('ef_traces', 'ef_sampling_freq'),
                    'Unfiltered':('pf_traces', 'pf_sampling_freq')}
            # check to see if we can proceed.
            missing_requirements = []
            for attr in tn[traces_shown]:
                if not (hasattr(trial, attr) and 
                    getattr(trial, attr).data is not None):
                    missing_requirements.append(attr)

            if missing_requirements:
                figure.text(0.5, 0.5, 'This visualization cannot be completed due to unmet requirements:\n\n%s' % '\n'.join(missing_requirements))
                return
            else:
                traces = getattr(trial, tn[traces_shown][0]).data
                sf = getattr(trial, tn[traces_shown][1]).data

            axes = figure.add_subplot(111)
            axes.set_axis_bgcolor(background[invert_colors])
            make_into_publication_axes(axes, base_unit_prefix=('', 'm'), 
                    scale_bar_origin_frac=as_frac(-25, -5),
                    target_size_frac=as_frac(150, 80),
                    y_label_rotation='vertical',
                    color=foreground[invert_colors])
            axes.lock_axes()

            # plot traces
            offsets = []
            y_mins = []
            y_maxs = []
            times = create_times_array(traces, sf)
            channel_separation = numpy.std(traces[0]) * channel_separation_std
            for i, trace in enumerate(traces):
                offset = -i*channel_separation
                offsets.append(offset)
                y_values = trace+offset
                y_mins.append(numpy.min(y_values))
                y_maxs.append(numpy.max(y_values))
                axes.signal_plot(times, y_values, 
                        color=foreground[invert_colors],
                        alpha=trace_opacity)

            axes.set_ylabel('Channel', color=foreground[invert_colors])
            axes.set_yticks(offsets)
            axes.set_yticklabels([str((i+1)) for i in range(len(offsets))],
                    color=foreground[invert_colors])

            axes.unlock_axes()

            y_min = min(y_mins)
            y_max = max(y_maxs)
            y_range = y_max - y_min

            axes.set_xlim(times[0], times[-1])
            axes.set_ylim((y_min - 0.03*y_range, y_max + 0.20*y_range))
            axes.get_yaxis().set_ticks_position('left')

        # plot rasters
        if traces_shown != 'None':
            ra = figure.add_axes(axes.get_position(), frameon=False)
            xlims = (times[0], times[-1])
        else:
            ra = figure.add_subplot(111, frameon=False)
            xlims = None
        ra.text(1+as_frac(28), 0.5, 'Cluster', 
                color=foreground[invert_colors],
                clip_on=False,
                verticalalignment='center',
                horizontalalignment='center',
                rotation='vertical',
                transform=ra.transAxes)

        ymin, ymax = (0.0, 1.0)
        yrange = ymax - ymin
        cft = trial.clustered_feature_times
        minx = 1e30
        maxx = -1e30
        poss = []
        for i, cluster_name in enumerate(sorted(cft.keys())):
            color = cluster_colors[invert_colors][
                    i%len(cluster_colors[invert_colors])]
            e_xs = cft[cluster_name]
            pos = ymax - i/max(1.0, float(len(cft.keys())-1))*yrange
            poss.append(pos)
            if len(e_xs) > 0:
                minx = min(minx, min(e_xs))
                maxx = max(maxx, max(e_xs))
                ra.plot(numpy.array(e_xs), 
                        numpy.ones(len(e_xs))*pos,
                        linewidth=0, 
                        marker='|', 
                        markersize=raster_size, 
                        color=color,
                        markeredgewidth=2)

        if xlims is not None:
            ra.set_xlim(xlims)
        ra.set_ylim(ymin-0.1*yrange, ymax+0.1*yrange)

        ra.get_yaxis().set_ticks_position('right')
        ra.set_yticks(poss)
        ra.set_yticklabels(sorted(cft.keys()))
        ra.set_xticks([])
        ra.set_xticklabels([''], visible=False)
        make_into_raster_axes(ra)

        # fix colors
        lines = ra.get_xticklines()
        if traces_shown != 'None':
            lines.extend(axes.get_yticklines())
        for line in lines:
            line.set_color(foreground[invert_colors])
        labels = ra.get_xticklabels()
        labels.extend(ra.get_yticklabels())
        for label in labels:
            label.set_color(foreground[invert_colors])