-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathl_average.m
118 lines (104 loc) · 3.92 KB
/
l_average.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
function wlog=l_average(wlog,varargin)
% Function computes running average over specified log curves
% The function needs equidistantly sampled data; no null values
% Written by: E. R., June 7, 2001
% Last updated: March 11, 2002. Remove pre-existing averaged curves before recreating them
% Avoids having more than one curve with the same mnemonic.
%
% wlog=l_average(wlog,varargin)
% INPUT
% wlog log structure
% varargin one or more cell arrays; the first element of each cell array is a keyword,
% the following arguments contains a parameter(s). Accepted keywords are
% 'curves' mnemonics of curves to average
% Default: {'curves','*'} meaning all curves
% 'length' length of averaging filter and units of measurement
% Default: {'length',wlog.step,wlog.curve_info{1,2}} no averaging (average over one sample)
% 'mnem' character string to append to mnemonic of original data
% if "mnem" is empty (e.g. {'mnem',''}), then the original curves are replaced
% by the averaged curves
% Default: {'mnem','mean'}, i.e. the string "mean" is appended to the mnemonics
% Example DTp ==> DTp_mean.
% 'weight' type of smoothing; possible values are: 'constant' (weight is
% constant) and 'binom' (binomial weight')
% Default: {'weight','constant')
%
% OUTPUT
% wlog log structure with averaged curves
% Set defaults of input arguments
param.curves='*';
param.length={wlog.step,wlog.curve_info{2,1}};
param.mnem='mean';
param.weight='constant';
% Decode and assign input arguments
param=assign_input(param,varargin);
if ~iscell(param.length)
param.length={param.length,wlog.curve_info{1,2}};
end
if ~iscell(param.curves)
if strcmp(param.curves,'*')
param.curves=wlog.curve_info(2:end,1);
else
param.curves={param.curves};
end
end
if wlog.step == 0
error(' Log must be uniformly sampled')
end
[nsamp,ncurves]=size(wlog.curves);
nnew=length(param.curves);
% Compute averaging distance in samples
dunits1=param.length{2};
dunits2=wlog.curve_info{1,2};
distance=param.length{1}/wlog.step;
if ~strcmp(dunits1,dunits2)
if strcmp(dunits1,'m') & strcmp(dunits2,'ft')
distance=distance/0.3048;
elseif strcmp(dunits1,'ft') & strcmp(dunits2,'m')
distance=distance*0.3048;
elseif strcmp(dunits1,'s') & strcmp(dunits2,'ms')
distance=distance*1000;
elseif strcmp(dunits1,'ms') & strcmp(dunits2,'s')
distance=distance/1000;
else
error([' Keyword "length" and depth curve have incompatible units:', dunits1,', ',dunits2])
end
end
if isempty(param.mnem)
for ii=1:nnew
iloc=curve_index1(wlog,param.curves{ii});
temp=wlog.curves(:,iloc);
idx=find(~isnan(temp));
ia=idx(1);
ie=idx(end);
wlog.curves(ia:ie,iloc)=smooth(temp(ia:ie),distance);
end
else
% Check if curves already exist and delete those that do
temss_curves=param.curves;
for ii=1:length(param.curves)
temss_curves{ii}=[temss_curves{ii},'_',param.mnem];
end
wlog=l_curve(wlog,'delete_ne',temss_curves);
% Reserve space for new curves and curve information
wlog.curves=[wlog.curves,NaN*zeros(nsamp,nnew)];
curve_info=[wlog.curve_info;cell(nnew,3)];
index=ncurves+(1:nnew);
for ii=1:nnew
iloc=curve_index1(wlog,param.curves{ii});
temp=wlog.curves(:,iloc);
idx=find(~isnan(temp));
ia=idx(1);
ie=idx(end);
if strcmpi(param.weight,'constant')
wlog.curves(ia:ie,index(ii))=smooth(temp(ia:ie),distance);
elseif strcmpi(param.weight,'binom')
wlog.curves(ia:ie,index(ii))=binsmooth(temp(ia:ie),distance);
else
error([' Unknown weight of smoothing: ',param.weight])
end
curve_info(index(ii),:)=[{[param.curves{ii},'_',param.mnem]}, ...
wlog.curve_info(iloc,2),{[wlog.curve_info{iloc,3},' (averaged)']}];
end
wlog.curve_info=curve_info;
end