| 1 |
gforget |
1.1 |
function [myFld,myFld1]=profiles_subgrid_stats_assemble(choiceVar,lev,choiceDir,choiceFld); |
| 2 |
|
|
%... one level at a time |
| 3 |
|
|
|
| 4 |
|
|
doSave=1 |
| 5 |
|
|
choiceGrid='v4'; |
| 6 |
|
|
%choiceDir=2; |
| 7 |
|
|
%choiceFld=2; |
| 8 |
|
|
|
| 9 |
|
|
%========= PART 1 : load grid & atlases ======== |
| 10 |
|
|
|
| 11 |
|
|
gcmfaces_global; |
| 12 |
|
|
|
| 13 |
|
|
%listSGN=[0 8 4 2 1];%for cs24 |
| 14 |
|
|
if strcmp(choiceGrid,'cs96'); |
| 15 |
|
|
%full suite for cs96 |
| 16 |
|
|
listSGN=[0 48 32 24 16 12 8 6 4 3 2 1]; |
| 17 |
|
|
dirGrid='/net/weddell/raid3/gforget/grids/gridCompleted/cube_FM/'; |
| 18 |
|
|
%dirGrid='/Users/gforget/mywork/projects_inprogress/2012mayInputs/insitu/processed/'; |
| 19 |
|
|
grid_load_native([dirGrid 'cube_96/'],6); |
| 20 |
|
|
else; |
| 21 |
|
|
;%for ecco v4 |
| 22 |
|
|
listSGN=[0 45 30 18 15 10 9 6 5 3 2 1] |
| 23 |
|
|
dirGrid='/net/nares/raid10/gforget/2012julyIters/GRID/'; |
| 24 |
|
|
%dirGrid='/net/weddell/raid3/gforget/ecco_v4/GRID/'; |
| 25 |
|
|
%dirGrid='GRID/'; |
| 26 |
|
|
%grid_load(dirGrid,5,'compact'); |
| 27 |
|
|
end; |
| 28 |
|
|
|
| 29 |
|
|
global atlasT atlasS; |
| 30 |
|
|
if isempty(atlasT); |
| 31 |
|
|
dirAtlas='/net/weddell/raid3/gforget/ecco_v4/input_files/'; |
| 32 |
|
|
%dirAtlas='/Users/gforget/mywork/projects_inprogress/2012mayInputs/atlas/bin/'; |
| 33 |
|
|
%atlasT=v4_read_bin([dirAtlas 'T_OWPv1_Y_eccollc_90x50.bin']); |
| 34 |
|
|
%atlasS=v4_read_bin([dirAtlas 'S_OWPv1_Y_eccollc_90x50.bin']); |
| 35 |
|
|
end; |
| 36 |
|
|
|
| 37 |
|
|
%========= PART 2 : load and average estimates of std ======== |
| 38 |
|
|
|
| 39 |
|
|
if choiceDir==1; |
| 40 |
|
|
dirOut='/net/nares/raid10/gforget/2012julyIters/ecco_it0003/mode_water_analyses/profiles_subgrid_stats/' |
| 41 |
|
|
elseif choiceDir==2; |
| 42 |
|
|
dirOut='/net/nares/raid10/gforget/2012julyIters/ecco_it0003/mode_water_analyses/profiles_subgrid_r3it3/' |
| 43 |
|
|
elseif choiceDir==3; |
| 44 |
|
|
dirOut='/net/nares/raid10/gforget/2012julyIters/ecco_it0003/mode_water_analyses/profiles_subgrid_argo/' |
| 45 |
|
|
end; |
| 46 |
|
|
|
| 47 |
|
|
%dirOut='~/mywork/projects_inprogress/2012mayInputs/insitu/tmp/'; |
| 48 |
|
|
|
| 49 |
|
|
%if result was not completed, then skip: |
| 50 |
|
|
test0=dir([dirOut choiceGrid '_' choiceVar '_k' num2str(lev) '_' num2str(1) '.mat']); |
| 51 |
|
|
if isempty(test0); myFld=NaN*mygrid.RAC; myFld1=myFld; return; end; |
| 52 |
|
|
|
| 53 |
|
|
|
| 54 |
|
|
myWeightPower=4 |
| 55 |
|
|
|
| 56 |
|
|
for sgn=listSGN; |
| 57 |
|
|
eval(['load ' dirOut choiceGrid '_' choiceVar '_k' num2str(lev) '_' num2str(sgn) '.mat myStat;']); |
| 58 |
|
|
%"bootstrap" |
| 59 |
|
|
kk=find(listSGN==sgn); |
| 60 |
|
|
if kk==1; |
| 61 |
|
|
myFld=myStat; |
| 62 |
|
|
w=myStat.nb/(sqrt(90*1170)^myWeightPower); |
| 63 |
|
|
myFld.nb=w; |
| 64 |
|
|
myFld.mea=myStat.mea.*w; |
| 65 |
|
|
myFld.prc10=myStat.prc10.*w; |
| 66 |
|
|
myFld.med=myStat.med.*w; |
| 67 |
|
|
myFld.prc90=myStat.prc90.*w; |
| 68 |
|
|
else; |
| 69 |
|
|
w=myStat.nb/(sgn^myWeightPower); |
| 70 |
|
|
if 0; |
| 71 |
|
|
figureL; |
| 72 |
|
|
subplot(2,1,1); qwckplot(w); colorbar; |
| 73 |
|
|
subplot(2,1,2); qwckplot(myFld.nb); colorbar; |
| 74 |
|
|
end; |
| 75 |
|
|
myFld.nb=myFld.nb+w; |
| 76 |
|
|
myFld.mea=myFld.mea+myStat.mea.*w; |
| 77 |
|
|
myFld.prc10=myFld.prc10+myStat.prc10.*w; |
| 78 |
|
|
myFld.med=myFld.med+myStat.med.*w; |
| 79 |
|
|
myFld.prc90=myFld.prc90+myStat.prc90.*w; |
| 80 |
|
|
end; |
| 81 |
|
|
end; |
| 82 |
|
|
|
| 83 |
|
|
%THIS WAS A BUG : myFld.nb=myFld.nb+w; |
| 84 |
|
|
myFld.mea=(myFld.mea./myFld.nb); |
| 85 |
|
|
myFld.prc10=(myFld.prc10./myFld.nb); |
| 86 |
|
|
myFld.med=(myFld.med./myFld.nb); |
| 87 |
|
|
myFld.prc90=(myFld.prc90./myFld.nb); |
| 88 |
|
|
myFld.msk=mygrid.mskC(:,:,lev); |
| 89 |
|
|
|
| 90 |
|
|
%original value & "local" value forcing: |
| 91 |
|
|
if choiceFld==1; |
| 92 |
|
|
myFld1=myFld.msk.*myFld.prc10; suff='prc10'; |
| 93 |
|
|
elseif choiceFld==2; |
| 94 |
|
|
myFld1=myFld.msk.*myFld.med; suff='med'; |
| 95 |
|
|
elseif choiceFld==3; |
| 96 |
|
|
myFld1=myFld.msk.*myFld.prc90; suff='prc90'; |
| 97 |
|
|
end; |
| 98 |
|
|
|
| 99 |
|
|
%========= PART 3 : smoothing setup ======== |
| 100 |
|
|
|
| 101 |
|
|
if 0;%simple smoothing, which does not account for no. of obs |
| 102 |
|
|
eval(['myFld.mean=myFld.msk.*atlas' choiceVar '(:,:,lev);']); |
| 103 |
|
|
myFld.sm0=diffsmooth2D(myFld1,mygrid.DXC*3,mygrid.DYC*3); |
| 104 |
|
|
dxy=3*sqrt(mygrid.RAC); |
| 105 |
|
|
myFld.sm1=diffsmooth2D(myFld1,dxy,dxy); |
| 106 |
|
|
myFld.sm2=diffsmooth2Drotated(myFld1,dxy,dxy/10,myFld.mean); |
| 107 |
|
|
end; |
| 108 |
|
|
|
| 109 |
|
|
|
| 110 |
|
|
%scale the diffusive operator: |
| 111 |
|
|
dxLarge=3*sqrt(mygrid.RAC); |
| 112 |
|
|
dxSmall=0.1*dxLarge; |
| 113 |
|
|
|
| 114 |
|
|
%time scale: |
| 115 |
|
|
tmp0=dxLarge./mygrid.DXC; tmp0(isnan(myFld1))=NaN; tmp00=nanmax(tmp0); |
| 116 |
|
|
tmp0=dxLarge./mygrid.DYC; tmp0(isnan(myFld1))=NaN; tmp00=max([tmp00 nanmax(tmp0)]); |
| 117 |
|
|
nbt=tmp00; |
| 118 |
|
|
nbt=ceil(1.1*2*nbt^2); |
| 119 |
|
|
|
| 120 |
|
|
dt=1; |
| 121 |
|
|
T=nbt*dt; |
| 122 |
|
|
|
| 123 |
|
|
%build diffusion operator: |
| 124 |
|
|
kLarge=dxLarge.*dxLarge/T/2; |
| 125 |
|
|
kSmall=dxSmall.*dxSmall/T/2; |
| 126 |
|
|
|
| 127 |
|
|
if 1;%isotropic diffusion, rather than slanted diffusion |
| 128 |
|
|
Kux=dxLarge.*dxLarge/T/2; |
| 129 |
|
|
Kvy=dxLarge.*dxLarge/T/2; |
| 130 |
|
|
Kuy=[]; Kvx=[]; |
| 131 |
|
|
else;%slanted diffusion |
| 132 |
|
|
eval(['myFld.mean=myFld.msk.*atlas' choiceVar '(:,:,lev);']); |
| 133 |
|
|
[Kux,Kuy,Kvx,Kvy]=diffrotated(kLarge,kSmall,myFld.mean); |
| 134 |
|
|
end; |
| 135 |
|
|
|
| 136 |
|
|
%finalize diffusion/smoothing problem set-up: |
| 137 |
|
|
myOp.dt=1; |
| 138 |
|
|
% myOp.nbt=nbt; |
| 139 |
|
|
myOp.eps=1e-3; |
| 140 |
|
|
myOp.Kux=Kux; |
| 141 |
|
|
myOp.Kuy=Kuy; |
| 142 |
|
|
myOp.Kvx=Kvx; |
| 143 |
|
|
myOp.Kvy=Kvy; |
| 144 |
|
|
|
| 145 |
|
|
%========= PART 4 : relaxation term setup ======== |
| 146 |
|
|
|
| 147 |
|
|
%1) set relaxation strength: (local <-> smoother) |
| 148 |
|
|
%--------------------------- |
| 149 |
|
|
|
| 150 |
|
|
%use the myFld.nb index, modified as follows |
| 151 |
|
|
w=myFld.nb; |
| 152 |
|
|
%I do a linear transiton in log10 |
| 153 |
|
|
w=log10(w); |
| 154 |
|
|
%by mapping [-2 2] to [2 -1] |
| 155 |
|
|
w=(-1-3*(w-2)/(2+2)); |
| 156 |
|
|
%go back to original units (~nb obs) and scale by nbt (nbt = 1 smoother) |
| 157 |
|
|
w=nbt*exp( w*log(10) ); |
| 158 |
|
|
%ensure stability |
| 159 |
|
|
w(w<1)=1; |
| 160 |
|
|
%enforce minimum forcing |
| 161 |
|
|
w(w>1e3*nbt)=1e3*nbt; |
| 162 |
|
|
if 0; |
| 163 |
|
|
%figureL; m_map_gcmfaces(log10(myFld.nb),0,{'myCaxis',[-4 3]}); |
| 164 |
|
|
figureL; m_map_gcmfaces(log10(w/nbt),0,{'myCaxis',[-2 2]}); return; |
| 165 |
|
|
end; |
| 166 |
|
|
myOp.tau=w*myOp.dt; |
| 167 |
|
|
|
| 168 |
|
|
% myOp.tau=0.5*myOp.dt; |
| 169 |
|
|
% myOp.tau=nbt*myOp.dt; |
| 170 |
|
|
% myOp.tau=nbt; |
| 171 |
|
|
|
| 172 |
|
|
%2) set relaxation field: ("local" value) |
| 173 |
|
|
%------------------------ |
| 174 |
|
|
|
| 175 |
|
|
fldRelax=myFld1; |
| 176 |
|
|
|
| 177 |
|
|
|
| 178 |
|
|
%========= PART 5 : resolve smoothing/relaxation problem ======== |
| 179 |
|
|
% |
| 180 |
|
|
% here we integrate to a balance between |
| 181 |
|
|
% "local" value (relaxation term) |
| 182 |
|
|
% vs smoothing (diffusion) |
| 183 |
|
|
|
| 184 |
|
|
myFld=gcmfaces_timestep(myOp,myFld1,fldRelax); |
| 185 |
|
|
|
| 186 |
|
|
%plot / save result: |
| 187 |
|
|
%=================== |
| 188 |
|
|
|
| 189 |
|
|
if 0; |
| 190 |
|
|
figureL; m_map_gcmfaces(log10(myFld),0,{'myCaxis',[-1.5 0.5]}); |
| 191 |
|
|
end; |
| 192 |
|
|
|
| 193 |
|
|
if doSave; |
| 194 |
|
|
eval(['save ' dirOut choiceGrid '_' choiceVar '_k' num2str(lev) '_' suff '.mat myFld myFld1;']); |
| 195 |
|
|
end; |
| 196 |
|
|
|