コード例 #1
0
def draw_single(src_dir, show=False):
    print os.path.dirname(src_dir)
    ID = os.path.basename(os.path.dirname(src_dir))
    paths = sorted(glob(os.path.join(src_dir, '0*')))
    # global vars
    data = []
    ymax = []
    for path in paths:

        be = load_data_from_path(path)
        responses = all_responses(be)
        data.append((stimuli_onset(be), responses))

        ymax.append(len(responses))

    ymax = np.amax(ymax)
    x_label = 'Ciclos'
    y_label = 'Taxa (respostas por segundo)'
    title = 'Particip. ' + ID + ': taxa de resp. durante as cores Verm. e Azul.'

    n_plots = len(paths)
    if n_plots == 1:
        figsize = (4, 4)
    elif n_plots == 2:
        figsize = (8, 4)
    elif n_plots == 3:
        figsize = (12, 4)
    else:
        figsize = (14, 4)

    # figure.add_axes([0.1, 0.1, 0.8, 0.8], frameon = 0)
    figure, axarr = plt.subplots(1,
                                 n_plots,
                                 sharey=True,
                                 sharex=False,
                                 figsize=figsize)
    figure.suptitle(title)
    figure.text(0.5, 0.02, x_label)
    #figure.text(0.014, 0.5, y_label, rotation='vertical',verticalalignment='center',horizontalalignment='right')

    for i, d in enumerate(data):
        (onsets, responses) = d
        plot_temporal_perfil(axarr[i], onsets, responses)
        #plt.xlim(xmax = 300)

    axarr[0].set_ylabel(y_label)
    # axarr[0].legend(loc='upper right')
    # axarr[1].set_xlabel(x_label)
    #plt.ylim(ymax = ymax, ymin = 0)
    #plt.text(-16,4,ID,fontsize=18)
    #figure.subplots_adjust(wspace=0.05,left=0.05, right=.98,bottom=0.1,top=0.92)
    figure.tight_layout()

    # save/plot figure
    if show:
        plt.show()
コード例 #2
0
def draw_single_proportion(src_dir, show=True):
    print(os.path.dirname(src_dir))
    ID = os.path.basename(os.path.dirname(src_dir))
    paths = sorted(glob(os.path.join(src_dir, '0*')))

    data = []
    x_label = 'Successive cycles'
    y_label = 'Button-pressing proportion'
    title = ID
    figure, axarr = plt.subplots(1,
                                 3,
                                 sharey=True,
                                 sharex=True,
                                 figsize=(9, 3))
    # figure.suptitle(title);
    # figure.text(0.5, 0.02, x_label)
    for path, axis in zip(paths, axarr):
        beha_data = load_data(os.path.join(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:])
        responses = all_responses(beha_data)

        red_data = rate_in(red_intervals, responses)
        blue_data = rate_in(blue_intervals, responses)

        relative_rate = [
            r / (r + b) if r + b > 0 else np.nan
            for r, b in zip(red_data, blue_data)
        ]
        axis.plot(relative_rate, color="k", label="Right")

        # 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)

        axis.set_ylim(0., 1.)
        axis.set_xlim(-0.5, len(relative_rate) + 0.5)
        axis.set_xticklabels([x for x in range(-1, len(relative_rate) + 1, 2)])

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

    axarr[0].set_ylabel(y_label)
    axarr[0].spines['left'].set_visible(True)
    axarr[1].set_xlabel(x_label)
    figure.tight_layout()

    # save/plot figure
    if show:
        plt.show()
コード例 #3
0
def draw_single(src_dir, show=False):
  print os.path.dirname(src_dir)
  ID = os.path.basename(os.path.dirname(src_dir))
  paths = sorted(glob(os.path.join(src_dir,'0*')))
  # global vars
  data = []
  ymax = []
  for path in paths:

      be = load_data_from_path(path)
      responses = all_responses(be)
      data.append((stimuli_onset(be), responses))

      ymax.append(len(responses))

  ymax = np.amax(ymax)
  x_label = 'Ciclos'
  y_label = 'Taxa (respostas por segundo)'
  title = 'Particip. '+ID+': taxa de resp. durante as cores Verm. e Azul.'

  n_plots = len(paths)
  if n_plots == 1:
      figsize = (4, 4)
  elif n_plots == 2:
      figsize = (8, 4)
  elif n_plots == 3:
      figsize = (12, 4)
  else:
      figsize = (14, 4)

  # figure.add_axes([0.1, 0.1, 0.8, 0.8], frameon = 0)
  figure, axarr = plt.subplots(1, n_plots, sharey=True, sharex=False, figsize=figsize) 
  figure.suptitle(title);
  figure.text(0.5, 0.02, x_label)
  #figure.text(0.014, 0.5, y_label, rotation='vertical',verticalalignment='center',horizontalalignment='right')

  for i, d in enumerate(data):
      (onsets, responses) = d
      plot_temporal_perfil(axarr[i], onsets, responses)
      #plt.xlim(xmax = 300)

  axarr[0].set_ylabel(y_label)
  # axarr[0].legend(loc='upper right')
  # axarr[1].set_xlabel(x_label)
  #plt.ylim(ymax = ymax, ymin = 0)
  #plt.text(-16,4,ID,fontsize=18)
  #figure.subplots_adjust(wspace=0.05,left=0.05, right=.98,bottom=0.1,top=0.92)
  figure.tight_layout()
  
  # save/plot figure
  if show:
    plt.show()
