-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_plotCBV.m
More file actions
198 lines (164 loc) · 7.17 KB
/
example_plotCBV.m
File metadata and controls
198 lines (164 loc) · 7.17 KB
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
% this is an aggregate script to run figure analysis at three different levels:
% 1. BME{bme_method}_GO{go_scenario}_year analysis
% 2. each year analysis
% 3. aggregate across years analysis
% config directory
cbvResultsDir = './7validation/CBV';
% get config patterns from the different BME and GO scenarios
% all_methods = {'10000133_go0', '10000133_go3', '13000313-01', '13000313-02', ...
% '13000313-10', '13000313-04', '13000313-20', '13000313-05', ...
% '13000313-06'};
% configNames = {
% 'Obs. only (flat GO)', ...
% 'Obs. only (fine GO)', ...
% 'Obs. + MERRA2-GMI', ...
% 'Obs. + M3fusion', ...
% 'Obs. + UKML', ...
% 'Obs. + OMI-MLS', ...
% 'Obs. + NJML', ...
% 'Obs. + MERRA2-GMI + OMI-MLS', ...
% 'Obs. + M3fusion + OMI-MLS'
% };
all_methods = {'10000133_go0', '10000133_go3', '13000313-01', '13000313-02','13000313-04', '13000313-08','13000313-10', '13000313-20','13000313-40', ... % single models
'13000313-06', '13000313-0A', '13000313-12', '13000313-22', '13000313-42', ... % Two model combinations involving M3fusion
'13000313-05', '13000313-09', '13000313-11', '13000313-21', ... % Two model combinations involving MERRA2-GMI
'13000313-16', ... % Three model combinations involving M3fusion
'13000313-15'}; % Three model combinations involving MERRA2-GMI
% methods without MERRA2-GMI or UKML or NJML
all_methods = {'10000133_go0' , ...
'10000133_go3', ...
'13000313-02', ...
'13000313-03', ...
'13000313-04', ...
'13000313-08', ...
'13000313-40', ...
'13000313-06', ...
'13000313-0A', ...
'13000313-12', ...
'13000313-22', ...
'13000313-16', ...
'13000313-42'};
goScenarios = repmat({3}, 1, length(all_methods)); % Assuming all methods use GO scenario 3
goScenarios{1} = 0; % Override GO scenario for the first method (Obs. only with flat GO)
% configNames = cell(1, length(all_methods));
% for i = 1:length(all_methods)
% configNames{i} = getBMEmethodName(all_methods{i}, goScenarios{i});
% end
% configNames = {
% 'Obs. only (fine GO)', ...
% 'Obs. + MERRA2-GMI', ...
% 'Obs. + UKML', ...
% 'Obs. + MERRA2-GMI + UKML'
% };
allYears = 1991:2021; % use [] for all years
metrics = {'R2', 'RMSE'}; % {'R2', 'RMSE', 'MAE', 'NMB'}
boxSize = 5; % only important in phase-3 plots. % use [] for all box sizes
goScenario = 3;
% in the all_methods, for the methods where go is not specified, we assume goScenario is 3. Change accordingly
for each_method = 1:length(all_methods)
if contains(all_methods{each_method}, 'go')
continue;
else
all_methods{each_method} = sprintf('%s_go%d', all_methods{each_method}, goScenario);
end
end
% Generate human-readable config names from method codes + GO scenarios
configNames = cell(1, length(all_methods));
for i = 1:length(all_methods)
baseMethod = regexprep(all_methods{i}, '_go\d+$', '');
configNames{i} = getBMEmethodName(baseMethod, goScenarios{i});
end
% plotLevels = {'phase1', 'phase2', 'phase3', 'phase4'};
% plotLevels = {'phase3', 'phase4'};
plotLevels = {'phase4'};
% example usage:
% phase 1
fprintf('\n=== Example 1: Phase 1 Plots ===\n');
% loop through each configuration to generate phase 1 plots in the corresponding directories
for eachYear = allYears
fprintf('\n--- Processing Year: %d ---\n', eachYear);
for i = 1:length(all_methods)
configPattern = sprintf('CBV_BME%s*_box%d*_%d.mat', all_methods{i}, boxSize, eachYear);
% search dir for files matching pattern
fileNames = dir(fullfile(cbvResultsDir, configPattern));
if isempty(fileNames)
warning('No files found for pattern: %s', configPattern);
continue;
end
figDir = fullfile(cbvResultsDir, 'figs', sprintf('%s_%d', all_methods{i}, eachYear));
% if figDir already exists, skip
if exist(figDir, 'dir')
fprintf('Figures already exist for %s, skipping...\n', configPattern);
continue;
end
fprintf('\n--- Processing Configuration: %s ---\n', configNames{i});
if ismember('phase1', plotLevels)
fprintf('Generating Phase 1 plots...\n');
plotCBVresults_Phase1(cbvResultsDir, ...
'filePattern', configPattern, ...
'saveDir', figDir, ...
'dpi', 300, ...
'visible', 'on');
close all;
end
if ismember('phase2', plotLevels)
fprintf('Generating Phase 2 plots...\n');
plotCBVresults_Phase2(cbvResultsDir, ...
'filePattern', configPattern, ...
'saveDir', figDir, ...
'dpi', 300, ...
'visible', 'on');
close all;
end
end
end
configPatterns = cell(1, length(all_methods));
for i = 1:length(all_methods)
configPatterns{i} = sprintf('CBV_BME%s*_box%d*.mat', all_methods{i}, boxSize);
end
% phase 3
fprintf('\n=== Example 2: Phase 3 Configuration Comparison ===\n');
if ismember('phase3', plotLevels)
fprintf('Generating Phase 3 configuration comparison plots...\n');
% figPaths = plotCBVresults_Phase3(repmat({cbvResultsDir}, 1, length(configPatterns)), configNames, ...
% 'filePattern', configPatterns, ...
% 'baselineConfig', 1, ...
% 'years', allYears, ...
% 'boxSize', boxSize, ...
% 'metrics', {'R2', 'RMSE', 'MAE', 'NMB'}, ...
% 'saveDir', fullfile(cbvResultsDir, 'figs', sprintf('%d_%d', allYears(1), allYears(end))), ...
% 'dpi', 300, ...
% 'visible', 'on', ...
% 'saveTables', true);
figPaths = plotCBVresults_Phase3(repmat({cbvResultsDir}, 1, length(configPatterns)), configNames, ...
'filePattern', configPatterns, ...
'baselineConfig', 1, ...
'years', allYears, ...
'boxSize', boxSize, ...
'metrics', metrics, ...
'saveDir', fullfile(cbvResultsDir, 'figs', sprintf('%d_%d', allYears(1), allYears(end))), ...
'dpi', 300, ...
'visible', 'on', ...
'saveTables', true);
% close all;
end
% phase 4 - Enhanced Time-Series Analysis with Unique Colors/Styles
fprintf('\n=== Example 3: Phase 4 Time-Series Analysis ===\n');
if ismember('phase4', plotLevels)
fprintf('Generating Phase 4 time-series plots with unique colors and line styles...\n');
% Extract method codes for color/style assignment (strip _goX suffix)
methodCodes = cellfun(@(x) regexprep(x, '_go\d+$', ''), all_methods, 'UniformOutput', false);
figPaths_phase4 = plotCBVresults_Phase4(...
repmat({cbvResultsDir}, 1, length(configPatterns)), configNames, ...
'filePattern', configPatterns, ...
'methodCodes', methodCodes, ...
'years', allYears, ...
'boxSize', boxSize, ...
'metrics', metrics, ...
'saveDir', fullfile(cbvResultsDir, 'figs', sprintf('phase4_%d_%d', allYears(1), allYears(end))), ...
'dpi', 300, ...
'visible', 'on', ...
'saveTables', true);
fprintf('Phase 4 complete. Generated figures saved to: %s\n', ...
fullfile(cbvResultsDir, 'figs', sprintf('phase4_%d_%d', allYears(1), allYears(end))));
end