diff --git a/src/libcode/vx_statistics/met_stats.cc b/src/libcode/vx_statistics/met_stats.cc index 1b55c112dc..5b7548dd68 100644 --- a/src/libcode/vx_statistics/met_stats.cc +++ b/src/libcode/vx_statistics/met_stats.cc @@ -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 @@ -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, @@ -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; diff --git a/src/libcode/vx_statistics/met_stats.h b/src/libcode/vx_statistics/met_stats.h index 5c6a5c0b1f..3527b8ac39 100644 --- a/src/libcode/vx_statistics/met_stats.h +++ b/src/libcode/vx_statistics/met_stats.h @@ -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; };