예제 #1
0
    # generate re-ordering of coordinates based on Y-position
    start = end = 0
    data = np.zeros((len(coords)))
    order = np.zeros(len(coords), dtype=int)
    inds = np.arange(len(coords), dtype=int)
    for i in np.asarray(info.groupby('hemisphere').count()['id']):
        end += i
        c = coords[start:end]
        order[start:end] = inds[c[:, 1].argsort()[::-1] + start]
        data[start:end] = np.arange(i)
        start = i
    np.put(data, order, data)
    OPTS['vmax'] = len(data) - n_right

    # plot original data and save
    save_brainmap(data, FIGDIR / 'raw_surf.png', lh, rh, **OPTS)

    spins = ['naive-nonpara', 'vazquez-rodriguez', 'vasa', 'hungarian', 'baum']
    for sptype in spins:
        spin = np.loadtxt(SPINDIR / name / sptype / f'{scale}_spins.csv',
                          delimiter=',',
                          dtype=int,
                          usecols=0)
        plot = np.append(data, [np.nan])[spin]  # accounts for 'baum' (-1 idx)
        save_brainmap(plot, FIGDIR / f'{sptype}_surf.png', lh, rh, **OPTS)

    # cornblath
    spin = np.loadtxt(SPINDIR / 'vertex' / 'vazquez-rodriguez' /
                      'fsaverage5_spins.csv',
                      delimiter=',',
                      dtype=int,
예제 #2
0
            # scatterplots comparing them to one another
            for method, surrs in zip(METHODS, [burt2018, burt2020, moran]):
                figdir = FIGDIR / name / method
                figdir.mkdir(exist_ok=True, parents=True)

                # brain maps of example brains
                vmin, vmax = np.percentile(surrs, [2.5, 97.5])
                for n, medial in enumerate(['medial', 'nomedial']):
                    fn = figdir / medial / f'{scale}.png'
                    if fn.exists():
                        continue
                    plotting.save_brainmap(surrs[n][:, 0],
                                           fn,
                                           annot.lh,
                                           annot.rh,
                                           subject_id='fsaverage5',
                                           colormap='coolwarm',
                                           colorbar=False,
                                           vmin=vmin,
                                           vmax=vmax,
                                           views=['lat', 'med'])

                # scatter plot of example brains
                fig, ax = plt.subplots(1, 1)
                ax.scatter(surrs[0][:, 0],
                           surrs[1][:, 0],
                           s=75,
                           edgecolor=np.array([60, 60, 60]) / 255,
                           facecolor=np.array([223, 121, 122]) / 255)
                for side in ['right', 'top']:
                    ax.spines[side].set_visible(False)
                ax.set(xlabel='with medial wall', ylabel='without medial wall')
OVERWRITE = True
OPTS = dict(subject_id='fsaverage5', views=['lat', 'med'], colormap='coolwarm')

if __name__ == "__main__":
    FIGDIR.mkdir(parents=True, exist_ok=True)
    parcellations = utils.get_cammoun_schaefer(data_dir=ROIDIR)

    for alpha in simnulls.ALPHAS:
        # create simulation with desired alpha (same seed as all others)
        sim = spatial.create_surface_grf(alpha=float(alpha[-3:]),
                                         seed=1234,
                                         medial_val=np.nan)
        # save plot of vertex-wise simulation
        fn = FIGDIR / alpha / 'vertex' / 'fsaverage5.png'
        if not fn.exists() or OVERWRITE:
            save_brainmap(sim, fn, **OPTS)

        # save plot of parcellated simulations (if desired)
        if SAVE_ALL:
            for parc, annots in parcellations.items():
                for scale, annot in annots.items():
                    # parcellate simulation according
                    data = np.hstack([
                        utils.parcellate(np.split(sim, 2)[n], hemi, FSIGNORE)
                        for n, hemi in enumerate(annot)
                    ])
                    # save plot of parcellated simulation
                    fn = FIGDIR / alpha / parc / f'{scale}.png'
                    if not fn.exists() or OVERWRITE:
                        save_brainmap(data,
                                      fn,
예제 #4
0
                          diagonal=False, cbar=True,
                          cbar_label='correlation (r)',
                          imshow_kwargs=dict(vmin=-0.5, vmax=1, cmap=cmap))

    # save resampling arrays
    plot_save_heatmap(np.column_stack([range(len(data)), spins]),
                      fname='resamples', diagonal=True, cbar=False,
                      aspect='auto', cmap=cmap,
                      imshow_kwargs=dict(cmap=cmap))

    # save sample brain maps
    for term in terms:
        # symmetrical colorbar
        vmin, vmax = np.percentile(data[term], [2.5, 97.5])
        lim = max(abs(vmin), abs(vmax))
        save_brainmap(data[term], f'{term}_0.png', lh=lh, rh=rh,
                      colormap=cmap, vmin=-lim, vmax=lim)
        # get spins, in case we want those, too
        for n, spin in enumerate(spins.T, 1):
            plot = np.asarray(data[term])[spin]
            save_brainmap(plot, f'{term}_{n}.png', lh=lh, rh=rh,
                          colormap=cmap, vmin=-lim, vmax=lim)

    # save example null distribution
    null_dist = np.loadtxt(
        NSDIR / PARC / 'nulls' / SPINTYPE / f'{SCALE}_nulls.csv'
    )
    fig, ax = plt.subplots(1, 1)
    ax = sns.kdeplot(null_dist, color=cmap(0), linewidth=3, shade=True)
    sns.despine(ax=ax, left=True)
    ax.set(yticks=[], xlim=(0.4, 1.1), xticks=(0.5, 0.75, 1.0))
    (x, y), = np.where(np.isin(data.columns, terms))
예제 #5
0
    t1t2 = pd.read_csv(path, index_col=0) \
             .assign(networks=RSN_AFILLIATION[PARC](SCALE).parcels) \
             .drop(drop)
    netmeans = t1t2.groupby('networks') \
                   .mean() \
                   .assign(network=YEO_CODES.keys())
    spins = np.loadtxt(SPINDIR / PARC / SPINTYPE / f'{SCALE}_spins.csv',
                       delimiter=',', dtype='int32', usecols=range(3))

    # get annotations
    fetcher = getattr(nndata, f'fetch_{PARC.split("-")[1]}')
    lh, rh = fetcher('fsaverage', data_dir=ROIDIR)[SCALE]

    # plot original
    data = np.asarray(t1t2['myelin'])
    save_brainmap(data, 't1wt2w_0.png', lh=lh, rh=rh,
                  colormap='coolwarm', vmin=1.0, vmax=1.6)
    for n, spin in enumerate(spins.T, 1):
        save_brainmap(data[spin], f't1wt2w_{n}.png', lh=lh, rh=rh,
                      colormap='coolwarm', vmin=1.0, vmax=1.6)

    null_dist = np.loadtxt(
        HCPDIR / PARC / 'nulls' / 'yeo' / SPINTYPE / f'{SCALE}_nulls.csv',
        delimiter=','
    )
    nulls = pd.DataFrame(dict(
        network=np.repeat(list(YEO_CODES.keys()), len(null_dist)),
        nulls=null_dist.flatten(order='F')
    ))

    fig, ax = plt.subplots(1, 1, figsize=(4, 6))
    ax = sns.boxplot(x='nulls', y='network', data=nulls, color='white',