-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha04_merge_gcdc_collections.m
89 lines (63 loc) · 2.34 KB
/
a04_merge_gcdc_collections.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
clear
clc
close all
%%% this script does one thing:
%
%%% (1) brings together sway frequency time series from multiple collection
%%% dates and merges into a single .mat file for each sensor/site
%% subset settings
%%% specify which sites you want to process (order defined in
%%% a00_data_file_settings.m
%%% can be single value or an array of numbers. count starts at 1.
sway_sites = [1 2]; % [1 2 3 4 5 6 7]
%%% specify starting date and ending date for combined time series
sd_i = datenum(2014,10,1); % yyyy,mm,dd
sd_f = datenum(2020,08,06); % yyyy,mm,dd
% time step of time series (seconds)
dt = 3600;
%% load data and file settings
a00_data_file_settings;
%%% sub-select to only the sensors selected in sway_sites (above)
tree_names = tree_names(sway_sites);
%% ********** MAIN CODE **********
%%% gcdc fields
Gfields = {'Rstd', 'Dpts', 'fmax', 'fmax_pxx', 'f_pth', 'Amin', 'Amax', 'Amed', 'Aavg', 'Astd', 'Rmin', 'Rmax', 'Rmed', 'Ravg'};
ngf = numel(Gfields);
%%
dt = (dt/3600); % convert time step to hours
nTrees = numel(tree_names);
for j=1:nTrees
%%% name of current sensor/tree
xT = char(tree_names(j));
%%% remove any previous version of the _all mat file
allSwayFile = [path_out_freq 'GCDC_L02_Tree_Sway_' xT '_all.mat'];
if exist(allSwayFile, 'file')==2
delete(allSwayFile);
end
%%% find all .mat frequency analysis files for this sensor/tree.
%%% specify as level 2 so we ignore level 1 (meta data) files, in case
%%% stored in the same directory
DD=dir([path_out_freq 'GCDC_L02*' char(xT) '*.mat']);
%%% count the files
nfiles = size(DD,1);
%%% cycle through the files, load, and combine
for k=1:nfiles
ifile = DD(k).name;
disp(ifile)
%%% load GCDC data
load([path_out_freq ifile])
%%% initialize SWAY structure and variables during first loop
if k==1
SWAY.TIME = time_builder(sd_i, sd_f, dt);
nt = size(SWAY.TIME,1);
for qq=1:ngf
eval(['SWAY.' char(Gfields(qq)) '=nan(nt,3);'])
end
end
%%% grid data
SWAY = data_grid(SWAY, GCDC, 1, 1, 0);
end
%%% save and clean up
save(allSwayFile, 'SWAY')
clear SWAY
end