-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_process_multicells.m
More file actions
165 lines (126 loc) · 3.69 KB
/
Copy pathplot_process_multicells.m
File metadata and controls
165 lines (126 loc) · 3.69 KB
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
slit_widths = {'10','16','24','open_400','24_SLM','open_400_SLM'}; % 20250713
% slit_widths = {'5','10','16','24','open_400','16_SLM'}; % 20250712
NS = length(slit_widths);
slit_pix = [10 16 24 400 24 400];% 20250713
% slit_pix = [5 10 16 24 400 16]; % 20250712
slit_um = slit_pix*0.83;
tr_all = cell(1,NS);
rois_all = cell(1,NS);
fs = 800;
for ns = 1:NS
datadir{ns} = sprintf('/ad/eng/research/eng_research_economo2/SFS/TICO2/20250713/730_left/slit_%s/analysis',slit_widths{ns});
load(fullfile(datadir{ns},'signal.mat'))
load(fullfile(datadir{ns},'rois.mat'))
tr_all{ns} = tr;
rois_all{ns} = roimat;
clearvars tr roimat
end
%%
win_detect = -round(fs*.003):-1;
nos_window = -round(.001*fs):round(.002*fs);
F_proc = cell(1,NS);
for ns = 1:NS
F_proc{ns} = process_voltage(tr_all{ns});
[F_proc{ns}.F_AP, F_proc{ns}.parameters_AP] = calc_APs(F_proc{ns}.F_det);
[F_proc{ns}.F_0, F_proc{ns}.parameters_0] = calc_F0(tr_all{ns});
%% get spike locations
[F_proc{ns}.t_s, F_proc{ns}.parameters_kspikes] = get_spike_locations(F_proc{ns}.F_det, F_proc{ns}.F_AP, F_proc{ns}.N_f, F_proc{ns}.dF_ur, F_proc{ns}.dF_dr);
F_nospike{ns} = tr_all{ns};
for nr = 1:NR
cur_mm = movmean(tr_all{ns}(nr,:),round(.005*fs));
for ks = find(t_s{ns}(nr,:))
F_nospike{ns}(nr,ks+nos_window) = cur_mm(ks+nos_window);
end
F_sub{ns}(nr,:) = bandpass(F_nospike{ns}(nr,:),[1 50], fs);
end
snr_trace{ns} = f_det{ns}./N_f{ns};
snr_AP{ns} = F_AP{ns}./N_f{ns};
dff_trace{ns} = -(tr_all{ns}-F_0{ns})./F_0{ns};
dff_AP{ns} = F_AP{ns}./F_0{ns}; % only valid at detected spikes
end
%% show SNR
compare_ns = 1:4;% %[3 5] [4 6]
figure
hold on
for ns = 1:length(compare_ns)
k_ns = compare_ns(ns);
if nnz(t_s{k_ns}(:))
scatter(ns*ones(1,nnz(t_s{k_ns}(:))), snr_AP{k_ns}(logical(t_s{k_ns}(:))),30,'k','filled')
end
end
title('SNR')
% xlim([0.5, NR + 0.5])
% ylim([0 max(ylim)])
xticks(1:length(compare_ns))
for nref = 1:length(compare_ns)
tickstr{nref} = sprintf('%.1f um (%s)',slit_um(compare_ns(nref)), strrep(slit_widths{compare_ns(nref)},'_',' '));
end
xticklabels(tickstr)
xlabel('slit width')
xlim([min(xlim)-0.5,max(xlim)+0.5])
ylabel('SNR')
%% get dF/F
compare_ns = 1:4;%1:4; % [3 5] [4 6]
figure
hold on
for ns = 1:length(compare_ns)
k_ns = compare_ns(ns);
if nnz(t_s{k_ns})
scatter(ns*ones(1,nnz(t_s{k_ns})), dff_AP{k_ns}(logical(t_s{k_ns}(:))),30,'filled')
end
end
% xlim([0.5, NR + 0.5])
ylim([0 max(ylim)])
title('DF/F')
xticks(1:length(compare_ns))
for nref = 1:length(compare_ns)
tickstr{nref} = sprintf('%.1f um (%s)',slit_um(compare_ns(nref)), strrep(slit_widths{compare_ns(nref)},'_',' '));
end
xticklabels(tickstr)
xlim([min(xlim)-0.5,max(xlim)+0.5])
ylabel('\DeltaF/F')
%%
for ns = 1:NS
figure('Name',slit_widths{ns})
YL = [0 0];
tvec = (1:size(snr_trace{ns},2))*(1/fs);
for nr = 1:NR
subplot(1,NR, nr)
hold on
plot(tvec,snr_trace{ns}(nr,:),'k')
scatter(tvec(t_s{ns}(nr,:)), snr_AP{ns}(nr,t_s{ns}(nr,:)),'r','filled')
xlabel('time (s)')
ylabel('SNR')
xlim([1 tvec(end)-1])
if min(ylim)<YL(1)
YL(1) = min(ylim);
end
if max(ylim)>YL(2)
YL(2) = max(ylim);
end
end
for nr = 1:NR
subplot(1,NR, nr)
ylim(YL)
end
end
%%
figure
YL = [0 0];
for nr = 1:NR
subplot(1,NR, nr)
hold on
plot(tvec,f_det{ns}(nr,:),'k')
scatter(tvec(t_s{ns}(nr,:)), f_det{ns}(nr,t_s{ns}(nr,:)),'r','filled')
xlim([1 tvec(end)-1])
if min(ylim)<YL(1)
YL(1) = min(ylim);
end
if max(ylim)>YL(2)
YL(2) = max(ylim);
end
end
for nr = 1:NR
subplot(1,NR, nr)
ylim(YL)
end