コード例 #1
0
ファイル: map_to_brain.py プロジェクト: vala1958/network
def plot_brain_substates_start_end(trial_num_states, lst_start_and_end_indices,
                                   obs, vmin, vmax, state_number, time_bins,
                                   name, trial_type, save_figures, file, title,
                                   kind_prepro, run):

    if len(lst_start_and_end_indices) > 8:
        print(
            'number of substates is to large (>8), please use other function or select manually, maximal 8'
        )
    else:

        allenMap, allenIndices = load_matrix('')
        sub_state_number_list = [
            x for x in range(0, len(lst_start_and_end_indices))
        ]

        figsize = get_figsize(lst_start_and_end_indices)

        fig, ax = plt.subplots(1,
                               len(lst_start_and_end_indices),
                               figsize=figsize,
                               tight_layout=False)

        for i in range(len(lst_start_and_end_indices)):
            average_obs_per_sub_state = (np.mean(
                obs[lst_start_and_end_indices[i][0]:
                    lst_start_and_end_indices[i][1], :],
                axis=0))
            if i == len(lst_start_and_end_indices) - 1:
                plot_area_values(fig,
                                 ax[i],
                                 allenMap,
                                 allenIndices,
                                 average_obs_per_sub_state,
                                 vmin=vmin,
                                 vmax=vmax,
                                 haveColorBar=True)
            else:
                plot_area_values(fig,
                                 ax[i],
                                 allenMap,
                                 allenIndices,
                                 average_obs_per_sub_state,
                                 vmin=vmin,
                                 vmax=vmax,
                                 haveColorBar=False)

            ax[i].set_title('state {}, substate {} '.format(
                state_number, sub_state_number_list[i]))

        if save_figures:
            new = name + ' plots results {} {} {}'.format(
                trial_type, time_bins, trial_num_states)
            subdirectory(file, new)
            plt.savefig(new +
                        '/brainmap_sub_{}_{}_{}_{}_{}_{}_{}_run{}.png'.format(
                            name, trial_type, time_bins, title, get_date(),
                            state_number, kind_prepro, run))

        plt.show()
コード例 #2
0
ファイル: map_to_brain.py プロジェクト: vala1958/network
def plot_brain_states_nan(trial_num_states, lst_average_obs_per_state, vmin,
                          vmax, time_bins, name, trial_type, delay,
                          save_figures, file, title, kind_prepro, run):
    """
    function to plot the brain states. each brainstate is one image and each is saved individually, including the
    possibility of empty (non existing) states
    """

    allenMap, allenIndices = load_matrix('')
    state_number_list = [x for x in range(0, trial_num_states)]

    for i in range(len(lst_average_obs_per_state)):

        sum_mean_all_roi = sum(lst_average_obs_per_state[i])

        if sum_mean_all_roi == 0:
            print('state {} does not exist!'.format(i))

        else:
            fig, ax = plt.subplots(1, 1, figsize=(6, 6), tight_layout=False)

            plot_area_values(fig,
                             ax,
                             allenMap,
                             allenIndices,
                             lst_average_obs_per_state[i],
                             vmin=vmin,
                             vmax=vmax,
                             haveColorBar=True)
            ax.set_title(
                'activity of the 27 Rois: {}, {}, {}\n{}s, {}, state {}  '.
                format(name, trial_type, time_bins, delay, title,
                       state_number_list[i]))

            if save_figures:
                new = name + ' plots results {} {} {}'.format(
                    trial_type, time_bins, trial_num_states)
                subdirectory(file, new)
                plt.savefig(new +
                            '/brainmap_{}_{}_{}_{}_{}_{}_{}_run{}.png'.format(
                                name, trial_type, time_bins, title, get_date(),
                                state_number_list[i], kind_prepro, run))

    # plot the as png exported legend
    plt.rcParams["axes.grid"] = False
    plt.figure(figsize=(4, 2))

    img = plt.imread('legend.png')
    plt.imshow(img)
    plt.axis('off')

    if save_figures:
        new = name + ' plots results {} {} {}'.format(trial_type, time_bins,
                                                      trial_num_states)
        subdirectory(file, new)
        plt.savefig(new + '/legend.png')

    plt.show()
コード例 #3
0
ファイル: map_to_brain.py プロジェクト: vala1958/network
def plot_brain_states_1(trial_num_states, lst_average_obs_per_state, vmin,
                        vmax, time_bins, name, trial_type, save_figures, file,
                        title, run):
    """
    function to plot the brainstates in one row and stored as one image, color bar only at the last map
    """

    allenMap, allenIndices = load_matrix('')
    state_number_list = [x for x in range(0, trial_num_states)]

    if trial_num_states > 8:
        print(
            'number of states is to large (squeezed plot), please use other plot function'
        )
    else:

        figsize = get_figsize(lst_average_obs_per_state)

        fig, ax = plt.subplots(1,
                               trial_num_states,
                               figsize=figsize,
                               tight_layout=False)

        for i in range(len(lst_average_obs_per_state)):
            if i == len(lst_average_obs_per_state) - 1:
                plot_area_values(fig,
                                 ax[i],
                                 allenMap,
                                 allenIndices,
                                 lst_average_obs_per_state[i],
                                 vmin=vmin,
                                 vmax=vmax,
                                 haveColorBar=True)
            else:
                plot_area_values(fig,
                                 ax[i],
                                 allenMap,
                                 allenIndices,
                                 lst_average_obs_per_state[i],
                                 vmin=vmin,
                                 vmax=vmax,
                                 haveColorBar=False)

            ax[i].set_title('state {}  '.format(state_number_list[i]))

        if save_figures:
            new = name + ' plots results {} {} {}'.format(
                trial_type, time_bins, trial_num_states)
            subdirectory(file, new)
            plt.savefig(new + '/brainmap_1_{}_{}_{}_{}_{}_{}_run{}.png'.format(
                name, trial_type, time_bins, title, get_date(),
                state_number_list[i], run))

        plt.show()
