In [1]:
clear all




In [2]:
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
from scipy import io
import scipy.io as sio
%matplotlib inline 
import pylab
import csv
from Tkinter import Tk
from tkFileDialog import askopenfilename
from tkFileDialog import askdirectory
import nibabel as nb
from scipy import io
#from nifti import NiftiImage
import nibabel as nb
from scipy.interpolate import interp1d
from scipy import ndimage

Open data


In [3]:
# from http://stackoverflow.com/questions/3579568/choosing-a-file-in-python-with-simple-dialog
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
filename = askopenfilename() # show an "Open" dialog box and return the path to the selected file
print(filename)


/media/sophie/008C0665790F0763/ComboPanNeuronalGCaMP6/938/938ss2onc250regcdFF20sMpsfkf250Smith0_4_60TS.mat

In [4]:
Ua=sio.loadmat(filename)
DT=Ua['TSo']
DT.shape


Out[4]:
(6011, 250)

In [5]:
# from http://stackoverflow.com/questions/3579568/choosing-a-file-in-python-with-simple-dialog
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
filename2 = askopenfilename() # show an "Open" dialog box and return the path to the selected file
print(filename2)


/media/sophie/008C0665790F0763/ComboPanNeuronalGCaMP6/938/938ss2onc250regcdFF20sMpsfkf250Smith0_4_60IC.nii

In [6]:
img1 = nb.load(filename2)
data = img1.get_data()
S=data.shape
S


Out[6]:
(165, 111, 10, 250)

In [7]:
S=data.shape
S


Out[7]:
(165, 111, 10, 250)

Z-score


In [8]:
Demean=np.zeros(S)
Dmaps=np.zeros(S)
Dvar=np.zeros(S)
Var=np.zeros(S[3])
D2=np.zeros([S[0],S[1],5,S[3]])
Tvar=np.zeros(S[3])

In [9]:
for i in range(S[3]):
    Demean[:,:,:,i]=data[:,:,:,i]-np.mean(np.mean(np.mean(data[:,:,:,i],0),0),0)

In [10]:
for i in range(S[3]):
    Dsq=np.reshape(Demean[:,:,:,i],S[0]*S[1]*S[2])
    Var[i]=np.sqrt(np.var(Dsq))
    Dvar=Demean[:,:,:,i]/Var[i]
    Dmaps[:,:,:,i]=Dvar-2.5
    Tvar[i]=np.var(DT[i,:])
Dmaps[Dmaps<0]=0

Open Masks


In [11]:
# from http://stackoverflow.com/questions/3579568/choosing-a-file-in-python-with-simple-dialog
from Tkinter import Tk
from tkFileDialog import askopenfilename

Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
filenameM = askopenfilename() # show an "Open" dialog box and return the path to the selected file
print(filenameM)
img1 = nb.load(filenameM)
Masks = img1.get_data()
Sm=Masks.shape
Masks=np.array(Masks)


/media/sophie/008C0665790F0763/ComboPanNeuronalGCaMP6/938/938Registration/JFRC938Transformedfullpsftrimmed.nii

In [12]:
filenameM='/home/sophie/RegionList'
with open(filenameM) as f:
    content = f.readlines()
Names=[Line.split('\t') for Line in content]
RegionName=[Names[i][0] for i in range(75)]
Num=[int(Names[i][2]) for i in range(75)]

Average in masks to sort components by brain region


In [13]:
Dmaps.shape


Out[13]:
(165, 111, 10, 250)

In [14]:
M=np.zeros((S[3],86))
Mapmean=np.zeros(S[3])
MMasks=np.zeros(86)

In [15]:
for i in range(S[3]):
    Mapmean[i]=np.mean(np.mean(np.mean(Dmaps[:,:,:,i])))
    for j in range(86):
        MMasks[j]=np.mean(np.mean(np.mean(Masks[:,:,:,j])))
        if MMasks[j]:
            M[i,j]=np.mean(np.mean(np.mean(Masks[:,:,:,j]*Dmaps[:,:,:,i])))/(MMasks[j]*Mapmean[i])

In [16]:
CompMainName=S[3]*['']
CompNameAdd=np.zeros((S[3],86))
for i in range(S[3]):
    Max=np.max(M[i,:])
    I=np.argmax(M[i,:])+1
    for j in range(86):
        J=[l for l in range(74) if Num[l]==(j+1)]
        if M[i,j]>0.2*Max:
            CompNameAdd[i,J]=1
    J=[l for l in range(74) if Num[l]==I]
    if J!= []:
        CompMainName[i]=Names[np.array(J)][0]


