This repository was archived by the owner on Oct 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaug27_rcf_spike_count_norm.m
More file actions
560 lines (459 loc) · 13.2 KB
/
aug27_rcf_spike_count_norm.m
File metadata and controls
560 lines (459 loc) · 13.2 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
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
%% spikes count analyses 2.0 RCF
%% looking at downcast only
zdepth_dc(18000,21)=nan;
zdepth_uc(18000,21)=nan;
spike_dc(18000,21)=nan;
spike_uc(18000,21)=nan;
spike_eq_dc(18000,21)=nan;
spike_eq_uc(18000,21)=nan;
time_dc(18000,21)=nan;
time_uc(18000,21)=nan;
depth=combdat.rcf.zdepth;%depth source
var=combdat.rcf.spikes.bbp700; %var to split
var2=combdat.rcf.spikes.bbp700_eq_filt;
time=combdat.rcf.time;
for i=1:21
zdepth_idx=depth(:,i);
min_depth=nanmin(zdepth_idx);
k=find(zdepth_idx==min_depth);
downcast=zdepth_idx(1:k);
downcast(isnan(downcast))=[];
zdepth_dc(1:length(downcast),i)=downcast;
upcast=zdepth_idx(k:18000);
upcast(isnan(upcast))=[];
zdepth_uc(1:length(upcast),i)=upcast;
% var to split into downcast/upcast
idx=var(:,i);
idx_dc=idx(1:k);
idx_dc(isnan(idx_dc))=[];
spike_dc(1:length(idx_dc),i)=idx_dc;
idx_uc=idx(k:18000);
idx_uc(isnan(idx_uc))=[];
spike_uc(1:length(idx_uc),i)=idx_uc;
% var2 to split into downcast/upcast
idx9=var2(:,i);
idx_dc=idx9(1:k);
idx_dc(isnan(idx_dc))=[];
spike_eq_dc(1:length(idx_dc),i)=idx_dc;
%time
idx4=time(:,i);
idx_dc=idx4(1:k);
idx_dc(isnan(idx_dc))=[];
time_dc(1:length(idx_dc),i)=idx_dc;
idx_uc=idx4(k:18000);
idx_uc(isnan(idx_uc))=[];
time_uc(1:length(idx_uc),i)=idx_uc;
clear min_depth zdepth_idx idx downcast upcast idx_dc idx_uc
end
%% check by plotting
aa=zdepth_dc==0;
zdepth_dc(aa)=nan;
spike_dc(aa)=nan;
time_dc(aa)=nan;
aa=zdepth_uc==0;
zdepth_uc(aa)=nan;
spike_uc(aa)=nan;
time_uc(aa)=nan;
%%
close all
for i=1:21
figure
plot(spike_eq_dc(:,i),zdepth_dc(:,i))
end
%% saving
spikecount.spike_rcf_dc=spike_dc;
spikecount.zdepth_rcf_dc=zdepth_dc;
spikecount.time_rcf_dc=time_dc;
spikecount.spike_eq_rcf_dc=spike_eq_dc;
%% calculating speed of rcf downcast
%change depth variable & time depending on speed needed
depth=spikecount.zdepth_rcf_dc;
time_idx=spikecount.time_rcf_dc;
%speed calc
distance=nanmin(depth);
time=nanmax(time_idx)-nanmin(time_idx);%[days]
times=time*86400;%convert to seconds to get speed in [m/s]
speed=distance./-times;
mean_speed=nanmean(speed);
std=std(speed);
max_speed=mean_speed+2*std;
min_speed=mean_speed-2*std;
%% saving
spikecount.rcf_speed_dc=speed;
%% Delet column five (outside 2 stdev) and 14 (uneven speed)
for i=1:21
figure
plot(time_dc(:,i),zdepth_dc(:,i))
end
%% counting spikes
%matrix with spike source
% a=spikecount.spike_rcf_dc;
% aa=a==0;
% a(aa)=nan;
% spikecount.spike_rcf_dc=a;
% count_column=sum(~isnan(a),1); %1 for column, 2 for row counts
%count_row=sum(~isnan(a),2); % cant do row because depths different
%% binning count_row
% % first, find matrix/vector in depth range, then use nnz to find non-zeros
% n=100;%depth bin
% k=0:-n:-1000;
% count_bin=nan(length(k),1);
% for i=1:length(k)-1
% j=i+1;
% aa=spikecount.zdepth_rcf_dc<=k(i)&spikecount.zdepth_rcf_dc>k(j);
% idx2=spikecount.spike_rcf_dc(aa);
% count_bin(i)=nnz(idx2);
% end
%
% count_depth=k';
% %% plotting
% close all
% figure
% scatter(count_bin,count_depth-(n/2))
% title('100 m binning, counting rcf spikes')
% xlabel('Number of spikes')
% ylabel('Depth bin (m)')
%
% %% saving
% spikecount.count_bin_100_rcf=count_bin;
% spikecount.count_depth_100_rcf=count_depth;
%% splitting into three time events
aa=isnan(spikecount.spike_rcf_dc);
spikecount.spike_rcf_dc(aa)=0;
spikecount.spike_eq_rcf_dc(aa)=0;
event1_s=spikecount.spike_rcf_dc(:,1:5);
event1_z=spikecount.zdepth_rcf_dc(:,1:5);
event1_f=spikecount.spike_eq_rcf_dc(:,1:5);
event2_s=spikecount.spike_rcf_dc(:,6:12);
event2_z=spikecount.zdepth_rcf_dc(:,6:12);
event2_f=spikecount.spike_eq_rcf_dc(:,6:12);
event3_s=spikecount.spike_rcf_dc(:,13:19);
event3_z=spikecount.zdepth_rcf_dc(:,13:19);
event3_f=spikecount.spike_eq_rcf_dc(:,13:19);
%% depth binning separate events and getting frequency
clear k n count_bin1 count_bin2 count_bin3
n=75;%depth bin
k=0:-n:-450;
count_bin1=nan(length(k),1);
count_bin2=nan(length(k),1);
count_bin3=nan(length(k),1);
clearvars aa i j idx idx1 idx2 idx3 idx4
for i=1:length(k)-1
j=i+1;
clear aa bb cc idx2 idx3 idx4
aa=event1_z<=k(i)&event1_z>k(j);
idx2=event1_s(aa);
count_bin1(i)=nnz(idx2)/nnz(aa);
%event2
bb=event2_z<=k(i)&event2_z>k(j);
idx3=event2_s(bb);
count_bin2(i)=nnz(idx3)/nnz(bb);
%event3
cc=event3_z<=k(i)&event3_z>k(j);
idx4=event3_s(cc);
count_bin3(i)=nnz(idx4)/nnz(cc);
end
count_depth_event=k';
%% plot
figure
scatter(count_bin1,count_depth_event-(n/2),'c','filled')
hold on
scatter(count_bin2,count_depth_event-(n/2),'b','filled')
hold on
scatter(count_bin3,count_depth_event-(n/2),'m','filled')
title('RCF spike frequency')
xlabel('Spike frequency')
ylabel('Depth (m)')
legend('week 1','week 2','week 3','location','southeast')
grid on
box on
%% for equal filter
clear k n count_bin1 count_bin2 count_bin3
n=75;%depth bin
k=0:-n:-450;
count_bin1f=nan(length(k),1);
count_bin2f=nan(length(k),1);
count_bin3f=nan(length(k),1);
clearvars aa i j idx idx1 idx2 idx3 idx4
for i=1:length(k)-1
j=i+1;
clear aa bb cc idx2 idx3 idx4
aa=event1_z<=k(i)&event1_z>k(j);
idx2=event1_f(aa);
count_bin1f(i)=nnz(idx2)/nnz(aa);
%event2
bb=event2_z<=k(i)&event2_z>k(j);
idx3=event2_f(bb);
count_bin2f(i)=nnz(idx3)/nnz(bb);
%event3
cc=event3_z<=k(i)&event3_z>k(j);
idx4=event3_f(cc);
count_bin3f(i)=nnz(idx4)/nnz(cc);
end
count_depth_event=k';
%% plot
figure
scatter(count_bin1f,count_depth_event-(n/2),'c','filled')
hold on
scatter(count_bin2f,count_depth_event-(n/2),'b','filled')
hold on
scatter(count_bin3f,count_depth_event-(n/2),'m','filled')
title('RCF spike frequency')
xlabel('Spike frequency')
ylabel('Depth (m)')
legend('week 1','week 2','week 3','location','southeast')
grid on
box on
%% normalizing spike values/cast
% count_bin1_norm=count_bin1;
% count_bin1_norm(1:3)=count_bin1_norm(1:3)/6;
% count_bin1_norm(4:6)=count_bin1_norm(4:6)/4;
% count_bin1_norm(7:15)=count_bin1_norm(7:15)/2;
%
% count_bin2_norm=count_bin2;
% count_bin2_norm(1:3)=count_bin2_norm(1:3)/8;
% count_bin2_norm(4:6)=count_bin2_norm(4:6)/4;
% count_bin2_norm(7:15)=nan;
%
% count_bin3_norm=count_bin3;
% count_bin3_norm(1:3)=count_bin3_norm(1:3)/7;
% count_bin3_norm(4:6)=count_bin3_norm(4:6)/4;
% count_bin3_norm(7:15)=nan;
%%
% figure
% scatter(count_bin1_norm,count_depth_event-(n/2),'c')
% hold on
% scatter(count_bin2_norm,count_depth_event-(n/2),'b')
% hold on
% scatter(count_bin3_norm,count_depth_event-(n/2),'m')
% title('RCF spike counts by event(75m)- normalized by cast number')
% xlabel('# spikes/# casts')
% ylabel('Depth (m)')
% legend('obs 1','obs 2','obs 3','location','southeast')
% grid on
% box on
%% saving
spikecount.norm.event1=count_bin1;
spikecount.norm.event2=count_bin2;
spikecount.norm.event3=count_bin3;
spikecount.norm.depth_bin=count_depth_event;
spikecount.norm.event1f=count_bin1f;
spikecount.norm.event2f=count_bin2f;
spikecount.norm.event3f=count_bin3f;
%% curve fitting
spike_event1=spikecount.norm.event1;
spike_event1s=spike_event1;
spike_event1s(1)=nan;
depth_event=-(spikecount.norm.depth_bin-(n/2));
spike_event2=spikecount.norm.event2;
spike_event2s=spike_event2;
spike_event2s(1)=nan;
spike_event3=spikecount.norm.event3;
spike_event3s=spike_event3;
spike_event3s(1)=nan;
%% plotting out of mat file specific filt
x=1:0.5:500;
y1=0.1836 *(x/112.5).^(-1.344 );
y2=0.1796 *(x/112.5).^(-0.8668 );
y3=0.1417 *(x/112.5).^(-0.9197 );
figure
scatter(spikecount.norm.event1,spikecount.norm.depth_bin-(n/2),'c','filled')
hold on
scatter(spikecount.norm.event2,spikecount.norm.depth_bin-(n/2),'b','filled')
hold on
scatter(spikecount.norm.event3,spikecount.norm.depth_bin-(n/2),'m','filled')
title('RCF spike frequency spec. filt')
xlabel('Spike frequency')
ylabel('Depth (m)')
grid on
box on
hold on
plot(y1,-x,'c')
xlim([0 0.4])
hold on
plot(y2,-x,'b')
hold on
plot(y3,-x,'m')
% legend('week 1','week 2','week 3','b=1.543','b=1.088','b=1.018','location','southeast')
%%
y1a=0.1836*(x/112.5).^(-1.042);
y1b=0.1836*(x/112.5).^(-1.765);
y2a=0.1796*(x/112.5).^(-0.7322);
y2b=0.1796 *(x/112.5).^(-1.001);
y3a=0.1417 *(x/112.5).^(-0.8387);
y3b=0.1417*(x/112.5).^(- 1.001);
hold on
plot(y1,-x,'c',y1a,-x,'c:',y1b,-x,'c:')
hold on
plot(y2,-x,'b',y2a,-x,'b:',y2b,-x,'b:')
hold on
plot(y3,-x,'m',y3a,-x,'m:',y3b,-x,'m:')
legend('P3A','P3B','P3C','b=1.543','b=1.088','b=1.018','location','southeast')
% title('Spike attenuation RCF')
% xlabel('Spike frequency')
% ylabel('Depth (m)')
% %legend('week 1','week 2','week 3','location','southeast')
% xlim([0 0.2])
%% now doing the same but combining all data
clear k n count_bin1 count_bin2 count_bin3
n=75;%depth bin
k=0:-n:-450;
count_bin_rcf=nan(length(k),1);
clearvars aa i j idx idx1 idx2 idx3 idx4
for i=1:length(k)-1
j=i+1;
clear aa bb cc idx2 idx3 idx4
aa=spikecount.zdepth_rcf_dc<=k(i)&spikecount.zdepth_rcf_dc>k(j);
idx2=spikecount.spike_rcf_dc(aa);
count_bin_rcf(i)=nnz(idx2)/nnz(aa);
end
count_depth_rcf=k';
%% plotting
figure
scatter(count_bin_rcf,count_depth_rcf-(n/2),'k','filled')
title('RCF spike frequency')
xlabel('Spike frequency')
ylabel('Depth (m)')
grid on
box on
%% saving
spikecount.rcf.spike_f=count_bin_rcf;
spikecount.rcf.depth_f=count_depth_rcf;
%% spike attenuation
rcf_s=count_bin_rcf;
rcf_s(1)=nan;
%% plotting attenuation
x=1:0.5:1100;
yall=0.1695 *(x/112.5).^(-1.011 );
yall1=0.1695 *(x/112.5).^(-0.8714);
yall2=0.1695 *(x/112.5).^(-1.151);
figure
scatter(spikecount.rcf.spike_f,spikecount.rcf.depth_f-(n/2),'r','filled')
hold on
plot(yall,-x,'r',yall1,-x,'r:',yall2,-x,'r:')
title('Spike frequency - specific filter')
xlabel('Spike frequency')
ylabel('Depth (m)')
xlim([0 0.4])
ylim([-1100 0])
grid on
box on
hold on
scatter(count_bin_eq_filt,count_depth-(n/2),'k','filled')
hold on
plot(y1,-x,'k')
xlim([0 0.4])
hold on
plot(y2,-x,'k:')
hold on
plot(y3,-x,'k:')
ylim([-1100 0])
legend('RCF','b=1.011','CI 95%','CI 95%','CTD','b=0.6406','CI 95%','CI 95%','location','southeast')
%% now repeating for equal filter
spike_event1f=spikecount.norm.event1f;
spike_event1fs=spike_event1f;
spike_event1fs(1)=nan;
depth_event=-(spikecount.norm.depth_bin-(n/2));
spike_event2f=spikecount.norm.event2f;
spike_event2fs=spike_event2f;
spike_event2fs(1)=nan;
spike_event3f=spikecount.norm.event3f;
spike_event3fs=spike_event3f;
spike_event3fs(1)=nan;
%% plotting out of mat file specific filt
x=1:0.5:500;
y1f=0.2125 *(x/112.5).^(-1.267);
y2f=0.2029 *(x/112.5).^(-0.7126 );
y3f=0.1748 *(x/112.5).^(-0.8677 );
figure
scatter(spikecount.norm.event1f,spikecount.norm.depth_bin-(n/2),'c','filled')
hold on
scatter(spikecount.norm.event2f,spikecount.norm.depth_bin-(n/2),'b','filled')
hold on
scatter(spikecount.norm.event3f,spikecount.norm.depth_bin-(n/2),'m','filled')
title('RCF spike frequency equal filter')
xlabel('Spike frequency')
ylabel('Depth (m)')
grid on
box on
hold on
plot(y1f,-x,'c')
xlim([0 0.4])
hold on
plot(y2f,-x,'b')
hold on
plot(y3f,-x,'m')
% legend('week 1','week 2','week 3','b=1.543','b=1.088','b=1.018','location','southeast')
%%
y1af=0.2125*(x/112.5).^(-0.927 );
y1bf=0.2125*(x/112.5).^(-1.608);
y2af=0.2029 *(x/112.5).^(-0.6006);
y2bf=0.2029 *(x/112.5).^(-0.8246);
y3af=0.1748 *(x/112.5).^(-0.7679);
y3bf=0.1748 *(x/112.5).^(- 0.9676);
hold on
plot(y1f,-x,'c',y1af,-x,'c:',y1bf,-x,'c:')
hold on
plot(y2f,-x,'b',y2af,-x,'b:',y2bf,-x,'b:')
hold on
plot(y3f,-x,'m',y3af,-x,'m:',y3bf,-x,'m:')
legend('P3A','P3B','P3C','b=1.267 ','b=0.7126','b=0.8677','location','southeast')
% title('Spike attenuation RCF')
% xlabel('Spike frequency')
% ylabel('Depth (m)')
% %legend('week 1','week 2','week 3','location','southeast')
% xlim([0 0.2])
%% now doing the same but combining all data
clear k n count_bin1 count_bin2 count_bin3
n=75;%depth bin
k=0:-n:-450;
count_bin_rcf_f=nan(length(k),1);
clearvars aa i j idx idx1 idx2 idx3 idx4
for i=1:length(k)-1
j=i+1;
clear aa bb cc idx2 idx3 idx4
aa=spikecount.zdepth_rcf_dc<=k(i)&spikecount.zdepth_rcf_dc>k(j);
idx2=spikecount.spike_eq_rcf_dc(aa);
count_bin_rcf_f(i)=nnz(idx2)/nnz(aa);
end
count_depth_rcf=k';
%% plotting
figure
scatter(count_bin_rcf_f,count_depth_rcf-(n/2),'k','filled')
title('RCF spike frequency')
xlabel('Spike frequency')
ylabel('Depth (m)')
grid on
box on
%% saving
spikecount.rcf.spike_eq_filt=count_bin_rcf_f;
%% spike attenuation
rcf_sf=count_bin_rcf_f;
rcf_sf(1)=nan;
%% plotting attenuation
x=1:0.5:1100;
yallf=0.1973 *(x/112.5).^(-0.9026 );
yall1f=0.1973 *(x/112.5).^(-0.7905);
yall2f=0.1973 *(x/112.5).^(-1.015);
figure
scatter(spikecount.rcf.spike_eq_filt,spikecount.rcf.depth_f-(n/2),'r','filled')
hold on
plot(yallf,-x,'r',yall1f,-x,'r:',yall2f,-x,'r:')
title('Spike frequency - equal filter')
xlabel('Spike frequency')
ylabel('Depth (m)')
xlim([0 0.4])
ylim([-1100 0])
grid on
box on
hold on
scatter(count_bin,count_depth-(n/2),'k','filled')
hold on
plot(y1,-x,'k')
xlim([0 0.4])
hold on
plot(y2,-x,'k:')
hold on
plot(y3,-x,'k:')
ylim([-1100 0])
legend('RCF','b=0.9026','CI 95%','CI 95%','CTD','b=0.7829','CI 95%','CI 95%','location','southeast')