Skip to content

Commit

Permalink
Per #1918, update gen_ens_prod to set the MET_ENS_MEMBER_ID environme…
Browse files Browse the repository at this point in the history
…nt variable when reading climatology data if the ens_member_ids config option has been set and the normalizing relative to climatology has been requested.
  • Loading branch information
JohnHalleyGotway committed Feb 25, 2022
1 parent 20d9404 commit 6e9aa5d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 11 deletions.
66 changes: 56 additions & 10 deletions met/src/tools/other/gen_ens_prod/gen_ens_prod.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ static void process_command_line(int, char **);
static void process_grid(const Grid &);
static void process_ensemble();

static void get_climo_mean_stdev(GenEnsProdVarInfo *, int,
bool, int, DataPlane &, DataPlane &);
static void get_ens_mean_stdev(GenEnsProdVarInfo *, DataPlane &, DataPlane &);
static bool get_data_plane(const char *, GrdFileType, VarInfo *, DataPlane &);

Expand Down Expand Up @@ -272,7 +274,7 @@ void process_grid(const Grid &fcst_grid) {

void process_ensemble() {
int i_var, i_ens, n_ens_vld, n_ens_inputs;
bool need_reset;
bool need_reset, set_climo_ens_mem_id;
DataPlane ens_dp, ctrl_dp;
DataPlane cmn_dp, csd_dp;
DataPlane emn_dp, esd_dp;
Expand All @@ -287,6 +289,13 @@ void process_ensemble() {
// Need to reinitialize counts and sums for each ensemble field
need_reset = true;

// When normalizing relative to climatology with MET_ENS_MEMBER_ID set,
// read climatology separately for each member
set_climo_ens_mem_id =
(conf_info.ens_member_ids.n() > 1) &&
((*var_it)->normalize == NormalizeType_ClimoAnom ||
(*var_it)->normalize == NormalizeType_ClimoStdAnom);

// Print out the normalization flag
cs << cs_erase;
if((*var_it)->normalize != NormalizeType_None) {
Expand Down Expand Up @@ -335,17 +344,13 @@ void process_ensemble() {
clear_counts();

// Read climatology data for this field
cmn_dp = read_climo_data_plane(
conf_info.conf.lookup_array(conf_key_climo_mean_field, false),
i_var, ens_valid_ut, grid);

csd_dp = read_climo_data_plane(
conf_info.conf.lookup_array(conf_key_climo_stdev_field, false),
i_var, ens_valid_ut, grid);
get_climo_mean_stdev((*var_it), i_var,
set_climo_ens_mem_id,
i_ens, cmn_dp, csd_dp);

// Compute the ensemble summary data, if needed
if((*var_it)->normalize == NormalizeType_FcstAnom ||
(*var_it)->normalize == NormalizeType_FcstStdAnom ) {
(*var_it)->normalize == NormalizeType_FcstStdAnom) {
get_ens_mean_stdev((*var_it), emn_dp, esd_dp);
}
else {
Expand All @@ -371,6 +376,13 @@ void process_ensemble() {
exit(1);
}

// Read climo data with MET_ENS_MEMBER_ID set
if(set_climo_ens_mem_id) {
get_climo_mean_stdev((*var_it), i_var,
set_climo_ens_mem_id, i_ens,
cmn_dp, csd_dp);
}

// Normalize, if requested
if((*var_it)->normalize != NormalizeType_None) {
normalize_data(ctrl_dp, (*var_it)->normalize,
Expand All @@ -391,6 +403,13 @@ void process_ensemble() {

} // end if need_reset

// Read climo data with MET_ENS_MEMBER_ID set
if(set_climo_ens_mem_id) {
get_climo_mean_stdev((*var_it), i_var,
set_climo_ens_mem_id, i_ens,
cmn_dp, csd_dp);
}

// Normalize, if requested
if((*var_it)->normalize != NormalizeType_None) {
normalize_data(ens_dp, (*var_it)->normalize,
Expand All @@ -411,7 +430,7 @@ void process_ensemble() {
if(((double) n_ens_vld/n_ens_inputs) < conf_info.vld_ens_thresh) {
mlog << Error << "\nprocess_ensemble() -> "
<< n_ens_vld << " of " << n_ens_inputs
<< " (" << (double)n_ens_vld/n_ens_inputs << ")"
<< " (" << (double)n_ens_vld/n_ens_inputs << ")"
<< " fields found for \"" << (*var_it)->get_var_info()->magic_str()
<< "\" does not meet the threshold specified by \""
<< conf_key_ens_ens_thresh << "\" (" << conf_info.vld_ens_thresh
Expand All @@ -430,6 +449,33 @@ void process_ensemble() {

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

void get_climo_mean_stdev(GenEnsProdVarInfo *ens_info, int i_var,
bool set_ens_mem_id, int i_ens,
DataPlane &cmn_dp, DataPlane &csd_dp) {

// Set the MET_ENS_MEMBER_ID environment variable
if(set_ens_mem_id) {
setenv(met_ens_member_id, ens_info->get_ens_member_id(i_ens).c_str(), 1);
}

cmn_dp = read_climo_data_plane(
conf_info.conf.lookup_array(conf_key_climo_mean_field, false),
i_var, ens_valid_ut, grid);

csd_dp = read_climo_data_plane(
conf_info.conf.lookup_array(conf_key_climo_stdev_field, false),
i_var, ens_valid_ut, grid);

// Unset the MET_ENS_MEMBER_ID environment variable
if(set_ens_mem_id) {
unsetenv(met_ens_member_id);
}

return;
}

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

void get_ens_mean_stdev(GenEnsProdVarInfo *ens_info,
DataPlane &emn_dp, DataPlane &esd_dp) {
int i_ens, nxy, j;
Expand Down
2 changes: 1 addition & 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 @@ -14,7 +14,7 @@
//
// Mod# Date Name Description
// ---- ---- ---- -----------
// 000 09/10/21 Halley Gotway Initial version (MET #1904).
// 000 09/10/21 Halley Gotway MET #1904 Initial version.
//
////////////////////////////////////////////////////////////////////////

Expand Down
2 changes: 2 additions & 0 deletions met/src/tools/other/gen_ens_prod/gen_ens_prod_conf_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ void GenEnsProdConfInfo::process_config(GrdFileType etype, StringArray * ens_fil
input_info.var_info = next_var;
input_info.file_index = 0;
input_info.file_list = ens_files;
input_info.ens_member_id = ens_member_ids[j];
ens_info->add_input(input_info);

// Add InputInfo to ens info list for each ensemble file provided
Expand All @@ -221,6 +222,7 @@ void GenEnsProdConfInfo::process_config(GrdFileType etype, StringArray * ens_fil
input_info.var_info = NULL;
input_info.file_index = k;
input_info.file_list = ens_files;
input_info.ens_member_id = ens_member_ids[j];
ens_info->add_input(input_info);
} // end for k

Expand Down

0 comments on commit 6e9aa5d

Please sign in to comment.