def test_fmtext(): "Tet FMText base class" t = fmtxt.FMText('test') print(t) tuc = fmtxt.FMText(u'FMText with unicode: \x80abc') print(str(tuc)) ts = fmtxt.FMText((t, tuc, u'unicode: \x80abc')) print(str(ts)) print(html(ts)) print(tex(ts))
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 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
def table(self, title=None, caption=None): """Table with effects and smallest p-value""" if self.test_type is LMGroup: cols = sorted( {col for res in self.values() for col in res.column_names}) table = fmtxt.Table('l' * (1 + len(cols)), title=title, caption=caption) table.cell('') table.cells(*cols) table.midrule() for key, lmg in self.items(): table.cell(key) for res in (lmg.tests[c] for c in cols): pmin = res.p.min() table.cell(fmtxt.FMText([fmtxt.p(pmin), star(pmin)])) elif self.test_type is anova: table = fmtxt.Table('lllll', title=title, caption=caption) table.cells('Test', 'Effect', fmtxt.symbol(self.test_type._statistic, 'max'), fmtxt.symbol('p'), 'sig') table.midrule() for key, res in self.items(): for i, effect in enumerate(res.effects): table.cells(key, effect) pmin = res.p[i].min() table.cell(fmtxt.stat(res._max_statistic(i))) table.cell(fmtxt.p(pmin)) table.cell(star(pmin)) key = '' else: table = fmtxt.Table('llll', title=title, caption=caption) table.cells('Effect', fmtxt.symbol(self.test_type._statistic, 'max'), fmtxt.symbol('p'), 'sig') table.midrule() for key, res in self.items(): table.cell(key) pmin = res.p.min() table.cell(fmtxt.stat(res._max_statistic())) table.cell(fmtxt.p(pmin)) table.cell(star(pmin)) return table
def source_trfs( ress: ResultCollection, heading: FMTextArg = None, brain_view: Union[str, Sequence[float]] = None, axw: float = None, surf: str = 'inflated', cortex: Any = ((1.00,) * 3, (.4,) * 3), vmax: float = None, xlim: Tuple[float, float] = None, times: Sequence[float] = None, cmap: str = None, labels: Dict[str, str] = None, rasterize: bool = None, brain_timewindow: float = 0.050 ): "Only used for TRFExperiment model-test" layout = BrainLayout(brain_view, axw) dt = brain_timewindow / 2 if heading is not None: doc = fmtxt.Section(heading) else: doc = fmtxt.FMText() if cmap is None: cmap = 'lux-a' if labels is None: labels = {} trf_table = fmtxt.Table('ll') for key, res in ress.items(): trf_resampled = resample(res.masked_difference(), 1000) label = labels.get(key, key) if rasterize is None: rasterize = len(trf_resampled.source) > 500 # times for anatomical plots if times is None: trf_tc = abs(trf_resampled).sum('source') trf_tc_mask = (~trf_resampled.get_mask()).sum('source') >= 10 times_ = find_peak_times(trf_tc, trf_tc_mask) else: times_ = times # butterfly-plot p = plot.Butterfly(trf_resampled, h=3, w=4, ylabel=False, title=label, vmax=vmax, xlim=xlim, show=False) for t in times_: p.add_vline(t, color='k') trf_table.cell(fmtxt.asfmtext(p, rasterize=rasterize)) p.close() # peak sources if not times_: trf_table.cell() sp = plot.brain.SequencePlotter() if layout.brain_view: sp.set_parallel_view(*layout.brain_view) sp.set_brain_args(surf=surf, cortex=cortex) for t in times_: yt = trf_resampled.mean(time=(t - dt, t + dt + 0.001)) if isinstance(cmap, str): vmax_ = vmax or max(-yt.min(), yt.max()) or 1 cmap_ = plot.soft_threshold_colormap(cmap, vmax_ / 10, vmax_) else: cmap_ = cmap sp.add_ndvar(yt, cmap=cmap_, label=f'{t * 1000:.0f} ms', smoothing_steps=10) p = sp.plot_table(view='lateral', orientation='vertical', **layout.table_args) trf_table.cell(p) p.close() doc.append(fmtxt.Figure(trf_table)) return doc