/usr/local/lib/python2.7/dist-packages/ipykernel/__main__.py:12: VisibleDeprecationWarning: converting an array with ndim > 0 to an index will result in an error in the future

In [17]:
J


Out[17]:
[69]

In [18]:
pylab.rcParams['figure.figsize'] = (13, 2.5)

h=5
tot=0
GoodICAnat=np.zeros(S[3])

for l in range(74):
    Final_maps=np.zeros((S[0],S[1],3))
    Fmap=np.zeros((S[0],S[1],3))
    C=np.zeros(3)

    n=0
    for i in range(len(CompMainName)):                    
        Dmmv=np.mean(data[:,:,:,i],2) 
        Dmmv[Dmmv<0.2*np.max(np.max(np.max(Dmmv)))]=0
        C=np.squeeze(np.random.rand(3,1))
        labeled, nrobject=ndimage.label(Dmmv>0)
        
        if CompMainName[i]==Names[l][0] and (sum(CompNameAdd[i,:])<5) and nrobject<200:
            n=n+1            
            
            for k in range(3):
                Fmap[:,:,k]=0.7*Dmmv*C[k]/np.max(C)
            Final_maps=Final_maps+Fmap
            #plt.plot(Time_fluoICA.T,(DT[:,i]/np.sqrt(np.var(DT[:,i]))-h*n+2),color=C/2)
            plt.plot((DT[:,i]/np.sqrt(np.var(DT[:,i]))-h*n+2),color=C/2)
            tot=tot+1
            GoodICAnat[i]=1
            #print(i)
            for j in range(86):
                if CompNameAdd[i,j]==1:                
                    print(Names[np.array(j)][0])
            print(i)
            
                    
    if n!=0:
        print(Names[l][1])

        plt.show()
        FM=Final_maps/np.max(np.max(Final_maps))
        FM[FM<0.1]=0
        plt.imshow(FM,interpolation='none')
        plt.show()
        frame1 = plt.gca()
        frame1.axes.get_xaxis().set_visible(False)
        frame1.axes.get_yaxis().set_visible(False)