コード例 #4
0
def rate_switching(src_dir, cycles_set=slice(0,8)):
    paths = sorted(glob(os.path.join(src_dir,'0*')))
    data = []
    for path in paths:
        all_gaze_data = load_data(os.path.join(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(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)[cycles_set]
        blue_data = rate_in(blue_intervals, switchings)[cycles_set]
        data.append((red_data,blue_data,switchings.shape[0]))
    return data
コード例 #5
0
def relative_rate_blue_red(src_dir, cycles_set=slice(0,8)):
    paths = sorted(glob(os.path.join(src_dir,'0*')))
    data = []
    for path in paths:
        beha_data = load_data(os.path.join(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:])
        responses = all_responses(beha_data)
        
        red_data = rate_in(red_intervals, responses)
        blue_data = rate_in(blue_intervals, responses)

        relative_rate_all = relative_rate(red_data, blue_data)
        data.append(relative_rate_all[cycles_set])
    return data
コード例 #6
0
def relative_rate_left_right(src_dir, target_intervals='all_onsets'):
    timestamps = 'time'
    paths = sorted(glob(os.path.join(src_dir,'0*')))
    data = []
    for path in paths:
        all_gaze_data = load_data(os.path.join(path,"gaze_coordenates_on_screen.txt"))
        all_gaze_data, 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(path,"behavioral_events.txt"))
        if 'all_onsets' in target_intervals: 
            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)
            data.append(relative_rate_all)

        elif 'left_right_onsets' in target_intervals:
            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)
            data.append([relative_rate_all[::2],relative_rate_all[1::2]])

        elif 'red_blue_onsets' in target_intervals:
            l_target_intervals = stimuli_onset(beha_data)

            red_intervals = zip(l_target_intervals[0], l_target_intervals[1])
            left_red_data = rate_in(red_intervals, left_timestamps)

            red_intervals = zip(l_target_intervals[0], l_target_intervals[1])
            right_red_data = rate_in(red_intervals, right_timestamps)
            
            blue_intervals = zip(l_target_intervals[1], l_target_intervals[0][1:])
            left_blue_data = rate_in(blue_intervals, left_timestamps)
            
            blue_intervals = zip(l_target_intervals[1], l_target_intervals[0][1:])
            right_blue_data = rate_in(blue_intervals, right_timestamps)
            
            relative_rate_positive = relative_rate(left_red_data, right_red_data)
            relative_rate_negative = relative_rate(left_blue_data, right_blue_data)

            data.append((relative_rate_positive, relative_rate_negative))
    return data
コード例 #7
0
def draw_single(src_dir, show=True):
    print(os.path.dirname(src_dir))
    ID = os.path.basename(os.path.dirname(src_dir))
    paths = sorted(glob(os.path.join(src_dir, '0*')))

    data = []
    ymax = []
    for path in paths:
        be = load_data(os.path.join(path, "behavioral_events.txt"))
        responses = all_responses(be)
        data.append((stimuli_onset(be), responses))

        ymax.append(len(responses))

    ymax = np.amax(ymax)
    x_label = 'Ciclos'
    y_label = 'Taxa (respostas por segundo)'
    title = 'Particip. ' + ID + ': taxa de resp. durante as cores Verm. e Azul.'

    n_plots = len(paths)
    if n_plots == 1:
        figsize = (4, 4)
    elif n_plots == 2:
        figsize = (8, 4)
    elif n_plots == 3:
        figsize = (12, 4)
    else:
        figsize = (14, 4)

    figure, axarr = plt.subplots(1,
                                 n_plots,
                                 sharey=True,
                                 sharex=False,
                                 figsize=figsize)
    figure.suptitle(title)
    figure.text(0.5, 0.02, x_label)
    for i, d in enumerate(data):
        (onsets, responses) = d
        temporal_perfil(axarr[i], onsets, responses)

    axarr[0].set_ylabel(y_label)
    figure.tight_layout()

    # save/plot figure
    if show:
        plt.show()
