def sensor_results( ress: ResultCollection, heading: FMTextArg = None, axw: float = None, vmax: float = None, cmap: str = None, ): "Only used for TRFExperiment model-test" if heading is not None: doc = fmtxt.Section(heading) else: doc = fmtxt.FMText() # table doc.append(fmtxt.Figure(ress.table(title='Model test'))) # plots tests topographies = [res.masked_difference() for res in ress.values()] if vmax is None: vlims = plot._base.find_fig_vlims([topographies], vmax) _, vmax = vlims.pop(None) panels = [] for (x, res), y in zip(ress.items(), topographies): title = [x, fmtxt.Stars.from_p(res.p.min())] p = plot.Topomap(y, cmap=cmap, vmax=vmax, title=title, axw=axw, show=False, clip='circle') panels.append(p.image()) p.close() doc.append(fmtxt.Figure(fmtxt.FloatingLayout(panels))) return doc
def report( self, brain_view: Union[str, Sequence[float]] = None, axw: float = None, surf: str = 'inflated', cortex: Any = ((1.00,) * 3, (.4,) * 3), ): doc = [] # plot model-test results layout = BrainLayout(brain_view, axw) sp = plot.brain.SequencePlotter() sp.set_brain_args(mask=(0, 0, 0, 1)) if layout.brain_view: sp.set_parallel_view(*layout.brain_view) sp.set_brain_args(surf=surf, cortex=cortex) # ROI overlay if self.masks: roi = self.masks[0] + self.masks[1] sp.add_ndvar_label(roi, color=(0, 1, 0), borders=2, overlay=True) # det data cmap = plot.soft_threshold_colormap('polar-lux-a', .2, 1) for label, term in self.terms.items(): res = self.ress[term] diffs = [res.difference.sub(source=hemi) for hemi in ['lh', 'rh']] diffs = [diff / diff.max() for diff in diffs] diff = concatenate(diffs, 'source') sp.add_ndvar(diff, cmap=cmap, vmax=1, label=label) p = sp.plot_table(view='lateral', orientation='vertical', **layout.table_args) doc.append(p) # generate table t = fmtxt.Table('l' * (2 * len(self.terms) + 1)) # header 1 t.cell('') for text in ['Left', 'Right']: t.cell(f'{text} H', width=len(self.terms)) # header 2 t.cell('') for _ in range(2): t.cells(*self.terms.keys()) t.midrule() for label, t1 in self.terms.items(): t.cell(label) for hemi in ['lh', 'rh']: for t2 in self.terms.values(): if t1 == t2: t.cell('') continue res = self.loc_ress[t1, t2, hemi].f_tests[0] stars = fmtxt.Stars.from_p(res.p) t.cell([stars, res._asfmtext()]) doc.append(t) return fmtxt.FloatingLayout(doc)
def source_results( ress: ResultCollection, ress_hemi: ResultCollection = None, heading: FMTextArg = None, brain_view: Union[str, Sequence[float]] = None, axw: float = None, surf: str = 'inflated', cortex: Any = ((1.00,) * 3, (.4,) * 3), sig: bool = True, vmax: float = None, cmap: str = None, alpha: float = 1., ): "Only used for TRFExperiment model-test" layout = BrainLayout(brain_view, axw) if heading is not None: doc = fmtxt.Section(heading) else: doc = fmtxt.FMText() tables = [ress.table(title='Model test')] if ress_hemi is not None: tables.append(ress_hemi.table(title="Lateralization")) doc.append(fmtxt.Figure(fmtxt.FloatingLayout(tables))) if sig and all(res.p.min() > 0.05 for res in ress.values()): return doc # plots tests panels = [] all_ress = (ress,) if ress_hemi is None else (ress, ress_hemi) for ress_i in all_ress: sp = plot.brain.SequencePlotter() if layout.brain_view: sp.set_parallel_view(*layout.brain_view) sp.set_brain_args(surf=surf, cortex=cortex) for x, res in ress_i.items(): y = res.masked_difference() if sig else res.difference sp.add_ndvar(y, label=x, cmap=cmap, vmax=vmax, alpha=alpha) panel = sp.plot_table(view='lateral', orientation='vertical', **layout.table_args) panels.append(panel) doc.append(fmtxt.Figure(panels)) for panel in panels: panel.close() return doc