AME_R
LO_R
55
accessory medulla
LO_R
60
LO_R
111
LO_R
ME_R
LO_L
ME_L
119
AME_R
LO_R
ME_R
128
LO_R
IB_R
LOP_R
ME_R
137
LO_R
149
LO_R
ME_R
210
lobula
NO
CAN_R
114
nodulus
PB
IB_R
ATL_R
81
PB
ICL_L
MB_CA_L
131
PB
IB_L
ATL_L
133
PB
148
PB
186
protocerebral bridge
LH_R
3
LH_R
6
LH_R
7
LH_R
10
LH_R
73
lateral horn
SAD
GNG
AMMC_L
IPS_L
216
saddle
LO_R
CAN_R
LOP_R
72
CAN_R
FLA_R
CAN_L
FLA_L
156
cantle
AMMC_R
AVLP_R
38
AMMC_R
50
AMMC_R
AVLP_R
190
antennal mechanosensory and motor center
IB_R
IB_L
77
IB_R
SPS_R
BU_L
IB_L
89
IB_R
IB_L
109
inferior bridge
ATL_R
207
PB
ATL_R
FB
223
antler
MB_VL_R
MB_ML_R
SIP_R
18
MB_PED_R
MB_VL_R
MB_CA_R
43
vertical lobe of adult mushroom body
CRE_R
MB_ML_R
47
CRE_R
MB_ML_R
CRE_L
MB_ML_L
48
medial lobe of adult mushroom body
LO_R
LOP_R
113
AME_R
LOP_R
118
LOP_R
ME_R
147
LOP_R
ME_R
164
lobula plate
EB
127
EB
153
ellipsoid body
AL_R
AL_L
0
CRE_R
AL_R
AL_L
9
CRE_R
AL_R
AL_L
24
AL_R
AL_L
26
AL_R
54
LAL_R
AL_R
BU_L
90
adult antennal lobe
ME_R
8
ME_R
14
LOP_R
ME_R
19
ME_R
25
ME_R
32
LO_R
ME_R
34
ME_R
40
LO_R
ME_R
42
ME_R
56
ME_R
58
LO_R
ME_R
66
LOP_R
ME_R
67
LO_R
ME_R
70
ME_R
93
ME_R
94
ME_R
95
ME_R
96
LOP_R
ME_R
103
ME_R
106
ME_R
108
ME_R
120
LOP_R
ME_R
125
ME_R
130
LOP_R
ME_R
138
ME_R
150
ME_R
151
LOP_R
ME_R
155
ME_R
158
ME_R
160
LOP_R
ME_R
179
ME_R
199
AME_R
ME_R
205
ME_R
229
LO_R
LOP_R
ME_R
230
medulla
EB
FB
182
fan-shaped body
MB_VL_R
SLP_R
SIP_R
SMP_R
79
SLP_R
SMP_R
221
superior lateral protocerebrum
CRE_R
SIP_R
SMP_R
35
superior intermediate protocerebrum
SMP_R
SMP_L
28
SMP_R
SMP_L
146
SMP_R
193
superior medial protocerebrum
AVLP_R
121
anterior ventrolateral protocerebrum
AMMC_R
IVLP_R
PLP_R
181
wedge
PLP_R
154
posterior lateral protocerebrum
LH_R
MB_CA_R
SCL_R
17
PLP_R
MB_CA_R
39
MB_CA_R
63
ICL_R
MB_CA_R
68
ATL_R
MB_CA_R
86
calyx of adult mushroom body
IB_R
SPS_R
117
superior posterior slope
FLA_R
AL_R
PRW
30
prow
AL_R
GA_R
64
AL_R
GA_R
116
GA_R
212
gall
AME_L
136
AME_L
ME_L
142
AME_L
152
AME_L
ME_L
211
accessory medulla
AME_L
LO_L
LOP_L
ME_L
98
AME_L
LO_L
115
LO_L
ME_L
PVLP_L
165
LO_L
171
LO_L
ME_L
177
LO_L
ME_L
217
lobula
BU_L
214
bulb
LH_L
1
LH_L
4
LH_L
15
LH_L
MB_CA_L
16
lateral horn
CAN_R
CAN_L
92
CAN_R
CAN_L
99
LOP_R
ME_R
CAN_L
105
SMP_R
CAN_L
MB_ML_L
SMP_L
122
SMP_R
CAN_L
SMP_L
140
CAN_L
231
cantle
AMMC_L
36
SAD
AMMC_L
IVLP_L
46
antennal mechanosensory and motor center
PRW
VES_L
101
vest
FB
ATL_L
80
PB
ATL_L
102
ATL_L
135
antler
SIP_R
MB_VL_L
SIP_L
AOTU_L
2
MB_PED_L
MB_VL_L
23
CRE_L
MB_VL_L
MB_ML_L
53
vertical lobe of adult mushroom body
CRE_L
MB_ML_L
22
medial lobe of adult mushroom body
FLA_R
AL_R
FLA_L
AL_L
12
flange
LOP_L
ME_L
129
lobula plate
AL_R
LAL_L
AL_L
27
AL_L
33
LAL_L
AL_L
82
adult antennal lobe
AME_L
LO_L
ME_L
61
BU_L
ME_L
69
ME_L
PLP_L
126
LO_L
LOP_L
ME_L
132
CAN_R
LO_L
ME_L
IPS_L
139
LO_L
ME_L
162
ME_L
166
ATL_R
LO_L
LOP_L
ME_L
167
CAN_R
MB_VL_R
LOP_L
ME_L
168
CAN_R
LO_L
ME_L
172
LO_L
ME_L
174
AME_L
LO_L
ME_L
176
ME_L
194
LO_L
ME_L
200
GA_R
LO_L
ME_L
225
medulla
SLP_L
SCL_L
84
SLP_L
SMP_L
MB_CA_L
SCL_L
208
SLP_L
215
superior lateral protocerebrum
BU_L
SMP_L
71
CAN_R
SMP_L
169
SMP_L
236
superior medial protocerebrum
AVLP_L
PVLP_L
SCL_L
104
AVLP_L
159
anterior ventrolateral protocerebrum
IVLP_L
SPS_L
85
AMMC_L
IVLP_L
112
wedge
PVLP_L
PLP_L
MB_CA_L
SCL_L
13
PLP_L
MB_CA_L
97
posterior lateral protocerebrum
ICL_L
MB_CA_L
5
MB_CA_L
29
MB_CA_L
41
MB_CA_L
44
MB_CA_R
MB_CA_L
SCL_L
62
MB_CA_L
228
calyx of adult mushroom body
IB_L
SPS_L
76
SPS_L
157
superior posterior slope
ICL_L
MB_PED_L
MB_CA_L
SCL_L
75
superior clamp
Looked at the components maps and time series and remove all the components which are localized on the edge of the brain and with activity unlike GCaMP6 transients.

