예제 #1
0
    def update(
        self,
        index: int,
        start_label: str = "start_time",
        before: float = 0.0,
        after: float = 1.0,
        order=None,
        group_inds=None,
        labels=None,
        align_to_zero=False,
        fig: go.FigureWidget = None,
    ):

        data, time_ts_aligned = self.align_data(start_label, before, after,
                                                index)
        if group_inds is None:
            group_inds = np.zeros(len(self.trials), dtype=np.int)
        if align_to_zero:
            for trial_no in order:
                data_zero_id = bisect(time_ts_aligned[trial_no], 0)
                data[trial_no] -= data[trial_no][data_zero_id]
        fig = fig if fig is not None else go.FigureWidget()
        fig.data = []
        fig.layout = {}
        return self.plot_group(group_inds, data, time_ts_aligned, fig, order)
예제 #2
0
    def update(
        self,
        index: int,
        start_label: str = "start_time",
        before: float = 0.0,
        after: float = 1.0,
        order=None,
        group_inds=None,
        labels=None,
        align_to_zero=False,
        sem=False,
        fig: go.FigureWidget = None,
    ):
        data, time_ts_aligned = self.align_data(start_label, before, after,
                                                index)
        if group_inds is None:
            group_inds = np.zeros(len(self.trials), dtype=np.int)
        if align_to_zero:
            for trial_no in order:
                data_zero_id = bisect(time_ts_aligned[trial_no], 0)
                data[trial_no] -= data[trial_no][data_zero_id]
        fig = go.FigureWidget() if fig is None else fig
        fig.data = []
        fig.layout = {}
        if sem:
            group_stats = []
            for group in np.unique(group_inds):
                this_mean = np.nanmean(data[group_inds == group, :], axis=0)
                err = scipy.stats.sem(data[group_inds == group, :],
                                      axis=0,
                                      nan_policy="omit")
                group_stats.append(
                    dict(
                        mean=this_mean,
                        lower=this_mean - 2 * err,
                        upper=this_mean + 2 * err,
                        group=group,
                    ))

            for stats in group_stats:
                plot_kwargs = dict()
                color = color_wheel[stats["group"]]
                if labels is not None:
                    plot_kwargs.update(text=labels[stats["group"]])
                fig.add_scattergl(x=time_ts_aligned[0],
                                  y=stats["lower"],
                                  line_color=color)
                fig.add_scattergl(x=time_ts_aligned[0],
                                  y=stats["upper"],
                                  line_color=color,
                                  fill='tonexty',
                                  opacity=0.2)
                fig.add_scattergl(x=time_ts_aligned[0],
                                  y=stats["mean"],
                                  line_color=color,
                                  **plot_kwargs)

        else:
            fig = self.plot_group(group_inds, data, time_ts_aligned, fig,
                                  order)
        return fig