def test_hdf5(): """Test HDF5 IO """ test_file = op.join(tempdir, 'test.hdf5') x = dict(a=dict(b=np.zeros(3)), c=np.zeros(2, np.complex128), d=[dict(e=(1, -2., 'hello'))]) write_hdf5(test_file, 1) assert_equal(read_hdf5(test_file), 1) assert_raises(IOError, write_hdf5, test_file, x) # file exists write_hdf5(test_file, x, overwrite=True) assert_raises(IOError, read_hdf5, test_file + 'FOO') # not found xx = read_hdf5(test_file) print(object_diff(x, xx)) assert_true(object_diff(x, xx) == '') # no assert_equal, ugly output
subj_ord = new_subj_ord ''' # yaml params with open(yaml_param_file, 'r') as yp: yaml_params = yaml.load(yp) subjects = yaml_params['subjects'] # already in npz file listening_difficulty = np.array(yaml_params['lis_diff']) spatial_mapping = yaml_params['spatial_mapping'] talker_mapping = yaml_params['talker_mapping'] t_min = yaml_params['t_min'] t_max = yaml_params['t_max'] t_peak = yaml_params['t_peak'] # hdf5 params params = read_hdf5(param_file) ''' RELEVANT KEYS: cond_mat: array (384, 4). columns are [attn, spatial, idents, gap] attns: maintain vs switch spatials: -30x30, 30x-30, -30x-30, 30x30 idents: MM, FF, MF, FM (male/female talkers) stim_times: array[0.0, 0.4, 1.2, 1.6, 2.6, 3.] ''' stim_times = params['stim_times'][0] # gap included already cond_mat = params['cond_mat'] # figure params with open(op.join(styledir, 'figure-params.yaml'), 'r') as fp: fig_params = yaml.load(fp) signifcol = fig_params['signif_color'] cue = fig_params['cue_color'] msk = fig_params['msk_color']
set_log_level('INFO') # set configuration fs = 44100 noise_db = 45 # dB for background noise stim_db = 65 # dB for stimuli min_resp_time = 0.1 max_resp_time = 2.0 feedback_dur = 0.5 isi = 0.2 running_total = 0 # you should run stimuli/generate_stimuli first to make the stimuli # load the result here stims = read_hdf5(op.join('stimuli', 'equally_spaced_sinewaves.hdf5')) orig_rms = stims['rms'] freqs = stims['freqs'] fs = stims['fs'] trial_order = stims['trial_order'] num_trials = len(trial_order) num_freqs = len(freqs) if num_freqs > 8: raise RuntimeError('Too many frequencies, not enough buttons.') # keep only sinusoids, order low-high, convert to list of arrays wavs = [stims[k] for k in sorted(stims.keys()) if k.startswith('stim_')] # instructions instructions = ('You will hear tones at {0} different frequencies. Your job is'
data = [] keydetection = [] for cue in ['NOCUE', 'WITHCUE']: # for sbj in [2, 4]: for sbj in [0, 1, 2, 4, 5, 7, 8, 9, 10, 11, 12, 15, 16, 17, 18, 19, 20, 21, 22]: # identify subject and block number if sbj <= 9: subj_num = '40%s' % sbj else: subj_num = '4%s' % sbj work_dir = ('/home/lindsey/Desktop/PythonFiles/Shams/Flashbeeps2.0/%s/Blocks' % cue) # import data file and relevant variables for bi in range(1, 16): blc_num = bi d = read_hdf5(op.join(work_dir, 'subj%s_block%s.hdf5' % (subj_num, blc_num))) presses = d['presses'] played = d['played'] flashed = d['flashed'] flash_timing = d['flipplay_times'] current_block = d['current_block'] condition_type = d['condition_stamp'] control = current_block[::, 3] wavfile = current_block[::, 1] number_pressed = [x for x, _ in presses] raw_RT = [x[1] for x in presses] timingcheck = trialtiming(control, flash_timing) if '3' in number_pressed: keydetection.append((sbj, cue, blc_num, number_pressed.count('3')))
# -*- coding: utf-8 -*- from os import path as op import numpy as np from expyfun import (ExperimentController, visual, assert_version, get_keyboard_input, decimals_to_binary) from expyfun.io import read_hdf5, read_wav feedback = False # should be False for MEG assert_version('9c4bcea') p = read_hdf5(op.join(op.dirname(__file__), 'params.hdf5')) stim_dir = op.join(op.dirname(__file__), p['stim_dir']) bg_color = [0.2] * 3 fix_color = [0.5] * 3 v_off = 2. with ExperimentController('standard_setup', full_screen=False, stim_db=75, noise_db=45, participant='s', session='0', output_dir=None, suppress_resamp=True, check_rms=None, version='9c4bcea') as ec: square = visual.Rectangle(ec, [0, 0, 10, 10], units='deg') ec.screen_text('expy_standard_setup_test.', wrap=False) ec.set_background_color(bg_color) fix = visual.FixationDot(ec, colors=[fix_color, bg_color])
Created on Thu Jul 26 11:35:55 2018 @author: rkmaddox """ import numpy as np from expyfun.io import read_hdf5 from pandas import DataFrame from statsmodels.formula.api import ols from statsmodels.stats.anova import anova_lm from statsmodels.graphics.gofplots import qqplot from scipy.stats import ttest_rel, ttest_1samp import matplotlib.pyplot as plt plt.ion pc = read_hdf5( '/home/maddy/Code/data_analysis/Flip_Detect/matrix1.hdf5')['data'] * 100 # sub - cond - snr snr = np.array([0, -3, -6]) conds = ['0', '90', '180', 'static'] n_sub = pc.shape[0] # plt.plot(snr, pc[:, 0].T, 'k') # plt.plot(snr, pc[:, 2].T, 'r') dpc = pc[:, :3] - pc[:, [3]] dpc_sem = np.std(dpc, axis=0) / np.sqrt(n_sub) dpc_mean = dpc.mean(0) for ci in range(dpc_mean.shape[0]):
fs = 44100 noise_db = 45 # dB for background noise stim_db = 65 # dB for stimuli min_resp_time = 0.1 max_resp_time = 2.0 max_wait = np.inf feedback_dur = 2.0 isi = 0.2 running_total = 0 # make the stimuli if necessary and then load them fname = 'equally_spaced_sinewaves.hdf5' if not op.isfile(fname): from stimuli.plot_generate_simple_stimuli import generate_stimuli generate_stimuli() stims = read_hdf5(fname) orig_rms = stims['rms'] freqs = stims['freqs'] fs = stims['fs'] trial_order = stims['trial_order'] num_trials = len(trial_order) num_freqs = len(freqs) if num_freqs > 8: raise RuntimeError('Too many frequencies, not enough buttons.') # keep only sinusoids, order low-high, convert to list of arrays wavs = [stims[k] for k in sorted(stims.keys()) if k.startswith('stim_')] # instructions instructions = ('You will hear tones at {0} different frequencies. Your job is'
min_resp_time = 0.1 max_resp_time = 2.0 max_wait = np.inf feedback_dur = 2.0 isi = 0.2 running_total = 0 # make the stimuli if necessary and then load them fname = 'equally_spaced_sinewaves.hdf5' if not op.isfile(fname): # This sys.path wrangling is only necessary for Sphinx automatic # documentation building sys.path.insert(0, os.getcwd()) from generate_simple_stimuli import generate_stimuli generate_stimuli() stims = read_hdf5(fname) orig_rms = stims['rms'] freqs = stims['freqs'] fs = stims['fs'] trial_order = stims['trial_order'] num_trials = len(trial_order) num_freqs = len(freqs) if num_freqs > 8: raise RuntimeError('Too many frequencies, not enough buttons.') # keep only sinusoids, order low-high, convert to list of arrays wavs = [stims[k] for k in sorted(stims.keys()) if k.startswith('stim_')] # instructions instructions = ('You will hear tones at {0} different frequencies. Your job is'
improvements = np.empty((len(subjects), 5)) sems = np.empty((len(subjects), 2)) pvals = np.zeros((len(subjects),)) lapse = np.empty((len(subjects), 1)) thresh = np.empty((len(subjects), 2)) slope = np.empty((len(subjects), 1)) perform_imp = np.empty((len(subjects), 1)) data_resamp = np.empty((len(subjects), 1000, 2, 5)) responses = [] biases = [] d_prime = np.empty((len(subjects), 5)) stem_perimp = np.empty((len(subjects), 1000, 2)) stem_thimp = np.empty((len(subjects), 1000, 2)) for i, s in enumerate(subjects): data = read_hdf5(path + 'percent_' + s) responses.append(data['responses']) thresholds[i] = data['thresholds'] per_cor[i] = data['percent'] ok = data['ok'] params = data['params'] curves[i] = [sigmoid(20 * np.log10(x_plot_fit), lower=0.5, upper=ok[2], midpt=p[0], slope=ok[1]) for p in params] perform_imp[i] = data['perform_imp'] lapse[i] = [ok[2]] slope[i] = [ok[1]] thresh[i] = [params[0], params[1]] percent = np.mean(per_cor, 0) inds = np.argsort(thresholds[:, 0])
# subj-level RT summary cols = ['subj', 'rt'] rt_summary = slot_hitonly[cols].groupby(cols[:-1]).aggregate('median') print(rt_summary.describe(), end='\n\n') # # # # # # # # # # # # # # # post-hoc: foils by slot # # # # # # # # # # # # # # # ph = slot_df.groupby(['lisdiff', 'slot'])['ff'].aggregate('sum').unstack(0) # ph.plot() # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # post-hoc: correlate switch-minus-maintain AUC against slot 4 AUC # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # hdf5 params params = read_hdf5(param_file) cond_mat = params['cond_mat'] df = pd.DataFrame() df['attn'] = np.array(params['attns'])[cond_mat[:, 0]] df['spat'] = np.array(params['spatials'])[cond_mat[:, 1]] df['iden'] = np.array(params['idents'])[cond_mat[:, 2]] df['lr'] = df['spat'].map(spatial_mapping) df['mf'] = df['iden'].map(talker_mapping) # load pupil data pupil_data = np.load(op.join(datadir, 'capd-pupil-data.npz')) subj_ord = pupil_data['subjects'] times = pupil_data['t_fit'] data = pupil_data['fits'] t_zero_ix = np.where(np.isclose(times, 0))[0][0] delta_t = times[-1] - times[t_zero_ix] assert np.array_equal(subj_ord, np.array(subjects))