-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdata_mean.m
173 lines (156 loc) · 5.9 KB
/
data_mean.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
%==========================================================================
% Deal with the data
% - hourly
% - daily mean
% - monthly mean
% - seasonal mean
% - annual mean
%
% Input : --- time0, the input time (MATLAB time format)
% --- data0, the input data
% --- out_type, set as 'hourly', 'daily', 'monthly', 'seasonal',
% 'annual'
% --- varargin{1}, tlim
% --- varargin{2}, window length
%
% Output : --- time, the output seasonal time (MATLAB time format or year)
% --- data, the output data
%
% Usage :
%
% v1.0
%
% Siqi Li
% 2021-05-26
%
% Updates:
%
%==========================================================================
function [time, data] = data_mean(time0, data0, out_type, varargin)
% tlim = [];
% window = 15;
%
% if nargin == 4
% tlim = varargin{1};
% end
% if nargin == 5
% tlim = varargin{1};
% window = varargin{2};
% end
varargin = read_varargin(varargin, {'tlim'}, {[]});
varargin = read_varargin(varargin, {'window'}, {15});
% time0 = buoy1(1).time;
% time0 = montht;
% data0 = buoy1(1).wspd;
tvec0 = datevec(time0);
dt = time0(2:end) - time0(1:end-1);
% Judge the input time type
if unique(tvec0(:,3))==1 & unique(tvec0(:,4:6)==0)
in_type = 'monthly';
else
if abs(unique(dt) - 1) < 1e-8
in_type = 'daily';
elseif abs(unique(dt) - 1/24) < 1e-8
in_type = 'hourly';
else
in_type = 'random';
end
end
disp(['In type : ' in_type])
disp(['Out type : ' out_type])
switch in_type
case 'random'
switch out_type
case 'random'
stop(in_type, out_type)
case 'hourly'
[time, data] = data_random2hourly(time0, data0, tlim, window);
case 'daily'
[time1, data1] = data_random2hourly(time0, data0, tlim, window);
[time, data] = data_hourly2daily(time1, data1, tlim);
case 'monthly'
[time1, data1] = data_random2hourly(time0, data0, tlim, window);
[time2, data2] = data_hourly2daily(time1, data1, tlim);
[time, data] = data_daily2monthly(time2, data2, tlim);
case 'seasonal'
[time1, data1] = data_random2hourly(time0, data0, tlim, window);
[time2, data2] = data_hourly2daily(time1, data1, tlim);
[time3, data3] = data_daily2monthly(time2, data2, tlim);
[time, data] = data_monthly2seasonal(time3, data3, tlim);
case 'annual'
[time1, data1] = data_random2hourly(time0, data0, tlim, window);
[time2, data2] = data_hourly2daily(time1, data1, tlim);
[time3, data3] = data_daily2monthly(time2, data2, tlim);
[time, data] = data_monthly2annual(time3, data3, tlim);
otherwise
stop(in_type, out_type)
end
case 'hourly'
switch out_type
case 'random'
stop(in_type, out_type)
case 'hourly'
[time, data] = data_random2hourly(time0, data0, tlim, window);
case 'daily'
[time1, data1] = data_random2hourly(time0, data0, tlim, window);
[time, data] = data_hourly2daily(time1, data1, tlim);
case 'monthly'
[time1, data1] = data_random2hourly(time0, data0, tlim, window);
[time2, data2] = data_hourly2daily(time1, data1, tlim);
[time, data] = data_daily2monthly(time2, data2, tlim);
case 'seasonal'
[time1, data1] = data_random2hourly(time0, data0, tlim, window);
[time2, data2] = data_hourly2daily(time1, data1, tlim);
[time3, data3] = data_daily2monthly(time2, data2, tlim);
[time, data] = data_monthly2seasonal(time3, data3, tlim);
case 'annual'
[time1, data1] = data_random2hourly(time0, data0, tlim, window);
[time2, data2] = data_hourly2daily(time1, data1, tlim);
[time3, data3] = data_daily2monthly(time2, data2, tlim);
[time, data] = data_monthly2annual(time3, data3, tlim);
otherwise
stop(in_type, out_type)
end
case 'daily'
switch out_type
case 'random'
stop(in_type, out_type)
case 'hourly'
stop(in_type, out_type)
case 'daily'
stop(in_type, out_type)
case 'monthly'
[time, data] = data_daily2monthly(time0, data0, tlim);
case 'seasonal'
[time1, data1] = data_daily2monthly(time0, data0, tlim);
[time, data] = data_monthly2seasonal(time1, data1, tlim);
case 'annual'
[time1, data1] = data_daily2monthly(time0, data0, tlim);
[time, data] = data_monthly2annual(time1, data1, tlim);
otherwise
stop(in_type, out_type)
end
case 'monthly'
switch out_type
case 'random'
stop(in_type, out_type)
case 'hourly'
stop(in_type, out_type)
case 'daily'
stop(in_type, out_type)
case 'monthly'
stop(in_type, out_type)
case 'seasonal'
[time, data] = data_monthly2seasonal(time0, data0, tlim);
case 'annual'
[time, data] = data_monthly2annual(time0, data0, tlim);
otherwise
stop(in_type, out_type)
end
end
end
function stop(in_type, out_type)
% disp(['In type : ' in_type])
% disp(['Out type : ' out_type])
error('Wrong out_type')
end