Skip to content

Commit

Permalink
Per #1904, correct the logic for handling the control member. The ens…
Browse files Browse the repository at this point in the history
…emble sum is used to compute both the mean and the standard deviation. Since we include control member in the mean but not the standard deviation, we need to track two different versions of that sum.
  • Loading branch information
JohnHalleyGotway committed Oct 1, 2021
1 parent 0561cd6 commit 2aa7b5a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 10 additions & 4 deletions met/src/tools/other/gen_ens_prod/gen_ens_prod.cc
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,11 @@ void clear_counts() {
min_na.set_const(bad_data_double, nxy);
max_na.set_const(bad_data_double, nxy);
sum_na.set_const(0.0, nxy);
ssq_na.set_const(0.0, nxy);

stdev_cnt_na.set_const(0.0, nxy);
stdev_sum_na.set_const(0.0, nxy);
stdev_ssq_na.set_const(0.0, nxy);

for(i=0; i<conf_info.get_max_n_cat(); i++) {
thresh_cnt_na[i].set_const(0.0, nxy);
for(j=0; j<conf_info.get_n_nbrhd(); j++) {
Expand Down Expand Up @@ -455,14 +458,17 @@ void track_counts(int i_var, const DataPlane &ens_dp, bool is_ctrl,
// Valid data count
cnt_na.buf()[i] += 1;

// Ensemble sum
sum_na.buf()[i] += ens;

// Ensemble min and max
if(ens <= min_na.buf()[i] || is_bad_data(min_na.buf()[i])) min_na.buf()[i] = ens;
if(ens >= max_na.buf()[i] || is_bad_data(max_na.buf()[i])) max_na.buf()[i] = ens;

// Standard deviation sum, sum of squares, and count, excluding control member
if(!is_ctrl) {
sum_na.buf()[i] += ens;
ssq_na.buf()[i] += ens*ens;
stdev_sum_na.buf()[i] += ens;
stdev_ssq_na.buf()[i] += ens*ens;
stdev_cnt_na.buf()[i] += 1;
}

Expand Down Expand Up @@ -579,7 +585,7 @@ void write_ens_nc(int i_var, int n_ens_vld,

// Compute ensemble summary
ens_mean[i] = (float) (sum_na[i]/cnt_na[i]);
ens_stdev[i] = (float) compute_stdev(sum_na[i], ssq_na[i], nint(stdev_cnt_na[i]));
ens_stdev[i] = (float) compute_stdev(stdev_sum_na[i], stdev_ssq_na[i], nint(stdev_cnt_na[i]));
ens_minus[i] = (float) ens_mean[i] - ens_stdev[i];
ens_plus[i] = (float) ens_mean[i] + ens_stdev[i];
ens_min[i] = (float) min_na[i];
Expand Down
3 changes: 2 additions & 1 deletion met/src/tools/other/gen_ens_prod/gen_ens_prod.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ static int nxy = 0;
static Met2dDataFileFactory mtddf_factory;

// Arrays to store running sums and counts
static NumArray cnt_na, min_na, max_na, sum_na, ssq_na, stdev_cnt_na;
static NumArray cnt_na, min_na, max_na, sum_na;
static NumArray stdev_cnt_na, stdev_sum_na, stdev_ssq_na;
static NumArray *thresh_cnt_na = (NumArray *) 0; // [n_thresh]
static NumArray **thresh_nbrhd_cnt_na = (NumArray **) 0; // [n_thresh][n_nbrhd]

Expand Down

0 comments on commit 2aa7b5a

Please sign in to comment.