In [34]:
BadICs=[92,99,72,156,216]

In [35]:
for idx in BadICs:
    GoodICAnat[idx] = 0.0

Reorder by larger sub-regions (~ presumed stimulus to motor)


In [36]:
LargerRegionsDic={'':'','AME_R':'OL','LO_R':'OL','NO':'CX','BU_R':'CX','PB':'CX','LH_R':'LH','LAL_R':'LX','SAD':'PENP'
               ,'CAN_R':'PENP','AMMC_R':'PENP','ICL_R':'INP','VES_R':'VMNP','IB_R':'INP','ATL_R':'INP','CRE_R':'INP'
               ,'MB_PED_R':'MB','MB_VL_R':'MB','MB_ML_R':'MB','FLA_R':'PENP','LOP_R':'OL','EB':'CX','AL_R':'AL',
                'ME_R':'OL','FB':'CX','SLP_R':'SNP','SIP_R':'SNP','SMP_R':'SNP','AVLP_R':'VLNP','PVLP_R':'VLNP',
                'IVLP_R':'VLNP','PLP_R':'VLNP','AOTU_R':'VLNP','GOR_R':'VMNP','MB_CA_R':'MB','SPS_R':'VMNP',
                'IPS_R':'VMNP','SCL_R':'INP','EPA_R':'VMNP','GNG':'GNG','PRW':'PENP','GA_R':'LX','AME_L':'OL'
                ,'LO_L':'OL','BU_L':'CX','LH_L':'LH','LAL_L':'LX','CAN_L':'PENP','AMMC_L':'PENP','ICL_L':'INP',
                'VES_L':'VMNP','IB_L':'INP','ATL_L':'INP','CRE_L':'INP','MB_PED_L':'MB','MB_VL_L':'MB',
                'MB_ML_L':'MB','FLA_L':'PENP','LOP_L':'OL','AL_L':'AL','ME_L':'OL','SLP_L':'SNP','SIP_L':'SNP',
                'SMP_L':'SNP','AVLP_L':'VLNP','PVLP_L':'VLNP','IVLP_L':'VLNP','PLP_L':'VLNP','AOTU_L':'VLNP',
                'GOR_L':'VMNP','MB_CA_L':'MB','SPS_L':'VMNP','IPS_L':'VMNP','SCL_L':'INP','EPA_L':'VMNP','GA_L':'LX'}

SmallRegionsSorted=['ME_L','ME_R','LO_R','LO_L','LOP_R','LOP_L','AME_R','AME_L',
                  'PLP_R','PLP_L','PVLP_R','PVLP_L','AVLP_R','AVLP_L','AOTU_R','AOTU_L','IVLP_R','IVLP_L',
                  'AL_R','AL_L',
                  'MB_CA_R','MB_CA_L','MB_PED_R','MB_PED_L','MB_VL_R','MB_VL_L','MB_ML_R','MB_ML_L',
                  'SMP_R','SMP_L','SIP_R','SLP_L','SLP_R','SIP_L',
                  'LH_R','LH_L',                  
                  'CRE_R','CRE_L','ICL_R','ICL_L','SCL_R','SCL_L','IB_R','IB_L','ATL_R','ATL_L',
                  'EB','PB','NO','FB',
                  'BU_R','BU_L','LAL_R','LAL_L','GA_R','GA_L',
                  'GOR_R','GOR_L','EPA_R','EPA_L','VES_R','VES_L','SPS_R','SPS_L','IPS_R','IPS_L',
                  'AMMC_R','AMMC_L','SAD','FLA_R','FLA_L','PRW','CAN_R','CAN_L',
                  'GNG','']

Tozip=range(len(SmallRegionsSorted))
SmallRegionsDic=dict(zip(SmallRegionsSorted,Tozip))

LargerRegion=[LargerRegionsDic[CompMainName[i]] for i in range(S[3])]

LargerRegionInd={ 'OL':1,'VLNP':2,'VMNP':3,'AL':4,'MB':5,'LH':6,'SNP':7,'CX':8,'LX':9,'INP':10,'PENP':11,'GNG':12,'':13}

