Ejemplo n.º 1
0
def baseline_tracking_extinction_switching_correlation():
    from constants import INNER_PATHS_DISCRIMINATION
    from methods import get_data_path

    X = [] 
    Y = []
    filenames = [os.path.join(get_data_path(), filename) for filename in INNER_PATHS_DISCRIMINATION]
    for filename in filenames:
        # ID = os.path.basename(os.path.dirname(filename))
        timestamps = 'time'
        paths = sorted(glob(os.path.join(filename,'0*')))

        baseline_tracking_path = paths[0]
        all_gaze_data = load_data(os.path.join(baseline_tracking_path,"gaze_coordenates_on_screen.txt"))
        left_gaze_mask, right_gaze_mask = gaze_mask_left_right(all_gaze_data)
        left_timestamps = all_gaze_data[left_gaze_mask][timestamps] 
        right_timestamps = all_gaze_data[right_gaze_mask][timestamps]

        beha_data = load_data(os.path.join(baseline_tracking_path,"behavioral_events.txt"))

        # left_right_onsets
        l_target_intervals = all_stimuli(beha_data)
        l_target_intervals = zip(l_target_intervals, l_target_intervals[1:])
        left_data = rate_in(l_target_intervals, left_timestamps)
        right_data = rate_in(l_target_intervals, right_timestamps)
        relative_rate_all = relative_rate(left_data, right_data)
        X.append(np.nanmean(relative_rate_all[::2])-np.nanmean(relative_rate_all[1::2])) 


        extintion_switching_path = paths[1]
        all_gaze_data = load_data(os.path.join(extintion_switching_path,"gaze_coordenates_on_screen.txt"))

        left_gaze_mask, right_gaze_mask = gaze_mask_left_right(all_gaze_data)
        switchings = switching_timestamps(all_gaze_data, left_gaze_mask, right_gaze_mask)
        beha_data = load_data(os.path.join(extintion_switching_path,"behavioral_events.txt"))
        target_intervals = stimuli_onset(beha_data)
        red_intervals = zip(target_intervals[0], target_intervals[1])
        blue_intervals = zip(target_intervals[1], target_intervals[0][1:])

        red_data = rate_in(red_intervals, switchings)
        blue_data = rate_in(blue_intervals, switchings)
        Y.append(np.nanmean(blue_data)-np.nanmean(red_data))

    return np.array(X), np.array(Y)
Ejemplo n.º 2
0
# self
from methods import get_data_path
from constants import INNER_PATHS
from drawing import save_all
# from drawing.eye_movements_dbscan import draw_single as draw_gaze_dbscan # NOTE: xy must be normalized
from drawing.eye_movements_quantiles import draw_single as draw_gaze_quantiles  # NOTE: xy must be normalized

from drawing.responses import draw_single as draw_responses

# matplotlib configurations
font = {'family': 'serif', 'size': 12}
matplotlib.rc('font', **font)

# assign the root data folder
data_path = get_data_path()

# save all figures inside its respective data folder
# save_all(data_path,draw_gaze_quantiles,'taxa_movimentos_oculares_B_quantis.png')
# save_all(data_path,draw_responses,'taxa_de_respostas_ao_botao_A.png')

# show single figure
ip = INNER_PATHS[1]
draw_responses(os.path.join(data_path, ip))
# draw_gaze_quantiles(os.path.join(data_path, ip))

