/[MITgcm]/MITgcm_contrib/gael/profilesMatlabProcessing/profiles_devel/profiles_subgrid_stats.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/profilesMatlabProcessing/profiles_devel/profiles_subgrid_stats.m

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


Revision 1.1 - (hide annotations) (download)
Thu May 16 15:33:27 2013 UTC (13 years, 3 months ago) by gforget
Branch: MAIN
- map insitu data stats.

1 gforget 1.1 function [myStat]=profiles_subgrid_stats(choiceProf,choiceLevel,choiceVar,choiceGrid,subGridN);
2    
3     %note : in wod09 ctd, we will use kk=2 to 33
4     % subGridN=8;%on the cs24 grid
5     % subGridN=18;%on the llc grid
6     %next things I need to do :
7     % IO/memory store
8     % loop over subGridN
9     % proper treatment of choiceLevel
10    
11    
12     %global variables:
13     gcmfaces_global;
14     global lon lat obs point;
15     global choiceGridOld; if isempty(choiceGridOld); choiceGridOld='x'; end;
16     global choiceProfOld; if isempty(choiceProfOld); choiceProfOld='x'; end;
17     global choiceVarOld; if isempty(choiceVarOld); choiceVarOld='x'; end;
18     global choiceLevelOld; if isempty(choiceLevelOld); choiceLevelOld=0; end;
19    
20     %choice of time/depth ranges
21     RC=squeeze(rdmds('/net/weddell/raid3/gforget/ecco_v4/GRID/RC'));
22     RF=squeeze(rdmds('/net/weddell/raid3/gforget/ecco_v4/GRID/RF'));
23     depth0=-RF(1:end-1); depth0(2:end-1)=depth0(1:end-2);
24     depth1=-RF(2:end); depth1(2:end-1)=depth1(3:end);
25     if choiceLevel>=1;
26     depth0=depth0(choiceLevel); depth1=depth1(choiceLevel);%choice of depth range
27     else;
28     error('not implemented');
29     end;
30     %
31     date0=datenum(1950,1,1); date1=datenum(2049,12,31);%choice of time range
32    
33     %get the grid:
34     if strcmp(choiceGrid,'cs24')&~strcmp(choiceGrid,choiceGridOld);
35     dirGrid='/net/weddell/raid3/gforget/grids/gridCompleted/cube_FM/';
36     % dirGrid='/Users/gforget/mywork/projects_inprogress/2012mayInputs/insitu/processed/';
37     grid_load_native([dirGrid 'cube_24/'],6);
38     gcmfaces_bindata;
39     elseif strcmp(choiceGrid,'cs96')&~strcmp(choiceGrid,choiceGridOld);
40     dirGrid='/net/weddell/raid3/gforget/grids/gridCompleted/cube_FM/';
41     % dirGrid='/Users/gforget/mywork/projects_inprogress/2012mayInputs/insitu/processed/';
42     grid_load_native([dirGrid 'cube_96/'],6);
43     gcmfaces_bindata;
44     elseif strcmp(choiceGrid,'v4')&~strcmp(choiceGrid,choiceGridOld);
45     dirGrid='/net/nares/raid10/gforget/2012julyIters/GRID/';
46     %dirGrid='/net/weddell/raid3/gforget/ecco_v4/GRID/';
47     grid_load(dirGrid,5,'compact');
48     gcmfaces_bindata;
49     end;
50     %
51     choiceGridOld=choiceGrid;
52    
53     %get the data:
54     if strcmp(choiceProf,'argo');
55     dirData='/net/nares/raid11/ecco-shared/ecco-version-4/input/input_insitu/';
56     listData={'argo_june2012_1992_to_2007*','argo_june2012_2008_to_2010*','argo_june2012_2011_to_2012*'};
57     suffOut='argo';
58     elseif strcmp(choiceProf,'model');
59     dirData='/net/nares/raid10/gforget/2012julyIters/ecco_it0003_link/mat/profiles/output/';
60     listData={'argo_june2012_1992_to_2007_model*','argo_june2012_2008_to_2010_model*','argo_june2012_2011_to_2012_model*'};
61     suffOut='model';
62     else;
63     dirData='/net/nares/raid11/gforget/2012mayInputs/insitu/processed/';
64     listData=dir([dirData '*.nc']);
65     for ii=1:length(listData); listData(ii).name=[listData(ii).name(1:end-3) '*']; end;
66     listData={listData(:).name};
67     %for ~ backward compatibility:
68     %listRm={'itp_MITprof*','bobbers_MITprof*','CLIMODE_Talley_ctd*','WOD09_XBT*'};
69     %remove climode and xbts
70     listRm={'bobbers_MITprof*','CLIMODE_Talley_ctd*','WOD09_XBT*'};
71     for ii=1:length(listRm); tmp1=find(~strcmp(listData,listRm{ii})); listData={listData{tmp1}}; end;
72     suffOut='';
73     end;
74     %
75     test1=~strcmp(choiceProf,choiceProfOld)|...
76     ~strcmp(choiceVar,choiceVarOld)|...
77     choiceLevel~=choiceLevelOld;
78     if test1;
79     [MITprof]=MITprof_stats_load(dirData,listData,choiceVar,['prof_' choiceVar suffOut]);
80     %in DRHODR case, switch to log10 :
81     if strcmp(choiceVar,'DRHODR'); MITprof.prof=log10(MITprof.prof); end;
82     %mask out values that are not in year range:
83     ii=find(MITprof.prof_date<date0|MITprof.prof_date>date1);
84     MITprof.prof(ii,:)=NaN;
85     %restrict to depth range of interest:
86     kk=find(MITprof.prof_depth>=depth0&MITprof.prof_depth<=depth1);
87     lon=MITprof.prof_lon; lat=MITprof.prof_lat; obs=MITprof.prof(:,kk);
88     end;
89     %
90     choiceLevelOld=choiceLevel;
91     choiceVarOld=choiceVar;
92     choiceProfOld=choiceProf;
93    
94     %get indices in full grid: (not necessarily the ecco_v4 one)
95     point=gcmfaces_bindata(lon,lat);
96    
97     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98    
99     %check nearest neighbor mapping:
100     % [tmp1,tmp2]=gcmfaces_bindata(lon,lat,lon);
101     % figureL; qwckplot(log10(tmp2));
102     % figureL; qwckplot(tmp1./tmp2);
103    
104     %map of full grid indices: (consistent with prof_point2)
105     indGrid=convert2array(mygrid.XC);
106     indGrid(:)=[1:length(indGrid(:))];
107     indGrid=convert2array(indGrid);
108    
109     %reduce grid and map reduced grid indices:
110     indBox=mygrid.XC;
111     if subGridN==0;
112     %global computation
113     indBox(:)=1;
114     else;
115     %regional computation
116     boxMax=0;
117     for iFace=1:mygrid.nFaces;
118     tmp1=indBox{iFace};
119     tmp3=ceil([1:size(tmp1,1)]'/subGridN);
120     tmp4=(ceil([1:size(tmp1,2)]/subGridN)-1)*max(tmp3);
121     tmp5=tmp3*ones(1,size(tmp1,2))+ones(size(tmp1,1),1)*tmp4;
122     indBox{iFace}=tmp5+boxMax;
123     boxMax=boxMax+max(tmp5(:));
124     end;
125     end;
126    
127     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128    
129     %main computational loop: stats for each region in indBox
130     %
131     indBox=convert2array(indBox);
132     box=repmat(indBox(point),[1 size(obs,2)]);
133     box(isnan(obs))=NaN;
134     boxList=unique(indBox(:));
135     boxList=boxList(find(~isnan(boxList)));
136     %
137     tmp1=convert2array(0*mygrid.XC);
138     myStat.mea=tmp1; myStat.prc90=tmp1; myStat.med=tmp1; myStat.prc10=tmp1; myStat.nb=tmp1;
139     %
140     for ii=boxList';
141     if mod(ii,1000)==0;
142     [choiceLevel ii length(boxList)]
143     end;
144     jj=find(box==ii);
145     if length(jj)>=10;
146     [nbOut,meanOut,prc10_Out,medOut,prc90_Out]=myStats(obs(jj));%need reduced params
147     jj=find(indBox==ii);
148     myStat.nb(jj)=nbOut;
149     myStat.mea(jj)=meanOut;
150     myStat.prc10(jj)=prc10_Out;
151     myStat.med(jj)=medOut;
152     myStat.prc90(jj)=prc90_Out;
153     end;
154     end;
155     %
156     myStat.nb=convert2array(myStat.nb);
157     myStat.mea=convert2array(myStat.mea);
158     myStat.prc10=convert2array(myStat.prc10);
159     myStat.med=convert2array(myStat.med);
160     myStat.prc90=convert2array(myStat.prc90);
161    
162     function [nbOut,meanOut,prc10_Out,medOut,prc90_Out]=myStats(obs);
163    
164     nbOut=sum(~isnan( obs ));
165    
166     meanOut=mean(obs);%sample mean
167     prc10_Out=prctile(obs,10);
168     %med_Out=prctile(obs,50);
169     medOut=median(obs);
170     prc90_Out=prctile(obs,90);
171    
172    

  ViewVC Help
Powered by ViewVC 1.1.22