forked from athurnherr/LDEO_IX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getshear2.m
183 lines (151 loc) · 4.08 KB
/
getshear2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
function [ds,dr,ps,p]=getshear(d,p,ps,dr)
%
% - compute shear profiles
% - use only central difference
% - use 2*std editing
%
% Martin Visbeck, LDEO, 3/7/97
% resolution of final shear profile in meter
idz=ps.dz;
disp(['GETSHEAR2: average shear profile over (ps.dz) ',num2str(idz),' [m]'])
% average over how much percent of the data
ps=setdefv(ps,'shear_stdf',2);
stdf=ps.shear_stdf;
disp([' maximum std (stdf) ',num2str(stdf),' of data '])
if nargin<4, dr.dummy=0; end
% check if only one istrument is to be used
if ps.up_dn_looker==2
% down looker only
d.weight(d.izu,:)=nan;
elseif ps.up_dn_looker==3
% up looker only
d.weight(d.izd,:)=nan;
end
% weightmin
ps=setdefv(ps,'shear_weightmin',0.1);
disp([' minimum weight ',num2str(ps.shear_weightmin),' of data '])
is1=sum(sum(isfinite(d.weight)));
w=double(d.weight>ps.shear_weightmin);
ii=find(w==0);
w(ii)=NaN;
is2=sum(sum(isfinite(w)));
disp([' will use ',int2str(is2/is1*100),' % of data '])
% compute central shear
% disp([' compute central diff shear '])
iiok=1:length(d.z);
us=[NaN*d.ru(1,iiok);diff2(d.ru(:,iiok))./diff2(d.izm);NaN*d.ru(1,iiok)].*w;
vs=[NaN*d.rv(1,iiok);diff2(d.rv(:,iiok))./diff2(d.izm);NaN*d.rv(1,iiok)].*w;
ws=[NaN*d.rw(1,iiok);diff2(d.rw(:,iiok))./diff2(d.izm);NaN*d.rw(1,iiok)].*w;
% loop over final depth profile
if existf(dr,'z')==1
z=dr.z;
else
izmax=-min(d.z);
izmax=-maxnan(-[izmax,p.zbottom]);
z=idz*0.5:idz:izmax;
end
ds.usm=zeros(length(z),1)*NaN;
ds.vsm=ds.usm;
ds.wsm=ds.usm;
ds.use=ds.usm;
ds.vse=ds.usm;
ds.wse=ds.usm;
ds.nn=ds.usm;
ds.z=ds.usm;
il=length(z);
iv=0;
%disp([' average shear estimates '])
for in=1:il
i=z(in);
iv =iv+1;
% up and down
i2=find(abs(-d.izm-i-idz/2) <= idz);
i1=i2(find(isfinite(us(i2)+vs(i2))));
ds.nn(iv)=length(i1);
if ds.nn(iv) > 2
usmm=median(us(i1)');
ussd1=std(us(i1));
ii=i1(find(abs(us(i1)-usmm)<stdf*ussd1));
if length(ii)>1
ds.usm(iv)=mean(us(ii));
ds.use(iv)=std(us(ii));
end
vsmm=median(vs(i1)');
vssd1=std(vs(i1));
ii=i1(find(abs(vs(i1)-vsmm)<stdf*vssd1));
if length(ii)>1
ds.vsm(iv)=mean(vs(ii));
ds.vse(iv)=std(vs(ii));
end
wsmm=median(ws(i1)');
wssd1=std(ws(i1));
ii=i1(find(abs(ws(i1)-wsmm)<stdf*wssd1));
if length(ii)>1
ds.wsm(iv)=mean(ws(ii));
ds.wse(iv)=std(ws(ii));
end
% if exist('test')==1
% hist(vs(ii),[-1:0.05:1]*.2e-1)
% title(['z = ',num2str(z(iv))])
% pause(0.01)
% end
end
% save depth vector
ds.z(iv)=i;
% end of shear loop
end
% integrate shear profile (from bottom up)
ii=find(isnan(ds.usm));
ds.usm(ii)=0;
ii=find(isnan(ds.vsm));
ds.vsm(ii)=0;
ii=find(isnan(ds.wsm));
ds.wsm(ii)=0;
ds.ur=flipud(cumsum(flipud(ds.usm)))*idz;
ds.vr=flipud(cumsum(flipud(ds.vsm)))*idz;
ds.wr=flipud(cumsum(flipud(ds.wsm)))*idz;
ds.ur=ds.ur-mean(ds.ur);
ds.vr=ds.vr-mean(ds.vr);
ds.wr=ds.wr-mean(ds.wr);
if existf(d,'down')==1
dz=2*abs(mean(diff(d.zd)));
fac=1/tan(d.down.Beam_angle*pi/180)*sqrt(2)*dz;
ds.ensemble_vel_err=ds.wse*fac;
dr.ensemble_vel_err=ds.wse*fac;
end
if nargin>3
dr.u_shear_method=ds.ur;
dr.v_shear_method=ds.vr;
dr.w_shear_method=ds.wr;
uds=stdnan(dr.u-mean(dr.u)-ds.ur);
vds=stdnan(dr.v-mean(dr.v)-ds.vr);
uvds=sqrt(uds.^2+vds.^2);
if uvds>meannan(dr.uerr)
warn=(' increased error because of shear - inverse difference');
disp(warn)
if uvds>1.5*meannan(dr.uerr) & uvds>0.1
p.warn(size(p.warn,1)+1,1:length(warn))=warn;
end
dr.uerr=dr.uerr/meannan(dr.uerr)*uvds/1.5;
end
end
%--------------------------------------------------
function x = diff2(x,k,dn)
%DIFF2 Difference function. If X is a vector [x(1) x(2) ... x(n)],
% then DIFF(X) returns a vector of central differences between
% elements [x(3)-x(1) x(4)-x(2) ... x(n)-x(n-2)]. If X is a
% matrix, the differences are calculated down each column:
% DIFF(X) = X(3:n,:) - X(1:n-2,:).
% DIFF(X,n) is the n'th difference function.
% J.N. Little 8-30-85
% Copyright (c) 1985, 1986 by the MathWorks, Inc.
if nargin < 2, k = 1; end
if nargin < 3, dn = 2; end
for i=1:k
[m,n] = size(x);
if m == 1
x = x(1+dn:n) - x(1:n-dn);
else
x = x(1+dn:m,:) - x(1:m-dn,:);
end
end