LargerRegionI=np.array([LargerRegionInd[LargerRegion[i]] for i in range(S[3])])

SmallRegion=np.array([SmallRegionsDic[CompMainName[i]] for i in range(S[3])])

NewOrder=np.argsort(SmallRegion)

SmallRegion[NewOrder]


Out[36]:
array([ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,
        1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,
        1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  2,
        2,  2,  2,  2,  2,  2,  2,  3,  3,  3,  3,  3,  3,  4,  4,  4,  4,
        4,  5,  5,  6,  7,  7,  7,  7,  7,  8,  9,  9,  9, 12, 12, 12, 13,
       13, 13, 13, 15, 16, 17, 17, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19,
       19, 20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
       21, 24, 24, 24, 24, 25, 25, 25, 25, 25, 26, 26, 27, 28, 28, 28, 28,
       28, 28, 29, 29, 29, 29, 29, 30, 30, 30, 31, 31, 31, 31, 31, 32, 32,
       32, 33, 34, 34, 34, 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, 38, 38,
       41, 42, 42, 42, 42, 43, 43, 43, 44, 44, 44, 44, 44, 45, 45, 45, 45,
       46, 46, 46, 47, 47, 47, 47, 47, 48, 49, 51, 51, 51, 51, 54, 54, 54,
       54, 56, 60, 61, 62, 62, 62, 63, 63, 64, 64, 64, 65, 66, 66, 66, 67,
       67, 67, 68, 69, 70, 71, 71, 72, 72, 72, 72, 72, 72, 72, 72, 73, 73,
       73, 73, 73, 73, 73, 73, 73, 73, 74, 75, 75, 75])

In [37]:
LargerRegionIndToName = {v: k for k, v in LargerRegionInd.iteritems()}

In [38]:
LargerRegionI


Out[38]:
array([ 4,  6,  5,  6,  6,  5,  6,  6,  1,  4,  6,  1, 11,  2,  1,  6,  6,
        5,  5,  1, 11, 11,  5,  5,  4,  1,  4,  4,  7,  5, 11,  1,  1,  4,
        1,  7, 11, 10, 11,  5,  1,  5,  1,  5,  5,  3, 11,  5,  5,  7, 11,
       11,  4,  5,  4,  1,  1,  7,  1,  4,  1,  1,  5,  5,  9,  2,  1,  1,
        5,  1,  1,  7, 11,  6, 11, 10,  3, 10,  3,  7, 10,  8,  4, 13,  7,
        2,  5,  8,  3, 10,  4,  5, 11,  1,  1,  1,  1,  2,  1, 11, 10,  3,
       10,  1,  2, 11,  1,  5,  1, 10,  2,  1,  2,  1,  8,  1,  9,  3,  1,
        1,  1,  2, 11,  2,  7,  1,  1,  8,  1,  1,  1,  8,  1,  8,  5, 10,
        1,  1,  1,  1, 11, 10,  1,  2,  5,  9,  7,  1,  8,  1,  1,  1,  1,
        8,  2,  1, 11,  3,  1,  2,  1,  7,  1, 11,  1,  1,  1,  1,  1,  7,
       11,  1,  1,  8,  1,  2,  1,  1,  5,  1,  7,  2,  8,  8,  5,  3,  8,
       11, 11,  1, 11,  5,  7,  7,  1, 11,  7,  3, 10,  1,  1,  7,  3, 11,
       10,  1,  5, 10,  7,  3,  1,  1,  9,  6,  8,  7, 11,  1,  6, 10,  7,
        7, 11, 10,  2,  1, 10,  6,  5,  1,  1, 11,  3,  7,  1,  1,  7, 10,
        6, 11, 12, 13,  7, 11, 10,  8, 13,  5, 10,  5])

In [40]:
GoodICAnat


