-
Notifications
You must be signed in to change notification settings - Fork 0
/
KStestforwholedata.m
executable file
·207 lines (156 loc) · 6.44 KB
/
KStestforwholedata.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
%% This Script performs the KS test for a whole day's worth of Data
% between two consecutive days worth of data that was downloaded. To check
% what timing of data has been downloaded, open the tbb_13_15 files
clear
% add path for the create_aoi_coords function
addpath '/Users/denny/OneDrive - Nanyang Technological University/Y4/FYP/H8_Codes'
Data_Folder = ...
'/Users/denny/OneDrive - Nanyang Technological University/Y4/FYP/H8_Processed_Data/';
%------------------------Config to change-------------
Volcano = 'Sinabung';
YYYYMM = '201906';
DD = {'03','04'};
DayNight = 'Night';
% mkdir([Data_Folder,'/',Volcano,'_',YYYYMM,'/NIGHT_KSTEST'])
% cd([Data_Folder,'/',Volcano,'_',YYYYMM,'/NIGHT_KSTEST'])
%------------------------------------------------------
for k = 1:length(DD)-1
beforeFoldername = [Volcano,'_',YYYYMM,'/',Volcano,'_',YYYYMM,DD{k},'_',DayNight];
afterFoldername = [Volcano,'_',YYYYMM,'/',Volcano,'_',YYYYMM,DD{k+1},'_',DayNight];
beforeMatfilename = [Volcano,'_',YYYYMM,DD{k},'_',DayNight,'.mat'];
afterMatfilename = [Volcano,'_',YYYYMM,DD{k+1},'_',DayNight,'.mat'];
% beforeFoldername = [Volcano,'_202311/',Volcano,'_20231130_',DayNight];
% afterFoldername = [Volcano,'_202312/',Volcano,'_20231201_',DayNight];
% beforeMatfilename = [Volcano,'_20231130_',DayNight,'.mat'];
% afterMatfilename = [Volcano,'_20231201_',DayNight,'.mat'];
% % check if file exists
% if exist ([Data_Folder,foldername,'/',matfilename], 'file') == 0
% error ('File does not exist!')
% end
load([Data_Folder,beforeFoldername,'/',beforeMatfilename])
clear("lat")
clear("lon")
% mkdir([Data_Folder,foldername,'/KSTestBTD'])
% cd([Data_Folder,foldername,'/KSTestBTD'])
%%
% tbb_13_14_before = tbb_13_14;
% tbb_13_15_before = tbb_13_15;
% tbb_14_15_before = tbb_14_15;
% tbb_7_13_before = tbb_7_13;
%
% clear("tbb_7_13","tbb_14_15","tbb_13_15","tbb_13_14")
%
% load([Data_Folder,afterFoldername,'/',afterMatfilename])
%
% tbb_13_14_after = tbb_13_14;
% tbb_13_15_after = tbb_13_15;
% tbb_14_15_after = tbb_14_15;
% tbb_7_13_after = tbb_7_13;
%
%
% before_variableNames = {'tbb_13_15_before','tbb_7_13_before',...
% 'tbb_13_14_before','tbb_14_15_before'};
%
% after_variableNames = {'tbb_13_15_after','tbb_7_13_after',...
% 'tbb_13_14_after','tbb_14_15_after'};
tbb_07_before = tbb_07;
tbb_08_before = tbb_08;
tbb_09_before = tbb_09;
tbb_10_before = tbb_10;
tbb_11_before = tbb_11;
tbb_12_before = tbb_12;
tbb_13_before = tbb_13;
tbb_14_before = tbb_14;
tbb_15_before = tbb_15;
tbb_16_before = tbb_16;
clear("tbb_07","tbb_08","tbb_09","tbb_10","tbb_11","tbb_12","tbb_13",...
"tbb_14","tbb_15","tbb_16")
load([Data_Folder,afterFoldername,'/',afterMatfilename])
tbb_07_after = tbb_07;
tbb_08_after = tbb_08;
tbb_09_after = tbb_09;
tbb_10_after = tbb_10;
tbb_11_after = tbb_11;
tbb_12_after = tbb_12;
tbb_13_after = tbb_13;
tbb_14_after = tbb_14;
tbb_15_after = tbb_15;
tbb_16_after = tbb_16;
% before_variableNames = {'tbb_07_before','tbb_08_before','tbb_09_before',...
% 'tbb_10_before','tbb_11_before','tbb_12_before','tbb_13_before',...
% 'tbb_14_before','tbb_15_before','tbb_16_before'};
%
% after_variableNames = {'tbb_07_after','tbb_08_after','tbb_09_after',...
% 'tbb_10_after','tbb_11_after','tbb_12_after','tbb_13_after',...
% 'tbb_14_after','tbb_15_after','tbb_16_after'};
%
% variableNames = {'tbb_07','tbb_08','tbb_09',...
% 'tbb_10','tbb_11','tbb_12','tbb_13',...
% 'tbb_14','tbb_15','tbb_16'};
before_variableNames = {'tbb_07_before'};
after_variableNames = {'tbb_07_after'};
variableNames = {'tbb_07'};
for i = 1:length(before_variableNames)
% Get the current variable name from the list
beforeVarName = before_variableNames{i};
% Use evalin to retrieve the variable from the workspace
beforeVarValue = evalin('base', beforeVarName);
beforeStruct = beforeVarValue;
% Get the current variable name from the list
afterVarName = after_variableNames{i};
% Use evalin to retrieve the variable from the workspace
afterVarValue = evalin('base', afterVarName);
afterStruct = afterVarValue;
beforefieldName = fieldnames(beforeStruct);
afterfieldName = fieldnames(afterStruct);
beforeCat = [];
afterCat = [];
for j = 1:length(beforefieldName)
beforeCat = [beforeCat;beforeStruct.(beforefieldName{j})(:)];
end
for j = 1:length(afterfieldName)
afterCat = [afterCat;afterStruct.(afterfieldName{j})(:)];
end
referenceData = beforeCat(:) - 273;
currentData = afterCat(:) - 273;
% Perform the KS test to compare the current data to the reference data
% can modify to test with other distributions
% currently will test every pairs of 10min interval
[h, p, kstat] = kstest2(referenceData, currentData);
% % Display the results
% fprintf('KS Test between Field %s & %s:\n', fieldNames{i},...
% fieldNames{i+1} );
% fprintf('KS Test Statistic: %.4f\n', kstat);
% fprintf('P-value: %.4f\n', p);
% % Store the field name and test result in the structure array
% results(i).FieldName = fieldNames{i};
% results(i).Test = h;
% results(i).PValue = p;
% results(i).Kstat = kstat;
% Create a plot to visualize the cumulative distribution functions of the two data sets
[ecdf1, x1] = ecdf(referenceData);
[ecdf2, x2] = ecdf(currentData);
figure;
plot(x1, ecdf1, 'b', 'LineWidth', 2);
hold on;
plot(x2, ecdf2, 'r', 'LineWidth', 2);
legend('3 June 2019', '4 June 2019','Location','best');
xlabel('Brightness Temperature (Celsius)','FontSize', 14, 'FontName', 'Arial');
ylabel('CDF Value','FontSize', 14, 'FontName', 'Arial');
old_title = sprintf('%s_KS-Test between %s and %s',variableNames{i},...
([Volcano,'_',YYYYMM,DD{k}]),...
([Volcano,'_',YYYYMM,DD{k+1}]));
% old_title = sprintf('%s_KS-Test between %s and %s',variableNames{i},...
% ([Volcano,'_20231130']),...
% ([Volcano,'_20231201']));
new_title = strrep(old_title,'_',' ');
% title([new_title,'. N=',num2str(length(currentData))],...
% 'FontSize', 14, 'FontName', 'Arial')
title(['KS-Test for Band 7. N=',num2str(length(currentData))],...
'FontSize', 14, 'FontName', 'Arial')
% Save the figure as an image file (e.g., PNG)
fig_filename = ([new_title,'.png']);
saveas(gcf, fig_filename);
close
end
end