/
point_stat_conf_info.cc
1266 lines (977 loc) · 37.3 KB
/
point_stat_conf_info.cc
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
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
// ** Copyright UCAR (c) 1992 - 2020
// ** University Corporation for Atmospheric Research (UCAR)
// ** National Center for Atmospheric Research (NCAR)
// ** Research Applications Lab (RAL)
// ** P.O.Box 3000, Boulder, Colorado, 80307-3000, USA
// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
////////////////////////////////////////////////////////////////////////
using namespace std;
#include <dirent.h>
#include <iostream>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <cmath>
#include "point_stat_conf_info.h"
#include "vx_data2d_factory.h"
#include "vx_data2d.h"
#include "vx_log.h"
extern bool use_var_id;
////////////////////////////////////////////////////////////////////////
//
// Code for class PointStatConfInfo
//
////////////////////////////////////////////////////////////////////////
PointStatConfInfo::PointStatConfInfo() {
init_from_scratch();
}
////////////////////////////////////////////////////////////////////////
PointStatConfInfo::~PointStatConfInfo() {
clear();
}
////////////////////////////////////////////////////////////////////////
void PointStatConfInfo::init_from_scratch() {
// Initialize pointers
vx_opt = (PointStatVxOpt *) 0;
clear();
return;
}
////////////////////////////////////////////////////////////////////////
void PointStatConfInfo::clear() {
// Initialize values
model.clear();
land_mask.clear();
topo_dp.clear();
topo_use_obs_thresh.clear();
topo_interp_fcst_thresh.clear();
msg_typ_group_map.clear();
mask_area_map.clear();
mask_sid_map.clear();
tmp_dir.clear();
output_prefix.clear();
version.clear();
// Deallocate memory
if(vx_opt) { delete [] vx_opt; vx_opt = (PointStatVxOpt *) 0; }
// Set count to zero
n_vx = 0;
return;
}
////////////////////////////////////////////////////////////////////////
void PointStatConfInfo::read_config(const char *default_file_name,
const char *user_file_name) {
// Read the config file constants
conf.read(replace_path(config_const_filename).c_str());
// Read the default config file
conf.read(default_file_name);
// Read the user-specified config file
conf.read(user_file_name);
return;
}
////////////////////////////////////////////////////////////////////////
void PointStatConfInfo::process_config(GrdFileType ftype,
bool cur_use_var_id) {
int i, j, n_fvx, n_ovx;
Dictionary *fdict = (Dictionary *) 0;
Dictionary *odict = (Dictionary *) 0;
Dictionary i_fdict, i_odict;
// Dump the contents of the config file
if(mlog.verbosity_level() >= 5) conf.dump(cout);
// Initialize
clear();
// Conf: version
version = parse_conf_version(&conf);
// Conf: model
model = parse_conf_string(&conf, conf_key_model);
// Conf: tmp_dir
tmp_dir = parse_conf_tmp_dir(&conf);
// Conf: output_prefix
output_prefix = conf.lookup_string(conf_key_output_prefix);
// Conf: message_type_group_map
msg_typ_group_map = parse_conf_message_type_group_map(&conf);
// Conf: message_type_group_map(SURFACE)
if(msg_typ_group_map.count((string)surface_msg_typ_group_str) == 0) {
mlog << Error << "\nPointStatConfInfo::process_config() -> "
<< "\"" << conf_key_message_type_group_map
<< "\" must contain an entry for \""
<< surface_msg_typ_group_str << "\".\n\n";
exit(1);
}
// Conf: fcst.field and obs.field
fdict = conf.lookup_array(conf_key_fcst_field);
odict = conf.lookup_array(conf_key_obs_field);
// Determine the number of fields (name/level) to be verified
n_fvx = parse_conf_n_vx(fdict);
n_ovx = parse_conf_n_vx(odict);
// Check for a valid number of verification tasks
if(n_fvx == 0 || n_fvx != n_ovx) {
mlog << Error << "\nPointStatConfInfo::process_config() -> "
<< "The number of verification tasks in \""
<< conf_key_obs_field << "\" (" << n_ovx
<< ") must be non-zero and match the number in \""
<< conf_key_fcst_field << "\" (" << n_fvx << ").\n\n";
exit(1);
}
// Allocate memory for the verification task options
n_vx = n_fvx;
vx_opt = new PointStatVxOpt [n_vx];
// Check for consistent number of climatology fields
check_climo_n_vx(&conf, n_vx);
// Parse settings for each verification task
for(i=0; i<n_vx; i++) {
// Get the current dictionaries
i_fdict = parse_conf_i_vx_dict(fdict, i);
i_odict = parse_conf_i_vx_dict(odict, i);
// Process the options for this verification task
vx_opt[i].process_config(ftype, i_fdict, i_odict, cur_use_var_id);
}
// Summarize output flags across all verification tasks
process_flags();
// If VL1L2 or VAL1L2 is requested, set the uv_index.
// When processing vectors, need to make sure the message types,
// masking regions, and interpolation methods are consistent.
if(output_flag[i_vl1l2] != STATOutputType_None ||
output_flag[i_val1l2] != STATOutputType_None) {
for(i=0; i<n_vx; i++) {
// Process u-wind
if(vx_opt[i].vx_pd.fcst_info->is_u_wind() &&
vx_opt[i].vx_pd.obs_info->is_u_wind()) {
// Search for corresponding v-wind
for(j=0; j<n_vx; j++) {
if(vx_opt[j].vx_pd.fcst_info->is_v_wind() &&
vx_opt[j].vx_pd.obs_info->is_v_wind() &&
vx_opt[i].vx_pd.fcst_info->req_level_name() ==
vx_opt[j].vx_pd.fcst_info->req_level_name() &&
vx_opt[i].vx_pd.obs_info->req_level_name() ==
vx_opt[j].vx_pd.obs_info->req_level_name() &&
vx_opt[i].is_uv_match(vx_opt[j])) {
vx_opt[i].vx_pd.fcst_info->set_uv_index(j);
vx_opt[i].vx_pd.obs_info->set_uv_index(j);
}
}
}
// Process v-wind
else if(vx_opt[i].vx_pd.fcst_info->is_v_wind() &&
vx_opt[i].vx_pd.obs_info->is_v_wind()) {
// Search for corresponding u-wind
for(j=0; j<n_vx; j++) {
if(vx_opt[j].vx_pd.fcst_info->is_u_wind() &&
vx_opt[j].vx_pd.obs_info->is_u_wind() &&
vx_opt[i].vx_pd.fcst_info->req_level_name() ==
vx_opt[j].vx_pd.fcst_info->req_level_name() &&
vx_opt[i].vx_pd.obs_info->req_level_name() ==
vx_opt[j].vx_pd.obs_info->req_level_name() &&
vx_opt[i].is_uv_match(vx_opt[j])) {
vx_opt[i].vx_pd.fcst_info->set_uv_index(j);
vx_opt[i].vx_pd.obs_info->set_uv_index(j);
}
}
}
} // end for i
} // end if
return;
}
////////////////////////////////////////////////////////////////////////
void PointStatConfInfo::process_flags() {
int i, j;
bool output_ascii_flag = false;
// Initialize
for(i=0; i<n_txt; i++) output_flag[i] = STATOutputType_None;
// Loop over the verification tasks
for(i=0; i<n_vx; i++) {
// Summary of output_flag settings
for(j=0; j<n_txt; j++) {
if(vx_opt[i].output_flag[j] == STATOutputType_Both) {
output_flag[j] = STATOutputType_Both;
output_ascii_flag = true;
}
else if(vx_opt[i].output_flag[j] == STATOutputType_Stat &&
output_flag[j] == STATOutputType_None) {
output_flag[j] = STATOutputType_Stat;
output_ascii_flag = true;
}
} // for j
} // for i
// Check for at least one output line type
if(!output_ascii_flag) {
mlog << Error << "\nPointStatVxOpt::process_config() -> "
<< "At least one output STAT type must be requested in \""
<< conf_key_output_flag << "\".\n\n";
exit(1);
}
return;
}
////////////////////////////////////////////////////////////////////////
void PointStatConfInfo::process_masks(const Grid &grid) {
int i, j;
MaskPlane mp;
StringArray sid;
ConcatString name;
mlog << Debug(2)
<< "Processing masking regions.\n";
// Mapping of grid definition strings to mask names
map<ConcatString,ConcatString> grid_map;
map<ConcatString,ConcatString> poly_map;
map<ConcatString,ConcatString> sid_map;
map<ConcatString,MaskLatLon> point_map;
// Initiailize
mask_area_map.clear();
mask_sid_map.clear();
// Process the masks for each vx task
for(i=0; i<n_vx; i++) {
// Initialize
vx_opt[i].mask_name.clear();
// Parse the masking grids
for(j=0; j<vx_opt[i].mask_grid.n(); j++) {
// Process new grid masks
if(grid_map.count(vx_opt[i].mask_grid[j]) == 0) {
mlog << Debug(3)
<< "Processing grid mask: "
<< vx_opt[i].mask_grid[j] << "\n";
parse_grid_mask(vx_opt[i].mask_grid[j], grid, mp, name);
grid_map[vx_opt[i].mask_grid[j]] = name;
mask_area_map[name] = mp;
}
// Store the name for the current grid mask
vx_opt[i].mask_name.add(grid_map[vx_opt[i].mask_grid[j]]);
} // end for j
// Parse the masking polylines
for(j=0; j<vx_opt[i].mask_poly.n(); j++) {
// Process new poly mask
if(poly_map.count(vx_opt[i].mask_poly[j]) == 0) {
mlog << Debug(3)
<< "Processing poly mask: "
<< vx_opt[i].mask_poly[j] << "\n";
parse_poly_mask(vx_opt[i].mask_poly[j], grid, mp, name);
poly_map[vx_opt[i].mask_poly[j]] = name;
mask_area_map[name] = mp;
}
// Store the name for the current poly mask
vx_opt[i].mask_name.add(poly_map[vx_opt[i].mask_poly[j]]);
} // end for j
// Parse the masking station ID's
for(j=0; j<vx_opt[i].mask_sid.n(); j++) {
// Process new station ID mask
if(sid_map.count(vx_opt[i].mask_sid[j]) == 0) {
mlog << Debug(3)
<< "Processing station ID mask: "
<< vx_opt[i].mask_sid[j] << "\n";
parse_sid_mask(vx_opt[i].mask_sid[j], sid, name);
sid_map[vx_opt[i].mask_sid[j]] = name;
mask_sid_map[name] = sid;
}
// Store the name for the current station ID mask
vx_opt[i].mask_name.add(sid_map[vx_opt[i].mask_sid[j]]);
} // end for j
// Parse the Lat/Lon point masks
for(j=0; j<(int) vx_opt[i].mask_llpnt.size(); j++) {
// Process new point masks -- no real work to do
if(point_map.count(vx_opt[i].mask_llpnt[j].name) == 0) {
mlog << Debug(3)
<< "Processing Lat/Lon point mask: "
<< vx_opt[i].mask_llpnt[j].name << "\n";
point_map[vx_opt[i].mask_llpnt[j].name] = vx_opt[i].mask_llpnt[j];
}
// Store the name for the current Lat/Lon point mask
vx_opt[i].mask_name.add(vx_opt[i].mask_llpnt[j].name);
} // end for j
// Check for unique mask names
check_mask_names(vx_opt[i].mask_name);
} // end for i
return;
}
////////////////////////////////////////////////////////////////////////
void PointStatConfInfo::process_geog(const Grid &grid,
const char *fcst_file) {
int i;
bool land, topo;
Dictionary *dict;
DataPlane geog_dp;
SurfaceInfo sfc_info;
// Loop over the verification tasks and check flags
for(i=0, land = topo = false; i<n_vx; i++) {
// Set to true if requested by any sub-task
if(vx_opt[i].land_flag) land = true;
if(vx_opt[i].topo_flag) topo = true;
}
mlog << Debug(2)
<< "Processing geography data.\n";
// Conf: land
if(land) {
dict = conf.lookup_dictionary(conf_key_land_mask);
geog_dp = parse_geog_data(dict, grid, fcst_file);
geog_dp.threshold(dict->lookup_thresh(conf_key_thresh));
land_mask = geog_dp.mask_plane();
}
// Conf: topo
if(topo) {
dict = conf.lookup_dictionary(conf_key_topo_mask);
topo_dp = parse_geog_data(dict, grid, fcst_file);
topo_use_obs_thresh = dict->lookup_thresh(conf_key_use_obs_thresh);
topo_interp_fcst_thresh = dict->lookup_thresh(conf_key_interp_fcst_thresh);
}
// Loop over the verification tasks and set the geography info
for(i=0; i<n_vx; i++) {
sfc_info.clear();
if(vx_opt[i].land_flag) {
sfc_info.land_ptr = &land_mask;
}
else {
sfc_info.land_ptr = 0;
}
if(vx_opt[i].topo_flag) {
sfc_info.topo_ptr = &topo_dp;
sfc_info.topo_use_obs_thresh = topo_use_obs_thresh;
sfc_info.topo_interp_fcst_thresh = topo_interp_fcst_thresh;
}
else {
sfc_info.topo_ptr = 0;
}
vx_opt[i].vx_pd.set_sfc_info(sfc_info);
}
return;
}
////////////////////////////////////////////////////////////////////////
void PointStatConfInfo::set_vx_pd() {
// This should be called after process_masks()
for(int i=0; i<n_vx; i++) vx_opt[i].set_vx_pd(this);
}
////////////////////////////////////////////////////////////////////////
int PointStatConfInfo::n_txt_row(int i_txt_row) const {
int i, n;
// Loop over the tasks and sum the line counts for this line type
for(i=0, n=0; i<n_vx; i++) n += vx_opt[i].n_txt_row(i_txt_row);
return(n);
}
////////////////////////////////////////////////////////////////////////
int PointStatConfInfo::n_stat_row() const {
int i, n;
// Loop over the line types and sum the line counts
for(i=0, n=0; i<n_txt; i++) n += n_txt_row(i);
return(n);
}
////////////////////////////////////////////////////////////////////////
int PointStatConfInfo::get_max_n_cat_thresh() const {
int i, n;
for(i=0,n=0; i<n_vx; i++) n = max(n, vx_opt[i].get_n_cat_thresh());
return(n);
}
////////////////////////////////////////////////////////////////////////
int PointStatConfInfo::get_max_n_cnt_thresh() const {
int i, n;
for(i=0,n=0; i<n_vx; i++) n = max(n, vx_opt[i].get_n_cnt_thresh());
return(n);
}
////////////////////////////////////////////////////////////////////////
int PointStatConfInfo::get_max_n_wind_thresh() const {
int i, n;
for(i=0,n=0; i<n_vx; i++) n = max(n, vx_opt[i].get_n_wind_thresh());
return(n);
}
////////////////////////////////////////////////////////////////////////
int PointStatConfInfo::get_max_n_fprob_thresh() const {
int i, n;
for(i=0,n=0; i<n_vx; i++) n = max(n, vx_opt[i].get_n_fprob_thresh());
return(n);
}
////////////////////////////////////////////////////////////////////////
int PointStatConfInfo::get_max_n_oprob_thresh() const {
int i, n;
for(i=0,n=0; i<n_vx; i++) n = max(n, vx_opt[i].get_n_oprob_thresh());
return(n);
}
////////////////////////////////////////////////////////////////////////
int PointStatConfInfo::get_max_n_eclv_points() const {
int i, n;
for(i=0,n=0; i<n_vx; i++) n = max(n, vx_opt[i].get_n_eclv_points());
return(n);
}
////////////////////////////////////////////////////////////////////////
bool PointStatConfInfo::get_vflag() const {
int i;
bool vflag = false;
// Vector output must be requested
if(output_flag[i_vl1l2] == STATOutputType_None &&
output_flag[i_val1l2] == STATOutputType_None) {
return(false);
}
// Vector components must be requested
for(i=0; i<n_vx; i++) {
if(!vx_opt[i].vx_pd.fcst_info || !vx_opt[i].vx_pd.obs_info) continue;
if((vx_opt[i].vx_pd.fcst_info->is_u_wind() &&
vx_opt[i].vx_pd.obs_info->is_u_wind()) ||
(vx_opt[i].vx_pd.fcst_info->is_v_wind() &&
vx_opt[i].vx_pd.obs_info->is_v_wind())) {
vflag = true;
break;
}
}
return(vflag);
}
////////////////////////////////////////////////////////////////////////
//
// Code for class PointStatVxOpt
//
////////////////////////////////////////////////////////////////////////
PointStatVxOpt::PointStatVxOpt() {
init_from_scratch();
}
////////////////////////////////////////////////////////////////////////
PointStatVxOpt::~PointStatVxOpt() {
clear();
}
////////////////////////////////////////////////////////////////////////
void PointStatVxOpt::init_from_scratch() {
clear();
return;
}
////////////////////////////////////////////////////////////////////////
void PointStatVxOpt::clear() {
int i;
// Initialize values
vx_pd.clear();
beg_ds = end_ds = bad_data_int;
fcat_ta.clear();
ocat_ta.clear();
fcnt_ta.clear();
ocnt_ta.clear();
cnt_logic = SetLogic_None;
fwind_ta.clear();
owind_ta.clear();
wind_logic = SetLogic_None;
land_flag = false;
topo_flag = false;
mask_grid.clear();
mask_poly.clear();
mask_sid.clear();
mask_llpnt.clear();
mask_name.clear();
eclv_points.clear();
cdf_info.clear();
ci_alpha.clear();
boot_info.clear();
interp_info.clear();
hira_info.clear();
rank_corr_flag = false;
msg_typ.clear();
duplicate_flag = DuplicateType_None;
obs_summary = ObsSummary_None;
obs_perc = bad_data_int;
for(i=0; i<n_txt; i++) output_flag[i] = STATOutputType_None;
return;
}
////////////////////////////////////////////////////////////////////////
//
// Check the settings that would impact the number of matched pairs
// when searching for U/V matches.
//
////////////////////////////////////////////////////////////////////////
bool PointStatVxOpt::is_uv_match(const PointStatVxOpt &v) const {
bool match = true;
//
// The following do not impact matched pairs:
// fcat_ta, ocat_ta,
// fcnt_ta, ocnt_ta, cnt_logic,
// fwind_ta, owind_ta, wind_logic,
// eclv_points, cdf_info, ci_alpha
// boot_info, hira_info, rank_corr_flag,
// output_flag
//
if(!(beg_ds == v.beg_ds ) ||
!(end_ds == v.end_ds ) ||
!(land_flag == v.land_flag ) ||
!(topo_flag == v.topo_flag ) ||
!(mask_grid == v.mask_grid ) ||
!(mask_poly == v.mask_poly ) ||
!(mask_sid == v.mask_sid ) ||
!(mask_llpnt == v.mask_llpnt ) ||
!(mask_name == v.mask_name ) ||
!(interp_info == v.interp_info ) ||
!(msg_typ == v.msg_typ ) ||
!(duplicate_flag == v.duplicate_flag) ||
!(obs_summary == v.obs_summary ) ||
!(obs_perc == v.obs_perc )) {
match = false;
}
return(match);
}
////////////////////////////////////////////////////////////////////////
void PointStatVxOpt::process_config(GrdFileType ftype,
Dictionary &fdict, Dictionary &odict, bool cur_use_var_id) {
int i, n;
VarInfoFactory info_factory;
map<STATLineType,STATOutputType>output_map;
Dictionary *dict;
// Initialize
clear();
// Allocate new VarInfo objects
vx_pd.fcst_info = info_factory.new_var_info(ftype);
vx_pd.obs_info = new VarInfoGrib;
// Set the VarInfo objects
vx_pd.fcst_info->set_dict(fdict);
vx_pd.obs_info->set_dict(odict);
// Set the GRIB code for point observations
if(!cur_use_var_id) vx_pd.obs_info->add_grib_code(odict);
// Dump the contents of the current VarInfo
if(mlog.verbosity_level() >= 5) {
mlog << Debug(5)
<< "Parsed forecast field:\n";
vx_pd.fcst_info->dump(cout);
mlog << Debug(5)
<< "Parsed observation field:\n";
vx_pd.obs_info->dump(cout);
}
// Check the levels for the forecast and observation fields. If the
// forecast field is a range of pressure levels, check to see if the
// range of observation field pressure levels is wholly contained in the
// fcst levels. If not, print a warning message.
if(vx_pd.fcst_info->level().type() == LevelType_Pres &&
!is_eq(vx_pd.fcst_info->level().lower(), vx_pd.fcst_info->level().upper()) &&
(vx_pd.obs_info->level().lower() < vx_pd.fcst_info->level().lower() ||
vx_pd.obs_info->level().upper() > vx_pd.fcst_info->level().upper())) {
mlog << Warning
<< "\nPointStatVxOpt::process_config() -> "
<< "The range of requested observation pressure levels "
<< "is not contained within the range of requested "
<< "forecast pressure levels. No vertical interpolation "
<< "will be performed for observations falling outside "
<< "the range of forecast levels. Instead, they will be "
<< "matched to the single nearest forecast level.\n\n";
}
// No support for wind direction
if(vx_pd.fcst_info->is_wind_direction() ||
vx_pd.obs_info->is_wind_direction()) {
mlog << Error << "\nPointStatVxOpt::process_config() -> "
<< "wind direction may not be verified using point_stat.\n\n";
exit(1);
}
// Check that the observation field does not contain probabilities
if(vx_pd.obs_info->is_prob()) {
mlog << Error << "\nPointStatVxOpt::process_config() -> "
<< "the observation field cannot contain probabilities.\n\n";
exit(1);
}
// Conf: output_flag
output_map = parse_conf_output_flag(&odict, txt_file_type, n_txt);
// Populate the output_flag array with map values
for(i=0; i<n_txt; i++) output_flag[i] = output_map[txt_file_type[i]];
// Conf: beg_ds and end_ds
dict = odict.lookup_dictionary(conf_key_obs_window);
parse_conf_range_int(dict, beg_ds, end_ds);
// Conf: cat_thresh
fcat_ta = fdict.lookup_thresh_array(conf_key_cat_thresh);
ocat_ta = odict.lookup_thresh_array(conf_key_cat_thresh);
// Conf: cnt_thresh
fcnt_ta = process_perc_thresh_bins(
fdict.lookup_thresh_array(conf_key_cnt_thresh));
ocnt_ta = process_perc_thresh_bins(
odict.lookup_thresh_array(conf_key_cnt_thresh));
// Conf: cnt_logic
cnt_logic = check_setlogic(
int_to_setlogic(fdict.lookup_int(conf_key_cnt_logic)),
int_to_setlogic(odict.lookup_int(conf_key_cnt_logic)));
// Conf: wind_thresh
fwind_ta = process_perc_thresh_bins(
fdict.lookup_thresh_array(conf_key_wind_thresh));
owind_ta = process_perc_thresh_bins(
odict.lookup_thresh_array(conf_key_wind_thresh));
// Conf: wind_logic
wind_logic = check_setlogic(
int_to_setlogic(fdict.lookup_int(conf_key_wind_logic)),
int_to_setlogic(odict.lookup_int(conf_key_wind_logic)));
// Dump the contents of the current thresholds
if(mlog.verbosity_level() >= 5) {
mlog << Debug(5)
<< "Parsed thresholds:\n"
<< "Forecast categorical thresholds: " << fcat_ta.get_str() << "\n"
<< "Observed categorical thresholds: " << ocat_ta.get_str() << "\n"
<< "Forecast continuous thresholds: " << fcnt_ta.get_str() << "\n"
<< "Observed continuous thresholds: " << ocnt_ta.get_str() << "\n"
<< "Continuous threshold logic: " << setlogic_to_string(cnt_logic) << "\n"
<< "Forecast wind speed thresholds: " << fwind_ta.get_str() << "\n"
<< "Observed wind speed thresholds: " << owind_ta.get_str() << "\n"
<< "Wind speed threshold logic: " << setlogic_to_string(wind_logic) << "\n";
}
// Verifying a probability field
if(vx_pd.fcst_info->is_prob()) {
fcat_ta = string_to_prob_thresh(fcat_ta.get_str().c_str());
}
// Check for equal threshold length for non-probability fields
if(!vx_pd.fcst_info->is_prob() &&
fcat_ta.n() != ocat_ta.n()) {
mlog << Error << "\nPointStatVxOpt::process_config() -> "
<< "The number of thresholds for each field in \"fcst."
<< conf_key_cat_thresh
<< "\" must match the number of thresholds for each "
<< "field in \"obs." << conf_key_cat_thresh << "\".\n\n";
exit(1);
}
// Add default continuous thresholds until the counts match
n = max(fcnt_ta.n(), ocnt_ta.n());
while(fcnt_ta.n() < n) fcnt_ta.add(na_str);
while(ocnt_ta.n() < n) ocnt_ta.add(na_str);
// Add default wind speed thresholds until the counts match
n = max(fwind_ta.n(), owind_ta.n());
while(fwind_ta.n() < n) fwind_ta.add(na_str);
while(owind_ta.n() < n) owind_ta.add(na_str);
// Verifying with multi-category contingency tables
if(!vx_pd.fcst_info->is_prob() &&
(output_flag[i_mctc] != STATOutputType_None ||
output_flag[i_mcts] != STATOutputType_None)) {
check_mctc_thresh(fcat_ta);
check_mctc_thresh(ocat_ta);
}
// Conf: land.flag
land_flag = odict.lookup_bool(conf_key_land_mask_flag);
// Conf: topo.flag
topo_flag = odict.lookup_bool(conf_key_topo_mask_flag);
// Conf: mask_grid
mask_grid = odict.lookup_string_array(conf_key_mask_grid);
// Conf: mask_poly
mask_poly = odict.lookup_string_array(conf_key_mask_poly);
// Conf: mask_sid
mask_sid = odict.lookup_string_array(conf_key_mask_sid);
// Conf: mask_llpnt
mask_llpnt = parse_conf_llpnt_mask(&odict);
// Conf: eclv_points
eclv_points = parse_conf_eclv_points(&odict);
// Conf: climo_cdf
cdf_info = parse_conf_climo_cdf(&odict);
// Conf: ci_alpha
ci_alpha = parse_conf_ci_alpha(&odict);
// Conf: boot
boot_info = parse_conf_boot(&odict);
// Conf: interp
interp_info = parse_conf_interp(&odict, conf_key_interp);
// Conf: hira
hira_info = parse_conf_hira(&odict);
// Conf: rank_corr_flag
rank_corr_flag = odict.lookup_bool(conf_key_rank_corr_flag);
// Conf: message_type
msg_typ = parse_conf_message_type(&odict);
// Conf: duplicate_flag
duplicate_flag = parse_conf_duplicate_flag(&odict);
// Conf: obs_summary
obs_summary = parse_conf_obs_summary(&odict);
// Conf: obs_perc_value
obs_perc = parse_conf_percentile(&odict);
// Conf: desc
vx_pd.set_desc(parse_conf_string(&odict, conf_key_desc).c_str());
// Conf: sid_inc
vx_pd.set_sid_inc_filt(parse_conf_sid_list(&odict, conf_key_sid_inc));
// Conf: sid_exc
vx_pd.set_sid_exc_filt(parse_conf_sid_list(&odict, conf_key_sid_exc));
// Conf: obs_qty
vx_pd.set_obs_qty_filt(parse_conf_obs_qty(&odict));
return;
}
////////////////////////////////////////////////////////////////////////
void PointStatVxOpt::set_vx_pd(PointStatConfInfo *conf_info) {
int i, n;
int n_msg_typ = msg_typ.n();
int n_mask = mask_name.n();
int n_interp = interp_info.n_interp;
ConcatString cs;
StringArray sa;
// Setup the VxPairDataPoint object with these dimensions:
// [n_msg_typ][n_mask][n_interp]
// Check for at least one message type
if(n_msg_typ == 0) {
mlog << Error << "\nPointStatVxOpt::set_vx_pd() -> "
<< "At least one output message type must be requested in \""
<< conf_key_message_type << "\".\n\n";
exit(1);
}
// Check for at least one masking region
if(n_mask == 0) {
mlog << Error << "\nPointStatVxOpt::set_vx_pd() -> "
<< "At least one output masking region must be requested in \""
<< conf_key_mask_grid << "\", \""
<< conf_key_mask_poly << "\", \""
<< conf_key_mask_sid << "\", or \""
<< conf_key_mask_llpnt << "\".\n\n";
exit(1);
}
// Check for at least one interpolation method
if(n_interp == 0) {
mlog << Error << "\nPointStatVxOpt::set_vx_pd() -> "
<< "At least one interpolation method must be requested in \""
<< conf_key_interp << "\".\n\n";
exit(1);
}
// Define the dimensions
vx_pd.set_pd_size(n_msg_typ, n_mask, n_interp);
// Store the surface message type group
cs = surface_msg_typ_group_str;
if(conf_info->msg_typ_group_map.count(cs) == 0) {
mlog << Error << "\nPointStatVxOpt::set_vx_pd() -> "
<< "\"" << conf_key_message_type_group_map
<< "\" must contain an entry for \"" << cs << "\".\n\n";
exit(1);
}
else {
vx_pd.set_msg_typ_sfc(conf_info->msg_typ_group_map[cs]);
}
// Store the surface land message type group
cs = landsf_msg_typ_group_str;
if(conf_info->msg_typ_group_map.count(cs) == 0) {
mlog << Error << "\nPointStatVxOpt::set_vx_pd() -> "
<< "\"" << conf_key_message_type_group_map
<< "\" must contain an entry for \"" << cs << "\".\n\n";
exit(1);
}
else {
vx_pd.set_msg_typ_lnd(conf_info->msg_typ_group_map[cs]);
}
// Store the surface water message type group
cs = watersf_msg_typ_group_str;
if(conf_info->msg_typ_group_map.count(cs) == 0) {
mlog << Error << "\nPointStatVxOpt::set_vx_pd() -> "
<< "\"" << conf_key_message_type_group_map
<< "\" must contain an entry for \"" << cs << "\".\n\n";
exit(1);
}
else {
vx_pd.set_msg_typ_wtr(conf_info->msg_typ_group_map[cs]);
}
// Define the verifying message type name and values
for(i=0; i<n_msg_typ; i++) {
vx_pd.set_msg_typ(i, msg_typ[i].c_str());
sa = conf_info->msg_typ_group_map[msg_typ[i]];
if(sa.n() == 0) sa.add(msg_typ[i]);
vx_pd.set_msg_typ_vals(i, sa);
}
// Define the masking information: grid, poly, sid, point
// Define the grid masks
for(i=0; i<mask_grid.n(); i++) {
n = i;
vx_pd.set_mask_area(n, mask_name[n].c_str(),
&(conf_info->mask_area_map[mask_name[n]]));
}
// Define the poly masks
for(i=0; i<mask_poly.n(); i++) {
n = i + mask_grid.n();
vx_pd.set_mask_area(n, mask_name[n].c_str(),
&(conf_info->mask_area_map[mask_name[n]]));
}
// Define the station ID masks
for(i=0; i<mask_sid.n(); i++) {
n = i + mask_grid.n() + mask_poly.n();
vx_pd.set_mask_sid(n, mask_name[n].c_str(),
&(conf_info->mask_sid_map[mask_name[n]]));
}