コード例 #8
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)
コード例 #9
0
        figsize = (11, 4)
    else:
        figsize = (16, 4)

    # figure.add_axes([0.1, 0.1, 0.8, 0.8], frameon = 0)
    figure, axarr = plt.subplots(1,
                                 n_plots,
                                 sharey=True,
                                 sharex=False,
                                 figsize=figsize)
    figure.suptitle(title)
    figure.text(0.5, 0.02, x_label)

    for i, path in enumerate(paths):
        be, ge = load_npdata_from_path(path)
        plot_temporal_perfil(axarr[i], stimuli_onset(be), ge['time'])

    axarr[0].set_ylabel(y_label)
    #axarr.legend(loc=(0.0,0.73))

    # axarr[1].set_xlabel(x_label)
    plt.ylim(ymin=0)

    figure.subplots_adjust(wspace=0.1,
                           left=0.05,
                           right=.98,
                           bottom=0.1,
                           top=0.92)
    #figure.tight_layout()
    plt.show()
コード例 #10
0
	n_plots = len(paths)
	if n_plots == 1:
		figsize = (6, 4)
	elif n_plots == 2:
		figsize = (11, 4)
	else:
		figsize = (16, 4)

	# figure.add_axes([0.1, 0.1, 0.8, 0.8], frameon = 0)
	figure, axarr = plt.subplots(1, n_plots, sharey=True, sharex=False, figsize=figsize) 
	figure.suptitle(title);
	figure.text(0.5, 0.02, x_label)

	for i, path in enumerate(paths):
		be, fx = load_npdata_from_path(path)
		plot_temporal_perfil(axarr[i], stimuli_onset(be), fx['start_time'])

		#axarr.set_ylabel(y_label)
		#axarr.legend(loc=(0.0,0.73))

		# axarr[1].set_xlabel(x_label)
	plt.ylim(ymin = 0)

	figure.subplots_adjust(wspace=0.1,left=0.05, right=.98,bottom=0.1,top=0.92)
	# figure.tight_layout()
	
	plt.show()

  # print all column names
  # for key in be.dtype.names:
  #   print key
コード例 #11
0
        figsize = (11, 4)
    else:
        figsize = (16, 4)

    # figure.add_axes([0.1, 0.1, 0.8, 0.8], frameon = 0)
    figure, axarr = plt.subplots(1,
                                 n_plots,
                                 sharey=True,
                                 sharex=False,
                                 figsize=figsize)
    figure.suptitle(title)
    figure.text(0.5, 0.02, x_label)

    for i, path in enumerate(paths):
        be, fx = load_npdata_from_path(path)
        plot_temporal_perfil(axarr[i], stimuli_onset(be), fx['start_time'])

        #axarr.set_ylabel(y_label)
        #axarr.legend(loc=(0.0,0.73))

        # axarr[1].set_xlabel(x_label)
    plt.ylim(ymin=0)

    figure.subplots_adjust(wspace=0.1,
                           left=0.05,
                           right=.98,
                           bottom=0.1,
                           top=0.92)
    # figure.tight_layout()

    plt.show()
コード例 #12
0
	n_plots = len(paths)
	if n_plots == 1:
		figsize = (6, 4)
	elif n_plots == 2:
		figsize = (11, 4)
	else:
		figsize = (16, 4)

	# figure.add_axes([0.1, 0.1, 0.8, 0.8], frameon = 0)
	figure, axarr = plt.subplots(1, n_plots, sharey=True, sharex=False, figsize=figsize) 
	figure.suptitle(title);
	figure.text(0.5, 0.02, x_label)

	for i, path in enumerate(paths):
		be, ge = load_npdata_from_path(path)
		plot_temporal_perfil(axarr[i], stimuli_onset(be), ge['time'])

	axarr[0].set_ylabel(y_label)
	#axarr.legend(loc=(0.0,0.73))

	# axarr[1].set_xlabel(x_label)
	plt.ylim(ymin = 0)

	figure.subplots_adjust(wspace=0.1,left=0.05, right=.98,bottom=0.1,top=0.92)
	#figure.tight_layout()
	plt.show()

	# print all column names
	# for key in be.dtype.names:
	#   print key