from mff import read_mff_header, read_mff_data #, getEpochInfos, mff_getSummaryInfo filePath ='/Users/jesong1126/Work/Data/VGT/VGT_105_fil_segA_mff_32_100_32_tp_bcr_blc.mff' hdr = read_mff_header.read_mff_header(filePath) nC = hdr['nChans'] nSamples = hdr['nSamples'] nSamplesPre = hdr['nSamplesPre'] nTrials = hdr['nTrials'] srate = hdr['Fs'] summaryInfo = hdr['orig'] trialsName = summaryInfo['epochLabels'] categoryName = list(set(trialsName)) nCategory = len(categoryName) data = read_mff_data.read_mff_data(filePath, 'epoch', 1, hdr['nTrials'], hdr) len(hdr['orig']['epochLabels']) #epochLabels = hdr['orig']['epochLabels'] #[epochLabel.encode('utf-8') for epochLabel in epochLabels] SegStatus = hdr['orig']['epochSegStatus'] GoodSeg = [] epochLabels = [] for i in range(len(SegStatus)): if SegStatus[i] == 'good' : GoodSeg.append(i) epochLabels.append(trialsName[i]) #GoodSeg = np.array(GoodSeg, 'i4') data = data[:,:,GoodSeg] nTrials = len(GoodSeg)
filePath = '/Users/jesong1126/Work/Data/VGT/VGT_105_fil_segA_mff_32_100_32_tp_bcr_blc.mff' hdr = read_mff_header.read_mff_header(filePath) nC = hdr['nChans'] nE = nC - 1 nSamples = hdr['nSamples'] nSamplesPre = hdr['nSamplesPre'] nTrials = hdr['nTrials'] srate = hdr['Fs'] summaryInfo = hdr['orig'] trialsName = summaryInfo['epochLabels'] categoryName = list(set(trialsName)) nCategory = len(categoryName) data = read_mff_data.read_mff_data(filePath, 'epoch', 1, hdr['nTrials'], hdr) len(hdr['orig']['epochLabels']) #epochLabels = hdr['orig']['epochLabels'] #[epochLabel.encode('utf-8') for epochLabel in epochLabels] SegStatus = hdr['orig']['epochSegStatus'] GoodSeg = [] epochLabels = [] for i in range(len(SegStatus)): if SegStatus[i] == 'good': GoodSeg.append(i) epochLabels.append(trialsName[i]) #GoodSeg = np.array(GoodSeg, 'i4') data = data[:nE, :, GoodSeg] nTrials = len(GoodSeg)
###----------------------------------------------------------------------------- # aaa = getSignalNbin(filePath, 'signal1.bin') # getEpochInfos(filePath, 500) # SignalBlocks = getSignalBlocks(filePath) # summaryInfo = mff_getSummaryInfo(filePath) # filePath = '/Users/jesong1126/Python27/Data/mffdata_test/MEP_107_LT.mff' hdr = read_mff_header(filePath) hdr.keys() summaryInfo = hdr['orig'] #event1 = read_mff_event(filePath, hdr) hdr['nTrials'] dataEpoch = read_mff_data(filePath, 'epoch', 1, hdr['nTrials'], hdr) print(dataEpoch.shape) ts = (np.arange(0, hdr['nSamples']) - hdr['nSamplesPre']) * (1000 / hdr['Fs']) plt.figure(1) plt.plot(ts, dataEpoch[:,:,0].T, ':') plt.xlim((ts[0], ts[-1])) hdr['nSamples'] startInd = 4001; lastInd = 40000 ; dataSample = read_mff_data(filePath, 'sample', startInd, lastInd, hdr) print dataSample.shape ts = (np.arange(0, hdr['nSamples']) - hdr['nSamplesPre']) * (1000 / hdr['Fs'])
def pbMFF_Callback(self): global s, nC, nSamples, nSamplesPre, nTrials, srate, trialsName global categoryName, nCategory import config from mff import read_mff_header, read_mff_data import numpy as np options = QtGui.QFileDialog.Options() mfffilenames = QtGui.QFileDialog.getOpenFileNames(self.pbMFF, "Select a mff file", "", "mff files (*.mff)", options= options) filePath = mfffilenames[0] #[0] print('%s' %filePath) hdr = read_mff_header.read_mff_header(filePath) nC = hdr['nChans'] ; config.nC = nC nSamples = hdr['nSamples'] ; config.nSamples = nSamples nSamplesPre = hdr['nSamplesPre'] ; config.nSamplesPre = nSamplesPre nTrials = hdr['nTrials'] ; config.nTrials = nTrials srate = hdr['Fs'] ; config.srate = srate baseline = (nSamplesPre * 1000 / srate) ; config.baseline = baseline msSamples = np.arange(0, nSamples,1) * 1000/srate - baseline config.msSamples = msSamples summaryInfo = hdr['orig'] ; # config.nC = nC trialsName = summaryInfo['epochLabels'] ; config.trialsName = trialsName categoryName = list(set(trialsName)) ; config.categoryName = categoryName nCategory = len(categoryName) ; config.nCategory = nCategory for i in range(nCategory): self.cbOneTCat.addItem(categoryName[i]) self.cbTwoTCat1.addItem(categoryName[i]) self.cbTwoTCat2.addItem(categoryName[i]) self.cbPairTCat1.addItem(categoryName[i]) self.cbPairTCat2.addItem(categoryName[i]) data = read_mff_data.read_mff_data(filePath, 'epoch', 1, hdr['nTrials'], hdr) SegStatus = hdr['orig']['epochSegStatus'] GoodSeg = []; BadSeg = []; #epochLabels = []; for i in range(len(SegStatus)): if SegStatus[i] == 'bad' : BadSeg.append(i) else : GoodSeg.append(i) nTrials = len(GoodSeg) ## average reference H = np.identity(nC) - np.ones((nC, nC))/nC s = np.zeros(data.shape) if nTrials > 1 : for i in range(nTrials): s[:,:,i] = np.dot(H, data[:,:, GoodSeg[i]]) else : s = np.dot(H, data) whichCat = np.zeros((nTrials, nCategory)) for j in range(nCategory): for i in range(nTrials): if (trialsName[i] == categoryName[j]): whichCat[i,j] = 1 whichCat = np.array(whichCat, dtype='i') config.s = s config.whichCat = whichCat config.categoryName = categoryName print('nC:%d' %nC) print('nSamples:%d' %nSamples) print('nTrials:%d' %nTrials) print('nCategory:%d' %nCategory) for i in range(nCategory): print('categoryName:%s' %categoryName[i]) print("EEG data is loaded.") return s
def pbMFF_Callback(self): global s, nC, nSamples, nSamplesPre, nTrials, srate, trialsName global categoryName, nCategory import config from mff import read_mff_header, read_mff_data import numpy as np options = QtGui.QFileDialog.Options() mfffilenames = QtGui.QFileDialog.getOpenFileNames(self.pbMFF, "Select a mff file", "", "mff files (*.mff)", options=options) filePath = mfffilenames[0] #[0] print('%s' % filePath) hdr = read_mff_header.read_mff_header(filePath) nC = hdr['nChans'] config.nC = nC nSamples = hdr['nSamples'] config.nSamples = nSamples nSamplesPre = hdr['nSamplesPre'] config.nSamplesPre = nSamplesPre nTrials = hdr['nTrials'] config.nTrials = nTrials srate = hdr['Fs'] config.srate = srate baseline = (nSamplesPre * 1000 / srate) config.baseline = baseline msSamples = np.arange(0, nSamples, 1) * 1000 / srate - baseline config.msSamples = msSamples summaryInfo = hdr['orig'] # config.nC = nC trialsName = summaryInfo['epochLabels'] config.trialsName = trialsName categoryName = list(set(trialsName)) config.categoryName = categoryName nCategory = len(categoryName) config.nCategory = nCategory for i in range(nCategory): self.cbOneTCat.addItem(categoryName[i]) self.cbTwoTCat1.addItem(categoryName[i]) self.cbTwoTCat2.addItem(categoryName[i]) self.cbPairTCat1.addItem(categoryName[i]) self.cbPairTCat2.addItem(categoryName[i]) data = read_mff_data.read_mff_data(filePath, 'epoch', 1, hdr['nTrials'], hdr) SegStatus = hdr['orig']['epochSegStatus'] GoodSeg = [] BadSeg = [] #epochLabels = []; for i in range(len(SegStatus)): if SegStatus[i] == 'bad': BadSeg.append(i) else: GoodSeg.append(i) nTrials = len(GoodSeg) ## average reference H = np.identity(nC) - np.ones((nC, nC)) / nC s = np.zeros(data.shape) if nTrials > 1: for i in range(nTrials): s[:, :, i] = np.dot(H, data[:, :, GoodSeg[i]]) else: s = np.dot(H, data) whichCat = np.zeros((nTrials, nCategory)) for j in range(nCategory): for i in range(nTrials): if (trialsName[i] == categoryName[j]): whichCat[i, j] = 1 whichCat = np.array(whichCat, dtype='i') config.s = s config.whichCat = whichCat config.categoryName = categoryName print('nC:%d' % nC) print('nSamples:%d' % nSamples) print('nTrials:%d' % nTrials) print('nCategory:%d' % nCategory) for i in range(nCategory): print('categoryName:%s' % categoryName[i]) print("EEG data is loaded.") return s
def pbEEG_Callback(self): global s, nC, nSamples, nSamplesPre, nTrials, srate, trialsName global categoryName, nCategory import config from mff import read_mff_header, read_mff_data import matplotlib.pyplot as plt import numpy as np options = QtWidgets.QFileDialog.Options() mfffilename, _ = QtWidgets.QFileDialog.getOpenFileNames(self.pbEEG, "Select a mff file", "", "mff files (*.mff)", options= options) filePath = mfffilename[0] hdr = read_mff_header.read_mff_header(filePath) nC = hdr['nChans'] ; config.nC = nC nSamples = hdr['nSamples'] ; config.nSamples = nSamples nSamplesPre = hdr['nSamplesPre'] ; config.nSamplesPre = nSamplesPre nTrials = hdr['nTrials'] ; config.nTrials = nTrials srate = hdr['Fs'] ; config.srate = srate summaryInfo = hdr['orig'] ; # config.nC = nC trialsName = summaryInfo['epochLabels'] ; config.trialsName = trialsName categoryName = list(set(trialsName)) ; config.categoryName = categoryName nCategory = len(categoryName) ; config.nCategory = nCategory for i in range(nTrials): self.cbTrial.addItem(trialsName[i]) data = read_mff_data.read_mff_data(filePath, 'epoch', 1, hdr['nTrials'], hdr) SegStatus = hdr['orig']['epochSegStatus'] GoodSeg = []; BadSeg = []; #epochLabels = []; for i in range(len(SegStatus)): if SegStatus[i] == 'bad' : BadSeg.append(i) else : GoodSeg.append(i) nTrials = len(GoodSeg) print('nC:%d' %nC) print('nSamples:%d' %nSamples) print('nTrials:%d' %nTrials) print('nCategory:%d' %nCategory) print('categoryName:%s' %categoryName) # print('categoryName:%s' %trialsName) ## average reference H = np.identity(nC) - np.ones((nC, nC))/nC s = np.zeros((nC, nSamples, nTrials)) sGFP = np.zeros((nSamples, nTrials)) if nTrials > 1: for i in range(nTrials): s[:,:,i] = np.dot(H, data[:,:,GoodSeg[i]]) sGFP[:,i] = np.std(s[:,:,i], axis=0) # s2 = s[:,:,i] * s[:,:,i] # gfp = s2.mean(axis=0) # sGFP = np.sqrt(gfp) else : s = np.dot(H, data) sGFP = np.std(s, axis=0) # s2 = s * s # gfp = s2.mean(axis=0) # sGFP = np.sqrt(gfp) baseline = (nSamplesPre * 1000 / srate) ; config.baseline = baseline msSamples = np.arange(0, nSamples,1) * 1000/srate - baseline config.msSamples = msSamples # global f1 if nTrials == nCategory : # f1 = plt.figure plt.plot(msSamples, sGFP) plt.title('gfp') plt.xlabel('ms') plt.legend(trialsName, loc='best') plt.show() print('EEG is ERP.') #eventsName = trialsName else : # f1 = plt.figure plt.plot(msSamples, sGFP) plt.title('gfp') plt.xlabel('ms') plt.show() print('EEG is Single trial. There are',nTrials,'trials. ') #eventsName = categoryName config.nSamples = nSamples config.msSamples = msSamples config.nTrials = nTrials config.trialsName = trialsName config.s = s config.sGFP = sGFP print("EEG data is loaded.") # self.pbEEG.configure(background = "red") return s
###----------------------------------------------------------------------------- # aaa = getSignalNbin(filePath, 'signal1.bin') # getEpochInfos(filePath, 500) # SignalBlocks = getSignalBlocks(filePath) # summaryInfo = mff_getSummaryInfo(filePath) # filePath = '/Users/jesong1126/Python27/Data/mffdata_test/MEP_107_LT.mff' hdr = read_mff_header(filePath) hdr.keys() summaryInfo = hdr['orig'] #event1 = read_mff_event(filePath, hdr) hdr['nTrials'] dataEpoch = read_mff_data(filePath, 'epoch', 1, hdr['nTrials'], hdr) print(dataEpoch.shape) ts = (np.arange(0, hdr['nSamples']) - hdr['nSamplesPre']) * (1000 / hdr['Fs']) plt.figure(1) plt.plot(ts, dataEpoch[:, :, 0].T, ':') plt.xlim((ts[0], ts[-1])) hdr['nSamples'] startInd = 4001 lastInd = 40000 dataSample = read_mff_data(filePath, 'sample', startInd, lastInd, hdr) print dataSample.shape ts = (np.arange(0, hdr['nSamples']) - hdr['nSamplesPre']) * (1000 / hdr['Fs'])
def pbEEG_Callback(self): global s, nC, nSamples, nSamplesPre, nTrials, srate, trialsName global categoryName, nCategory import config from mff import read_mff_header, read_mff_data import matplotlib.pyplot as plt import numpy as np options = QtWidgets.QFileDialog.Options() mfffilename, _ = QtWidgets.QFileDialog.getOpenFileNames( self.pbEEG, "Select a mff file", "", "mff files (*.mff)", options=options) filePath = mfffilename[0] hdr = read_mff_header.read_mff_header(filePath) nC = hdr['nChans'] config.nC = nC nSamples = hdr['nSamples'] config.nSamples = nSamples nSamplesPre = hdr['nSamplesPre'] config.nSamplesPre = nSamplesPre nTrials = hdr['nTrials'] config.nTrials = nTrials srate = hdr['Fs'] config.srate = srate summaryInfo = hdr['orig'] # config.nC = nC trialsName = summaryInfo['epochLabels'] config.trialsName = trialsName categoryName = list(set(trialsName)) config.categoryName = categoryName nCategory = len(categoryName) config.nCategory = nCategory for i in range(nTrials): self.cbTrial.addItem(trialsName[i]) data = read_mff_data.read_mff_data(filePath, 'epoch', 1, hdr['nTrials'], hdr) SegStatus = hdr['orig']['epochSegStatus'] GoodSeg = [] BadSeg = [] #epochLabels = []; for i in range(len(SegStatus)): if SegStatus[i] == 'bad': BadSeg.append(i) else: GoodSeg.append(i) nTrials = len(GoodSeg) print('nC:%d' % nC) print('nSamples:%d' % nSamples) print('nTrials:%d' % nTrials) print('nCategory:%d' % nCategory) print('categoryName:%s' % categoryName) # print('categoryName:%s' %trialsName) ## average reference H = np.identity(nC) - np.ones((nC, nC)) / nC s = np.zeros((nC, nSamples, nTrials)) sGFP = np.zeros((nSamples, nTrials)) if nTrials > 1: for i in range(nTrials): s[:, :, i] = np.dot(H, data[:, :, GoodSeg[i]]) sGFP[:, i] = np.std(s[:, :, i], axis=0) # s2 = s[:,:,i] * s[:,:,i] # gfp = s2.mean(axis=0) # sGFP = np.sqrt(gfp) else: s = np.dot(H, data) sGFP = np.std(s, axis=0) # s2 = s * s # gfp = s2.mean(axis=0) # sGFP = np.sqrt(gfp) baseline = (nSamplesPre * 1000 / srate) config.baseline = baseline msSamples = np.arange(0, nSamples, 1) * 1000 / srate - baseline config.msSamples = msSamples # global f1 if nTrials == nCategory: # f1 = plt.figure plt.plot(msSamples, sGFP) plt.title('gfp') plt.xlabel('ms') plt.legend(trialsName, loc='best') plt.show() print('EEG is ERP.') #eventsName = trialsName else: # f1 = plt.figure plt.plot(msSamples, sGFP) plt.title('gfp') plt.xlabel('ms') plt.show() print('EEG is Single trial. There are', nTrials, 'trials. ') #eventsName = categoryName config.nSamples = nSamples config.msSamples = msSamples config.nTrials = nTrials config.trialsName = trialsName config.s = s config.sGFP = sGFP print("EEG data is loaded.") # self.pbEEG.configure(background = "red") return s