Ejemplo n.º 1
0
def annotated_plot(dm):

	"""
	desc:
		Plots mean pupil size separately for dark and bright trials, and
		annotates the plot with significance markers.

	arguments:
		dm:
			type: DataMatrix
	"""

	plot.new(size=(8,6))
	lm = trace_lmer_simple(dm)
	plt.axvline(RT, color='black', linestyle=':')
	x = np.arange(3000)
	for color, a in [
			('black', 1.96), # p < .05
			('red', 2.57), # p < .01
			('orange', 2.81), # p < .005
			('yellow', 3.29) # p < .001
			]:
		threshold = series.threshold(lm.t,
			lambda t: abs(t) > a, min_length=1)
		print('Alpha %.5f (%.2f)' % (a, series.reduce_(threshold)[1]))
		plot.threshold(threshold[1], color=color, linewidth=1)
	dm_dark = dm.type == 'ctrl'
	plot.trace(dm_dark.pupil, color=grey[3],
		label='Neutral (N=%d)' % len(dm_dark))
	pupil.brightness_plot(dm, subplot=True)
	plt.xticks(range(0, 3001, 500), np.linspace(0,3,7))
	plt.xlabel('Time since word onset (s)')
	plt.ylabel('Pupil size (normalized to word onset)')
	plot.save('annotated_plot')
Ejemplo n.º 2
0
def plot_pupiltrace(dm, suffix='', interaction=False):

	"""
	desc:
		Create a plot of the pupil trace annotated with significant regions.

	arguments:
		dm:
			type: DataMatrix

	keywords:
		suffix:			A suffix for the plot.
		interaction:	Indicates whether the log_velocity by side interaction
						should be included.
	"""

	plot.new(size=(12, 6))
	# Plot the three velocities as separate lines
	for color, velocity in ( (orange[1], 30), (blue[1], 3), (green[1], .3) ):
		dm_ = dm.velocity == velocity
		plot.trace(dm_.pupil, label='%s cm/s (N=%d)' % (velocity, len(dm_)),
			color=color)
	# Run statistical model, and annotate the figure with three alpha levels:
	# .05, .01, and .005
	if interaction:
		model = 'pupil ~ log_velocity*side + (1+log_velocity*side|subject_nr)'
	else:
		model = 'pupil ~ log_velocity + (1+log_velocity|subject_nr)'
	lm = lme4.lmer_series(dm, formula=model, winlen=3,
		cacheid='lmer%s' % suffix)
	for y, color1, color2, alpha in [
		(.94, grey[2], blue[0], .05),
		(.942, grey[3], blue[1], .01),
		(.944, grey[4], blue[2], .005),
		(.946, grey[5], blue[2], .001)
		]:
		a = series.threshold(lm.p, lambda p: p > 0 and p < alpha,
			min_length=1)
		plot.threshold(a[1], y=y, color=color1, linewidth=4)
		if interaction:
			plot.threshold(a[3], y=y+.01, color=color2, linewidth=4)
	# Mark the baseline period
	plt.axvspan(50, 90, color='black', alpha=.2)
	# Mark the cue onset
	plt.axvline(90, color='black')
	# Adjust the x axis such that 0 is the cue onset, and the units are time in
	# seconds (assuming 33 ms per sample)
	plt.xticks(np.arange(40, 540, 50), np.arange(-50, 450, 50)*.033)
	plt.xlim(0, 540)
	plt.xlabel('Time since auditory cue (s)')
	plt.ylabel('Pupil size (relative to baseline)')
	plt.legend(frameon=False)
	plot.save('pupiltrace'+suffix)
Ejemplo n.º 3
0
def brightness_plot(dm, subplot=False):

    """
	desc:
		Plots mean pupil size separately for dark and bright trials over time.

	arguments:
		dm:
			type: DataMatrix

	keywords:
		subplot:	Indicates whether a new plot should be created, or not.
	"""

    if not subplot:
        plot.new()
    dm_bright = dm.type == "light"
    dm_dark = dm.type == "dark"
    plot.trace(dm_bright.pupil, color=orange[1], label="Bright (N=%d)" % len(dm_bright))
    plot.trace(dm_dark.pupil, color=blue[1], label="Dark (N=%d)" % len(dm_dark))
    plt.legend(frameon=False)
    if not subplot:
        plot.save("brightness_plot")
Ejemplo n.º 4
0
def valence_plot(dm, subplot=False):

    """
	desc:
		Plots mean pupil size separately for positive and negative trials over
		time.

	arguments:
		dm:
			type: DataMatrix

	keywords:
		subplot:	Indicates whether a new plot should be created, or not.
	"""

    if not subplot:
        plot.new()
    dm_pos = dm.category == "positive"
    dm_neg = dm.category == "negative"
    plot.trace(dm_pos.pupil, color=green[1], label="Positive (N=%d)" % len(dm_pos))
    plot.trace(dm_neg.pupil, color=red[1], label="Negative (N=%d)" % len(dm_neg))
    plt.legend(frameon=False)
    if not subplot:
        plot.save("valence_plot")
Ejemplo n.º 5
0
    series= dm.pupil,
    baseline=dm.ptrace_rsvp,
    bl_start=0,
    bl_end=2,
    method='subtractive'
)

# Splitting datamatrix between the two type of stimuli
blueDM, redDM = ops.split(dm.target_object, "blue", "red")

# Plot for preprocessed trace
plt.figure()
plt.title('Preprocesed trace')
for tone, cdm in ops.split(redDM.tone_red):
    colour = "#FF3333" if tone == "bright" else "#8B0000"
    plot.trace(cdm.pupil, color=colour)
    
for tone, cdm in ops.split(blueDM.tone_blue):
    colour = "#00FFFF" if tone == "bright" else "#00008B"
    plot.trace(cdm.pupil, color=colour)

plt.tight_layout()
plt.savefig(path + "/preprocessed.png")
plt.clf()

# Splitting the tones in order to plot the pupil size changes.
brightBlueDM, darkBlueDM = ops.split(
    blueDM.tone_blue, "bright", "dark")
brightRedDM, darkRedDM = ops.split(
    redDM.tone_red, "bright", "dark")
def plotmean(dm, col):
	
	plot.trace((dm.c == 1)[col], color=COLOR1)
	plot.trace((dm.c == 2)[col], color=COLOR2)
	plt.xlabel('Time (ms)')
	plt.ylabel('Pupil size')