コード例 #1
0
ファイル: stat_test.py プロジェクト: jesong1126/PermuStat
import numpy as np   
import matplotlib.pyplot as plt 
from mpl_toolkits.mplot3d import Axes3D
from scipy.stats import norm #, t
import matplotlib.mlab as mlab
from swcm import Imatrix 
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)):
コード例 #2
0
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from scipy.stats import norm  #, t
import matplotlib.mlab as mlab
from swcm import Imatrix
from mff import read_mff_header, read_mff_data  #, getEpochInfos, mff_getSummaryInfo
from pandas import DataFrame
import pandas as pd

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 = []
コード例 #3
0
ファイル: PermuStat.py プロジェクト: jesong1126/PermuStat
    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  
コード例 #4
0
ファイル: PermuStat.py プロジェクト: jesong1126/PermuStat
    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
コード例 #5
0
ファイル: GeoSource5.py プロジェクト: jesong1126/PermuStat
    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  
コード例 #6
0
ファイル: GeoSource5.py プロジェクト: jesong1126/PermuStat
    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