1 |
gforget |
1.7 |
function []=cost_altimeter(dirModel,dirMat); |
2 |
|
|
%object: compute or plot the various sea level statistics |
3 |
|
|
% (std model-obs, model, obs, leading to cost function terms) |
4 |
|
|
%inputs: dirModel is the model run directory |
5 |
|
|
% dirMat is the directory where diagnozed .mat files will be saved |
6 |
|
|
% -> set it to '' to use the default [dirModel 'mat/'] |
7 |
|
|
% doComp is the switch from computation to plot |
8 |
gforget |
1.13 |
|
9 |
gforget |
1.4 |
doComp=1; |
10 |
|
|
if doComp==1; |
11 |
gforget |
1.11 |
doSave=1; |
12 |
|
|
doPlot=0; |
13 |
gforget |
1.4 |
else; |
14 |
gforget |
1.11 |
doSave=0; |
15 |
|
|
doPlot=1; |
16 |
gforget |
1.4 |
end; |
17 |
|
|
doPrint=0; |
18 |
|
|
|
19 |
gforget |
1.14 |
%%%%%%%%%%% |
20 |
|
|
%load grid: |
21 |
|
|
%%%%%%%%%%% |
22 |
|
|
|
23 |
|
|
gcmfaces_global; |
24 |
|
|
if ~isfield(mygrid,'XC'); grid_load('./GRID/',5,'compact'); end; |
25 |
|
|
if ~isfield(mygrid,'LATS_MASKS'); gcmfaces_lines_zonal; end; |
26 |
|
|
|
27 |
|
|
%%%%%%%%%%%%%%% |
28 |
|
|
%define pathes: |
29 |
|
|
%%%%%%%%%%%%%%% |
30 |
|
|
|
31 |
gforget |
1.16 |
nameSigma='sigma_MDT_glob_eccollc.bin'; |
32 |
|
|
if ~isempty(dir([dirModel nameSigma])); |
33 |
gforget |
1.14 |
dirSigma=dirModel; |
34 |
gforget |
1.17 |
elseif ~isempty(dir([dirModel 'inputfiles/' nameSigma])); |
35 |
|
|
dirSigma=[dirModel 'inputfiles/']; |
36 |
gforget |
1.14 |
else; |
37 |
gforget |
1.16 |
error(['could not find ' nameSigma]); |
38 |
gforget |
1.14 |
end; |
39 |
|
|
|
40 |
|
|
if isempty(dir([dirModel 'barfiles'])); |
41 |
|
|
dirEcco=dirModel; |
42 |
|
|
else; |
43 |
|
|
dirEcco=[dirModel 'barfiles' filesep]; |
44 |
|
|
end; |
45 |
|
|
|
46 |
|
|
%nameSigma={'sigma_MDT_glob_eccollc.bin','sigma_SLA_smooth_eccollc.bin','sigma_SLA_PWS07r2_glob_eccollc.bin'}; maxLatObs=66 |
47 |
gforget |
1.17 |
nameSigma={'sigma_MDT_glob_eccollc.bin','slaerr_largescale_r5.err','slaerr_gridscale_r5.err'}; maxLatObs=90 |
48 |
gforget |
1.14 |
|
49 |
|
|
if isempty(dirMat); dirMat=[dirModel 'mat/']; else; dirMat=[dirMat '/']; end; |
50 |
|
|
if isempty(dir(dirMat)); mkdir([dirMat]); end; |
51 |
|
|
if ~isdir([dirMat 'cost/']); mkdir([dirMat 'cost/']); end; |
52 |
|
|
runName=pwd; tmp1=strfind(runName,filesep); runName=runName(tmp1(end)+1:end); |
53 |
|
|
|
54 |
gforget |
1.15 |
|
55 |
|
|
%%%%%%%%%%%%%%%%% |
56 |
|
|
%global means: |
57 |
|
|
%%%%%%%%%%%%%%%%% |
58 |
|
|
|
59 |
|
|
tmpName=dir([dirEcco 'm_eta_day*data']); |
60 |
|
|
avisoName=which('MSL_aviso.bin'); |
61 |
|
|
if length(tmpName)==1&~isempty(avisoName); |
62 |
|
|
m_eta_day=rdmds2gcmfaces([dirEcco tmpName.name(1:end-5)]); |
63 |
|
|
avisoName=which('MSL_aviso.bin'); |
64 |
|
|
etaglo_aviso=read2memory(avisoName)'; |
65 |
|
|
%global mean |
66 |
|
|
nt=size(m_eta_day{1},3); etaglo=NaN*zeros(1,nt); |
67 |
|
|
area=mygrid.mskC(:,:,1).*mygrid.RAC; areatot=nansum(area); |
68 |
|
|
for tt=1:nt; |
69 |
|
|
etaglo(tt)=nansum(area.*m_eta_day(:,:,tt))/areatot; |
70 |
|
|
end; |
71 |
|
|
%monthly mean |
72 |
|
|
etaglo_mon=NaN*zeros(1,240); |
73 |
|
|
etaglo_aviso_mon=NaN*zeros(1,240); |
74 |
|
|
etadate=datenum([1992 1 1 12 0 0])+[1:nt]-1; |
75 |
|
|
for mm=1:240; |
76 |
|
|
t0=datenum([1992 1+(mm-1) 1 0 0 0]); |
77 |
|
|
t1=datenum([1992 1+mm 1 0 0 0]); |
78 |
|
|
tt=find(etadate>t0&etadate<t1); |
79 |
|
|
etaglo_mon(mm)=mean(etaglo(tt)); |
80 |
|
|
etaglo_aviso_mon(mm)=mean(etaglo_aviso(tt)); |
81 |
|
|
end; |
82 |
|
|
% |
83 |
|
|
if doSave; eval(['save ' dirMat 'cost/cost_altimeter_etaglo.mat etaglo*;']); end; |
84 |
|
|
end; |
85 |
|
|
|
86 |
gforget |
1.14 |
%%%%%%%%%%%%%%%%% |
87 |
|
|
%do computations: |
88 |
|
|
%%%%%%%%%%%%%%%%% |
89 |
|
|
|
90 |
gforget |
1.4 |
for doDifObsOrMod=1:3; |
91 |
gforget |
1.14 |
|
92 |
gforget |
1.11 |
if doDifObsOrMod==1; suf='modMobs'; elseif doDifObsOrMod==2; suf='obs'; else; suf='mod'; end; |
93 |
|
|
|
94 |
|
|
if doComp==0; |
95 |
|
|
eval(['load ' dirMat 'cost/cost_altimeter_' suf '.mat myflds;']); |
96 |
|
|
else; |
97 |
|
|
|
98 |
|
|
tic; |
99 |
|
|
%mdt cost function term (misfit plot) |
100 |
gforget |
1.14 |
dif_mdt=rdmds2gcmfaces([dirEcco 'mdtdiff_smooth']); |
101 |
gforget |
1.12 |
sig_mdt=read_bin([dirSigma nameSigma{1}],1,0); |
102 |
gforget |
1.11 |
sig_mdt(find(sig_mdt==0))=NaN; |
103 |
|
|
%store: |
104 |
|
|
myflds.dif_mdt=dif_mdt; |
105 |
|
|
myflds.sig_mdt=sig_mdt; |
106 |
|
|
|
107 |
|
|
%skip blanks: |
108 |
gforget |
1.14 |
tmp1=dir([dirEcco 'sladiff_smooth*data']); |
109 |
gforget |
1.11 |
nrec=tmp1.bytes/90/1170/4; |
110 |
|
|
ttShift=17; |
111 |
|
|
%skip 1992 |
112 |
|
|
listRecs=[1+365-ttShift:17+365*18-ttShift]; |
113 |
|
|
nRecs=length(listRecs); TT=1993+[0:nRecs-1]/365.25; |
114 |
|
|
|
115 |
|
|
toc; tic; |
116 |
|
|
%pointwise/1day terms: |
117 |
|
|
sladiff_point=repmat(0*mygrid.RAC,[1 1 nRecs]); count_point=sladiff_point; |
118 |
|
|
for ii=1:3; |
119 |
|
|
if ii==1; myset='tp'; elseif ii==2; myset='gfo'; else; myset='ers'; end; |
120 |
|
|
%topex pointwise misfits: |
121 |
|
|
if doDifObsOrMod==1; |
122 |
gforget |
1.14 |
sladiff_tmp=cost_altimeter_read([dirEcco 'sladiff_' myset '_raw'],ttShift+listRecs); |
123 |
gforget |
1.11 |
elseif doDifObsOrMod==2; |
124 |
gforget |
1.14 |
sladiff_tmp=cost_altimeter_read([dirEcco 'slaobs_' myset '_raw'],ttShift+listRecs); |
125 |
gforget |
1.11 |
else; |
126 |
gforget |
1.14 |
sladiff_tmp=cost_altimeter_read([dirEcco 'sladiff_' myset '_raw'],ttShift+listRecs); |
127 |
|
|
sladiff_tmp=sladiff_tmp+cost_altimeter_read([dirEcco 'slaobs_' myset '_raw'],ttShift+listRecs); |
128 |
gforget |
1.11 |
end; |
129 |
|
|
%add to overall data set: |
130 |
|
|
sladiff_point=sladiff_point+sladiff_tmp; count_point=count_point+(sladiff_tmp~=0); |
131 |
|
|
%finalize data set: |
132 |
|
|
sladiff_tmp(sladiff_tmp==0)=NaN; |
133 |
|
|
%compute rms: |
134 |
|
|
count_tmp=sum(~isnan(sladiff_tmp),3); count_tmp(find(count_tmp<10))=NaN; msk_tmp=1+0*count_tmp; |
135 |
|
|
eval(['myflds.rms_' myset '=sqrt(nansum(sladiff_tmp.^2,3)./count_tmp);']); |
136 |
|
|
eval(['myflds.std_' myset '=nanstd(sladiff_tmp,0,3).*msk_tmp;']); |
137 |
|
|
end; |
138 |
|
|
%finalize overall data set: |
139 |
|
|
count_point(count_point==0)=NaN; |
140 |
|
|
sladiff_point=sladiff_point./count_point; |
141 |
|
|
%compute overall rms,std: |
142 |
|
|
count_tmp=sum(~isnan(sladiff_point),3); count_tmp(find(count_tmp<10))=NaN; msk_tmp=1+0*count_tmp; |
143 |
|
|
myflds.rms_sladiff_point=sqrt(nansum(sladiff_point.^2,3)./count_tmp); |
144 |
|
|
myflds.std_sladiff_point=nanstd(sladiff_point,0,3).*msk_tmp; |
145 |
|
|
% |
146 |
|
|
msk_point=1*(count_point>0); |
147 |
|
|
%fill blanks: |
148 |
|
|
warning('off','MATLAB:divideByZero'); |
149 |
|
|
msk=mygrid.mskC(:,:,1); msk(find(abs(mygrid.YC)>maxLatObs))=NaN; |
150 |
|
|
myflds.xtrp_rms_sladiff_point=diffsmooth2D_extrap_inv(myflds.rms_sladiff_point,msk); |
151 |
|
|
myflds.xtrp_std_sladiff_point=diffsmooth2D_extrap_inv(myflds.std_sladiff_point,msk); |
152 |
|
|
warning('on','MATLAB:divideByZero'); |
153 |
|
|
%get weight: |
154 |
gforget |
1.12 |
sig_sladiff_point=read_bin([dirSigma nameSigma{3}],1,0); |
155 |
gforget |
1.11 |
sig_sladiff_point(find(sig_sladiff_point==0))=NaN; |
156 |
|
|
myflds.sig_sladiff_point=sig_sladiff_point; |
157 |
|
|
|
158 |
|
|
%computational mask : only points that were actually observed, and in 35d average |
159 |
gforget |
1.14 |
msk_point35d=cost_altimeter_read([dirEcco 'sladiff_raw'],listRecs); |
160 |
gforget |
1.11 |
msk_point35d=1*(msk_point35d~=0); |
161 |
|
|
tmp1=sum(msk_point35d==0&msk_point~=0); |
162 |
|
|
tmp2=sum(msk_point35d~=0&msk_point~=0); |
163 |
|
|
fprintf('after masking : %d omitted, %d retained \n',tmp1,tmp2); |
164 |
|
|
msk_point=msk_point.*msk_point35d; |
165 |
|
|
msk_point(msk_point==0)=NaN; |
166 |
|
|
%plotting mask : regions of less than 100 observations are omitted |
167 |
|
|
msk_100pts=1*(nansum(msk_point,3)>=100); |
168 |
|
|
msk_100pts(msk_100pts==0)=NaN; |
169 |
|
|
%store |
170 |
|
|
myflds.msk_100pts=msk_100pts; |
171 |
|
|
|
172 |
|
|
toc; tic; |
173 |
|
|
%lsc cost function term: |
174 |
|
|
if doDifObsOrMod==1; |
175 |
gforget |
1.14 |
sladiff_smooth=cost_altimeter_read([dirEcco 'sladiff_smooth'],listRecs); |
176 |
gforget |
1.11 |
elseif doDifObsOrMod==2; |
177 |
gforget |
1.14 |
sladiff_smooth=cost_altimeter_read([dirEcco 'slaobs_smooth'],listRecs); |
178 |
gforget |
1.11 |
else; |
179 |
gforget |
1.14 |
sladiff_smooth=cost_altimeter_read([dirEcco 'sladiff_smooth'],listRecs); |
180 |
|
|
sladiff_smooth=sladiff_smooth+cost_altimeter_read([dirEcco 'slaobs_smooth'],listRecs); |
181 |
gforget |
1.11 |
end; |
182 |
|
|
%mask missing points: |
183 |
|
|
sladiff_smooth(sladiff_smooth==0)=NaN; |
184 |
|
|
sladiff_smooth=sladiff_smooth.*msk_point; |
185 |
|
|
count_tmp=sum(~isnan(sladiff_smooth),3); count_tmp(find(count_tmp<10))=NaN; msk_tmp=1+0*count_tmp; |
186 |
|
|
%compute rms: |
187 |
|
|
rms_sladiff_smooth=msk_tmp.*sqrt(nanmean(sladiff_smooth.^2,3)); |
188 |
|
|
std_sladiff_smooth=msk_tmp.*nanstd(sladiff_smooth,0,3); |
189 |
|
|
%get weight: |
190 |
gforget |
1.12 |
sig_sladiff_smooth=read_bin([dirSigma nameSigma{2}],1,0); |
191 |
gforget |
1.11 |
sig_sladiff_smooth(find(sig_sladiff_smooth==0))=NaN; |
192 |
|
|
%store: |
193 |
|
|
myflds.rms_sladiff_smooth=rms_sladiff_smooth; |
194 |
|
|
myflds.std_sladiff_smooth=std_sladiff_smooth; |
195 |
|
|
myflds.sig_sladiff_smooth=sig_sladiff_smooth; |
196 |
|
|
|
197 |
|
|
toc; tic; |
198 |
|
|
%pointwise/point35days cost function term: |
199 |
|
|
if doDifObsOrMod==1; |
200 |
gforget |
1.14 |
sladiff_point35d=cost_altimeter_read([dirEcco 'sladiff_raw'],listRecs); |
201 |
gforget |
1.11 |
elseif doDifObsOrMod==2; |
202 |
gforget |
1.14 |
sladiff_point35d=cost_altimeter_read([dirEcco 'slaobs_raw'],listRecs); |
203 |
gforget |
1.11 |
else; |
204 |
gforget |
1.14 |
sladiff_point35d=cost_altimeter_read([dirEcco 'sladiff_raw'],listRecs); |
205 |
|
|
sladiff_point35d=sladiff_point35d+cost_altimeter_read([dirEcco 'slaobs_raw'],listRecs); |
206 |
gforget |
1.11 |
end; |
207 |
|
|
%mask missing points: |
208 |
|
|
sladiff_point35d(sladiff_point35d==0)=NaN; |
209 |
|
|
sladiff_point35d=sladiff_point35d.*msk_point; |
210 |
|
|
count_tmp=sum(~isnan(sladiff_point35d),3); count_tmp(find(count_tmp<10))=NaN; msk_tmp=1+0*count_tmp; |
211 |
|
|
%compute rms: |
212 |
|
|
rms_sladiff_point35d=msk_tmp.*sqrt(nanmean(sladiff_point35d.^2,3)); |
213 |
|
|
std_sladiff_point35d=msk_tmp.*nanstd(sladiff_point35d,0,3); |
214 |
|
|
%store: |
215 |
|
|
myflds.rms_sladiff_point35d=rms_sladiff_point35d; |
216 |
|
|
myflds.std_sladiff_point35d=std_sladiff_point35d; |
217 |
|
|
|
218 |
|
|
if 0; |
219 |
|
|
%difference between scales |
220 |
|
|
rms_sladiff_35dMsmooth=msk_tmp.*sqrt(nanmean((sladiff_point35d-sladiff_smooth).^2,3)); |
221 |
|
|
std_sladiff_35dMsmooth=msk_tmp.*nanstd((sladiff_point35d-sladiff_smooth),0,3); |
222 |
|
|
%store: |
223 |
|
|
myflds.rms_sladiff_35dMsmooth=rms_sladiff_35dMsmooth; |
224 |
|
|
myflds.std_sladiff_35dMsmooth=std_sladiff_35dMsmooth; |
225 |
|
|
|
226 |
|
|
%difference between scales |
227 |
|
|
rms_sladiff_pointMpoint35d=msk_tmp.*sqrt(nanmean((sladiff_point-sladiff_point35d).^2,3)); |
228 |
|
|
std_sladiff_pointMpoint35d=msk_tmp.*nanstd((sladiff_point-sladiff_point35d),0,3); |
229 |
|
|
%store: |
230 |
|
|
myflds.rms_sladiff_pointMpoint35d=rms_sladiff_pointMpoint35d; |
231 |
|
|
myflds.std_sladiff_pointMpoint35d=std_sladiff_pointMpoint35d; |
232 |
|
|
end; |
233 |
|
|
|
234 |
|
|
%compute zonal mean/median: |
235 |
|
|
for ii=1:4; |
236 |
|
|
switch ii; |
237 |
|
|
case 1; tmp1='mdt'; cost_fld=(mygrid.mskC(:,:,1).*myflds.dif_mdt./myflds.sig_mdt).^2; |
238 |
|
|
case 2; tmp1='lsc'; cost_fld=(mygrid.mskC(:,:,1).*myflds.rms_sladiff_smooth./myflds.sig_sladiff_smooth).^2; |
239 |
|
|
case 3; tmp1='point35d'; cost_fld=(mygrid.mskC(:,:,1).*myflds.rms_sladiff_point35d./myflds.sig_sladiff_point).^2; |
240 |
|
|
case 4; tmp1='point'; cost_fld=(mygrid.mskC(:,:,1).*myflds.rms_sladiff_point./myflds.sig_sladiff_point).^2; |
241 |
|
|
end; |
242 |
|
|
cost_zmean=calc_zonmean_T(cost_fld); eval(['mycosts_mean.' tmp1 '=cost_zmean;']); |
243 |
|
|
cost_zmedian=calc_zonmedian_T(cost_fld); eval(['mycosts_median.' tmp1 '=cost_zmedian;']); |
244 |
|
|
end; |
245 |
|
|
|
246 |
|
|
toc; %write to disk: |
247 |
|
|
if doSave; eval(['save ' dirMat 'cost/cost_altimeter_' suf '.mat myflds mycosts_mean mycosts_median;']); end; |
248 |
|
|
|
249 |
|
|
end;%if doComp |
250 |
|
|
|
251 |
|
|
if doPlot; |
252 |
|
|
cc=[-0.4:0.05:-0.25 -0.2:0.03:-0.05 -0.03:0.01:0.03 0.05:0.03:0.2 0.25:0.05:0.4]; |
253 |
|
|
figure; m_map_gcmfaces(myflds.dif_mdt,0,{'myCaxis',cc}); drawnow; |
254 |
|
|
cc=[0:0.005:0.02 0.03:0.01:0.05 0.06:0.02:0.1 0.14:0.03:0.2 0.25:0.05:0.4]; |
255 |
|
|
figure; m_map_gcmfaces(myflds.rms_sladiff_smooth,0,{'myCaxis',cc}); drawnow; |
256 |
|
|
figure; m_map_gcmfaces(myflds.rms_sladiff_point35d,0,{'myCaxis',cc}); drawnow; |
257 |
|
|
figure; m_map_gcmfaces(myflds.rms_sladiff_point,0,{'myCaxis',cc}); drawnow; |
258 |
|
|
end; |
259 |
|
|
|
260 |
|
|
if doPlot&doPrint; |
261 |
|
|
dirFig='../figs/altimeter/'; ff0=gcf-4; |
262 |
|
|
for ff=1:4; |
263 |
|
|
figure(ff+ff0); saveas(gcf,[dirFig runName '_' suf num2str(ff)],'fig'); |
264 |
|
|
eval(['print -depsc ' dirFig runName '_' suf num2str(ff) '.eps;']); |
265 |
|
|
eval(['print -djpeg90 ' dirFig runName '_' suf num2str(ff) '.jpg;']); |
266 |
|
|
end; |
267 |
|
|
end; |
268 |
|
|
|
269 |
gforget |
1.4 |
end;%for doDifObsOrMod=1:3; |
270 |
|
|
|
271 |
|
|
|
272 |
|
|
|
273 |
|
|
function [fldOut]=cost_altimeter_read(fileIn,recIn); |
274 |
|
|
|
275 |
|
|
nrec=length(recIn); |
276 |
|
|
global mygrid; siz=[size(convert2gcmfaces(mygrid.XC)) nrec]; |
277 |
|
|
lrec=siz(1)*siz(2)*4; |
278 |
|
|
myprec='float32'; |
279 |
|
|
|
280 |
|
|
fldOut=zeros(siz); |
281 |
|
|
fid=fopen([fileIn '.data'],'r','b'); |
282 |
|
|
for irec=1:nrec; |
283 |
gforget |
1.11 |
status=fseek(fid,(recIn(irec)-1)*lrec,'bof'); |
284 |
|
|
fldOut(:,:,irec)=fread(fid,siz(1:2),myprec); |
285 |
gforget |
1.4 |
end; |
286 |
|
|
|
287 |
|
|
fldOut=convert2gcmfaces(fldOut); |
288 |
|
|
|
289 |
|
|
|
290 |
|
|
|