Esempio n. 1
0
def plot_param_ratio_corr_exp(
    exp,
    title="Ratio vs. Spectral Features",
    cbar=False,
    show=False,
    save_fig=False,
    file_path=fp.eeg_corrs,
    file_name="Spectral_Features_Ratio_corr",
):
    """Same as `plot_param_ratio_corr`, but for the exponent."""

    fig, ax1 = plt.subplots(figsize=(2.5, 1.75))
    ax1 = sns.heatmap(exp[0].reshape((1, 1)),
                      cmap="bwr",
                      annot=True,
                      cbar=cbar,
                      ax=ax1,
                      vmin=-1,
                      vmax=1,
                      annot_kws={"size": 30})

    plt.tick_params(axis='both',
                    which='both',
                    bottom=False,
                    top=False,
                    labelbottom=False,
                    left=False,
                    labelleft=False)

    if save_fig:
        plt.savefig(fp.make_file_path(file_path, file_name + '_exp', 'pdf'))

    if not show:
        plt.close()
Esempio n. 2
0
def plot_interacting_sims(data,
                          param1,
                          param2,
                          plot_log=False,
                          show=False,
                          save_fig=False,
                          file_path=fp.sims_interacting,
                          file_name='InteractingSims'):
    """Plots heatmaps for interacting parameter simulations.

    Parameters
    ----------
    data : list of lists
        List of power spectra.
    param1 : string
        Param used in simulation.
    param2 : string
        Param used in simulation.
    plot_log : boolean
        Whether to log values before plotting the heatmap.
    show : boolean
        Whether to display to plot.
    save_fig : boolean
        Whether to save out the figure.
    file_path : string
        Path to save the plot to.
    file_name : string
        File name to save the plot with.
    """

    # Calculate ratios
    ratios = calc_interacting_param_ratios(data)

    if plot_log:
        ratios = np.log10(ratios)
        vmin, vmax = 0, 1.6
    else:
        vmin, vmax = None, None

    fig, ax = plt.subplots()
    sns.heatmap(ratios,
                vmin,
                vmax,
                xticklabels=PARAMS[param2],
                yticklabels=PARAMS[param1])
    plt.yticks(rotation=0)

    ax.invert_yaxis()
    plt.xlabel(param2, {'fontsize': 14})
    plt.ylabel(param1, {'fontsize': 14})
    plt.tight_layout()

    if save_fig:
        plt.savefig(fp.make_file_path(file_path, file_name, 'pdf'))

    if not show:
        plt.close()
Esempio n. 3
0
def plot_param_ratio_corr(data,
                          title="Ratio vs. Spectral Features",
                          y_labels=["Theta", "Alpha", "Beta"],
                          show=True,
                          save_fig=False,
                          file_path=fp.eeg_corrs,
                          file_name="Spectral_Features_Ratio_corr"):
    """Plot correlations between BandRatio measures and spectral features.

    Parameters
    ----------
    data: 2x3 ndarray
        Correlations of BandRatios to Spectral Features.
    title: string
        Title of plot.
    y_labels: list of strings
        Labels of slow and fast wave to use on y-axis.
    show : boolean
        Whether to display to plot.
    save_fig: boolean
        If True - save plot.
    file_path : string
        Path to save the plot to.
    file_name : string
        File name to save the plot with.
    """

    if not np.all(data):
        raise RuntimeError("No data - cannot proceed.")

    fig, ax2 = plt.subplots()
    ax2 = sns.heatmap(data,
                      cmap="bwr",
                      yticklabels=y_labels,
                      xticklabels=FEATURE_LABELS,
                      annot=True,
                      ax=ax2,
                      vmin=-1,
                      vmax=1,
                      annot_kws={"size": 20})
    plt.yticks(rotation=45, verticalalignment='center')

    plt.tight_layout()

    if save_fig:
        plt.savefig(fp.make_file_path(file_path, file_name, 'pdf'))

    if not show:
        plt.close()
Esempio n. 4
0
def plot_param_topo(data, raw, label='', save=False):
    """Plots the topography of a spectral parameter."""

    fig, ax = plt.subplots()
    mne.viz.plot_topomap(data,
                         raw.info,
                         vmin=min(data),
                         vmax=max(data),
                         cmap=cm.viridis,
                         contours=0,
                         axes=ax)
    ax.set_title(label)

    if save:
        fig.savefig(fp.make_file_path(fp.eeg_topos, label + '-topo', 'pdf'))
