/[MITgcm]/MITgcm_contrib/gael/comm/course-idma2016/matlab/idma_box_mean.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/comm/course-idma2016/matlab/idma_box_mean.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (hide annotations) (download)
Thu Jan 14 14:56:36 2016 UTC (9 years, 6 months ago) by gforget
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +42 -21 lines
- turn idma_box_mean.m and idma_box_subset.m into functions.
- add help to the each function.

1 gforget 1.2 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 gforget 1.1
13 gforget 1.2 demoSTATS=1;%set this to one to activate display of results at one level
14 gforget 1.1
15 gforget 1.2 %%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 gforget 1.1 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 gforget 1.2 tmp1=MITprof_subset(p,'date',dd);
34 gforget 1.1 tmp1=tmp1.prof;
35     %
36 gforget 1.2 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 gforget 1.1 %
41     end;
42     end;
43    
44 gforget 1.2 %%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 gforget 1.1

  ViewVC Help
Powered by ViewVC 1.1.22