/[MITgcm]/MITgcm_contrib/gael/matlab_class/ecco_v4/cost_seaicearea.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/matlab_class/ecco_v4/cost_seaicearea.m

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


Revision 1.16 - (hide annotations) (download)
Thu Jan 28 01:38:47 2016 UTC (9 years, 6 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65t, checkpoint65u
Changes since 1.15: +5 -4 lines
- minor changes.

1 gforget 1.2 function []=cost_seaicearea(dirModel,dirMat,doComp,dirTex,nameTex);
2 heimbach 1.1 %object: compute cost function term for sea ice data
3     %inputs: dimodel is the model directory
4     % dirMat is the directory where diagnozed .mat files will be saved
5     % -> set it to '' to use the default [dirModel 'mat/']
6     % doComp is a switch (1->compute; 0->display)
7     %optional: dirTex is the directory where tex and figures files are created
8     % (if not specified then display all results to screen instead)
9 gforget 1.2 % nameTex is the tex file name (default : 'myPlots')
10 heimbach 1.1
11 gforget 1.15 if isempty(dirMat); dirMat=[dirModel 'mat' filesep]; else; dirMat=[dirMat filesep]; end;
12 gforget 1.13 if isempty(dir(dirMat)); mkdir([dirMat]); end;
13 heimbach 1.1
14     %determine if and where to create tex and figures files
15 gforget 1.15 dirMat=[dirMat filesep];
16 heimbach 1.1 if isempty(who('dirTex'));
17     addToTex=0;
18     else;
19     if ~ischar(dirTex); error('mis-specified dirTex'); end;
20 gforget 1.2 addToTex=1;
21     if isempty(who('nameTex')); nameTex='myPlots'; end;
22 gforget 1.15 fileTex=[dirTex filesep nameTex '.tex'];
23 heimbach 1.1 end;
24    
25 gforget 1.5 %grid, params and inputs
26     gcmfaces_global; global myparms;
27 heimbach 1.1 if ~isfield(mygrid,'XC'); grid_load('./GRID/',5,'compact'); end;
28     if ~isfield(mygrid,'LATS_MASKS'); gcmfaces_lines_zonal; end;
29 gforget 1.5 if isfield(myparms,'yearsta'); yearsta=myparms.yearsta; yearend=myparms.yearend;
30     else; yearsta=1992; yearend=2011;
31     end;
32 heimbach 1.1
33 gforget 1.8 [lonPairs,latPairs,names] = line_greatC_TUV_MASKS_core2_antarctic;
34     lonLims=[lonPairs(1:5,1);lonPairs(1,1)];
35    
36     if doComp;
37     %grid, params and inputs
38 heimbach 1.1 fld_err=ones(90,1170);
39     fld_err=convert2gcmfaces(fld_err);
40     fld_w=fld_err.^-2;
41    
42 gforget 1.14 if isempty(dir([dirModel 'barfiles']));
43     dirEcco=dirModel;
44     else;
45     dirEcco=[dirModel 'barfiles' filesep];
46     end;
47    
48 gforget 1.16 nameData='nsidc79_monthly_';
49     if ~isempty(dir([dirModel nameData '*']));
50 gforget 1.14 dirData=dirModel;
51     else;
52 gforget 1.16 error(['could not find ' nameData '*']);
53 gforget 1.14 end;
54 heimbach 1.1
55 gforget 1.14 fileModel=dir([dirEcco 'm_siv4_area*data']);
56     fileModel=fileModel.name;
57 heimbach 1.1
58 heimbach 1.3 nyears=yearend-yearsta+1;
59     nmonths=12*nyears;
60    
61 gforget 1.7 %misfits :
62 heimbach 1.3 fld_dif=convert2gcmfaces(NaN*ones(90,90*13,nmonths));
63 gforget 1.8 fld_nsidc=convert2gcmfaces(NaN*ones(90,90*13,nmonths));
64 heimbach 1.3
65 gforget 1.7 %monthly mean climatology :
66     climMod=convert2gcmfaces(zeros(90,90*13,12));
67     climObs=convert2gcmfaces(zeros(90,90*13,12));
68     climMsk=convert2gcmfaces(zeros(90,90*13,12));
69     climNb=convert2gcmfaces(zeros(90,90*13,12));
70    
71     %monthly integrals :
72 gforget 1.4 IceAreaNorthMod=NaN*zeros(1,nmonths);
73     IceAreaNorthObs=NaN*zeros(1,nmonths);
74    
75     IceAreaSouthMod=NaN*zeros(6,nmonths);
76     IceAreaSouthObs=NaN*zeros(6,nmonths);
77 heimbach 1.3
78 gforget 1.7 %computational loop :
79 heimbach 1.3 for ycur=yearsta:yearend;
80 heimbach 1.1 tic;
81     for mcur=1:12;
82 heimbach 1.3 mm=(ycur-yearsta)*12+mcur;
83    
84 gforget 1.16 fld_dat=read_bin([dirData nameData num2str(ycur)],mcur,0);
85 heimbach 1.1
86 gforget 1.6 fld_dat=fld_dat.*mygrid.mskC(:,:,1);%land mask
87     fld_dat(find(fld_dat<-99))=NaN;%missing data
88     msk=1+0*fld_dat;%combined mask
89 heimbach 1.1
90 gforget 1.16 fld_mod=read_bin([dirEcco fileModel],mm,0);
91 gforget 1.6 fld_mod=fld_mod.*msk;%mask consistent with fld_dat
92 gforget 1.7
93     %misfits :
94 heimbach 1.1 fld_dif(:,:,mm)=fld_mod-fld_dat;
95 gforget 1.8 fld_nsidc(:,:,mm)=fld_dat;
96 heimbach 1.1
97 gforget 1.7 %climatology :
98     tmp1=msk; tmp1(isnan(tmp1))=0; climMsk(:,:,mcur)=climMsk(:,:,mcur)+tmp1;
99     tmp1=fld_mod; tmp1(isnan(tmp1))=0; climMod(:,:,mcur)=climMod(:,:,mcur)+tmp1;
100     tmp1=fld_dat; tmp1(isnan(tmp1))=0; climObs(:,:,mcur)=climObs(:,:,mcur)+tmp1;
101    
102     %integrals :
103 heimbach 1.1 fld=fld_mod.*mygrid.RAC.*(mygrid.YC>0); IceAreaNorthMod(mm)=nansum(fld);
104     fld=fld_dat.*mygrid.RAC.*(mygrid.YC>0); IceAreaNorthObs(mm)=nansum(fld);
105 gforget 1.5
106     fld=fld_mod.*mygrid.RAC.*(mygrid.YC<0); IceAreaSouthMod(1,mm)=nansum(fld);
107     fld=fld_dat.*mygrid.RAC.*(mygrid.YC<0); IceAreaSouthObs(1,mm)=nansum(fld);
108 heimbach 1.3
109     for kk=1:5;
110     tmpmsk=0.*mygrid.XC;
111 gforget 1.5 if lonLims(kk+1) > lonLims(kk)
112     tmpmsk(find(mygrid.XC >= lonLims(kk) & mygrid.XC < lonLims(kk+1)))=1.;
113 heimbach 1.3 else
114 gforget 1.5 tmpmsk(find(mygrid.XC >= lonLims(kk) & mygrid.XC <= 180.))=1.;
115     tmpmsk(find(mygrid.XC >= -180. & mygrid.XC < lonLims(kk+1)))=1.;
116 heimbach 1.3 end
117     tmpmsk=tmpmsk.*(mygrid.YC<0);
118     %
119     fld=fld_mod.*mygrid.RAC.*tmpmsk;
120 gforget 1.5 IceAreaSouthMod(kk+1,mm)=nansum(fld);
121 heimbach 1.3 %
122     fld=fld_dat.*mygrid.RAC.*tmpmsk;
123 gforget 1.5 IceAreaSouthObs(kk+1,mm)=nansum(fld);
124 heimbach 1.3 end
125 heimbach 1.1
126     end;
127     toc;
128     end;
129    
130 gforget 1.7 %misfits :
131 gforget 1.8 mis_rms=sqrt(nanmean(fld_dif.^2,3));
132     obs_std=nanstd(fld_nsidc,[],3);
133     mod_std=nanstd(fld_nsidc+fld_dif,[],3);
134 heimbach 1.1
135 gforget 1.7 %climatology :
136     for mcur=1:12;
137     tmp1=climMsk(:,:,mcur); tmp1(tmp1==0)=NaN;
138     climNb(:,:,mcur)=tmp1;
139     climMod(:,:,mcur)=climMod(:,:,mcur)./tmp1;
140     climObs(:,:,mcur)=climObs(:,:,mcur)./tmp1;
141     end;
142     clear climMsk;
143    
144 gforget 1.10 if ~isdir([dirMat 'cost/']); mkdir([dirMat 'cost/']); end;
145     eval(['save ' dirMat '/cost/cost_seaicearea.mat fld_err mis_rms obs_std mod_std IceArea* clim*;']);
146 heimbach 1.1
147     else;%display previously computed results
148    
149 gforget 1.9 if isdir([dirMat 'cost/']); dirMat=[dirMat 'cost/']; end;
150    
151 gforget 1.8 eval(['load ' dirMat '/cost_seaicearea.mat;']);
152    
153     %variance maps:
154     figure; m_map_gcmfaces(mis_rms,0,{'myCaxis',[0:0.1:1.]});
155     myCaption={'modeled-observed rms -- sea ice concentration'};
156     if addToTex; write2tex(fileTex,2,myCaption,gcf); end;
157    
158     figure; m_map_gcmfaces(obs_std,0,{'myCaxis',[0:0.1:1.]});
159     myCaption={'observed std -- sea ice concentration'};
160     if addToTex; write2tex(fileTex,2,myCaption,gcf); end;
161    
162     figure; m_map_gcmfaces(mod_std,0,{'myCaxis',[0:0.1:1.]});
163     myCaption={'modelled std -- sea ice concentration'};
164     if addToTex; write2tex(fileTex,2,myCaption,gcf); end;
165 heimbach 1.1
166 gforget 1.8 %arctic maps
167     figureL;
168     subplot(2,2,1); m_map_gcmfaces(climMod(:,:,3),2,{'myCaxis',[0:0.1:1.]});
169     subplot(2,2,2); m_map_gcmfaces(climObs(:,:,3),2,{'myCaxis',[0:0.1:1.]});
170     subplot(2,2,3); m_map_gcmfaces(climMod(:,:,9),2,{'myCaxis',[0:0.1:1.]});
171     subplot(2,2,4); m_map_gcmfaces(climObs(:,:,9),2,{'myCaxis',[0:0.1:1.]});
172 gforget 1.12 myCaption={'ECCO (left) and NSIDC (right, gsfc bootstrap) ice concentration in March (top) and September (bottom).'};
173 gforget 1.8 if addToTex; write2tex(fileTex,2,myCaption,gcf); end;
174 heimbach 1.1
175 gforget 1.8 %southern ocean maps
176     figureL;
177     subplot(2,2,1); m_map_gcmfaces(climMod(:,:,3),3,{'myCaxis',[0:0.1:1.]});
178     subplot(2,2,2); m_map_gcmfaces(climObs(:,:,3),3,{'myCaxis',[0:0.1:1.]});
179     subplot(2,2,3); m_map_gcmfaces(climMod(:,:,9),3,{'myCaxis',[0:0.1:1.]});
180     subplot(2,2,4); m_map_gcmfaces(climObs(:,:,9),3,{'myCaxis',[0:0.1:1.]});
181 gforget 1.12 myCaption={'ECCO (left) and NSIDC (right, gsfc bootstrap) ice concentration in March (top) and September (bottom).'};
182 gforget 1.8 if addToTex; write2tex(fileTex,2,myCaption,gcf); end;
183 heimbach 1.1
184 gforget 1.8 %northern/southern integrals
185     ny=length(IceAreaNorthMod)/12;
186     yy=yearsta+[0:ny-1];
187    
188     figureL;
189     subplot(1,2,1);
190     plot(yy,IceAreaNorthMod(3:12:end),'LineWidth',2); hold on;
191     plot(yy,IceAreaNorthObs(3:12:end),'r','LineWidth',2);
192     plot(yy,IceAreaNorthMod(9:12:end),'LineWidth',2);
193     plot(yy,IceAreaNorthObs(9:12:end),'r','LineWidth',2);
194     axis([yearsta yearsta+ny-1 0 20e12]);
195     ylabel('m^2'); title('Northern Hemisphere');
196     subplot(1,2,2);
197     plot(yy,IceAreaSouthMod(1,3:12:end),'LineWidth',2); hold on;
198     plot(yy,IceAreaSouthObs(1,3:12:end),'r','LineWidth',2);
199     plot(yy,IceAreaSouthMod(1,9:12:end),'LineWidth',2);
200     plot(yy,IceAreaSouthObs(1,9:12:end),'r','LineWidth',2);
201     axis([yearsta yearsta+ny-1 0 20e12]);
202     ylabel('m^2'); title('Southern Hemisphere');
203 heimbach 1.1
204 gforget 1.12 myCaption={'ECCO (blue) and NSIDC (red, gsfc bootstrap) ice concentration in March and September',...
205 gforget 1.8 'in Northern Hemisphere (left) and Southern Hemisphere (right)'};
206 heimbach 1.1 if addToTex; write2tex(fileTex,2,myCaption,gcf); end;
207    
208 gforget 1.8 %southern basin integrals
209    
210     for mm=[3 9];
211     figureL;
212     for ii=1:6;
213     subplot(3,2,ii);
214     if ii==1; iiTxt='Entire Southern Ocean';
215     else; iiTxt=sprintf('%dE to %dE',lonLims(ii-1),lonLims(ii));
216     end;
217     plot(yy,IceAreaSouthMod(ii,mm:12:end),'LineWidth',2); hold on;
218     plot(yy,IceAreaSouthObs(ii,mm:12:end),'r','LineWidth',2);
219     aa=axis; aa(1:2)=[yearsta yearsta+ny-1]; axis(aa);
220     ylabel('m^2'); title(iiTxt);
221     end;
222     if mm==3; mmTxt='March'; elseif mm==9; mmTxt='September'; else; '???'; end;
223 gforget 1.12 myCaption={'ECCO (blue) and NSIDC (red, gsfc bootstrap) ice concentration in ',mmTxt,' per Southern Ocean sector'};
224 gforget 1.8 if addToTex; write2tex(fileTex,2,myCaption,gcf); end;
225     end;
226    
227 heimbach 1.1 end;
228    
229    

  ViewVC Help
Powered by ViewVC 1.1.22