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