def test_keep_only():

	dm = DataMatrix(length=2)
	dm.a = 'a', 'b'
	dm.b = 0, 1
	ops.keep_only(dm, ['b'])
	ok_('a' not in dm.column_names)
	ok_('b' in dm.column_names)
Exemplo n.º 2
0
def subset(dm):
    '''Selects a subset of columns'''
    dm = ops.keep_only(dm, dm.blockID, dm.trialid, dm.block_condition,
                       dm.correct_selection, dm.loop_rt, dm.subject_nr)
    '''Columns available: 
    ['acc', 'accuracy', 'average_response_time', 'avg_rt', 'background', 'bidi', 'blockID', 'blockOrder', 'block_condition', 
    'canvas_backend', 'checkFix', 'clock_backend', 'color_backend', 'compensation', 'coordinates', 'correct', 'correct_block_feedback', 
    'correct_feedback', 'correct_keyboard_response', 'correct_selection', 'correct_sketchpad', 'count_README', 'count_add_block', 
    'count_blank', 'count_block_feedback', 'count_default_settings', 'count_eight_options', 'count_exp_sequence', 'count_experiment', 
    'count_experiment_settings', 'count_eye_tracker', 'count_feedback', 'count_final_feedback', 'count_form_base', 'count_get_input', 
    'count_globals', 'count_item', 'count_itemArray', 'count_keyboard_response', 'count_logger', 'count_new_inline_script', 'count_new_loop', 
    'count_new_quest_staircase_init', 'count_new_quest_staircase_next_1', 'count_pygaze_init', 'count_pygaze_log', 'count_pygaze_start_recording', 
    'count_pygaze_stop_recording', 'count_python_definitions', 'count_select_target', 'count_sketchpad', 'count_smoothing', 'count_speak_target', 
    'count_speech', 'count_startup_variables', 'count_trial', 'datetime', 'description', 'disable_garbage_collection', 'ecc', 'experiment_file', 
    'experiment_path', 'eye_used', 'final_acc', 'final_rt', 'fixetlist_rsvp', 'fixstlist_rsvp', 'fixxlist_rsvp', 'fixylist_rsvp', 'font_bold', 
    'font_family', 'font_italic', 'font_size', 'font_underline', 'foreground', 'form_clicks', 'form_response', 'fullscreen', 'height', 'itemIds', 
    'keyboard_backend', 'likelihoodThr', 'live_row', 'live_row_eight_options', 'live_row_new_loop', 'logfile', 'loop_rt', 'mode2', 'mouse_backend', 
    'numberOfTrials', 'opensesame_codename', 'opensesame_version', 'opt8', 'path', 'practiceMode', 'psychopy_screen', 'ptrace_rsvp', 'quest_test_value', 
    'repeat_cycle', 'response', 'response_block_feedback', 'response_feedback', 'response_final_feedback', 'response_keyboard_response', 'response_sketchpad', 
    'response_time', 'response_time_block_feedback', 'response_time_feedback', 'response_time_final_feedback', 'response_time_keyboard_response', 
    'response_time_sketchpad', 'round_decimals', 'rounds', 'sampler_backend', 'showCue', 'size', 'sound_buf_size', 'sound_channels', 'sound_freq', 
    'sound_sample_size', 'stabilize', 'staircase', 'start', 'subject_nr', 'subject_parity', 'synth_backend', 't_offset_rsvp', 't_onset_rsvp', 
    'target', 'time_README', 'time_add_block', 'time_blank', 'time_block_feedback', 'time_default_settings', 'time_eight_options', 'time_exp_sequence', 
    'time_experiment', 'time_experiment_settings', 'time_eye_tracker', 'time_feedback', 'time_final_feedback', 'time_form_base', 'time_get_input', 'time_globals', 
    'time_item', 'time_itemArray', 'time_keyboard_response', 'time_logger', 'time_new_inline_script', 'time_new_loop', 'time_new_quest_staircase_init', 
    'time_new_quest_staircase_next_1', 'time_pygaze_init', 'time_pygaze_log', 'time_pygaze_start_recording', 'time_pygaze_stop_recording', 
    'time_python_definitions', 'time_select_target', 'time_sketchpad', 'time_smoothing', 'time_speak_target', 'time_speech', 'time_startup_variables', 
    'time_trial', 'title', 'total_acc', 'total_correct', 'total_response_time', 'total_responses', 'total_rt', 'transparent_variables', 'trialCounter', 
    'trialThreshold', 'trialThresholdOption', 'trialid', 'ttrace_rsvp', 'uniform_coordinates', 'width', 'winner', 'xtrace_rsvp', 'ytrace_rsvp']
    '''

    return dm
Exemplo n.º 3
0
def descriptives(dm):

	"""
	desc:
		Provides basic descriptives of response times. These are printed
		directly to the stdout.

	arguments:
		dm:
			type: DataMatrix
	"""

	ops.keep_only(dm, cols=['type', 'rt'])
	gm = ops.group(dm, by=[dm.type])
	gm.mean_rt = series.reduce_(gm.rt)
	gm.se_rt = series.reduce_(gm.rt, lambda x: np.nanstd(x)/np.sqrt(len(x)))
	gm.n = series.reduce_(gm.rt, lambda x: np.sum(~np.isnan(x)))
	del gm.rt
	print(gm)