Out[40]:
array([ 1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  0.,  1.,
        1.,  1.,  1.,  1.,  1.,  1.,  1.,  0.,  0.,  0.,  1.,  1.,  1.,
        1.,  0.,  1.,  1.,  0.,  0.,  1.,  0.,  1.,  1.,  1.,  0.,  1.,
        1.,  1.,  1.,  1.,  1.,  1.,  0.,  1.,  0.,  1.,  0.,  1.,  0.,
        0.,  0.,  1.,  1.,  1.,  0.,  0.,  0.,  0.,  1.,  1.,  1.,  1.,
        0.,  1.,  1.,  1.,  1.,  1.,  1.,  0.,  1.,  0.,  1.,  1.,  0.,
        0.,  1.,  1.,  1.,  1.,  0.,  1.,  1.,  1.,  0.,  0.,  1.,  1.,
        0.,  0.,  1.,  1.,  1.,  1.,  1.,  1.,  0.,  0.,  1.,  1.,  1.,
        1.,  0.,  1.,  0.,  1.,  1.,  0.,  1.,  1.,  1.,  1.,  1.,  1.,
        1.,  1.,  1.,  1.,  1.,  1.,  0.,  0.,  1.,  1.,  1.,  1.,  1.,
        1.,  1.,  1.,  1.,  0.,  1.,  1.,  1.,  1.,  1.,  1.,  0.,  1.,
        0.,  0.,  0.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,
        0.,  1.,  1.,  1.,  1.,  0.,  1.,  0.,  1.,  1.,  1.,  1.,  1.,
        1.,  0.,  1.,  1.,  0.,  1.,  0.,  1.,  1.,  0.,  1.,  0.,  1.,
        1.,  0.,  0.,  0.,  1.,  0.,  0.,  0.,  1.,  0.,  0.,  1.,  1.,
        0.,  0.,  0.,  0.,  1.,  1.,  0.,  0.,  0.,  0.,  1.,  0.,  1.,
        1.,  0.,  1.,  1.,  1.,  0.,  1.,  1.,  0.,  1.,  0.,  0.,  0.,
        1.,  0.,  1.,  0.,  1.,  0.,  0.,  1.,  1.,  1.,  1.,  0.,  0.,
        0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.])

In [41]:
pylab.rcParams['figure.figsize'] = (13, 2.5)

h=5
tot=0
NumberInLargeRegion=np.zeros(13)

for l in range(1,13):
    print(LargerRegionIndToName[l])
    Final_maps=np.zeros((S[0],S[1],3))
    Fmap=np.zeros((S[0],S[1],3))
    C=np.zeros(3)

    n=0
    for i in range(len(CompMainName)):                    
        Dmmv=np.mean(data[:,:,:,i],2) 
        Dmmv[Dmmv<0.2*np.max(np.max(np.max(Dmmv)))]=0
        C=np.squeeze(np.random.rand(3,1))
        labeled, nrobject=ndimage.label(Dmmv>0)
        
        if LargerRegionI[i]==l:          
            if GoodICAnat[i]==1:
                for k in range(3):
                    Fmap[:,:,k]=0.7*Dmmv*C[k]/np.max(C)
                Final_maps=Final_maps+Fmap
                #plt.plot(Time_fluoICA.T,(DT[:,i]/np.sqrt(np.var(DT[:,i]))-h*n+2),color=C/2)
                plt.plot((DT[:,i]/np.sqrt(np.var(DT[:,i]))-h*n+2),color=C/2)
                tot=tot+1
                print(i)
                n=n+1 
                    
    if n!=0:

        plt.show()
        FM=Final_maps/np.max(np.max(Final_maps))
        FM[FM<0.1]=0
        plt.imshow(FM,interpolation='none')
        plt.show()
        frame1 = plt.gca()
        frame1.axes.get_xaxis().set_visible(False)
        frame1.axes.get_yaxis().set_visible(False)
        
    NumberInLargeRegion[l]=n


OL
8
14
19
25
32
34
40
42
55
56
61
66
67
69
70
93
94
95
96
98
103
106
108
111
113
115
118
119
120
125
126
128
129
130
132
136
137
138
139
142
147
149
150
151
152
155
158
160
162
164
165
166
167
168
171
172
174
176
177
179
194
199
200
205
210
211
217
225
229
230
VLNP
13
85
97
104
112
121
154
159
181
VMNP
76
101
117
157
AL
0
9
24
26
54
82
90
MB
2
5
17
18
23
29
39
41
43
44
48
62
63
68
86
228
LH
1
3
4
6
7
10
15
16
73
SNP
28
35
71
79
84
146
169
193
208
215
221
236
CX
81
114
127
131
133
148
153
182
186
214
LX
64
116
212
INP
75
80
89
102
109
135
207
223
PENP
12
36
38
46
50
122
140
190
231
GNG

In [42]:
# Output number of component per region
np.savetxt('/'.join(filename.split('/')[:-1])+'/NumberInLargeRegions.txt',NumberInLargeRegion)

In [ ]: