1 |
function [boxmean,tim,dep]=idma_box_mean(p,w); |
2 |
% |
3 |
% IDMA_BOX_MEAN computes monthly averages (over 1992-2011) of all profiles |
4 |
% in p that passed all QCs (i.e. such that weight w>0); both p and |
5 |
% w are in MITprof format as obtained using idma_box_subset; |
6 |
% boxmean, tim, dep are two dimensional arrays (w. month, depth indices) |
7 |
% |
8 |
% Example: box_l=[-180 -140]; box_L=[-10 10]-30; box_D=[0 300]; |
9 |
% [prof_T,prof_Testim,prof_Tweight]=idma_box_subset(box_l,box_L,box_D); |
10 |
% [boxmean,tim,dep]=idma_box_mean(prof_T,prof_Tweight); |
11 |
% figureL; pcolor(tim,-dep,boxmean); colorbar; |
12 |
|
13 |
demoSTATS=1;%set this to one to activate display of results at one level |
14 |
|
15 |
%%define time and depth arrays |
16 |
tim=1992+[0.5:239.5]/12; |
17 |
dep=p.prof_depth; |
18 |
[dep,tim]=meshgrid(dep,tim); |
19 |
|
20 |
%%mask out points that did not pass all QCs |
21 |
p.prof(w.prof==0)=NaN; |
22 |
|
23 |
%%compute averages |
24 |
boxnb=NaN*zeros(240,p.nr); |
25 |
boxmean=NaN*zeros(240,p.nr); |
26 |
boxmedian=NaN*zeros(240,p.nr); |
27 |
boxstd=NaN*zeros(240,p.nr); |
28 |
for yy=1992:2011; |
29 |
for mm=1:12; |
30 |
dd=[datenum(yy,mm,0) datenum(yy,mm+1,0)]; |
31 |
tt=(yy-1992)*12+mm; |
32 |
% |
33 |
tmp1=MITprof_subset(p,'date',dd); |
34 |
tmp1=tmp1.prof; |
35 |
% |
36 |
boxnb(tt,:)=sum(~isnan(tmp1),1); |
37 |
boxmean(tt,:)=nanmean(tmp1,1); |
38 |
boxmedian(tt,:)=nanmedian(tmp1,1); |
39 |
boxstd(tt,:)=nanstd(tmp1,1); |
40 |
% |
41 |
end; |
42 |
end; |
43 |
|
44 |
%%display results |
45 |
if demoSTATS; |
46 |
figure; |
47 |
kk=2; |
48 |
subplot(3,1,1); plot(tim(:,kk),boxnb(:,kk)); |
49 |
legend('sample size','Location','NorthWest'); |
50 |
subplot(3,1,2); plot(tim(:,kk),boxmean(:,kk)); ylabel('degree C'); |
51 |
hold on; plot(tim,boxmedian(:,kk),'r'); |
52 |
legend('sample mean','sample median','Location','NorthWest'); |
53 |
subplot(3,1,3); plot(tim(:,kk),boxstd(:,kk)); ylabel('degree C'); |
54 |
legend('sample std','Location','NorthWest'); |
55 |
end; |
56 |
|