Skip to content

Commit

Permalink
Per #2339, update stat_analysis to support -job aggregate_stat -line_…
Browse files Browse the repository at this point in the history
…type SEEPS_MPR -out_line_type SEEPS. While this runs, I still need to test it.
  • Loading branch information
JohnHalleyGotway committed Nov 12, 2022
1 parent 23f0d79 commit b90e0c7
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 12 deletions.
95 changes: 95 additions & 0 deletions src/tools/core/stat_analysis/aggr_stat_line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3439,6 +3439,101 @@ void aggr_seeps_lines(LineDataFile &f, STATAnalysisJob &job,
return;
}


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

void aggr_seeps_mpr_lines(LineDataFile &f, STATAnalysisJob &job,
map<ConcatString, AggrSEEPSMPRInfo> &m,
int &n_in, int &n_out) {
STATLine line;
AggrSEEPSMPRInfo aggr;
SEEPSMPRData cur;
ConcatString key, fcst_var, obs_var;

//
// Process the STAT lines
//
while(f >> line) {

if(line.is_header()) continue;

n_in++;

if(job.is_keeper(line)) {

job.dump_stat_line(line);

if(line.type() != stat_seeps_mpr) {
mlog << Error << "\naggr_seeps_mpr_lines() -> "
<< "should only encounter SEEPS_MPR line types.\n"
<< "ERROR occurred on STAT line:\n" << line << "\n\n";
throw(1);
}

//
// Only aggregate consistent variable names
//
if(fcst_var.empty()) fcst_var = line.fcst_var();
if(obs_var.empty()) obs_var = line.obs_var();

if(fcst_var != line.fcst_var() ||
obs_var != line.obs_var()) {
mlog << Error << "\naggr_seeps_mpr_lines() -> "
<< "both the forecast and observation variable types must "
<< "remain constant. Try setting \"-fcst_var\" and/or "
<< "\"-obs_var\".\n"
<< "ERROR occurred on STAT line:\n" << line << "\n\n";
throw(1);
}

//
// Parse the current SSVAR line
//
parse_seeps_mpr_line(line, cur);

//
// Build the map key for the current line
//
key = job.get_case_info(line);

//
// Add a new map entry, if necessary
//
if(m.count(key) == 0) {
aggr.pd.n_obs = 0;
aggr.pd.f_na.clear();
aggr.pd.o_na.clear();
aggr.pd.seeps_mpr.clear();
aggr.hdr.clear();
m[key] = aggr;
}

//
// Increment counts
//
m[key].pd.n_obs += 1;
m[key].pd.f_na.add(cur.fcst);
m[key].pd.o_na.add(cur.obs);
m[key].pd.lat_na.add(cur.obs_lat);
m[key].pd.lon_na.add(cur.obs_lon);

// Allocated here but deallocated by PairDataPoint
SeepsScore *score = new SeepsScore;
*score = cur.seeps_mpr;
m[key].pd.seeps_mpr.push_back(score);

//
// Keep track of the unique header column entries
//
m[key].hdr.add(line);

n_out++;
}
} // end while

return;
}

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

