Skip to content

Commit

Permalink
Per #1809, use ProbGenPCTInfo to store pointers to the individual mat…
Browse files Browse the repository at this point in the history
…ched pair objects. This is cleaner than the last kludgy solution.
  • Loading branch information
JohnHalleyGotway committed Nov 13, 2021
1 parent b9dd9f0 commit ac1045c
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 53 deletions.
63 changes: 33 additions & 30 deletions met/src/tools/tc_utils/tc_gen/tc_gen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static int find_genesis_match (const GenesisInfo &,
const GenesisInfoArray &,
const TrackInfoArray &,
bool, double, int, int);
static void find_probgen_match (ProbGenInfo &,
static int find_probgen_match (const ProbGenInfo &,
const GenesisInfoArray &,
const TrackInfoArray &,
bool, double, int, int);
Expand Down Expand Up @@ -737,8 +737,9 @@ void do_probgen_pct(const TCGenVxOpt &vx_opt,
const GenesisInfoArray &best_ga,
const TrackInfoArray &oper_ta,
ProbGenPCTInfo &pgi) {
int i, j, time_diff;
int i, i_bga, j, time_diff;
bool is_event;
const GenesisInfo *bgi;

// Initialize
pgi.clear();
Expand All @@ -748,18 +749,23 @@ void do_probgen_pct(const TCGenVxOpt &vx_opt,
for(i=0; i<model_pa.n_prob_gen(); i++) {

// Search for a BEST track match
find_probgen_match(model_pa.prob_gen(i), best_ga, oper_ta,
vx_opt.GenesisMatchPointTrack,
vx_opt.GenesisMatchRadius,
vx_opt.GenesisMatchBeg,
vx_opt.GenesisMatchEnd);
i_bga = find_probgen_match(model_pa.prob_gen(i), best_ga, oper_ta,
vx_opt.GenesisMatchPointTrack,
vx_opt.GenesisMatchRadius,
vx_opt.GenesisMatchBeg,
vx_opt.GenesisMatchEnd);

// Pointer to the matching BEST track
bgi = (is_bad_data(i_bga) ?
(const GenesisInfo *) 0 :
&best_ga[i_bga]);

// Loop over the individual probabilities
for(j=0; j<model_pa.prob_gen(i).n_prob(); j++) {

// Event verifies is the BEST genesis occurs in the specified time window
if(model_pa.prob_gen(i).best_gen()) {
time_diff = model_pa.prob_gen(i).best_gen()->genesis_time() -
if(bgi) {
time_diff = bgi->genesis_time() -
model_pa.prob_gen(i).init();
is_event = time_diff >= 0 &&
time_diff <= (model_pa.prob_gen(i).prob_item(j) * sec_per_hour);
Expand All @@ -769,7 +775,7 @@ void do_probgen_pct(const TCGenVxOpt &vx_opt,
}

// Store pair info
pgi.add(model_pa.prob_gen(i), j, is_event);
pgi.add(model_pa.prob_gen(i), j, bgi, is_event);

} // end for j
} // end for i
Expand All @@ -780,9 +786,9 @@ void do_probgen_pct(const TCGenVxOpt &vx_opt,

////////////////////////////////////////////////////////////////////////

int find_genesis_match(const GenesisInfo &fcst_gi,
int find_genesis_match(const GenesisInfo &fcst_gi,
const GenesisInfoArray &bga,
const TrackInfoArray &ota,
const TrackInfoArray &ota,
bool point2track, double rad,
int beg, int end) {
int i, j, i_best, i_oper;
Expand Down Expand Up @@ -868,11 +874,11 @@ int find_genesis_match(const GenesisInfo &fcst_gi,

////////////////////////////////////////////////////////////////////////

void find_probgen_match(ProbGenInfo &prob_gi,
const GenesisInfoArray &bga,
const TrackInfoArray &ota,
bool point2track, double rad,
int beg, int end) {
int find_probgen_match(const ProbGenInfo &prob_gi,
const GenesisInfoArray &bga,
const TrackInfoArray &ota,
bool point2track, double rad,
int beg, int end) {
int i, j, i_best, i_oper;

ConcatString case_cs;
Expand Down Expand Up @@ -950,11 +956,7 @@ void find_probgen_match(ProbGenInfo &prob_gi,
<< " has NO MATCH in the BEST or operational tracks.\n";
}

// Store a pointer to the match
if(!is_bad_data(i_best)) prob_gi.set_best_gen(&bga[i_best]);
else prob_gi.set_best_gen((GenesisInfo *) 0);

return;
return(i_best);
}


Expand Down Expand Up @@ -1903,11 +1905,11 @@ void write_pct_genmpr_row(StatHdrColumns &shc,
shc.set_alpha(bad_data_double);

// Write a line for each matched pair
for(i=0; i<pgi.PGIMap[lead_hr].size(); i++) {
for(i=0; i<pgi.FcstGenMap[lead_hr].size(); i++) {

// Pointers for current case
const ProbGenInfo *fgi = pgi.PGIMap[lead_hr][i];
const GenesisInfo *bgi = fgi->best_gen();
const ProbGenInfo *fgi = pgi.FcstGenMap[lead_hr][i];
const GenesisInfo *bgi = pgi.BestGenMap[lead_hr][i];

// Store timing info
shc.set_fcst_lead_sec(fgi->genesis_lead());
Expand Down Expand Up @@ -1949,9 +1951,10 @@ void write_pct_genmpr_row(StatHdrColumns &shc,
AsciiTable &at, int r, int c) {

// Pointers for current case
const ProbGenInfo *fgi = pgi.PGIMap[lead_hr][index];
const GenesisInfo *bgi = fgi->best_gen();
int i_prob = pgi.IdxMap[lead_hr][index];
const ProbGenInfo *fgi = pgi.FcstGenMap[lead_hr][index];
const GenesisInfo *bgi = pgi.BestGenMap[lead_hr][index];

int i_prob = pgi.FcstIdxMap[lead_hr][index];

//
// Genesis Matched Pairs (GENMPR):
Expand All @@ -1965,7 +1968,7 @@ void write_pct_genmpr_row(StatHdrColumns &shc,
//

at.set_entry(r, c+0, // Total number of pairs
(int) pgi.PGIMap[lead_hr].size());
(int) pgi.FcstGenMap[lead_hr].size());

at.set_entry(r, c+1, // Index of current pair
index+1);
Expand Down Expand Up @@ -2016,7 +2019,7 @@ void write_pct_genmpr_row(StatHdrColumns &shc,
na_str);

at.set_entry(r, c+17, // Operational category
(pgi.EvtMap[lead_hr][index] ? "FY_OY" : "FY_ON" ));
(pgi.BestEvtMap[lead_hr][index] ? "FYOY" : "FYON" ));

return;
}
Expand Down
45 changes: 26 additions & 19 deletions met/src/tools/tc_utils/tc_gen/tc_gen_conf_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1246,9 +1246,10 @@ void ProbGenPCTInfo::clear() {
BestBeg = BestEnd = (unixtime) 0;

PCTMap.clear();
PGIMap.clear();
IdxMap.clear();
EvtMap.clear();
FcstGenMap.clear();
FcstIdxMap.clear();
BestGenMap.clear();
BestEvtMap.clear();

VxOpt = (const TCGenVxOpt *) 0;
LeadTimes.clear();
Expand All @@ -1275,45 +1276,51 @@ void ProbGenPCTInfo::set_vx_opt(const TCGenVxOpt *vx_opt) {

////////////////////////////////////////////////////////////////////////

void ProbGenPCTInfo::add(const ProbGenInfo &pgi, int index, bool is_event) {
void ProbGenPCTInfo::add(const ProbGenInfo &fgi, int index,
const GenesisInfo *bgi, bool is_event) {
int i;
unixtime ut;

// Store the model name
if(Model.empty()) Model = pgi.technique();
if(Model.empty()) Model = fgi.technique();

// Track the range of forecast initalization times
if(InitBeg == 0 || InitBeg > pgi.init()) InitBeg = pgi.init();
if(InitEnd == 0 || InitEnd < pgi.init()) InitEnd = pgi.init();
ut = fgi.init();
if(InitBeg == 0 || InitBeg > ut) InitBeg = ut;
if(InitEnd == 0 || InitEnd < ut) InitEnd = ut;

// Track the range of verifying BEST genesis events
if(pgi.best_gen()) {
unixtime ut = pgi.best_gen()->genesis_time();
if(bgi) {
ut = bgi->genesis_time();
if(BestBeg == 0 || BestBeg > ut) BestBeg = ut;
if(BestEnd == 0 || BestEnd < ut) BestEnd = ut;
}

// Current lead time and probability value
int lead_hr = nint(pgi.prob_item(index));
double prob = pgi.prob(index) / 100.0;
int lead_hr = nint(fgi.prob_item(index));
double prob = fgi.prob(index) / 100.0;

// Add new map entries, if needed
if(!LeadTimes.has(lead_hr)) {

LeadTimes.add(lead_hr);
vector<const ProbGenInfo *> empty_pgi;
vector<const ProbGenInfo *> empty_fgi;
vector<int> empty_idx;
vector<const GenesisInfo *> empty_bgi;
vector<bool> empty_evt;

PCTMap[lead_hr] = DefaultPCT;
PGIMap[lead_hr] = empty_pgi;
IdxMap[lead_hr] = empty_idx;
EvtMap[lead_hr] = empty_evt;
PCTMap [lead_hr] = DefaultPCT;
FcstGenMap[lead_hr] = empty_fgi;
FcstIdxMap[lead_hr] = empty_idx;
BestGenMap[lead_hr] = empty_bgi;
BestEvtMap[lead_hr] = empty_evt;
}

// Update map entries
PGIMap[lead_hr].push_back(&pgi);
IdxMap[lead_hr].push_back(index);
EvtMap[lead_hr].push_back(is_event);
FcstGenMap[lead_hr].push_back(&fgi);
FcstIdxMap[lead_hr].push_back(index);
BestGenMap[lead_hr].push_back(bgi);
BestEvtMap[lead_hr].push_back(is_event);

// Increment counts
if(is_event) PCTMap[lead_hr].pct.inc_event (prob);
Expand Down
10 changes: 6 additions & 4 deletions met/src/tools/tc_utils/tc_gen/tc_gen_conf_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,17 +340,19 @@ class ProbGenPCTInfo {
map<int,PCTInfo> PCTMap;

// Map of lead times to vectors of pair info
map<int,vector<const ProbGenInfo *>> PGIMap;
map<int,vector<int>> IdxMap;
map<int,vector<bool>> EvtMap;
map<int,vector<const ProbGenInfo *>> FcstGenMap;
map<int,vector<int>> FcstIdxMap;
map<int,vector<const GenesisInfo *>> BestGenMap;
map<int,vector<bool>> BestEvtMap;

//////////////////////////////////////////////////////////////////

void clear();

void set_vx_opt(const TCGenVxOpt *);

void add(const ProbGenInfo &, int, bool);
void add(const ProbGenInfo &, int,
const GenesisInfo *, bool);

};

Expand Down

0 comments on commit ac1045c

Please sign in to comment.