-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetRawCalciumActivityStack.py
197 lines (163 loc) · 7.62 KB
/
getRawCalciumActivityStack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import tools.extractSaveData as extractSaveData
import tools.dataAnalysis as dataAnalysis
import pdb
from oauth2client import tools
tools.argparser.add_argument("-m","--mouse", help="specify name of the mouse", required=False)
tools.argparser.add_argument("-d","--date", help="specify name of the mouse", required=False)
args = tools.argparser.parse_args()
mouseD = '201008_t00' # id of the mouse to analyze
#mouseD = '190108_m24'
expDateD = 'some' # specific date e.g. '180214', 'some' for manual selection or 'all'
recordings='some' # 'all or 'some'
# in case mouse, and date were specified as input arguments
if args.mouse == None:
mouse = mouseD
else:
mouse = args.mouse
if args.date == None:
try:
expDate = expDateD
except :
expDate = 'all'
else:
expDate = args.date
#print mouse, expDate
#sys.exit(0) #pdb.set_trace()
eSD = extractSaveData.extractSaveData(mouse) # find data folder of specific mouse, create data folder, and hdf5 handle
#pdb.set_trace()
(foldersRecordings,dataFolder) = eSD.getRecordingsList(mouse,expDate=expDate,recordings=recordings) # get recordings for specific mouse and date
dataDirs = []
allTiffs = []
allRawRecs = []
imagesRead = False
#dA = dataAnalysis.dataAnalysis()
for f in range(len(foldersRecordings)):
for r in range(len(foldersRecordings[f][2])):
(existenceImaging, tiffList) = eSD.checkIfDeviceWasRecorded(foldersRecordings[f][0], foldersRecordings[f][1], foldersRecordings[f][2][r], 'SICaImaging')
(existenceGeneric, fileHandleGeneric) = eSD.checkIfDeviceWasRecorded(foldersRecordings[f][0],foldersRecordings[f][1],foldersRecordings[f][2][r],'PreAmpInput')
# pdb.set_trace()
# tiffList = tiffList[-7:-1]
# if camera was recorded
if existenceImaging and not imagesRead:
# pdb.set_trace()
dataDirs.append(eSD.dataBase2 + foldersRecordings[f][0] + '/')
allTiffs.extend(tiffList)
print('analysis on :', tiffList[2:], len(tiffList[2:]))
imgData = eSD.getRawCalciumImagingData(foldersRecordings[f][0], tiffList[2:])
imagesRead = True
if existenceGeneric:
#print(foldersRecordings[f][0],foldersRecordings[f][1],foldersRecordings[f][2][r])
# (foldersRecordings[f][0],foldersRecordings[f][1],foldersRecordings[f][2][r],'frameTimes',fileHandleFTimes)
(values, vTimes) = eSD.readRawData(foldersRecordings[f][0],foldersRecordings[f][1],foldersRecordings[f][2][r], 'PreAmpInput', fileHandleGeneric)
allRawRecs.append([vTimes,values])
#(existence,fileHandle) = eSD.checkIfDeviceWasRecorded(foldersRecordings[f][0],foldersRecordings[f][2][r],'Imaging')
#if existence:
# (frames,fTimes,imageMetaInfo) = eSD.readRawData(foldersRecordings[f][0],foldersRecordings[f][2][r],'Imaging',fileHandle)
# eSD.saveImageStack(frames,fTimes,imageMetaInfo,[foldersRecordings[f][0],foldersRecordings[f][2][r],'raw_imaging_data'])
# eSD.saveTif(frames[:,:,:,0], mouse,foldersRecordings[f][0],foldersRecordings[f][2][r]) # tif file for possible image registration in ImageJ
#break
#break
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.gridspec as gridspec
f = plt.figure()
gs = gridspec.GridSpec(4, 3,
#width_ratios=[1,2],
#height_ratios=[4,1]
)
#plt.imshow(np.average(imgData[0][1][2::],axis=0))
ax10 = plt.subplot(gs[0])
ax10.set_title('Jorge\'s power-supply \n average image')
ax20 = plt.subplot(gs[1])
ax20.set_title('Hamamatsu\'s power-supply \n average image')
ax30 = plt.subplot(gs[2])
ax30.set_title('Arduino\'s power-supply \n average image')
ax11 = plt.subplot(gs[3])
ax11.set_title('single image')
ax21 = plt.subplot(gs[4])
ax21.set_title('single image')
ax31 = plt.subplot(gs[5])
ax31.set_title('single image')
#ax22 = plt.subplot(gs[7])
#ax32 = plt.subplot(gs[8])
jorgePS = 218
hamaPS = 231
arduPS = 234
widthh = 60
#pdb.set_trace()
ax10.imshow(np.average(imgData[0][1][::2],axis=0))
ax10.axhline(y=jorgePS)
ax10.axhline(y=jorgePS+widthh)
ax20.imshow(np.average(imgData[1][1][::2],axis=0))
ax20.axhline(y=hamaPS)
ax20.axhline(y=hamaPS+widthh)
ax30.imshow(np.average(imgData[3][1][::2],axis=0))
ax30.axhline(y=arduPS)
ax30.axhline(y=arduPS+widthh)
#pdb.set_trace()
ax11.imshow(imgData[0][1][::2][-1])
ax11.axhline(y=jorgePS)
ax11.axhline(y=jorgePS+widthh)
ax21.imshow(imgData[1][1][::2][-1])
ax21.axhline(y=hamaPS)
ax21.axhline(y=hamaPS+widthh)
ax31.imshow(imgData[3][1][::2][-1])
ax31.axhline(y=arduPS)
ax31.axhline(y=arduPS+widthh)
ax12 = plt.subplot(gs[6])
ax12.set_title('cuts through avg. image')
ax12.plot(np.average(np.average(imgData[0][1][::2],axis=0)[:,jorgePS:(jorgePS+widthh)],axis=1),c='C0',label='jorge')
#ax12.plot(np.average(np.average(imgData[1][1][::2],axis=0)[:,jorgePS:(jorgePS+30)],axis=1),c='C0')
ax12.plot(np.average(np.average(imgData[1][1][::2],axis=0)[:,hamaPS:(hamaPS+widthh)],axis=1),c='C1',label='hamamatsu')
#ax12.plot(np.average(np.average(imgData[3][1][::2],axis=0)[:,jorgePS:(jorgePS+30)],axis=1),c='C0')
ax12.plot(np.average(np.average(imgData[3][1][::2],axis=0)[:,arduPS:(arduPS+widthh)],axis=1),c='C2',label='arduino')
ax12.legend()
###########################################
ax22 = plt.subplot(gs[7])
#ax22.plot(np.average(imgData[0][1][::2][-1][:,jorgePS:(jorgePS+30)],axis=1),c='C0',label='jorge')
#ax22.plot(np.average(imgData[2][1][::2][-1][:,hamaPS:(hamaPS+30)],axis=1),c='C1',label='hamamatsu')
#ax22.plot(np.average(imgData[4][1][::2][-1][:,arduPS:(arduPS+30)],axis=1),c='C2',label='arduino')
ax12.set_title('normalized cuts through single image')
avgJ = np.average(imgData[0][1][::2][-1][:,jorgePS:(jorgePS+widthh)],axis=1)
avgH = np.average(imgData[1][1][::2][-1][:,hamaPS:(hamaPS+widthh)],axis=1)
avgA = np.average(imgData[3][1][::2][-1][:,arduPS:(arduPS+widthh)],axis=1)
sigJ = (avgJ - np.mean(avgJ[:200]))/np.std(avgJ[:200])
sigH = (avgH - np.mean(avgH[:200]))/np.std(avgH[:200])
sigA = (avgA - np.mean(avgA[:200]))/np.std(avgA[:200])
#pdb.set_trace()
ax22.plot(sigJ,c='C0',label='jorge')
ax22.plot(sigH,c='C1',label='hamamatsu')
ax22.plot(sigA,c='C2',label='arduino')
ax22.legend()
###########################################
ax13 = plt.subplot(gs[9])
ax13.set_title('raw data (out of pre-AMP) trace')
recIdx = 3
ax13.plot(allRawRecs[0][0],allRawRecs[0][1][recIdx])
ax23 = plt.subplot(gs[10])
ax23.set_title('raw data (out of pre-AMP) trace')
ax23.plot(allRawRecs[1][0],allRawRecs[1][1][recIdx])
ax33 = plt.subplot(gs[11])
ax33.plot(allRawRecs[2][0],allRawRecs[2][1][recIdx])
ax33.set_title('raw data (out of pre-AMP) trace')
##################################################
ax13 = plt.subplot(gs[8])
ax13.set_title('histogram of raw data')
jorgeData = np.copy(allRawRecs[0][1][recIdx])
hamaData = np.copy(allRawRecs[1][1][recIdx])
arduiData = np.copy(allRawRecs[2][1][recIdx])
#pdb.set_trace()
binss = np.linspace(-0.062,0.004,200)
ax13.hist(jorgeData,bins=binss,histtype='step',label='jorge')
ax13.hist(hamaData,bins=binss,histtype='step',label='hamamatsu')
ax13.hist(arduiData,bins=binss,histtype='step',label='arduino')
ax13.set_yscale('log')
plt.legend(loc=2)
#ax11.plot(np.average(np.average(imgData[0][1][2::],axis=0)[:,215:235],axis=1),c='C0')
#ax11.plot(np.average(np.average(imgData[1][1][2::],axis=0)[:,215:235],axis=1),c='C0')
#plt.plot(np.average(np.average(imgData[2][1][2::],axis=0)[:,215:235],axis=1),c='C1')
#plt.plot(np.average(np.average(imgData[3][1][2::],axis=0)[:,215:235],axis=1),c='C1')
#plt.plot(np.average(np.average(imgData[4][1][2::],axis=0)[:,215:235],axis=1),c='C2')
#plt.plot(np.average(np.average(imgData[5][1][2::],axis=0)[:,215:235],axis=1),c='C2')
plt.show()
pdb.set_trace()