# from helpers import delete_from_inner_paths
# from helpers import copy_to_inner_paths
# filenames = ['README.md']
# frompath = os.path.join(data_path,'README.md')
# copy_to_inner_paths(data_path, data_path, filenames)
Ejemplo n.º 3
0
def draw_proportions(cycles_set=slice(0, 9), show=True, output_path=None):
    def get_axis_limits(ax, xscale=.45, yscale=0.05):
        """
        https://stackoverflow.com/questions/24125058/add-label-to-subplot-in-matplotlib
        """
        return ax.get_xlim()[1] * xscale, ax.get_ylim()[1] * yscale

    filenames = [
        os.path.join(get_data_path(), filename) for filename in INNER_PATHS
        if filename in INNER_PATHS_DISCRIMINATION
    ]
    data = np.array([
        relative_rate_blue_red(filename, cycles_set) for filename in filenames
    ])

    x_label = 'Successive cycles'
    y_label = 'Button-pressing proportion'
    figure, axarr = plt.subplots(1,
                                 3,
                                 sharey=True,
                                 sharex=False,
                                 figsize=(6, 3))
    cycles_list = range(0, data.shape[2])
    for condition, axis in zip(range(0, 3), axarr):
        data_means = np.array(
            [np.nanmean(data[:, condition, cycles]) for cycles in cycles_list])
        data_min = np.array(
            [np.nanmin(data[:, condition, cycles]) for cycles in cycles_list])
        data_max = np.array(
            [np.nanmax(data[:, condition, cycles]) for cycles in cycles_list])

        axis.plot(data_means, color='k')
        axis.plot((-0.5, len(data_means) - 1 + 0.5), (0.5, 0.5),
                  color='k',
                  ls='dotted',
                  alpha=0.3)
        axis.errorbar(np.arange(len(data_means)),
                      data_means,
                      [data_means - data_min, data_max - data_means],
                      fmt='.k',
                      ecolor='k',
                      lw=1,
                      alpha=0.3)

        axis.set_xlim([-0.5, len(data_means) - 1 + 0.5])
        # remove outer frame
        axis.spines['top'].set_visible(False)
        axis.spines['bottom'].set_visible(False)
        axis.spines['left'].set_visible(False)
        axis.spines['right'].set_visible(False)

        lowx, highx = axis.get_xlim()
        axis.yaxis.set_ticks(np.arange(0, 1.1, 0.25))
        axis.xaxis.set_ticks([0, 8])

        #remove ticks
        axis.xaxis.set_ticks_position('none')
        axis.yaxis.set_ticks_position('none')

    size = 14
    axarr[0].set_ylabel(y_label)
    axarr[0].spines['left'].set_visible(True)
    axarr[0].annotate('A', xy=get_axis_limits(axarr[0]), size=size)

    axarr[1].set_xlabel(x_label)
    axarr[1].annotate('B', xy=get_axis_limits(axarr[1]), size=size)

    axarr[2].annotate('A', xy=get_axis_limits(axarr[2]), size=size)

    offset = 0
    x = 1
    for axis in axarr:
        axis.set_xticklabels([x + offset, 9 + offset])
        offset = offset + 9

    figure.tight_layout()
    figure.subplots_adjust(wspace=0.05)

    # bw = 0.26
    # w = .28
    # size = 14
    # figure.text(bw, 0.25, 'A',size=size)
    # figure.text(bw+w, 0.25, 'B',size=size)
    # figure.text(bw+(w*2), 0.25, 'A',size=size)

    if output_path:
        plt.savefig(output_path, bbox_inches='tight')
        plt.close()
    else:
        # save/plot figure
        if show:
            plt.show()
Ejemplo n.º 4
0
#     from constants import INNER_PATHS
#     from methods import get_data_path

#     filenames = [os.path.join(get_data_path(), filename) for filename in INNER_PATHS]
#     data = np.array([relative_rate_blue_red(filename) for filename in filenames])
#     print(data.shape)
#     data_means = np.array([np.mean(data[:, condition, cycles]) for condition in range(0,3) for cycles in range(0,8)])
#     data_min = np.array([np.min(data[:, condition, cycles]) for condition in range(0,3) for cycles in range(0,8)])
#     data_max = np.array([np.max(data[:, condition, cycles]) for condition in range(0,3) for cycles in range(0,8)])

#     axis = plt.gca()
#     plt.plot(data_means, color='k')
#     plt.errorbar(np.arange(len(data_means)),
#         data_means,
#         [data_means-data_min,data_max-data_means],
#         fmt='k', ecolor='gray', lw=1)
#     plt.show()

if __name__ == '__main__':
    from constants import INNER_PATHS
    from methods import get_data_path

    filenames = [
        os.path.join(get_data_path(), filename) for filename in INNER_PATHS
    ]
    for filename in filenames:
        print(filename)
        draw_single_proportion(filename)

    draw_proportions()
    # draw_proportions(output_path=os.path.join(get_data_path(),'button_press.png'))