Exemplo n.º 4
0
def test_keep_only():

    dm = DataMatrix(length=2)
    dm.a = 'a', 'b'
    dm.b = 0, 1
    dm.c = 'y', 'z'
    for cols in (['b', 'c'], [dm.b, dm.c]):
        dm = ops.keep_only(dm, *cols)
        assert 'a' not in dm.column_names
        assert 'b' in dm.column_names
        assert 'c' in dm.column_names
Exemplo n.º 5
0
def subset(dm):
    '''Selects a subset of columns'''
    dm = ops.keep_only(dm, dm.trialid, dm.ptrace_rsvp, dm.target_object,
                       dm.tone_red, dm.tone_blue, dm.trial_correct, dm.path)
    '''
    Columns available: 
    ['arrow_correct', 'arrow_orientation', 'bright_blue_contrast', 'bright_red_contrast', 
    'dark_blue_contrast', 'dark_red_contrast', 'fixetlist_rsvp', 'fixstlist_rsvp', 'fixxlist_rsvp', 
    'fixylist_rsvp', 'gazed', 'gazed_left', 'gazed_right', 'path', 'pos_blue', 'pos_red', 
    'practicemode', 'ptrace_rsvp', 'pupil_size', 't_offset_rsvp', 't_onset_rsvp', 'target_letter', 
    'target_object', 'tone_blue', 'tone_red', 'trial_answer', 'trial_correct', 'trialid', 
    'ttrace_rsvp', 'xtrace_rsvp', 'ytrace_rsvp']
    '''

    return dm
Exemplo n.º 6
0
    def __getitem__(self, key):

        if isinstance(key, BaseColumn):
            return self._getcolbyobject(key)
        if isinstance(key, basestring):
            return self._getcolbyname(key)
        if isinstance(key, int):
            return self._getrow(key)
        if isinstance(key, slice):
            return self._slice(key)
        if isinstance(key, Sequence):
            if all(isinstance(v, (basestring, BaseColumn)) for v in key):
                from datamatrix import operations as ops
                return ops.keep_only(self, *key)
            return self._slice(key)
        if isinstance(key, DataMatrix):
            return self._where(key)
        raise KeyError('Invalid key, index, or slice: %s' % key)
Exemplo n.º 7
0
def filter_(dm):

	"""
	desc:
		Applies basic filtering to the parsed data, by removing unnecessary
		columns, filtering out practice trials, etc. This function does not do
		pupil-size preprocessing; this is handled by pupil.preprocess()

	arguments:
		dm:
			type: DataMatrix

	returns:
		type:	DataMatrix
	"""

	# Keep only relevant columns to speed up processing
	ops.keep_only(dm, ['trialid', 'word', 'type', 'ptrace_target', 'category',
		'ptrace_fixation', 'subject_nr', 'response_time_keyboard_response',
		'correct_keyboard_response', 'practice'])
	dm.rename('response_time_keyboard_response', 'rt')
	dm.rename('correct_keyboard_response', 'correct')
	# Remove practice trials, and the misspelled word
	print('Filtering')
	if constants.EXP == 'control':
		dm = dm.practice == 'no'
	else:
		dm = dm.trialid >= 10
		dm = dm.word != 'trbrant'
	# Show all words and trialcounts
	for word in dm.word.unique:
		print('%s\t%d' % (word, len(dm.word == word)))
	# First show error information, and then remove error trials
	errors = len(dm.correct == 0)
	error_percent = 100. * errors / len(dm)
	n_word = len(dm.word.unique)
	print('N(word) = %d Errors(Total) = %d (%.2f %%) of %d' \
		% (n_word, errors, error_percent, len(dm)))
	categories = ('positive', 'negative', 'animal') \
		if constants.EXP == 'control' else ('light', 'dark', 'ctrl', 'animal')
	print(dm.category.unique)
	for type_ in categories:
		if constants.EXP == 'control':
			dm_ = dm.category == type_
		else:
			dm_ = dm.type == type_
		total = len(dm_)
		errors = len((dm_) & (dm.correct == 0))
		error_percent = 100. * errors / total
		n_word = len(dm_.word.unique)
		print('N(word) = %d, Errors(%s) = %d (%.2f %%) of %d' \
			% (n_word, type_, errors, error_percent, total))
	dm = dm.correct == 1
	if constants.EXP == 'control':
		return dm
	# Add new columns
	print('Adding columns')
	dm.rating_brightness = FloatColumn
	dm.rating_valence = FloatColumn
	dm.rating_intensity = FloatColumn
	dm.word_len = IntColumn
	dm.word_len = [len(word) for word in dm.word]
	# Integrate the normative ratings and French lexicon project into the data
	print('Integrating normative ratings')
	ratings = io.readtxt('ratings.csv')
	ratings.ascii_word = [word.encode('ascii', errors='ignore') \
		for word in ratings.word]
	for row in dm:
		# The animal names haven't been rated
		if row.type == 'animal':
			continue
		# The special characters have been stripped in the EDF file, but not from
		# the ratings data. We assert that we have exactly one match between the
		# ascii-fied and original word to make sure that we map things correctly.
		# In addition, in the auditory experiment the special characters were
		# converted to html hex notation. So we strip those characters.
		word = ''.join([l for l in row.word if l.isalpha()])
		rating = ratings.ascii_word == word
		assert(len(rating) == 1)
		row.rating_brightness = rating.rating_brightness[0]
		row.rating_valence = rating.rating_valence[0]
		row.rating_intensity = rating.rating_intensity[0]
	return dm