-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpppdemo2.m
More file actions
426 lines (317 loc) · 10.3 KB
/
Copy pathpppdemo2.m
File metadata and controls
426 lines (317 loc) · 10.3 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
%% PPPDEMO2 example script
%
% Demo script to read a whole year of data from NRCAN summary files and
% combine for every statuion the single day solutions into a single
% multi-day solution with statistical testing.
%
% Created: 12 April 2020 by Hans van der Marel
% Modified: 14 April 2020 by Hans van der Marel
% - minor changes
% - path to 2018 files (in legacy format)
% 15 July 2025 by Hans van der Marel
% - backported some changes from pppdemoxl back to pppdemo2
%% Add toolbox directories to the path
addpath('D:\Surfdrive\Matlab\toolbox\crsutil');
addpath('D:\Surfdrive\Matlab\toolbox\nrcan');
%% Get the directory names with NRCAN summary files
%
% For each year, the solutions for every station is stored in a unique
% subdirectory for each station.
campaign='2019';
fprintf('Get directory names with NRCAN summary files\n\n');
% Modify/select code to set the campaign directory
% dirroot=fullfile('d:\Iceland\NRCAN\',campaign); filepattern='*.sum';
dirroot=fullfile('d:\Iceland\DATAPACK\2_GPS\00_DATA',campaign,'03_PPP');
filepattern='*.zip';
legacyformat=false;
% End of select
dirnames=dir(dirroot);
dirnames=dirnames([dirnames.isdir]);
dirnames=dirnames(~cellfun(@(x) strncmp(x,{'.'},1), {dirnames.name}));
%% Combine single-day solutions into a multi-day solution for each station
%
% We loop over each directory and combine for each station the single day
% solutions into a multi-day solution.
%
% If the OMT exceeds a certain threshold, we try once more without the day
% with the largest omtfile value. The execution is done within a try-catch
% construction in order to catch various other errors.
%
% When the combination is succesfull it is saved in a structure array
maxomt_for_reprocessing=2;
maxomt_for_save=10;
clear pppsave;
clear pppremoved pppskipped;
pppremoved=[];
pppskipped=[];
kk=0;
for k=1:numel(dirnames)
fprintf('Processing %s ...\n\n',dirnames(k).name);
try
% Read the NRCAN summary files
filespec=fullfile(dirroot,dirnames(k).name,filepattern);
pppstruct = xtrNRCAN(filespec,'legacy',legacyformat);
% Check if the station names in pppstruct match the directory name
name=unique(pppstruct.name);
if numel(name) ~=1 || ~strcmpi(dirnames(k).name,char(name))
for l=1:numel(pppstruct.name)
fprintf('Changed station name in %s from %s to %s\n',pppstruct.obsfile{l},pppstruct.name{l},dirnames(k).name);
pppstruct.name{l}=dirnames(k).name;
end
fprintf('\n')
end
% Compute doy numbers
mdaterangeobs=cellfun(@(x) datenum(x),pppstruct.daterange);
mdateobs=floor(mean(mdaterangeobs,2));
mdatevec=datevec(mdateobs);
doy=mdateobs-datenum(mdatevec(:,1),0,0);
% Combine the single day solutions into one multi-day solution with statistical testing
pppcomb=pppcombine(pppstruct);
fprintf('Processing %s done (OMT value %.3f)\n',dirnames(k).name,pppcomb.omt)
fprintf('Observation file OMT\n')
for l=1:numel(pppcomb.obsfile)
fprintf('%20s %8.3f\n',pppcomb.obsfile{l},pppcomb.omtfile(l))
end
fprintf('\n\n')
% If OMT > max_OMT, try again, removing the worst day (but only with at least 3 days)
select=1:numel(pppcomb.omtfile);
while pppcomb.omt > maxomt_for_reprocessing && numel(pppcomb.omtfile) > 2
[~,i]=max(pppcomb.omtfile);
doyremoved=doy(select(i));
fprintf('*** Removing solution file %s from combination (doy=%d) ***\n\n',pppcomb.obsfile{i},doyremoved)
select(i)=[];
%pppremoved=[ pppremoved ; pppcomb.name pppcomb.obsfile(i) {pppcomb.omtfile(i)} ];
pppremoved=[ pppremoved ; pppcomb.name pppcomb.obsfile(i) {pppcomb.omtfile(i)} kk+1 doyremoved];
pppcomb=pppcombine(pppstruct,select);
fprintf('Re-processing %s done (OMT value %.3f)\n',dirnames(k).name,pppcomb.omt)
fprintf('Observation file OMT\n')
for l=1:numel(pppcomb.obsfile)
fprintf('%17s %8.3f\n',pppcomb.obsfile{l},pppcomb.omtfile(l))
end
fprintf('\n\n')
end
% add array with doy to pppcomb just before saving
pppcomb.doys=doy(select);
if pppcomb.omt < maxomt_for_save
kk=kk+1;
pppsave(kk)=pppcomb;
else
pppskipped=[ pppskipped ; pppcomb.name {pppcomb.obsfile} {pppcomb.omt} {'Max OMT exceeded'} ];
end
catch ME
ME
warning(['There was an error processing ' dirnames(k).name ])
pppskipped=[ pppskipped ; dirnames(k).name {pppstruct.obsfile(segment)} { nan } { ME.message } ];
end
end
% Summarize the removed data files
nremoved=size(pppremoved,1);
if nremoved > 0
fprintf('\n\nFiles removed from the combination (%d):\n\n',nremoved)
fprintf('Name Obsfile OMT\n')
for k=1:nremoved
fprintf('%s %s %10.4g\n',pppremoved{k,1},pppremoved{k,2},pppremoved{k,3})
end
fprintf('\n\n')
else
fprintf('\n\nNo files are removed from the combination (because of outliers)\n\n')
end
% Summarize the skipped stations
nskipped=size(pppskipped,1);
if nskipped > 0
fprintf('Stations which were skipped because of errors (%d):\n\n',nskipped)
fprintf('Name #Obsfiles OMT Obsfiles Reason\n')
for k=1:nskipped
fprintf('%s %5d %10.4g ',pppskipped{k,1},numel(pppskipped{k,2}),pppskipped{k,3});
for i=1:numel(pppskipped{k,2})
fprintf(' %s',pppskipped{k,2}{i})
end
fprintf(' %s\n',pppskipped{k,4})
end
fprintf('\n\n')
else
fprintf('No stations are skipped (because of errors)\n\n')
end
%% Plot the OMT values
stations={pppsave.name};
numstations=numel(stations);
omtarray=[];
for k=1:numstations
%daynum=cellfun(@(x) str2num(x(5:7)),pppsave(k).obsfile);
daynum=pppsave(k).doys;
omtarray=[ omtarray ; repmat(k,size(daynum)) daynum pppsave(k).omtfile pppsave(k).omtfile2d pppsave(k).omtfile1d ];
end
remarray=[];
nremoved=size(pppremoved,1);
for k=1:nremoved
%daynum=str2num(pppremoved{k,2}(5:7));
daynum=pppremoved{k,5};
%kk=find(ismember(stations,pppremoved{k,1}));
kk=pppremoved{k,4};
%if ~isempty(kk)
remarray=[ remarray ; kk daynum ];
%end
end
figure('Name','Overall Model Test','NumberTitle','off','Position',[ 40 60 600 900])
subplot('Position',[ 0.1 0.1 0.6 .82])
symsize=omtarray(:,3)*25;
symsize(symsize < 5)=5;
scatter(omtarray(:,2),omtarray(:,1),symsize,omtarray(:,3),'s','filled');
if ~isempty(remarray)
hold on
scatter(remarray(:,2),remarray(:,1),35,[1 0 0],'x');
end
hp=gca;
colorbar
colormap(jet)
hp.YTick=1:numstations;
hp.YTickLabel=stations;
hp.YDir='reverse';
ylim([0 numstations+1])
hp.XTick=unique(omtarray(:,2));
hp.XTickLabel=hp.XTick;
hp.XTickLabelRotation=90;
xlim([ min(hp.XTick-1) max(hp.XTick+1)]);
hp.Box='on';
hp.FontSize=9;
year=char(unique(cellfun(@(x) x(1:4),[ pppsave.daterange ],'UniformOutput',false)));
%xlabel(year);
title([ 'Single day OMT (' year ')'])
subplot('Position',[ 0.78 0.1 0.17 .82])
omt=[pppsave.omt];
barh(omt)
hb=gca;
hb.YTick=1:numstations;
hb.YTickLabel=stations;
hb.YDir='reverse';
ylim([0 numstations+1])
hb.FontSize=9;
title('Multi day OMT')
%% Plot 2D- adn 1D-OMT values
figure('Name','2D/1D Overall Model Test','NumberTitle','off','Position',[ 40 60 600 900])
subplot('Position',[ 0.1 0.1 0.6 .82])
symsize=omtarray(:,4)*25;
symsize(symsize < 5)=5;
scatter(omtarray(:,2),omtarray(:,1),symsize,omtarray(:,4),'o','filled');
hold on
symsize=omtarray(:,5)*25;
symsize(symsize < 5)=5;
scatter(omtarray(:,2),omtarray(:,1),symsize,omtarray(:,5),'^');
if ~isempty(remarray)
scatter(remarray(:,2),remarray(:,1),35,[1 0 0],'x');
end
hp=gca;
colorbar
colormap(jet)
hp.YTick=1:numstations;
hp.YTickLabel=stations;
hp.YDir='reverse';
ylim([0 numstations+1])
hp.XTick=unique(omtarray(:,2));
hp.XTickLabel=hp.XTick;
hp.XTickLabelRotation=90;
xlim([ min(hp.XTick-1) max(hp.XTick+1)]);
hp.Box='on';
hp.FontSize=9;
year=char(unique(cellfun(@(x) x(1:4),[ pppsave.daterange ],'UniformOutput',false)));
%xlabel(year);
title([ 'Single day 2D/1D OMT (' year ')'])
subplot('Position',[ 0.78 0.1 0.17 .82])
omt=[[pppsave.omt2d]' [pppsave.omt1d]'];
barh(omt)
hb=gca;
hb.YTick=1:numstations;
hb.YTickLabel=stations;
hb.YDir='reverse';
ylim([0 numstations+1])
hb.FontSize=9;
title('Multi day OMT')
%% Plot with the station quality
figure('Name','Station Quality','NumberTitle','off','Position',[ 40 60 600 900])
subplot('Position',[ 0.1 0.1 0.22 .82])
sigma=cell2mat({ pppsave.scorNEU }')*1000;
sigma=sigma(:,1:3);
barh(sigma)
ha=gca;
ha.YTick=1:numstations;
ha.YTickLabel=stations;
ha.YDir='reverse';
ylim([0 numstations+1])
xrange=xlim;
xrange(2)=min(ceil(xrange(2)*1.1),10);
xlim(xrange);
ha.FontSize=9;
xlabel('\sigma_{NEU} [mm]')
legend({'N','E','U'})
title(['\sigma_{NEU} (' year ')'])
subplot('Position',[ 0.4 0.1 0.22 .82])
wrms=cell2mat({ pppsave.wrmsNEU }')*1000;
barh(wrms)
hb=gca;
hb.YTick=1:numstations;
hb.YTickLabel=stations;
hb.YDir='reverse';
ylim([0 numstations+1])
xrange=xlim;
xrange(2)=min(ceil(xrange(2)*1.1),15);
hb.FontSize=9;
xlabel('w-rmse [mm]')
legend({'N','E','U'})
title(['W-RMSE (' year ')'])
subplot('Position',[ 0.7 0.1 0.22 .82])
omtneu=cell2mat({ pppsave.omtNEU }');
barh(omtneu)
hc=gca;
hc.YTick=1:numstations;
hc.YTickLabel=stations;
hc.YDir='reverse';
ylim([0 numstations+1]);
hc.FontSize=9;
xlabel('OMT [-]')
legend({'N','E','U'})
title(['OMT (' year ')'])
%%
figure('Name','Weighted RMS','NumberTitle','off','Position',[ 40 60 600 900])
subplot('Position',[ 0.1 0.1 0.22 .82])
wrms=cell2mat({ pppsave.wrmsNEU }')*1000;
barh(wrms)
ha=gca;
ha.YTick=1:numstations;
ha.YTickLabel=stations;
ha.YDir='reverse';
ylim([0 numstations+1])
xlim([0 15]);
ha.FontSize=9;
xlabel('w-rmse [mm]')
legend({'N','E','U'})
title(['W-RMSE (' year ')'])
subplot('Position',[ 0.4 0.1 0.22 .82])
rms=cell2mat({ pppsave.rmsNEU }')*1000;
barh(rms)
hb=gca;
hb.YTick=1:numstations;
hb.YTickLabel=stations;
hb.YDir='reverse';
ylim([0 numstations+1])
xlim([0 20]);
hb.FontSize=9;
xlabel('rmse [mm]')
legend({'N','E','U'})
title(['RMSE (' year ')'])
subplot('Position',[ 0.7 0.1 0.22 .82])
omtneu=cell2mat({ pppsave.omtNEU }');
barh(omtneu)
hc=gca;
hc.YTick=1:numstations;
hc.YTickLabel=stations;
hc.YDir='reverse';
ylim([0 numstations+1]);
hc.FontSize=9;
xlabel('OMT [-]')
legend({'N','E','U'})
title(['OMT (' year ')'])
%% Print sitelist
fprintf('site,latitude(deg),longitude(deg)\n')
for k=1:numel(pppsave)
fprintf('%4s,%.10f,%.10f\n',pppsave(k).name,pppsave(k).plh(1:2)*180/pi)
end