示例#1
0
def add_lfp_filt(f, fs = 384.384384384):

	lfp = f['lfp'].value
	nchan, ntrials, nsamp = lfp.shape

	lfp_filt = np.empty_like(lfp)

	for i in range(nchan):
		for j in range(ntrials):
			lfp_filt[i, j, :] = EEG.remove_60hz(lfp[i, j, :])

	f.create_dataset('lfp_filt', data = lfp_filt, compression = 'gzip')
示例#2
0
def combine(epoch = 'Pre', stimtype = 'noise'):

	'''
	combine left and right ear stimulation blocks into one pandas DataFrame
	'''
	sesspaths = glob.glob(os.path.join(studydir, 'Sessions', epoch, '*'))
	
	for sesspath in sesspaths:
		absol, sessID = os.path.split(sesspath)
		print sessID
		fpaths = glob.glob(os.path.join(sesspath, 'fileconversion', '*.h5'))
		subjIDs = np.unique([os.path.splitext(os.path.split(fpath)[1])[0].split('_')[0] for fpath in fpaths])

		hemis = 'rl'
		ears = 'rl'

		for subjID in subjIDs:

			LFP = []; LFPFILT = []; ATTEN = []; EAR = []; HEMI = []; RELHEMI = []; SESSID = [];

			for ear in ears:

				fpath = glob.glob(os.path.join(sesspath, 'fileconversion', '%s_%s_%s_b*.h5' % (subjID, ear.upper(), stimtype)))[0]

				fin = h5py.File(fpath, 'r')
				lfp = fin['lfp'].value
				stimparams = fin['stimID'].value
				fin.close()

				nchan, ntrials, nsamp = lfp.shape

				for i in xrange(nchan):

					[LFP.append(lfp[i, j, :]) for j in xrange(ntrials)]
					[LFPFILT.append(EEG.remove_60hz(lfp[i, j, :])) for j in xrange(ntrials)]
					ATTEN.extend(stimparams[:, 1].tolist())
					EAR.extend([ear]*ntrials)
					HEMI.extend([hemis[i]]*ntrials)
					if ear==hemis[i]:
						relhemi = 'ipsi'
					elif ear!=hemis[i]:
						relhemi = 'contra'
					RELHEMI.extend([relhemi]*ntrials)
					SESSID.extend([sessID]*ntrials)

			d = dict(lfp = LFP, lfpfilt = LFPFILT, atten = ATTEN, ear = EAR, hemi = HEMI, relhemi = RELHEMI, sess = SESSID)
			df = pd.DataFrame(d)

			fout = pd.HDFStore(os.path.join(sesspath, 'both', '%s_both.h5' % subjID))
			fout['df'] = df
			fout.close()