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.4 |
doComp=1; |
9 |
|
|
if doComp==1; |
10 |
gforget |
1.11 |
doSave=1; |
11 |
|
|
doPlot=0; |
12 |
gforget |
1.4 |
else; |
13 |
gforget |
1.11 |
doSave=0; |
14 |
|
|
doPlot=1; |
15 |
gforget |
1.4 |
end; |
16 |
|
|
doPrint=0; |
17 |
|
|
|
18 |
|
|
for doDifObsOrMod=1:3; |
19 |
gforget |
1.11 |
|
20 |
|
|
if doDifObsOrMod==1; suf='modMobs'; elseif doDifObsOrMod==2; suf='obs'; else; suf='mod'; end; |
21 |
|
|
|
22 |
|
|
%%%%%%%%%%% |
23 |
|
|
%load grid: |
24 |
|
|
%%%%%%%%%%% |
25 |
|
|
|
26 |
|
|
gcmfaces_global; |
27 |
|
|
if ~isfield(mygrid,'XC'); grid_load('./GRID/',5,'compact'); end; |
28 |
|
|
if ~isfield(mygrid,'LATS_MASKS'); gcmfaces_lines_zonal; end; |
29 |
|
|
|
30 |
|
|
%%%%%%%%%%%%%%% |
31 |
|
|
%define pathes: |
32 |
|
|
%%%%%%%%%%%%%%% |
33 |
|
|
|
34 |
|
|
dirSigma='/net/nares/raid11/ecco-shared/ecco-version-4/input/input_err/'; |
35 |
|
|
%nameSigma={'sigma_MDT_glob_eccollc.bin','sigma_SLA_smooth_eccollc.bin','sigma_SLA_PWS07r2_glob_eccollc.bin'}; maxLatObs=66 |
36 |
|
|
nameSigma={'sigma_MDT_glob_eccollc.bin','slaerr_largescale_r4.err','slaerr_gridscale_r4.err'}; maxLatObs=90 |
37 |
|
|
|
38 |
|
|
if isempty(dirMat); dirMat=[dirModel 'mat/']; else; dirMat=[dirMat '/']; end; |
39 |
|
|
if isempty(dir(dirMat)); eval(['!mkdir ' dirMat ';']); end; |
40 |
|
|
if ~isdir([dirMat 'cost/']); mkdir([dirMat 'cost/']); end; |
41 |
|
|
runName=pwd; tmp1=strfind(runName,'/'); runName=runName(tmp1(end)+1:end); |
42 |
|
|
|
43 |
|
|
%%%%%%%%%%%%%%%%% |
44 |
|
|
%do computations: |
45 |
|
|
%%%%%%%%%%%%%%%%% |
46 |
|
|
|
47 |
|
|
if doComp==0; |
48 |
|
|
eval(['load ' dirMat 'cost/cost_altimeter_' suf '.mat myflds;']); |
49 |
|
|
else; |
50 |
|
|
|
51 |
|
|
tic; |
52 |
|
|
%mdt cost function term (misfit plot) |
53 |
|
|
dif_mdt=rdmds2gcmfaces([dirModel 'barfiles/mdtdiff_smooth']); |
54 |
gforget |
1.12 |
sig_mdt=read_bin([dirSigma nameSigma{1}],1,0); |
55 |
gforget |
1.11 |
sig_mdt(find(sig_mdt==0))=NaN; |
56 |
|
|
%store: |
57 |
|
|
myflds.dif_mdt=dif_mdt; |
58 |
|
|
myflds.sig_mdt=sig_mdt; |
59 |
|
|
|
60 |
|
|
%skip blanks: |
61 |
|
|
tmp1=dir([dirModel 'barfiles/sladiff_smooth*data']); |
62 |
|
|
nrec=tmp1.bytes/90/1170/4; |
63 |
|
|
ttShift=17; |
64 |
|
|
%skip 1992 |
65 |
|
|
listRecs=[1+365-ttShift:17+365*18-ttShift]; |
66 |
|
|
nRecs=length(listRecs); TT=1993+[0:nRecs-1]/365.25; |
67 |
|
|
|
68 |
|
|
toc; tic; |
69 |
|
|
%pointwise/1day terms: |
70 |
|
|
sladiff_point=repmat(0*mygrid.RAC,[1 1 nRecs]); count_point=sladiff_point; |
71 |
|
|
for ii=1:3; |
72 |
|
|
if ii==1; myset='tp'; elseif ii==2; myset='gfo'; else; myset='ers'; end; |
73 |
|
|
%topex pointwise misfits: |
74 |
|
|
if doDifObsOrMod==1; |
75 |
|
|
sladiff_tmp=cost_altimeter_read([dirModel 'barfiles/sladiff_' myset '_raw'],ttShift+listRecs); |
76 |
|
|
elseif doDifObsOrMod==2; |
77 |
|
|
sladiff_tmp=cost_altimeter_read([dirModel 'barfiles/slaobs_' myset '_raw'],ttShift+listRecs); |
78 |
|
|
else; |
79 |
|
|
sladiff_tmp=cost_altimeter_read([dirModel 'barfiles/sladiff_' myset '_raw'],ttShift+listRecs); |
80 |
|
|
sladiff_tmp=sladiff_tmp+cost_altimeter_read([dirModel 'barfiles/slaobs_' myset '_raw'],ttShift+listRecs); |
81 |
|
|
end; |
82 |
|
|
%add to overall data set: |
83 |
|
|
sladiff_point=sladiff_point+sladiff_tmp; count_point=count_point+(sladiff_tmp~=0); |
84 |
|
|
%finalize data set: |
85 |
|
|
sladiff_tmp(sladiff_tmp==0)=NaN; |
86 |
|
|
%compute rms: |
87 |
|
|
count_tmp=sum(~isnan(sladiff_tmp),3); count_tmp(find(count_tmp<10))=NaN; msk_tmp=1+0*count_tmp; |
88 |
|
|
eval(['myflds.rms_' myset '=sqrt(nansum(sladiff_tmp.^2,3)./count_tmp);']); |
89 |
|
|
eval(['myflds.std_' myset '=nanstd(sladiff_tmp,0,3).*msk_tmp;']); |
90 |
|
|
end; |
91 |
|
|
%finalize overall data set: |
92 |
|
|
count_point(count_point==0)=NaN; |
93 |
|
|
sladiff_point=sladiff_point./count_point; |
94 |
|
|
%compute overall rms,std: |
95 |
|
|
count_tmp=sum(~isnan(sladiff_point),3); count_tmp(find(count_tmp<10))=NaN; msk_tmp=1+0*count_tmp; |
96 |
|
|
myflds.rms_sladiff_point=sqrt(nansum(sladiff_point.^2,3)./count_tmp); |
97 |
|
|
myflds.std_sladiff_point=nanstd(sladiff_point,0,3).*msk_tmp; |
98 |
|
|
% |
99 |
|
|
msk_point=1*(count_point>0); |
100 |
|
|
%fill blanks: |
101 |
|
|
warning('off','MATLAB:divideByZero'); |
102 |
|
|
msk=mygrid.mskC(:,:,1); msk(find(abs(mygrid.YC)>maxLatObs))=NaN; |
103 |
|
|
myflds.xtrp_rms_sladiff_point=diffsmooth2D_extrap_inv(myflds.rms_sladiff_point,msk); |
104 |
|
|
myflds.xtrp_std_sladiff_point=diffsmooth2D_extrap_inv(myflds.std_sladiff_point,msk); |
105 |
|
|
warning('on','MATLAB:divideByZero'); |
106 |
|
|
%get weight: |
107 |
gforget |
1.12 |
sig_sladiff_point=read_bin([dirSigma nameSigma{3}],1,0); |
108 |
gforget |
1.11 |
sig_sladiff_point(find(sig_sladiff_point==0))=NaN; |
109 |
|
|
myflds.sig_sladiff_point=sig_sladiff_point; |
110 |
|
|
|
111 |
|
|
%computational mask : only points that were actually observed, and in 35d average |
112 |
|
|
msk_point35d=cost_altimeter_read([dirModel 'barfiles/sladiff_raw'],listRecs); |
113 |
|
|
msk_point35d=1*(msk_point35d~=0); |
114 |
|
|
tmp1=sum(msk_point35d==0&msk_point~=0); |
115 |
|
|
tmp2=sum(msk_point35d~=0&msk_point~=0); |
116 |
|
|
fprintf('after masking : %d omitted, %d retained \n',tmp1,tmp2); |
117 |
|
|
msk_point=msk_point.*msk_point35d; |
118 |
|
|
msk_point(msk_point==0)=NaN; |
119 |
|
|
%plotting mask : regions of less than 100 observations are omitted |
120 |
|
|
msk_100pts=1*(nansum(msk_point,3)>=100); |
121 |
|
|
msk_100pts(msk_100pts==0)=NaN; |
122 |
|
|
%store |
123 |
|
|
myflds.msk_100pts=msk_100pts; |
124 |
|
|
|
125 |
|
|
toc; tic; |
126 |
|
|
%lsc cost function term: |
127 |
|
|
if doDifObsOrMod==1; |
128 |
|
|
sladiff_smooth=cost_altimeter_read([dirModel 'barfiles/sladiff_smooth'],listRecs); |
129 |
|
|
elseif doDifObsOrMod==2; |
130 |
|
|
sladiff_smooth=cost_altimeter_read([dirModel 'barfiles/slaobs_smooth'],listRecs); |
131 |
|
|
else; |
132 |
|
|
sladiff_smooth=cost_altimeter_read([dirModel 'barfiles/sladiff_smooth'],listRecs); |
133 |
|
|
sladiff_smooth=sladiff_smooth+cost_altimeter_read([dirModel 'barfiles/slaobs_smooth'],listRecs); |
134 |
|
|
end; |
135 |
|
|
%mask missing points: |
136 |
|
|
sladiff_smooth(sladiff_smooth==0)=NaN; |
137 |
|
|
sladiff_smooth=sladiff_smooth.*msk_point; |
138 |
|
|
count_tmp=sum(~isnan(sladiff_smooth),3); count_tmp(find(count_tmp<10))=NaN; msk_tmp=1+0*count_tmp; |
139 |
|
|
%compute rms: |
140 |
|
|
rms_sladiff_smooth=msk_tmp.*sqrt(nanmean(sladiff_smooth.^2,3)); |
141 |
|
|
std_sladiff_smooth=msk_tmp.*nanstd(sladiff_smooth,0,3); |
142 |
|
|
%get weight: |
143 |
gforget |
1.12 |
sig_sladiff_smooth=read_bin([dirSigma nameSigma{2}],1,0); |
144 |
gforget |
1.11 |
sig_sladiff_smooth(find(sig_sladiff_smooth==0))=NaN; |
145 |
|
|
%store: |
146 |
|
|
myflds.rms_sladiff_smooth=rms_sladiff_smooth; |
147 |
|
|
myflds.std_sladiff_smooth=std_sladiff_smooth; |
148 |
|
|
myflds.sig_sladiff_smooth=sig_sladiff_smooth; |
149 |
|
|
|
150 |
|
|
toc; tic; |
151 |
|
|
%pointwise/point35days cost function term: |
152 |
|
|
if doDifObsOrMod==1; |
153 |
|
|
sladiff_point35d=cost_altimeter_read([dirModel 'barfiles/sladiff_raw'],listRecs); |
154 |
|
|
elseif doDifObsOrMod==2; |
155 |
|
|
sladiff_point35d=cost_altimeter_read([dirModel 'barfiles/slaobs_raw'],listRecs); |
156 |
|
|
else; |
157 |
|
|
sladiff_point35d=cost_altimeter_read([dirModel 'barfiles/sladiff_raw'],listRecs); |
158 |
|
|
sladiff_point35d=sladiff_point35d+cost_altimeter_read([dirModel 'barfiles/slaobs_raw'],listRecs); |
159 |
|
|
end; |
160 |
|
|
%mask missing points: |
161 |
|
|
sladiff_point35d(sladiff_point35d==0)=NaN; |
162 |
|
|
sladiff_point35d=sladiff_point35d.*msk_point; |
163 |
|
|
count_tmp=sum(~isnan(sladiff_point35d),3); count_tmp(find(count_tmp<10))=NaN; msk_tmp=1+0*count_tmp; |
164 |
|
|
%compute rms: |
165 |
|
|
rms_sladiff_point35d=msk_tmp.*sqrt(nanmean(sladiff_point35d.^2,3)); |
166 |
|
|
std_sladiff_point35d=msk_tmp.*nanstd(sladiff_point35d,0,3); |
167 |
|
|
%store: |
168 |
|
|
myflds.rms_sladiff_point35d=rms_sladiff_point35d; |
169 |
|
|
myflds.std_sladiff_point35d=std_sladiff_point35d; |
170 |
|
|
|
171 |
|
|
if 0; |
172 |
|
|
%difference between scales |
173 |
|
|
rms_sladiff_35dMsmooth=msk_tmp.*sqrt(nanmean((sladiff_point35d-sladiff_smooth).^2,3)); |
174 |
|
|
std_sladiff_35dMsmooth=msk_tmp.*nanstd((sladiff_point35d-sladiff_smooth),0,3); |
175 |
|
|
%store: |
176 |
|
|
myflds.rms_sladiff_35dMsmooth=rms_sladiff_35dMsmooth; |
177 |
|
|
myflds.std_sladiff_35dMsmooth=std_sladiff_35dMsmooth; |
178 |
|
|
|
179 |
|
|
%difference between scales |
180 |
|
|
rms_sladiff_pointMpoint35d=msk_tmp.*sqrt(nanmean((sladiff_point-sladiff_point35d).^2,3)); |
181 |
|
|
std_sladiff_pointMpoint35d=msk_tmp.*nanstd((sladiff_point-sladiff_point35d),0,3); |
182 |
|
|
%store: |
183 |
|
|
myflds.rms_sladiff_pointMpoint35d=rms_sladiff_pointMpoint35d; |
184 |
|
|
myflds.std_sladiff_pointMpoint35d=std_sladiff_pointMpoint35d; |
185 |
|
|
end; |
186 |
|
|
|
187 |
|
|
%compute zonal mean/median: |
188 |
|
|
for ii=1:4; |
189 |
|
|
switch ii; |
190 |
|
|
case 1; tmp1='mdt'; cost_fld=(mygrid.mskC(:,:,1).*myflds.dif_mdt./myflds.sig_mdt).^2; |
191 |
|
|
case 2; tmp1='lsc'; cost_fld=(mygrid.mskC(:,:,1).*myflds.rms_sladiff_smooth./myflds.sig_sladiff_smooth).^2; |
192 |
|
|
case 3; tmp1='point35d'; cost_fld=(mygrid.mskC(:,:,1).*myflds.rms_sladiff_point35d./myflds.sig_sladiff_point).^2; |
193 |
|
|
case 4; tmp1='point'; cost_fld=(mygrid.mskC(:,:,1).*myflds.rms_sladiff_point./myflds.sig_sladiff_point).^2; |
194 |
|
|
end; |
195 |
|
|
cost_zmean=calc_zonmean_T(cost_fld); eval(['mycosts_mean.' tmp1 '=cost_zmean;']); |
196 |
|
|
cost_zmedian=calc_zonmedian_T(cost_fld); eval(['mycosts_median.' tmp1 '=cost_zmedian;']); |
197 |
|
|
end; |
198 |
|
|
|
199 |
|
|
toc; %write to disk: |
200 |
|
|
if doSave; eval(['save ' dirMat 'cost/cost_altimeter_' suf '.mat myflds mycosts_mean mycosts_median;']); end; |
201 |
|
|
|
202 |
|
|
end;%if doComp |
203 |
|
|
|
204 |
|
|
if doPlot; |
205 |
|
|
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]; |
206 |
|
|
figure; m_map_gcmfaces(myflds.dif_mdt,0,{'myCaxis',cc}); drawnow; |
207 |
|
|
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]; |
208 |
|
|
figure; m_map_gcmfaces(myflds.rms_sladiff_smooth,0,{'myCaxis',cc}); drawnow; |
209 |
|
|
figure; m_map_gcmfaces(myflds.rms_sladiff_point35d,0,{'myCaxis',cc}); drawnow; |
210 |
|
|
figure; m_map_gcmfaces(myflds.rms_sladiff_point,0,{'myCaxis',cc}); drawnow; |
211 |
|
|
end; |
212 |
|
|
|
213 |
|
|
if doPlot&doPrint; |
214 |
|
|
dirFig='../figs/altimeter/'; ff0=gcf-4; |
215 |
|
|
for ff=1:4; |
216 |
|
|
figure(ff+ff0); saveas(gcf,[dirFig runName '_' suf num2str(ff)],'fig'); |
217 |
|
|
eval(['print -depsc ' dirFig runName '_' suf num2str(ff) '.eps;']); |
218 |
|
|
eval(['print -djpeg90 ' dirFig runName '_' suf num2str(ff) '.jpg;']); |
219 |
|
|
end; |
220 |
|
|
end; |
221 |
|
|
|
222 |
gforget |
1.4 |
end;%for doDifObsOrMod=1:3; |
223 |
|
|
|
224 |
|
|
|
225 |
|
|
|
226 |
|
|
function [fldOut]=cost_altimeter_read(fileIn,recIn); |
227 |
|
|
|
228 |
|
|
nrec=length(recIn); |
229 |
|
|
global mygrid; siz=[size(convert2gcmfaces(mygrid.XC)) nrec]; |
230 |
|
|
lrec=siz(1)*siz(2)*4; |
231 |
|
|
myprec='float32'; |
232 |
|
|
|
233 |
|
|
fldOut=zeros(siz); |
234 |
|
|
fid=fopen([fileIn '.data'],'r','b'); |
235 |
|
|
for irec=1:nrec; |
236 |
gforget |
1.11 |
status=fseek(fid,(recIn(irec)-1)*lrec,'bof'); |
237 |
|
|
fldOut(:,:,irec)=fread(fid,siz(1:2),myprec); |
238 |
gforget |
1.4 |
end; |
239 |
|
|
|
240 |
|
|
fldOut=convert2gcmfaces(fldOut); |
241 |
|
|
|
242 |
|
|
|
243 |
|
|
|