Skip to content

Commit

Permalink
Per #2395, remove the n_dir_undef and n_dira_undef variables that are…
Browse files Browse the repository at this point in the history
… superceded by the new dcount and dacount VL1L2Info members to keep track of the number of valid wind direction vectors.
  • Loading branch information
JohnHalleyGotway committed May 16, 2024
1 parent 27bff62 commit 0365952
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 44 deletions.
62 changes: 24 additions & 38 deletions src/libcode/vx_statistics/met_stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,7 @@ VL1L2Info & VL1L2Info::operator+=(const VL1L2Info &c) {
for(int i=0; i<n_alpha; i++) v_info.alpha[i] = alpha[i];

v_info.vcount = vcount + c.vcount;
v_info.dcount = dcount + c.dcount;

if(v_info.vcount > 0) {
v_info.uf_bar = (uf_bar*vcount + c.uf_bar*c.vcount) /v_info.vcount;
Expand All @@ -1374,12 +1375,15 @@ VL1L2Info & VL1L2Info::operator+=(const VL1L2Info &c) {
v_info.uvoo_bar = (uvoo_bar*vcount + c.uvoo_bar*c.vcount) /v_info.vcount;
v_info.f_speed_bar = (f_speed_bar*vcount + c.f_speed_bar*c.vcount)/v_info.vcount;
v_info.o_speed_bar = (o_speed_bar*vcount + c.o_speed_bar*c.vcount)/v_info.vcount;
v_info.dir_bar = (dir_bar*vcount + c.dir_bar*c.vcount) /v_info.vcount;
v_info.absdir_bar = (absdir_bar*vcount + c.absdir_bar*c.vcount) /v_info.vcount;
v_info.dir2_bar = (dir2_bar*vcount + c.dir2_bar*c.vcount) /v_info.vcount;
}
if(v_info.dcount > 0) {
v_info.dir_bar = (dir_bar*dcount + c.dir_bar*c.dcount) /v_info.dcount;
v_info.absdir_bar = (absdir_bar*dcount + c.absdir_bar*c.dcount) /v_info.dcount;
v_info.dir2_bar = (dir2_bar*dcount + c.dir2_bar*c.dcount) /v_info.dcount;
}

v_info.vacount = vacount + c.vacount;
v_info.dacount = dacount + c.dacount;

if(v_info.vacount > 0) {
v_info.ufa_bar = (ufa_bar*vacount + c.ufa_bar*c.vacount) /v_info.vacount;
Expand All @@ -1391,9 +1395,11 @@ VL1L2Info & VL1L2Info::operator+=(const VL1L2Info &c) {
v_info.uvooa_bar = (uvooa_bar*vacount + c.uvooa_bar*c.vacount) /v_info.vacount;
v_info.fa_speed_bar = (fa_speed_bar*vacount + c.fa_speed_bar*c.vacount)/v_info.vacount;
v_info.oa_speed_bar = (oa_speed_bar*vacount + c.oa_speed_bar*c.vacount)/v_info.vacount;
v_info.dira_bar = (dira_bar*vacount + c.dira_bar*c.vacount) /v_info.vacount;
v_info.absdira_bar = (absdira_bar*vacount + c.absdira_bar*c.vacount) /v_info.vacount;
v_info.dira2_bar = (dira2_bar*vacount + c.dira2_bar*c.vacount) /v_info.vacount;
}
if(v_info.dacount > 0) {
v_info.dira_bar = (dira_bar*dacount + c.dira_bar*c.dacount) /v_info.dacount;
v_info.absdira_bar = (absdira_bar*dacount + c.absdira_bar*c.dacount) /v_info.dacount;
v_info.dira2_bar = (dira2_bar*dacount + c.dira2_bar*c.dacount) /v_info.dacount;
}

v_info.compute_stats();
Expand Down Expand Up @@ -1436,6 +1442,7 @@ void VL1L2Info::zero_out() {
dir2_bar = 0.0;

vcount = 0;
dcount = 0;

//
// VAL1L2 Quantities
Expand All @@ -1455,6 +1462,7 @@ void VL1L2Info::zero_out() {
dira2_bar = 0.0;

vacount = 0;
dacount = 0;

return;
}
Expand All @@ -1464,8 +1472,6 @@ void VL1L2Info::zero_out() {
void VL1L2Info::clear() {

n = 0;
n_dir_undef = 0;
n_dira_undef = 0;
n_alpha = 0;
if(alpha) { delete [] alpha; alpha = (double *) nullptr; }

Expand Down Expand Up @@ -1515,8 +1521,6 @@ void VL1L2Info::assign(const VL1L2Info &c) {
logic = c.logic;

n = c.n;
n_dir_undef = c.n_dir_undef;
n_dira_undef = c.n_dira_undef;
allocate_n_alpha(c.n_alpha);
for(i=0; i<c.n_alpha; i++) { alpha[i] = c.alpha[i]; }

Expand All @@ -1535,6 +1539,7 @@ void VL1L2Info::assign(const VL1L2Info &c) {
dir2_bar = c.dir2_bar;

vcount = c.vcount;
dcount = c.dcount;

// VAL1L2 Quantities
ufa_bar = c.ufa_bar;
Expand All @@ -1551,6 +1556,7 @@ void VL1L2Info::assign(const VL1L2Info &c) {
dira2_bar = c.dira2_bar;

vacount = c.vacount;
dacount = c.dacount;

//
// Statistics
Expand Down Expand Up @@ -1662,13 +1668,12 @@ void VL1L2Info::set(const PairDataPoint &pd_u_all,
f_speed_bar += wgt*sqrt(uf*uf + vf*vf);
o_speed_bar += wgt*sqrt(uo*uo + vo*vo);

// Exclude undefined angle differences from the running sums
// Compute direction difference
d_diff = angle_difference(uf, vf, uo, vo);

if(is_bad_data(d_diff)) {
n_dir_undef += 1;
}
else {
// Ignore undefined direction differences
if(!is_bad_data(d_diff)) {
dcount += 1;
dir_wgt_sum += pd_u.wgt_na[i];
dir_bar += pd_u.wgt_na[i]*d_diff;
absdir_bar += pd_u.wgt_na[i]*abs(d_diff);
Expand All @@ -1691,13 +1696,12 @@ void VL1L2Info::set(const PairDataPoint &pd_u_all,
fa_speed_bar += wgt*sqrt((uf-uc)*(uf-uc) + (vf-vc)*(vf-vc));
oa_speed_bar += wgt*sqrt((uo-uc)*(uo-uc) + (vo-vc)*(vo-vc));

// Exclude undefined angle differences from the running sums
// Compute anomalous direction difference
d_diff = angle_difference(uf-uc, vf-vc, uo-uc, vo-vc);

if(is_bad_data(d_diff)) {
n_dira_undef += 1;
}
else {
// Ignore undefined anomalous direction differences
if(!is_bad_data(d_diff)) {
dacount += 1;
dira_wgt_sum += pd_u.wgt_na[i];
dira_bar += pd_u.wgt_na[i]*d_diff;
absdira_bar += pd_u.wgt_na[i]*abs(d_diff);
Expand Down Expand Up @@ -1882,15 +1886,6 @@ void VL1L2Info::compute_stats() {

DIR_ABSERR.v = fabs(DIR_ERR.v);

// Print undefined wind direction warning message
if(n_dir_undef > 0) {
mlog << Warning << "\nVL1L2Info::compute_stats() -> "
<< "Skipping " << n_dir_undef << " of " << vcount
<< " vector pairs for which the direction difference is undefined.\n"
<< "Set the \"wind_thresh\" and \"wind_logic\" configuration options "
<< "to exclude zero vectors.\n\n";
}

DIR_ME.v = dir_bar;
DIR_MAE.v = absdir_bar;
DIR_MSE.v = dir2_bar;
Expand All @@ -1912,15 +1907,6 @@ void VL1L2Info::compute_stats() {
}

ANOM_CORR_UNCNTR.v = compute_anom_corr_uncntr(uvffa_bar, uvooa_bar, uvfoa_bar);

// Print undefined wind direction warning message
if(n_dira_undef > 0) {
mlog << Warning << "\nVL1L2Info::compute_stats() -> "
<< "Skipping " << n_dira_undef << " of " << vacount
<< " anomaly vector pairs for which the direction difference is undefined.\n"
<< "Set the \"wind_thresh\" and \"wind_logic\" configuration options "
<< "to exclude zero vectors.\n\n";
}
}

// Compute parametric confidence intervals
Expand Down
10 changes: 4 additions & 6 deletions src/libcode/vx_statistics/met_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,6 @@ class VL1L2Info {
// Number of points
int n;

// Number of points for which the wind direction difference is undefined
int n_dir_undef;
int n_dira_undef;

// VL1L2 Quantities

double uf_bar;
Expand Down Expand Up @@ -336,7 +332,8 @@ class VL1L2Info {
CIInfo DIR_MSE;
CIInfo DIR_RMSE;

int vcount;
int vcount; // Vector count
int dcount; // Direction count

// VAL1L2 Quantities
double ufa_bar;
Expand All @@ -355,7 +352,8 @@ class VL1L2Info {
double absdira_bar; // Average anomalous absolute direction difference
double dira2_bar; // Average anomalous squared direction difference

int vacount;
int vacount; // Vector anomaly count
int dacount; // Direction anomaly count

// Compute sums
void set(const PairDataPoint &, const PairDataPoint &);
Expand Down

0 comments on commit 0365952

Please sign in to comment.