コード例 #4
0
ファイル: map_to_brain.py プロジェクト: vala1958/network
def plot_brain_substates_1(trial_num_states, lst_sub_states, obs, vmin, vmax,
                           state_number, time_bins, name, trial_type,
                           save_figures, file, title, run):
    """
    function with a double loop for more then 8 states (does not work probably)
    """
    allenMap, allenIndices = load_matrix('')
    sub_state_number_list = [x for x in range(0, len(lst_sub_states))]

    figsize = get_figsize(lst_sub_states)
    number_of_rows = int(np.ceil(len(lst_sub_states) / 8))
    print(number_of_rows)

    fig, ax = plt.subplots(number_of_rows,
                           8,
                           figsize=figsize,
                           tight_layout=False)
    for j in range(number_of_rows):
        for i in range(8):
            average_obs_per_sub_state = (np.mean(obs[lst_sub_states[(j * 8) +
                                                                    i], :],
                                                 axis=0))
            plot_area_values(fig,
                             ax[j, i],
                             allenMap,
                             allenIndices,
                             average_obs_per_sub_state,
                             vmin=vmin,
                             vmax=vmax,
                             haveColorBar=False)
            ax[j, i].set_title('state {}, substate {} '.format(
                state_number, sub_state_number_list[i]))

    if save_figures:
        new = name + ' plots results {} {} {}'.format(trial_type, time_bins,
                                                      trial_num_states)
        subdirectory(file, new)
        plt.savefig(new + '/brainmap_sub_{}_{}_{}_{}_{}_{}_run{}.png'.format(
            name, trial_type, time_bins, title, get_date(), state_number, run))

    plt.show()
コード例 #5
0
ファイル: map_to_brain.py プロジェクト: vala1958/network
def plot_brain_substates_2(trial_num_states, lst_sub_states, obs, vmin, vmax,
                           state_number, time_bins, name, trial_type,
                           save_figures, file, title, kind_prepro, run):
    """
    function with a double loop for more then 8 states
    """
    allenMap, allenIndices = load_matrix('')
    sub_state_number_list = [x for x in range(0, len(lst_sub_states))]

    figsize = get_figsize_2(lst_sub_states)
    number_of_rows = int(np.ceil(len(lst_sub_states) / 8))

    fig, ax = plt.subplots(number_of_rows,
                           8,
                           figsize=figsize,
                           tight_layout=False)
    ax = ax.ravel()
    for i in range(len(lst_sub_states)):
        if len(lst_sub_states) < 8:
            if i == len(lst_sub_states) - 1:
                average_obs_per_sub_state = (np.mean(obs[lst_sub_states[i], :],
                                                     axis=0))
                plot_area_values(fig,
                                 ax[i],
                                 allenMap,
                                 allenIndices,
                                 average_obs_per_sub_state,
                                 vmin=vmin,
                                 vmax=vmax,
                                 haveColorBar=True)
            else:
                average_obs_per_sub_state = (np.mean(obs[lst_sub_states[i], :],
                                                     axis=0))
                plot_area_values(fig,
                                 ax[i],
                                 allenMap,
                                 allenIndices,
                                 average_obs_per_sub_state,
                                 vmin=vmin,
                                 vmax=vmax,
                                 haveColorBar=False)
        else:
            if i == 7 or i == 15 or i == 23:
                average_obs_per_sub_state = (np.mean(obs[lst_sub_states[i], :],
                                                     axis=0))
                plot_area_values(fig,
                                 ax[i],
                                 allenMap,
                                 allenIndices,
                                 average_obs_per_sub_state,
                                 vmin=vmin,
                                 vmax=vmax,
                                 haveColorBar=True)
            else:
                average_obs_per_sub_state = (np.mean(obs[lst_sub_states[i], :],
                                                     axis=0))
                plot_area_values(fig,
                                 ax[i],
                                 allenMap,
                                 allenIndices,
                                 average_obs_per_sub_state,
                                 vmin=vmin,
                                 vmax=vmax,
                                 haveColorBar=False)

        ax[i].set_title('state {}, substate {} '.format(
            state_number, sub_state_number_list[i]))

    if save_figures:
        new = name + ' plots results {} {} {}'.format(trial_type, time_bins,
                                                      trial_num_states)
        subdirectory(file, new)
        plt.savefig(new +
                    '/brainmap_sub_{}_{}_{}_{}_{}_{}_{}_run{}.png'.format(
                        name, trial_type, time_bins, title, kind_prepro,
                        get_date(), state_number, run))

    plt.show()
