예제 #1
0
def word_summary(dm):

    """
	desc:
		Plots the mean pupil size for dark and bright words as a bar plot. The
		time window is indicated by the PEAKWIN constant. This data is also
		written to a .csv file.

	arguments:
		dm:
			type: DataMatrix
	"""

    dm = (dm.type == "light") | (dm.type == "dark")
    x = np.arange(dm.pupil.depth)
    sm = DataMatrix(length=len(dm.word.unique))
    sm.word = 0
    sm.type = 0
    sm.pupil_win = FloatColumn
    sm.pupil_win_se = FloatColumn
    sm.pupil_full = FloatColumn
    sm.pupil_full_se = FloatColumn
    for i, w in enumerate(dm.word.unique):
        _dm = dm.word == w
        sm.word[i] = w
        sm.type[i] = (dm.word == w).type[0]
        sm.pupil_win[i], sm.pupil_win_se[i] = size_se(_dm, PEAKWIN[0], PEAKWIN[1])
        sm.pupil_full[i], sm.pupil_full_se[i] = size_se(_dm)
    sm = operations.sort(sm, sm.pupil_win)
    io.writetxt(sm, "%s/word_summary.csv" % OUTPUT_FOLDER)

    plot.new(size=(4, 3))
    dx = 0
    for color, type_ in ((orange[1], "light"), (blue[1], "dark")):
        sm_ = sm.type == type_
        x = np.arange(len(sm_))
        plt.plot(sm_.pupil_win, "o-", color=color)
        if type_ == "dark":
            yerr = (np.zeros(len(sm_)), sm_.pupil_win_se)
        else:
            yerr = (sm_.pupil_win_se, np.zeros(len(sm_)))
        plt.errorbar(x, sm_.pupil_win, yerr=yerr, linestyle="", color=color, capsize=0)
    plt.xlim(-1, 33)
    plt.ylabel("Pupil size (normalized)")
    plt.xlabel("Word")
    plt.xticks([])
    plot.save("word_summary")
예제 #2
0
for path in os.listdir('data-ratings'):
	if not path.endswith('.csv'):
		continue
	print('Reading %s' % path)
	if dm is None:
		dm = io.readtxt('data-ratings/%s' % path)
	else:
		dm <<= io.readtxt('data-ratings/%s' % path)

# This word was misspelled
dm = dm.word != 'térébrant'
# There are 30 participants who provided 2 ratings for 122 words
assert(len(dm) == 30*2*102)

rm = DataMatrix(length=101)
rm.word = ''
rm._type = ''
rm.rating_brightness = FloatColumn
rm.rating_valence = FloatColumn
rm.rating_intensity = FloatColumn
for row, word in zip(rm, dm.word.unique):
	dm_ = dm.word == word
	dme = dm_.rating_type == 'emotion'
	dmb = dm_.rating_type == 'brightness'
	# Pénombre was accidentally rated twice.
	assert(len(dmb)==30 or word == 'pénombre')
	assert(len(dme)==30 or word == 'pénombre')
	row.word = word
	row._type = dme.type[0]
	row.rating_brightness = dmb.rating.mean
	row.rating_valence = dme.rating.mean