Skip to content

Commit

Permalink
Per #3030, add GRADInfo::set_stat() member function
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnHalleyGotway committed Dec 12, 2024
1 parent 258d1a1 commit e54eb54
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
36 changes: 36 additions & 0 deletions src/libcode/vx_statistics/met_stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3639,6 +3639,10 @@ GRADInfo & GRADInfo::operator=(const GRADInfo &c) {
GRADInfo & GRADInfo::operator+=(const GRADInfo &c) {
GRADInfo g_info;

// Return if nothing to add
if(c.total == 0) return *this;

// Gradient definition must remain constant
if(dx != c.dx || dy != c.dy) {
mlog << Error << "\nGRADInfo::operator+=() -> "
<< "the gradient DX (" << dx << " vs " << c.dx
Expand Down Expand Up @@ -3774,6 +3778,7 @@ double GRADInfo::magnitude_rmse() const {
double GRADInfo::laplace_rmse() const {
return square_root(lap_mse);
}

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

void GRADInfo::set(int grad_dx, int grad_dy,
Expand Down Expand Up @@ -3856,6 +3861,37 @@ void GRADInfo::set(int grad_dx, int grad_dy,

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

void GRADInfo::set_stat(const string &stat_name, double v) {

// Store the statistic by name
if(stat_name == "TOTAL" ) total = nint(v);
else if(stat_name == "FGBAR" ) fgbar = v;
else if(stat_name == "OGBAR" ) ogbar = v;
else if(stat_name == "MGBAR" ) mgbar = v;
else if(stat_name == "EGBAR" ) egbar = v;
else if(stat_name == "DX" ) dx = nint(v);
else if(stat_name == "DY" ) dy = nint(v);
else if(stat_name == "FGMAG" ) fgmag = v;
else if(stat_name == "OGMAG" ) ogmag = v;
else if(stat_name == "MAG_RMSE" ) mag_mse = v*v;
else if(stat_name == "LAPLACE_RMSE") lap_mse = v*v;
// Ignore derived quantities
else if(stat_name == "S1" ||
stat_name == "S1_OG" ||
stat_name == "FGOG_RATIO") {
}
else {
mlog << Error << "\nGRADInfo::set_stat() -> "
<< "unknown gradient statistic name \"" << stat_name
<< "\"!\n\n";
exit(1);
}

return;
}

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

double GRADInfo::get_stat(const string &stat_name) const {
double v = bad_data_double;

Expand Down
3 changes: 2 additions & 1 deletion src/libcode/vx_statistics/met_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -633,12 +633,13 @@ class GRADInfo {

void clear();

// Compute sums
// Compute gradient sums
void set(int grad_dx, int grad_dy,
const NumArray &fgx_na, const NumArray &fgy_na,
const NumArray &ogx_na, const NumArray &ogy_na,
const NumArray &wgt_na);

void set_stat(const std::string &, double);
double get_stat(const std::string &) const;
};

Expand Down

0 comments on commit e54eb54

Please sign in to comment.