Skip to content

Commit

Permalink
Per #2882, get branch feature_2882_seeps_qa compiling again. Recommen…
Browse files Browse the repository at this point in the history
…d revisiting the volume of SEEPS-related Debug log messages and reducing them once its fully tested.
  • Loading branch information
JohnHalleyGotway committed Aug 14, 2024
1 parent 486ce9d commit 606ff74
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 61 deletions.
146 changes: 105 additions & 41 deletions src/libcode/vx_seeps/seeps.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ void SeepsAggScore::clear() {
////////////////////////////////////////////////////////////////////////

SeepsAggScore & SeepsAggScore::operator+=(const SeepsAggScore &c) {
const char *method_name = "SeepsAggScore::operator+=() -> ";

// Check for degenerate case
if(n_obs == 0 && c.n_obs == 0) return *this;
Expand All @@ -139,8 +140,10 @@ SeepsAggScore & SeepsAggScore::operator+=(const SeepsAggScore &c) {
s_olfh = weighted_average(s_olfh, w1, c.s_olfh, w2);
s_ohfd = weighted_average(s_ohfd, w1, c.s_ohfd, w2);
s_ohfl = weighted_average(s_ohfl, w1, c.s_ohfl, w2);
mlog << Debug(9) << "SEEPS 155: " << s_odfl << " " << s_odfh << "\n";

mlog << Debug(9) << method_name
<< "s_odfl, o_odfh => "
<< s_odfl << " " << s_odfh << "\n";

pv1 = weighted_average(pv1, w1, c.pv1, w2);
pv2 = weighted_average(pv2, w1, c.pv2, w2);
pv3 = weighted_average(pv3, w1, c.pv3, w2);
Expand Down Expand Up @@ -197,7 +200,8 @@ ConcatString SeepsClimoBase::get_climo_filename() {

seeps_ready = file_exists(seeps_filename.c_str());
if (seeps_ready) {
mlog << Debug(7) << method_name << "SEEPS climo name=\""
mlog << Debug(7) << method_name
<< "SEEPS climo name=\""
<< seeps_filename.c_str() << "\"\n";
}
else {
Expand Down Expand Up @@ -273,13 +277,17 @@ SeepsClimoRecord *SeepsClimo::create_climo_record(
double *p1, double *p2, double *t1, double *t2, double *scores) {
int offset;
SeepsClimoRecord *record = new SeepsClimoRecord();
const char *method_name = "SeepsClimo::create_climo_record() -> ";

record->sid = sid;
record->lat = lat;
record->lon = lon;
record->elv = elv;
if (standalone_debug_seeps && SAMPLE_STATION_ID == sid) {
cout << " sid=" << sid << ", lat=" << lat << ", lon=" << lon << ", elv=" << elv << "\n";
cout << method_name
<< "sid=" << sid << ", lat=" << lat
<< ", lon=" << lon << ", elv=" << elv
<< "\n";
}
for (int idx=0; idx<SEEPS_MONTH; idx++) {
record->p1[idx] = p1[idx];
Expand All @@ -288,15 +296,17 @@ SeepsClimoRecord *SeepsClimo::create_climo_record(
record->t2[idx] = t2[idx];

if (standalone_debug_seeps && SAMPLE_STATION_ID == sid) {
cout << str_format("\t%2d: %6.3f %6.3f %6.3f %6.3f ",
cout << method_name
<< str_format("\t%2d: %6.3f %6.3f %6.3f %6.3f ",
(idx+1), record->p1[idx], record->p2[idx],
record->t1[idx], record->t2[idx]);
}
for (int idx_m=0; idx_m<SEEPS_MATRIX_SIZE; idx_m++) {
offset = idx*SEEPS_MATRIX_SIZE + idx_m;
record->scores[idx][idx_m] = scores[offset];
if (standalone_debug_seeps && SAMPLE_STATION_ID == sid) {
cout << str_format(" %.3f", record->scores[idx][idx_m]);
cout << method_name
<< str_format(" %.3f", record->scores[idx][idx_m]);
}
}
if (standalone_debug_seeps && SAMPLE_STATION_ID == sid) cout << "\n";
Expand Down Expand Up @@ -335,18 +345,24 @@ SeepsRecord *SeepsClimo::get_record(int sid, int month, int hour) {
record->p2 = climo_record->p2[month-1];
record->t1 = climo_record->t1[month-1];
record->t2 = climo_record->t2[month-1];
mlog << Debug(9) << "SEEPS.cc 352 record info: sid, lat, lon, month, p1, p2, t1, t2 => "
<< record->sid << " " << record->lat << " " << record->lon << " " << record->month
<< " " << record->p1 << " " << record->p2 << " " << record->t1 << " " << record->t2 <<"\n";
mlog << Debug(9) << method_name
<< "record info: sid, lat, lon, month, p1, p2, t1, t2 => "
<< record->sid << " " << record->lat << " "
<< record->lon << " " << record->month << " "
<< record->p1 << " " << record->p2 << " "
<< record->t1 << " " << record->t2 << "\n";
for (int idx=0; idx<SEEPS_MATRIX_SIZE; idx++) {
record->scores[idx] = climo_record->scores[month-1][idx];
mlog << Debug(7) << "SEEPS.cc 356 record info (SEEPS matrix): score => " << record->scores[idx] <<"\n";
mlog << Debug(7) << method_name
<< "record info (SEEPS matrix): score => "
<< record->scores[idx] << "\n";
}
}
else if (!is_eq(p1, bad_data_double)) {
increase_filtered_count();
mlog << Debug(7) << method_name << " filtered by threshold p1="
<< climo_record->p1[month-1] <<"\n";
mlog << Debug(7) << method_name
<< "filtered by threshold p1="
<< climo_record->p1[month-1] << "\n";
}
}
}
Expand All @@ -358,7 +374,8 @@ SeepsRecord *SeepsClimo::get_record(int sid, int month, int hour) {
<< "or disable output for SEEPS and SEEPS_MPR.\n\n";
exit(1);
}
mlog << Debug(9) << "get_record() -> sid = " << sid
mlog << Debug(9) << method_name
<< "sid = " << sid
<< ", month = " << month << ", hour = " << hour
<< ", filtered_count = " << get_filtered_count() << "\n";

Expand All @@ -371,14 +388,18 @@ double SeepsClimo::get_seeps_category(int sid, double p_fcst, double p_obs,
int month, int hour) {
double score = bad_data_double;
SeepsRecord *record = get_record(sid, month, hour);
const char *method_name = "SeepsClimo::get_seeps_category() -> ";

if (nullptr != record) {
// Determine location in contingency table
int ic = (p_obs>record->t1)+(p_obs>record->t2);
int jc = (p_fcst>record->t1)+(p_fcst>record->t2);

score = record->scores[(jc*3)+ic];
mlog << Debug(9) << "seeps.cc 392 " << ic << " " << jc << " " << score << "\n";
mlog << Debug(9) << method_name
<< "ic, jc, score => "
<< ic << " " << jc << " "
<< score << "\n";
delete record;
}

Expand All @@ -391,27 +412,35 @@ SeepsScore *SeepsClimo::get_seeps_score(int sid, double p_fcst, double p_obs,
int month, int hour) {
SeepsScore *score = nullptr;
SeepsRecord *record = get_record(sid, month, hour);
const char *method_name = "SeepsClimo::get_seeps_score() -> ";

if (nullptr != record) {
score = new SeepsScore();
score->p1 = record->p1;
score->p2 = record->p2;
score->t1 = record->t1;
score->t2 = record->t2;
mlog << Debug(9) << "seeps.cc 412: p1, p2, t1, t2 " << score->p1 << " " << score->p2 << " " << score->t1 << " " << score->t2 << " " << "\n";
mlog << Debug(9) << method_name
<< "p1, p2, t1, t2 => "
<< score->p1 << " " << score->p2 << " "
<< score->t1 << " " << score->t2
<< "\n";

score->obs_cat = (p_obs>record->t1)+(p_obs>record->t2);
score->fcst_cat = (p_fcst>record->t1)+(p_fcst>record->t2);
score->s_idx = (score->fcst_cat*3)+score->obs_cat;
score->score = record->scores[score->s_idx];
mlog << Debug(9) << "seeps.cc 418: obs_cat, fc_cat, s_idx, score " << score->obs_cat << " " << score->fcst_cat << " " << score->s_idx << " " << score->score << " " << "\n";
mlog << Debug(9) << method_name
<< "obs_cat, fc_cat, s_idx, score => "
<< score->obs_cat << " " << score->fcst_cat
<< " " << score->s_idx << " " << score->score
<< "\n";
delete record;
}

return score;
}


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

void SeepsClimo::print_all() {
Expand Down Expand Up @@ -472,9 +501,9 @@ void SeepsClimo::print_record(SeepsRecord *record, bool with_header) {

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

void SeepsClimo::read_seeps_climo(ConcatString filename) {
void SeepsClimo::read_seeps_climo_grid(ConcatString filename) {
clock_t clock_time = clock();
const char *method_name = "SeepsClimo::read_records() -> ";
const char *method_name = "SeepsClimo::read_seeps_climo_grid() -> ";

try {
double p1_00_buf[SEEPS_MONTH];
Expand All @@ -493,8 +522,12 @@ void SeepsClimo::read_seeps_climo(ConcatString filename) {

// dimensions: month = 12 ; nstn = 5293 ; nmatrix = 9 ;
get_dim(nc_file, dim_name_nstn, nstn, true);
mlog << Debug(6) << method_name << "dimensions nstn = " << nstn << "\n";
if (standalone_debug_seeps) cout << "dimensions nstn = " << nstn << "\n";
mlog << Debug(6) << method_name
<< "dimensions nstn = " << nstn << "\n";
if (standalone_debug_seeps) {
cout << method_name
<< "dimensions nstn = " << nstn << "\n";
}

int *sid_array = new int[nstn];
double *lat_array = new double[nstn];
Expand Down Expand Up @@ -644,8 +677,12 @@ void SeepsClimo::read_seeps_climo(ConcatString filename) {
nc_file->close();

float duration = (float)(clock() - clock_time)/CLOCKS_PER_SEC;
mlog << Debug(6) << method_name << "took " << duration << " seconds\n";
if (standalone_debug_seeps) cout << method_name << "took " << duration << " seconds\n";
mlog << Debug(6) << method_name
<< "took " << duration << " seconds\n";
if (standalone_debug_seeps) {
cout << method_name
<< "took " << duration << " seconds\n";
}
}
catch(int i_err) {

Expand Down Expand Up @@ -680,15 +717,28 @@ SeepsClimoGrid::~SeepsClimoGrid() {
////////////////////////////////////////////////////////////////////////

void SeepsClimoGrid::init_from_scratch() {
p1_buf = p2_buf = t1_buf = t2_buf = nullptr;
s12_buf = s13_buf = s21_buf = s23_buf = s31_buf = s32_buf = nullptr;

// Initialize pointers
p1_buf = nullptr;
p2_buf = nullptr;
t1_buf = nullptr;
t2_buf = nullptr;
s_odfl_buf = nullptr;
s_odfh_buf = nullptr;
s_olfd_buf = nullptr;
s_olfh_buf = nullptr;
s_ohfd_buf = nullptr;
s_ohfl_buf = nullptr;

clear();
}

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

void SeepsClimoGrid::clear() {

SeepsClimoBase::clear();

if (nullptr != p1_buf) { delete [] p1_buf; p1_buf = nullptr; }
if (nullptr != p2_buf) { delete [] p2_buf; p2_buf = nullptr; }
if (nullptr != t1_buf) { delete [] t1_buf; t1_buf = nullptr; }
Expand All @@ -707,6 +757,7 @@ SeepsScore *SeepsClimoGrid::get_record(int ix, int iy,
double p_fcst, double p_obs) {
SeepsScore *seeps_record = nullptr;
const char *method_name = "SeepsClimoGrid::get_record() -> ";

if (!is_eq(p_fcst, -9999.0) && !is_eq(p_obs, -9999.0)) {
int offset = iy * nx + ix;
double p1 = p1_buf[offset];
Expand All @@ -715,7 +766,7 @@ SeepsScore *SeepsClimoGrid::get_record(int ix, int iy,
// Determine location in contingency table
int ic = (p_obs>t1_buf[offset])+(p_obs>t2_buf[offset]);
int jc = (p_fcst>t1_buf[offset])+(p_fcst>t2_buf[offset]);
double score = get_seeps_category(offset, ic, jc);
double score = get_seeps_score(offset, ic, jc);

seeps_record = new SeepsScore();
seeps_record->obs_cat = ic;
Expand All @@ -729,7 +780,9 @@ SeepsScore *SeepsClimoGrid::get_record(int ix, int iy,
}
else if (~is_eq(p1, bad_data_double)) {
increase_filtered_count();
mlog << Debug(7) << method_name << " filtered by threshold p1=" << p1_buf[offset] <<"\n";
mlog << Debug(7) << method_name
<< " filtered by threshold p1="
<< p1_buf[offset] << "\n";
}
}

Expand All @@ -740,9 +793,10 @@ SeepsScore *SeepsClimoGrid::get_record(int ix, int iy,

double SeepsClimoGrid::get_seeps_score(int offset, int obs_cat, int fcst_cat) {
double score = bad_data_double;
const char *method_name = "SeepsClimoGrid::get_seeps_score() -> ";

if (offset < 0 || offset >= (nx * ny)) {
mlog << Error << "\nSeepsClimoGrid::get_seeps_score() -> "
mlog << Error << method_name
<< "offset (" << offset << ") is too big ("
<< (nx*ny) << ")\n";
return score;
Expand All @@ -764,8 +818,10 @@ double SeepsClimoGrid::get_seeps_score(int offset, int obs_cat, int fcst_cat) {
else if (fcst_cat == 1) score = s_ohfl_buf[offset];
else score = 0.;
}
mlog << Debug(9) << "In get_seeps_score() -> obs_cat = " << obs_cat
<< ", fcst_cat = " << fcst_cat << ", score = " << score << "\n";
mlog << Debug(9) << method_name
<< "obs_cat = " << obs_cat
<< ", fcst_cat = " << fcst_cat
<< ", score = " << score << "\n";

return score;
}
Expand All @@ -783,15 +839,19 @@ void SeepsClimoGrid::read_seeps_climo_grid(ConcatString filename) {
if (!has_dim(nc_file, dim_name_lat) || !has_dim(nc_file, dim_name_lon)) {
mlog << Error << "\n" << method_name
<< "\"" << filename << "\" is not valid SEEPS climo file\n\n";
//exit(1);
exit(1);
}

get_dim(nc_file, dim_name_lat, ny, true);
get_dim(nc_file, dim_name_lon, nx, true);
mlog << Debug(6) << method_name << "dimensions lon = " << nx << " lat = " << ny
mlog << Debug(6) << method_name
<< "dimensions lon = " << nx << " lat = " << ny
<< " month=" << month << "\n";
if (standalone_debug_seeps) cout << "dimensions lon = " << nx << " lat = " << ny
<< " month=" << month << "\n";;
if (standalone_debug_seeps) {
cout << method_name
<< "dimensions lon = " << nx << " lat = " << ny
<< " month=" << month << "\n";
}

// Variables in climo file named as s_odfl, s_odfh etc. These then stored
// into new convention s_odfl, s_odfh etc.
Expand Down Expand Up @@ -827,8 +887,8 @@ void SeepsClimoGrid::read_seeps_climo_grid(ConcatString filename) {
dims.add(ny);
dims.add(nx);

mlog << Debug(9) << "read_seeps_climo_grid() -> var_odfl_00 = "
<< &var_odfl_00 << "\n";
mlog << Debug(9) << method_name
<< "var_odfl_00 = " << &var_odfl_00 << "\n";

if (IS_INVALID_NC(var_p1_00) || !get_nc_data(&var_p1_00, p1_buf, dims, curs)) {
mlog << Error << "\n" << method_name
Expand Down Expand Up @@ -883,21 +943,25 @@ void SeepsClimoGrid::read_seeps_climo_grid(ConcatString filename) {
nc_file->close();

for(int i = 0; i < ny+3; i++) {
mlog << Debug(9) << "read_seeps_climo_grid() -> s_odfl_buf["
<< i << "] = " << s_odfl_buf[i] << "\n";
mlog << Debug(9) << method_name
<< "s_odfl_buf[" << i << "] = " << s_odfl_buf[i] << "\n";
}

float duration = (float)(clock() - clock_time)/CLOCKS_PER_SEC;
mlog << Debug(6) << method_name << "took " << duration << " seconds\n";
if (standalone_debug_seeps) cout << method_name << "took " << duration << " seconds\n";
mlog << Debug(6) << method_name
<< "took " << duration << " seconds\n";
if (standalone_debug_seeps) {
cout << method_name
<< "took " << duration << " seconds\n";
}
}
catch(...) {

set_seeps_ready(false);
mlog << Error << "\n" << method_name
<< "encountered an error on reading " << filename << ".\n\n";

exit(-1);

} // end catch block

}
Expand Down
9 changes: 4 additions & 5 deletions src/libcode/vx_seeps/seeps.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,18 @@ class SeepsClimo : public SeepsClimoBase {
~SeepsClimo();

SeepsRecord *get_record(int sid, int month, int hour);
double get_score(int sid, double p_fcst, double p_obs,
int month, int hour);
double get_seeps_category(int sid, double p_fcst, double p_obs,
int month, int hour);
SeepsScore *get_seeps_score(int sid, double p_fcst, double p_obs,
int month, int hour);

void print_all();
void print_record(SeepsRecord *record, bool with_header=false);

//
//
//

SeepsRecord get_seeps_record(int sid) const;

};

////////////////////////////////////////////////////////////////////////
Expand All @@ -229,7 +228,7 @@ class SeepsClimoGrid : public SeepsClimoBase {
double *s_olfd_buf;
double *s_olfh_buf;
double *s_ohfd_buf;
double *s_ohfl_buf;
double *s_ohfl_buf;

void init_from_scratch();

Expand Down
Loading

0 comments on commit 606ff74

Please sign in to comment.