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