/[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.2 - (hide annotations) (download)
Thu May 30 20:19:31 2013 UTC (13 years, 3 months ago) by gforget
Branch: MAIN
Changes since 1.1: +35 -25 lines
- augment stats to listStats={'prc10','mea','med','prc90','std','iqr','mad'};
- profiles_subgrid_stats.m : add choiceType selector ('anom','estim' or 'obs')

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

  ViewVC Help
Powered by ViewVC 1.1.22