コード例 #6
0
ファイル: map_to_brain.py プロジェクト: vala1958/network
def plot_brain_states_2_nan(trial_num_states, lst_average_obs_per_state, vmin,
                            vmax, time_bins, name, trial_type, save_figures,
                            file, title, kind_prepro, run):
    """
    function with a double loop for more then 8 states , saved as one image, including  the possibility of empty states
     """

    allenMap, allenIndices = load_matrix('')
    state_number_list = [x for x in range(0, trial_num_states)]

    figsize_2 = get_figsize_2(lst_average_obs_per_state)
    number_of_rows = int(np.ceil(len(lst_average_obs_per_state) / 8))

    fig, ax = plt.subplots(number_of_rows,
                           8,
                           figsize=figsize_2,
                           tight_layout=False)
    ax = ax.ravel()

    for i in range(len(lst_average_obs_per_state)):

        sum_mean_all_roi = sum(lst_average_obs_per_state[i])

        if sum_mean_all_roi == 0:
            print('state {} does not exist!'.format(i))
        else:

            if len(lst_average_obs_per_state) < 8:
                if i == len(lst_average_obs_per_state) - 1:
                    plot_area_values(fig,
                                     ax[i],
                                     allenMap,
                                     allenIndices,
                                     lst_average_obs_per_state[i],
                                     vmin=vmin,
                                     vmax=vmax,
                                     haveColorBar=True)

                else:
                    plot_area_values(fig,
                                     ax[i],
                                     allenMap,
                                     allenIndices,
                                     lst_average_obs_per_state[i],
                                     vmin=vmin,
                                     vmax=vmax,
                                     haveColorBar=False)

            else:
                if i == 7 or i == 15 or i == 23:
                    plot_area_values(fig,
                                     ax[i],
                                     allenMap,
                                     allenIndices,
                                     lst_average_obs_per_state[i],
                                     vmin=vmin,
                                     vmax=vmax,
                                     haveColorBar=True)
                else:
                    plot_area_values(fig,
                                     ax[i],
                                     allenMap,
                                     allenIndices,
                                     lst_average_obs_per_state[i],
                                     vmin=vmin,
                                     vmax=vmax,
                                     haveColorBar=False)

        ax[i].set_title('state {} '.format(state_number_list[i]))
        ax[i].set_yticks([])
        ax[i].set_xticks([])

    if save_figures:
        new = name + ' plots results {} {} {}'.format(trial_type, time_bins,
                                                      trial_num_states)
        subdirectory(file, new)
        plt.savefig(new + '/brainmap_2_{}_{}_{}_{}_{}_{}_run{}.png'.format(
            name, trial_type, time_bins, title, get_date(), kind_prepro, run))

    plt.show()
コード例 #7
0
ファイル: map_to_brain.py プロジェクト: vala1958/network
def plot_brain_states_1_nan(trial_num_states, lst_average_obs_per_state, vmin,
                            vmax, time_bins, name, trial_type, save_figures,
                            file, title, kind_prepro, run):
    """
    function to plot the brain states in one row and stored as one image, including the option of empty states
    """

    allenMap, allenIndices = load_matrix('')
    state_number_list = [x for x in range(0, trial_num_states)]

    if trial_num_states > 8:
        print(
            'number of states is to large (squeezed plot), please use other plot function'
        )
    else:
        figsize = get_figsize(lst_average_obs_per_state)

        fig, ax = plt.subplots(1,
                               trial_num_states,
                               figsize=figsize,
                               tight_layout=False)

        for i in range(len(lst_average_obs_per_state)):

            sum_mean_all_roi = sum(lst_average_obs_per_state[i])

            if sum_mean_all_roi == 0:
                print('state {} does not exist!'.format(i))

            else:

                if i == trial_num_states - 1:
                    plot_area_values(fig,
                                     ax[i],
                                     allenMap,
                                     allenIndices,
                                     lst_average_obs_per_state[i],
                                     vmin=vmin,
                                     vmax=vmax,
                                     haveColorBar=True)
                else:
                    plot_area_values(fig,
                                     ax[i],
                                     allenMap,
                                     allenIndices,
                                     lst_average_obs_per_state[i],
                                     vmin=vmin,
                                     vmax=vmax,
                                     haveColorBar=False)

            ax[i].set_title('state {}  '.format(state_number_list[i]))
            ax[i].set_yticks([])
            ax[i].set_xticks([])

        if save_figures:
            new = name + ' plots results {} {} {}'.format(
                trial_type, time_bins, trial_num_states)
            subdirectory(file, new)
            plt.savefig(new + '/brainmap_1_{}_{}_{}_{}_{}_{}_run{}.png'.format(
                name, trial_type, time_bins, title, get_date(), kind_prepro,
                run))

        plt.show()