Beispiel #1
0
def simulation_onedata(num_activ,fname,TimeShift,WidthShift,IntensityRange,mitc_,outputdir,minic=2,plotall = True):
#    ActivChan = range(int(num_activ))

    # Read the resting state data and compute the concentration matrix
    data = sio.loadmat(fname,appendmat = False)
    data = nirs(data)
    data.CalcOD()
    data.MBLL(6)
    data = nirs.PruneChan(data,8)
    # Pick (num_activ) random channels to simulate the activation
    num_activ = int(num_activ * len(data.Chan)/100)
    data.ActivChan = random.sample(data.usefulChan,num_activ)
  
    # Add signals to the concentration matrix    
    data = GenerateSignals(data,data.ActivChan,[5,20],TimeShift,WidthShift,IntensityRange)
    temp = deepcopy(data)
    data.conc[:,:,0] = BPFilter(data.conc[:,:,0],data,[0.005,1.4])    
#    data = nirs.Normalize(data)
    
    # Compute the block average HRF for each channel
    temp.conc[:,:,0] = BPFilter(temp.conc[:,:,0],data,[0.005,0.5])
    temp = HRFAvg(temp,5,20)
    data.HRF = temp.HRF
    data.tHRF = temp.tHRF
    
    
    # Compute the mean block average HRF for the activated channels
    data.mHRF = np.mean(data.HRF[:,data.ActivChan,:],1)

    
    #Now for the ICA procedure     int(0.1*np.size(data.Chan))
    data.ICA = icastream(data,minic,'Sim',[0.7/20, 1.3/20, 1.4],[5,20],[2.5,mitc_],\
                    outputdir,plotall = False,dump = False,plotResults = False)
#    with open(outputdir+'/icastream.dump', 'wb') as output:
#        cPickle.dump(data, output, cPickle.HIGHEST_PROTOCOL)
#    try:
#        ManuscriptPlotSim(data,dirname = outputdir)
#    except:
#        print 'Deu ruim no plot final'
        
    if hasattr(data,'A_'):
        if plotall == True:
            PlotICSpatial(data,data.ICA,dirname=outputdir)

    return data.ICA
Beispiel #2
0
#files = os.path.split(fname)[1]

if files == []:
    raise NameError('No .nirs file was loaded.')


# Read all the .nirs an d extract the useful info out of them inside a hmr2 class
pretime = 2
posttime = 10
data = []
MITC_ = np.array([0.5])#np.arange(0.45,0.55,0.02)
for file_num in range(np.size(files)):
    # Read the resting state data and compute the concentration matrix
    print files[file_num]
    data_aux = sio.loadmat(files[file_num],appendmat = False) 
    data_aux = nirs(data_aux)
    
    # Channels where the actvation pattern was seen
#    data_aux.ActivChan = np.array([0,1,4,5,7,38])
    
    data_aux.stimDur = 8
    
    data_aux.CalcOD()
    data_aux.BPFilter([0.005,1.4])  
    dod = (data_aux.dod[:,0:50]+data_aux.dod[:,50::])/2
    del data_aux.dod
    data_aux.dod = dod    
#    data_aux.PruneChan(0,2.5,[0])
#    data_aux.Normalize(chromo = 'Phantom')

    # Compute the block average HRF for each channel