void aggr_time_series_lines(LineDataFile &f, STATAnalysisJob &job,
Expand Down
10 changes: 10 additions & 0 deletions src/tools/core/stat_analysis/aggr_stat_line.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ struct AggrSEEPSInfo {
SeepsAggScore agg_score;
};

struct AggrSEEPSMPRInfo {
StatHdrInfo hdr;
PairDataPoint pd;
};

struct AggrTimeSeriesInfo {
StatHdrInfo hdr;
ConcatString fcst_var, obs_var;
Expand Down Expand Up @@ -300,6 +305,11 @@ extern void aggr_seeps_lines(
std::map<ConcatString, AggrSEEPSInfo> &,
int &, int &);

extern void aggr_seeps_mpr_lines(
LineDataFile &, STATAnalysisJob &,
std::map<ConcatString, AggrSEEPSMPRInfo> &,
int &, int &);

extern void aggr_time_series_lines(
LineDataFile &, STATAnalysisJob &,
std::map<ConcatString, AggrTimeSeriesInfo> &,
Expand Down
3 changes: 0 additions & 3 deletions src/tools/core/stat_analysis/parse_stat_line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,6 @@ void parse_seeps_line(STATLine &l, SeepsAggScore &agg_score) {

void parse_seeps_mpr_line(STATLine &l, SEEPSMPRData &s_data) {

s_data.fcst_var = l.fcst_var();
s_data.obs_var = l.obs_var();

s_data.obs_sid = l.get_item("OBS_SID");
s_data.obs_lat = atof(l.get_item("OBS_LAT"));
s_data.obs_lon = atof(l.get_item("OBS_LON"));
Expand Down
2 changes: 0 additions & 2 deletions src/tools/core/stat_analysis/parse_stat_line.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ struct ORANKData {

// SEEPS Matched Pair (SEEPS_MPR) data structure
struct SEEPSMPRData {
ConcatString fcst_var;
ConcatString obs_var;
ConcatString obs_sid, obs_qc;
double obs_lat, obs_lon, fcst, obs;
SeepsScore seeps_mpr;
Expand Down
101 changes: 94 additions & 7 deletions src/tools/core/stat_analysis/stat_analysis_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -621,13 +621,14 @@ void do_job_aggr_stat(const ConcatString &jobstring, LineDataFile &f,
AsciiTable out_at;
int i, n;

map<ConcatString, AggrCTCInfo> ctc_map;
map<ConcatString, AggrMCTCInfo> mctc_map;
map<ConcatString, AggrPCTInfo> pct_map;
map<ConcatString, AggrPSumInfo> psum_map;
map<ConcatString, AggrWindInfo> wind_map;
map<ConcatString, AggrENSInfo> orank_map;
map<ConcatString, AggrMPRInfo> mpr_map;
map<ConcatString, AggrCTCInfo> ctc_map;
map<ConcatString, AggrMCTCInfo> mctc_map;
map<ConcatString, AggrPCTInfo> pct_map;
map<ConcatString, AggrPSumInfo> psum_map;
map<ConcatString, AggrWindInfo> wind_map;
map<ConcatString, AggrENSInfo> orank_map;
map<ConcatString, AggrMPRInfo> mpr_map;
map<ConcatString, AggrSEEPSMPRInfo> seeps_mpr_map;

//
// Check that the -line_type and -out_line_type options have been
Expand Down Expand Up @@ -670,6 +671,7 @@ void do_job_aggr_stat(const ConcatString &jobstring, LineDataFile &f,
// PCT, PSTD, PJC, PRC, ECLV,
// WDIR (wind direction)
// -line_type ORANK, -out_line_type RHIST, PHIST, RELP, SSVAR
// -line_type SEEPS_MPR, -out_line_type SEEPS
//

//
Expand Down Expand Up @@ -822,6 +824,21 @@ void do_job_aggr_stat(const ConcatString &jobstring, LineDataFile &f,
}
}

//
// Sum the SEEPS_MPR lines:
// SEEPS_MPR -> SEEPS
//
else if(in_lt == stat_seeps_mpr &&
has_line_type(out_lt, stat_seeps)) {

aggr_seeps_mpr_lines(f, job, seeps_mpr_map, n_in, n_out);
for(it=out_lt.begin(); it!=out_lt.end(); it++) {
write_job_aggr_seeps_mpr(job, *it, seeps_mpr_map, out_at);
if(!job.stat_out) write_table(out_at, sa_out);
}
}


//
// Read the matched pair lines:
// MPR -> FHO, CTC, CTS, MCTC, MCTS, CNT,
Expand Down Expand Up @@ -2753,6 +2770,76 @@ void write_job_aggr_seeps(STATAnalysisJob &job, STATLineType lt,

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

void write_job_aggr_seeps_mpr(STATAnalysisJob &job, STATLineType lt,
map<ConcatString, AggrSEEPSMPRInfo> &m,
AsciiTable &at) {
map<ConcatString, AggrSEEPSMPRInfo>::iterator it;
int n, n_row, n_col, r, c;
StatHdrColumns shc;
SeepsAggScore agg_score;

//
// Setup the output table
//
n_row = 1 + m.size();
n_col = 1 + job.by_column.n() + n_seeps_columns;
write_job_aggr_hdr(job, n_row, n_col, at);

//
// Write the rest of the header row
//
c = 1 + job.by_column.n();
write_header_row(seeps_columns, n_seeps_columns, 0, at, 0, c);

//
// Setup the output STAT file
//
job.setup_stat_file(n_row, n);

mlog << Debug(2) << "Computing output for "
<< (int) m.size() << " case(s).\n";

//
// Loop through the map
//
for(it = m.begin(), r=1; it != m.end(); it++) {

//
// Write the output STAT header columns
//
shc = it->second.hdr.get_shc(it->first, job.by_column,
job.hdr_name, job.hdr_value, lt);

//
// Initialize
//
c = 0;

//
// Compute the aggregated SEEPS score
//
compute_aggregated_seeps(&it->second.pd, &agg_score);

//
// SEEPS output line
//
if(job.stat_out) {
write_header_cols(shc, job.stat_at, job.stat_row);
write_seeps_cols(&agg_score, job.stat_at,
job.stat_row++, n_header_columns);
}
else {
at.set_entry(r, c++, "SEEPS:");
write_case_cols(it->first, at, r, c);
write_seeps_cols(&agg_score, at, r++, c);
}
} // end for it

return;
}

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

void write_job_aggr_orank(STATAnalysisJob &job, STATLineType lt,
map<ConcatString, AggrENSInfo> &m,
AsciiTable &at, gsl_rng *rng_ptr) {
Expand Down
3 changes: 3 additions & 0 deletions src/tools/core/stat_analysis/stat_analysis_job.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ extern void write_job_aggr_ssvar(STATAnalysisJob &, STATLineType,
extern void write_job_aggr_seeps(STATAnalysisJob &, STATLineType,
std::map<ConcatString, AggrSEEPSInfo> &, AsciiTable &);

extern void write_job_aggr_seeps_mpr(STATAnalysisJob &, STATLineType,
std::map<ConcatString, AggrSEEPSMPRInfo> &, AsciiTable &);

extern void write_job_aggr_orank(STATAnalysisJob &, STATLineType,
std::map<ConcatString, AggrENSInfo> &, AsciiTable &,
gsl_rng *);
Expand Down

0 comments on commit b90e0c7

Please sign in to comment.