/[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.15 - (hide annotations) (download)
Mon Oct 5 21:55:46 2015 UTC (9 years, 9 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65r, checkpoint65p, checkpoint65q
Changes since 1.14: +3 -3 lines
- improved treatment of directory names.

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     if ~isempty(dir([dirModel 'nsidc79_monthly_*']));
49     dirData=dirModel;
50     else;
51     dirData='/net/nares/raid11/ecco-shared/ecco-version-4/input/input_nsidc_all/';
52     end;
53 heimbach 1.1
54 gforget 1.14 fileModel=dir([dirEcco 'm_siv4_area*data']);
55     fileModel=fileModel.name;
56 heimbach 1.1
57 heimbach 1.3 nyears=yearend-yearsta+1;
58     nmonths=12*nyears;
59    
60 gforget 1.7 %misfits :
61 heimbach 1.3 fld_dif=convert2gcmfaces(NaN*ones(90,90*13,nmonths));
62 gforget 1.8 fld_nsidc=convert2gcmfaces(NaN*ones(90,90*13,nmonths));
63 heimbach 1.3
64 gforget 1.7 %monthly mean climatology :
65     climMod=convert2gcmfaces(zeros(90,90*13,12));
66     climObs=convert2gcmfaces(zeros(90,90*13,12));
67     climMsk=convert2gcmfaces(zeros(90,90*13,12));
68     climNb=convert2gcmfaces(zeros(90,90*13,12));
69    
70     %monthly integrals :
71 gforget 1.4 IceAreaNorthMod=NaN*zeros(1,nmonths);
72     IceAreaNorthObs=NaN*zeros(1,nmonths);
73    
74     IceAreaSouthMod=NaN*zeros(6,nmonths);
75     IceAreaSouthObs=NaN*zeros(6,nmonths);
76 heimbach 1.3
77 gforget 1.7 %computational loop :
78 heimbach 1.3 for ycur=yearsta:yearend;
79 heimbach 1.1 tic;
80     for mcur=1:12;
81 heimbach 1.3 mm=(ycur-yearsta)*12+mcur;
82    
83 gforget 1.14 fld_dat=read_bin([dirData 'nsidc79_monthly_' num2str(ycur)],mcur,0);
84 heimbach 1.1
85 gforget 1.6 fld_dat=fld_dat.*mygrid.mskC(:,:,1);%land mask
86     fld_dat(find(fld_dat<-99))=NaN;%missing data
87     msk=1+0*fld_dat;%combined mask
88 heimbach 1.1
89 gforget 1.11 fld_mod=read_bin([dirModel fileModel],mm,0);
90 gforget 1.6 fld_mod=fld_mod.*msk;%mask consistent with fld_dat
91 gforget 1.7
92     %misfits :
93 heimbach 1.1 fld_dif(:,:,mm)=fld_mod-fld_dat;
94 gforget 1.8 fld_nsidc(:,:,mm)=fld_dat;
95 heimbach 1.1
96 gforget 1.7 %climatology :
97     tmp1=msk; tmp1(isnan(tmp1))=0; climMsk(:,:,mcur)=climMsk(:,:,mcur)+tmp1;
98     tmp1=fld_mod; tmp1(isnan(tmp1))=0; climMod(:,:,mcur)=climMod(:,:,mcur)+tmp1;
99     tmp1=fld_dat; tmp1(isnan(tmp1))=0; climObs(:,:,mcur)=climObs(:,:,mcur)+tmp1;
100    
101     %integrals :
102 heimbach 1.1 fld=fld_mod.*mygrid.RAC.*(mygrid.YC>0); IceAreaNorthMod(mm)=nansum(fld);
103     fld=fld_dat.*mygrid.RAC.*(mygrid.YC>0); IceAreaNorthObs(mm)=nansum(fld);
104 gforget 1.5
105     fld=fld_mod.*mygrid.RAC.*(mygrid.YC<0); IceAreaSouthMod(1,mm)=nansum(fld);
106     fld=fld_dat.*mygrid.RAC.*(mygrid.YC<0); IceAreaSouthObs(1,mm)=nansum(fld);
107 heimbach 1.3
108     for kk=1:5;
109     tmpmsk=0.*mygrid.XC;
110 gforget 1.5 if lonLims(kk+1) > lonLims(kk)
111     tmpmsk(find(mygrid.XC >= lonLims(kk) & mygrid.XC < lonLims(kk+1)))=1.;
112 heimbach 1.3 else
113 gforget 1.5 tmpmsk(find(mygrid.XC >= lonLims(kk) & mygrid.XC <= 180.))=1.;
114     tmpmsk(find(mygrid.XC >= -180. & mygrid.XC < lonLims(kk+1)))=1.;
115 heimbach 1.3 end
116     tmpmsk=tmpmsk.*(mygrid.YC<0);
117     %
118     fld=fld_mod.*mygrid.RAC.*tmpmsk;
119 gforget 1.5 IceAreaSouthMod(kk+1,mm)=nansum(fld);
120 heimbach 1.3 %
121     fld=fld_dat.*mygrid.RAC.*tmpmsk;
122 gforget 1.5 IceAreaSouthObs(kk+1,mm)=nansum(fld);
123 heimbach 1.3 end
124 heimbach 1.1
125     end;
126     toc;
127     end;
128    
129 gforget 1.7 %misfits :
130 gforget 1.8 mis_rms=sqrt(nanmean(fld_dif.^2,3));
131     obs_std=nanstd(fld_nsidc,[],3);
132     mod_std=nanstd(fld_nsidc+fld_dif,[],3);
133 heimbach 1.1
134 gforget 1.7 %climatology :
135     for mcur=1:12;
136     tmp1=climMsk(:,:,mcur); tmp1(tmp1==0)=NaN;
137     climNb(:,:,mcur)=tmp1;
138     climMod(:,:,mcur)=climMod(:,:,mcur)./tmp1;
139     climObs(:,:,mcur)=climObs(:,:,mcur)./tmp1;
140     end;
141     clear climMsk;
142    
143 gforget 1.10 if ~isdir([dirMat 'cost/']); mkdir([dirMat 'cost/']); end;
144     eval(['save ' dirMat '/cost/cost_seaicearea.mat fld_err mis_rms obs_std mod_std IceArea* clim*;']);
145 heimbach 1.1
146     else;%display previously computed results
147    
148 gforget 1.9 if isdir([dirMat 'cost/']); dirMat=[dirMat 'cost/']; end;
149    
150 gforget 1.8 eval(['load ' dirMat '/cost_seaicearea.mat;']);
151    
152     %variance maps:
153     figure; m_map_gcmfaces(mis_rms,0,{'myCaxis',[0:0.1:1.]});
154     myCaption={'modeled-observed rms -- sea ice concentration'};
155     if addToTex; write2tex(fileTex,2,myCaption,gcf); end;
156    
157     figure; m_map_gcmfaces(obs_std,0,{'myCaxis',[0:0.1:1.]});
158     myCaption={'observed std -- sea ice concentration'};
159     if addToTex; write2tex(fileTex,2,myCaption,gcf); end;
160    
161     figure; m_map_gcmfaces(mod_std,0,{'myCaxis',[0:0.1:1.]});
162     myCaption={'modelled std -- sea ice concentration'};
163     if addToTex; write2tex(fileTex,2,myCaption,gcf); end;
164 heimbach 1.1
165 gforget 1.8 %arctic maps
166     figureL;
167     subplot(2,2,1); m_map_gcmfaces(climMod(:,:,3),2,{'myCaxis',[0:0.1:1.]});
168     subplot(2,2,2); m_map_gcmfaces(climObs(:,:,3),2,{'myCaxis',[0:0.1:1.]});
169     subplot(2,2,3); m_map_gcmfaces(climMod(:,:,9),2,{'myCaxis',[0:0.1:1.]});
170     subplot(2,2,4); m_map_gcmfaces(climObs(:,:,9),2,{'myCaxis',[0:0.1:1.]});
171 gforget 1.12 myCaption={'ECCO (left) and NSIDC (right, gsfc bootstrap) ice concentration in March (top) and September (bottom).'};
172 gforget 1.8 if addToTex; write2tex(fileTex,2,myCaption,gcf); end;
173 heimbach 1.1
174 gforget 1.8 %southern ocean maps
175     figureL;
176     subplot(2,2,1); m_map_gcmfaces(climMod(:,:,3),3,{'myCaxis',[0:0.1:1.]});
177     subplot(2,2,2); m_map_gcmfaces(climObs(:,:,3),3,{'myCaxis',[0:0.1:1.]});
178     subplot(2,2,3); m_map_gcmfaces(climMod(:,:,9),3,{'myCaxis',[0:0.1:1.]});
179     subplot(2,2,4); m_map_gcmfaces(climObs(:,:,9),3,{'myCaxis',[0:0.1:1.]});
180 gforget 1.12 myCaption={'ECCO (left) and NSIDC (right, gsfc bootstrap) ice concentration in March (top) and September (bottom).'};
181 gforget 1.8 if addToTex; write2tex(fileTex,2,myCaption,gcf); end;
182 heimbach 1.1
183 gforget 1.8 %northern/southern integrals
184     ny=length(IceAreaNorthMod)/12;
185     yy=yearsta+[0:ny-1];
186    
187     figureL;
188     subplot(1,2,1);
189     plot(yy,IceAreaNorthMod(3:12:end),'LineWidth',2); hold on;
190     plot(yy,IceAreaNorthObs(3:12:end),'r','LineWidth',2);
191     plot(yy,IceAreaNorthMod(9:12:end),'LineWidth',2);
192     plot(yy,IceAreaNorthObs(9:12:end),'r','LineWidth',2);
193     axis([yearsta yearsta+ny-1 0 20e12]);
194     ylabel('m^2'); title('Northern Hemisphere');
195     subplot(1,2,2);
196     plot(yy,IceAreaSouthMod(1,3:12:end),'LineWidth',2); hold on;
197     plot(yy,IceAreaSouthObs(1,3:12:end),'r','LineWidth',2);
198     plot(yy,IceAreaSouthMod(1,9:12:end),'LineWidth',2);
199     plot(yy,IceAreaSouthObs(1,9:12:end),'r','LineWidth',2);
200     axis([yearsta yearsta+ny-1 0 20e12]);
201     ylabel('m^2'); title('Southern Hemisphere');
202 heimbach 1.1
203 gforget 1.12 myCaption={'ECCO (blue) and NSIDC (red, gsfc bootstrap) ice concentration in March and September',...
204 gforget 1.8 'in Northern Hemisphere (left) and Southern Hemisphere (right)'};
205 heimbach 1.1 if addToTex; write2tex(fileTex,2,myCaption,gcf); end;
206    
207 gforget 1.8 %southern basin integrals
208    
209     for mm=[3 9];
210     figureL;
211     for ii=1:6;
212     subplot(3,2,ii);
213     if ii==1; iiTxt='Entire Southern Ocean';
214     else; iiTxt=sprintf('%dE to %dE',lonLims(ii-1),lonLims(ii));
215     end;
216     plot(yy,IceAreaSouthMod(ii,mm:12:end),'LineWidth',2); hold on;
217     plot(yy,IceAreaSouthObs(ii,mm:12:end),'r','LineWidth',2);
218     aa=axis; aa(1:2)=[yearsta yearsta+ny-1]; axis(aa);
219     ylabel('m^2'); title(iiTxt);
220     end;
221     if mm==3; mmTxt='March'; elseif mm==9; mmTxt='September'; else; '???'; end;
222 gforget 1.12 myCaption={'ECCO (blue) and NSIDC (red, gsfc bootstrap) ice concentration in ',mmTxt,' per Southern Ocean sector'};
223 gforget 1.8 if addToTex; write2tex(fileTex,2,myCaption,gcf); end;
224     end;
225    
226 heimbach 1.1 end;
227    
228    

  ViewVC Help
Powered by ViewVC 1.1.22