def main():

    ## Load data

    cf_theta = np.load(dp.make_file_path(dp.sims_single, 'cf_theta', 'npy'))
    cf_alpha = np.load(dp.make_file_path(dp.sims_single, 'cf_alpha', 'npy'))
    cf_beta = np.load(dp.make_file_path(dp.sims_single, 'cf_beta', 'npy'))

    pw_theta = np.load(dp.make_file_path(dp.sims_single, 'pw_theta', 'npy'))
    pw_alpha = np.load(dp.make_file_path(dp.sims_single, 'pw_alpha', 'npy'))
    pw_beta = np.load(dp.make_file_path(dp.sims_single, 'pw_beta', 'npy'))

    bw_theta = np.load(dp.make_file_path(dp.sims_single, 'bw_theta', 'npy'))
    bw_alpha = np.load(dp.make_file_path(dp.sims_single, 'bw_alpha', 'npy'))
    bw_beta = np.load(dp.make_file_path(dp.sims_single, 'bw_beta', 'npy'))

    f_data = np.load(dp.make_file_path(dp.sims_single, 'exp_data', 'npy'))
    offset = np.load(dp.make_file_path(dp.sims_single, 'offset_data', 'npy'))
    exp = np.load(dp.make_file_path(dp.sims_single, 'exp_data', 'npy'))
    a_shift = np.load(
        dp.make_file_path(dp.sims_single, 'shifting_alpha', 'npy'))

    cf_theta_df = prep_single_sims(cf_theta, "CF")
    cf_alpha_df = prep_single_sims(cf_alpha, "CF")
    cf_beta_df = prep_single_sims(cf_beta, "CF")

    pw_theta_df = prep_single_sims(pw_theta, "PW")
    pw_alpha_df = prep_single_sims(pw_alpha, "PW")
    pw_beta_df = prep_single_sims(pw_beta, "PW")

    bw_theta_df = prep_single_sims(bw_theta, "BW")
    bw_alpha_df = prep_single_sims(bw_alpha, "BW")
    bw_beta_df = prep_single_sims(bw_beta, "BW")

    for ratio in ["TAR", "TBR", "ABR"]:

        fig = plt.figure(figsize=PE_FIG_SIZE)

        # low cf
        ax = fig.add_subplot(331)
        ax.set_xlabel("CF")
        ax.set_ylabel(ratio)
        ax.plot(cf_theta_df.iloc[:, 3], cf_theta_df[ratio], linewidth=LW)

        # low pw
        ax = fig.add_subplot(332)
        ax.set_xlabel("PW")
        ax.set_ylabel(ratio)
        ax.plot(pw_theta_df.iloc[:, 3], pw_theta_df[ratio], linewidth=LW)

        if max(pw_theta_df[ratio]) - min(pw_theta_df[ratio]) < .5:

            maxx = np.max(pw_theta_df[ratio])
            ax.set_ylim([maxx - .3, maxx + .1])

        # low bw
        ax = fig.add_subplot(333)
        ax.set_xlabel("BW")
        ax.set_ylabel(ratio)
        ax.plot(bw_theta_df.iloc[:, 3], bw_theta_df[ratio], linewidth=LW)

        if max(bw_theta_df[ratio]) - min(bw_theta_df[ratio]) < .3:

            maxx = np.max(bw_theta_df[ratio])
            ax.set_ylim([maxx - .3, maxx + .1])

        # middle cf
        ax = fig.add_subplot(334)
        ax.set_xlabel("CF")
        ax.set_ylabel(ratio)
        ax.plot(cf_alpha_df.iloc[:, 3], cf_alpha_df[ratio], linewidth=LW)

        # middle pw
        ax = fig.add_subplot(335)
        ax.set_xlabel("PW")
        ax.set_ylabel(ratio)
        ax.plot(pw_alpha_df.iloc[:, 3], pw_alpha_df[ratio], linewidth=LW)

        if max(pw_alpha_df[ratio]) - min(pw_alpha_df[ratio]) < .3:

            maxx = np.max(pw_alpha_df[ratio])
            ax.set_ylim([maxx - .3, maxx + .1])

        # middle bw
        ax = fig.add_subplot(336)
        ax.set_xlabel("BW")
        ax.set_ylabel(ratio)
        ax.plot(bw_alpha_df.iloc[:, 3], bw_alpha_df[ratio], linewidth=LW)

        if max(bw_alpha_df[ratio]) - min(bw_alpha_df[ratio]) < .3:

            maxx = np.max(bw_alpha_df[ratio])
            ax.set_ylim([maxx - .3, maxx + .1])

        # high cf
        ax = fig.add_subplot(337)
        ax.set_xlabel("CF")
        ax.set_ylabel(ratio)
        ax.plot(cf_beta_df.iloc[:, 3], cf_beta_df[ratio], linewidth=LW)

        # high pw
        ax = fig.add_subplot(338)
        ax.set_xlabel("PW")
        ax.set_ylabel(ratio)
        ax.plot(pw_beta_df.iloc[:, 3], pw_beta_df[ratio], linewidth=LW)

        if max(pw_beta_df[ratio]) - min(pw_beta_df[ratio]) < .3:

            maxx = np.max(pw_beta_df[ratio])
            ax.set_ylim([maxx - .3, maxx + .1])

        # high bw
        ax = fig.add_subplot(339)
        ax.set_xlabel("BW")
        ax.set_ylabel(ratio)
        ax.plot(bw_beta_df.iloc[:, 3], bw_beta_df[ratio], linewidth=LW)

        if max(bw_beta_df[ratio]) - min(bw_beta_df[ratio]) < .3:

            maxx = np.max(bw_beta_df[ratio])
            ax.set_ylim([maxx - .3, maxx + .1])

        plt.tight_layout()
        plt.savefig(
            fp.make_file_path(fp.sims_single, 'periodic_' + ratio,
                              SAVE_FORMAT))
        plt.clf()

        ################################################

        f_df = prep_single_sims(f_data, "EXP", periodic_param=0)
        offset_df = prep_single_sims(offset, "OFF", periodic_param=0)
        exp_df = prep_single_sims(exp, "EXP", periodic_param=0)
        a_shift_df = prep_single_sims(a_shift, "Alpha CF")

        fig = plt.figure(figsize=AP_FIG_SIZE)

        # offset
        ax = fig.add_subplot(211)
        ax.set_xlabel("Offset")
        ax.set_ylabel(ratio)
        ax.plot(offset_df.iloc[:, 3], offset_df[ratio], linewidth=LW)
        ax.locator_params(axis='y', nbins=4)

        # exponent
        ax = fig.add_subplot(212)
        ax.set_xlabel("Exponent")
        ax.set_ylabel(ratio)
        ax.plot(exp_df.iloc[:, 3], exp_df[ratio], linewidth=LW)

        fig.subplots_adjust(left=0.2, hspace=0.6)

        plt.savefig(
            fp.make_file_path(fp.sims_single, 'aperiodic_' + ratio,
                              SAVE_FORMAT))