diff --git a/data/config/MODEMultivarConfig_default b/data/config/MODEMultivarConfig_default index 66ab5dfdf3..8d4d7f8406 100644 --- a/data/config/MODEMultivarConfig_default +++ b/data/config/MODEMultivarConfig_default @@ -53,6 +53,11 @@ quilt = FALSE; // multivar_logic = "#1 && #2 && #3"; +// +// MODE Multivar intensity computation flag +// +multivar_intensity_flag = [FALSE, TRUE, TRUE]; + // // Forecast and observation fields to be verified // @@ -84,6 +89,8 @@ fcst = { filter_attr_thresh = []; merge_thresh = >=3.5; merge_flag = NONE; + multivar_name = "ALPHA_BETA_GAMMA"; + multivar_level = "LO"; } obs = fcst; diff --git a/docs/Users_Guide/mode.rst b/docs/Users_Guide/mode.rst index 98ab658ea4..2d304b21a1 100644 --- a/docs/Users_Guide/mode.rst +++ b/docs/Users_Guide/mode.rst @@ -197,6 +197,8 @@ mode configuration file The default configuration file for the MODE tool, **MODEConfig_default**, can be found in the installed *share/met/config* directory. Another version of the configuration file is provided in *scripts/config*. We encourage users to make a copy of the configuration files prior to modifying their contents. Descriptions of **MODEConfig_default** and the required variables for any MODE configuration file are also provided below. While the configuration file contains many entries, most users will only need to change a few for their use. Specific options are described in the following subsections. +A second default configuration file for the multivar MODE option, **MODEMultivarConfig_default**, is also found in the installed *share/met/config* directory. We encourage users to make a copy of this default configuration file when setting up a multivar configuration prior to modifying content. The two default config files **MODEConfig_default** and **MODEMultivarConfig_default** are similar, with **MODEMultivarConfig_default** having example multivar specific content. + Note that environment variables may be used when editing configuration files, as described in the :numref:`config_env_vars`. _____________________ @@ -324,7 +326,7 @@ The **merge_flag** entry controls what type of merging techniques will be applie • **BOTH** indicates that both techniques should be used. -By default, the double thresholding merging technique is applied. +By default, the double thresholding **THRESH** merging technique is applied in single variable mode. The merging defaults to **NONE** with multivariate mode. _____________________ diff --git a/src/basic/vx_util/file_exists.cc b/src/basic/vx_util/file_exists.cc index 6d007303a4..a51db6f164 100644 --- a/src/basic/vx_util/file_exists.cc +++ b/src/basic/vx_util/file_exists.cc @@ -1,5 +1,3 @@ - - // *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* // ** Copyright UCAR (c) 1992 - 2023 // ** University Corporation for Atmospheric Research (UCAR) diff --git a/src/libcode/vx_shapedata/mode_field_info.cc b/src/libcode/vx_shapedata/mode_field_info.cc index 6cecb55d07..06311f5d47 100644 --- a/src/libcode/vx_shapedata/mode_field_info.cc +++ b/src/libcode/vx_shapedata/mode_field_info.cc @@ -9,6 +9,7 @@ //////////////////////////////////////////////////////////////////////// +#include #include "vx_config.h" #include "vx_data2d.h" @@ -20,6 +21,7 @@ #include "mode_field_info.h" +using std::string; //////////////////////////////////////////////////////////////////////// @@ -219,32 +221,87 @@ if ( dict->lookup(conf_key_conv_thresh) ) { } -if ( dict->lookup(conf_key_merge_thresh) ) { - - merge_thresh_array = dict->lookup_thresh_array(conf_key_merge_thresh); - -} - if ( dict->lookup(conf_key_vld_thresh) ) { vld_thresh = dict->lookup_double(conf_key_vld_thresh); } -// for the multivar case, go without parent, and error out if merge flag is -// not set for the individual field +// For the multivar case, more complex logic regarding merge_flag and merge_thresh +// If individual entry has a merge_flag, it must have a merge_thresh (unless merge_flag=NONE) +// If individual entry has no merge_flag, check the parent and go with that flag and thresh +// If individual entry has no merge_flag, but individual entry has a merge_thresh, it's an error + if ( _multivar ) { + // set defaults to no merging + merge_thresh.clear(); + merge_flag = MergeType_None; + + // pull out the name + string name = var_info->name(); + if ( dict->lookup(conf_key_merge_flag, false)) { - merge_flag = int_to_mergetype(dict->lookup_int(conf_key_merge_flag)); + // this individual entry has merge_flag + merge_flag = int_to_mergetype(dict->lookup_int(conf_key_merge_flag, + default_dictionary_error_out, + default_dictionary_print_warning, + false)); + string merge_name = mergetype_to_string(merge_flag); + if (dict->lookup(conf_key_merge_thresh, false)) { + // the individual entry also has a merge_thresh, this is good + merge_thresh_array = dict->lookup_thresh_array(conf_key_merge_thresh, + default_dictionary_error_out, + default_dictionary_print_warning, + false); + } else { + // get the parent's merge_thresh, just to have something. Error out if the merge_flag is not none + // because that is inconsistent + merge_thresh_array = dict->lookup_thresh_array(conf_key_merge_thresh); + + if (merge_flag != MergeType_None) { + mlog << Error << "\nMode_Field_Info::set() -> " + << "Field:" << name << ". " + << " When 'merge_flag' is explicitly set, 'merge_thresh' must be explicitly set for multivariate mode\n\n"; + exit ( 1 ); + } + + } } else { - mlog << Error << "\nMode_Field_Info::set() -> " - << "'merge_flag' must be explicitly set for all fields with multivariate mode\n\n"; - exit ( 1 ); + // individual entry does not have a merge_flag, try parent + if ( dict->lookup(conf_key_merge_flag, true)) { + // the parent does have a merge flag + merge_flag = int_to_mergetype(dict->lookup_int(conf_key_merge_flag)); + string merge_name = mergetype_to_string(merge_flag); + if (dict->lookup(conf_key_merge_thresh, false)) { + // individual entry has a merge_thresh but no merge_flag, this is not good + mlog << Error << "\nMode_Field_Info::set() -> " + << "Field:" << name << ". " + << "When 'merge_flag' is not explicitly set, 'merge_thresh' cannot explicitly set for multivariate mode\n\n"; + exit ( 1 ); + } else { + // individual entry doesn't have a merge_thresh, parent has a merge_flag + // expect parent to have a merge_thresh + merge_thresh_array = dict->lookup_thresh_array(conf_key_merge_thresh); + if (merge_thresh_array.n() == 0 && merge_flag != MergeType_None) { + // parent has a merge_flag but no merge_thresh + mlog << Error << "\nMode_Field_Info::set() -> " + << "Field:" << name << ". using parent merge_flag: " << merge_name + << " Parent has no 'merge_thresh', not allowed in multivariate mode\n\n"; + exit ( 1 ); + } else { + string thresh_str = merge_thresh_array.thresh()->get_str(); + mlog << Debug(2) << "Field:" << name << ". Using parent merge_flag: " + << merge_name << " and parent merge_thresh:" << thresh_str + << "\n"; + } + } + } } } else { if ( dict->lookup(conf_key_merge_flag, true)) { merge_flag = int_to_mergetype(dict->lookup_int(conf_key_merge_flag)); } + merge_thresh_array = dict->lookup_thresh_array(conf_key_merge_thresh); } filter_attr_map = parse_conf_filter_attr_map(dict); diff --git a/src/tools/core/mode/mode.cc b/src/tools/core/mode/mode.cc index 079a5db734..88e18d0b40 100644 --- a/src/tools/core/mode/mode.cc +++ b/src/tools/core/mode/mode.cc @@ -115,6 +115,7 @@ const char * const program_name = "mode"; static const char default_config_filename [] = "MET_BASE/config/MODEConfig_default"; +static const char default_multivar_config_filename [] = "MET_BASE/config/MODEMultivarConfig_default"; /////////////////////////////////////////////////////////////////////// @@ -169,6 +170,12 @@ int met_main(int argc, char * argv []) if ( config.is_multivar() ) { + + // read again, this time with the mvmode defaults, which are slightly different + + config.clear(); + config.read_config(default_multivar_config_filename, user_config_filename); + // exit inside this method if something is not implemented config.check_multivar_not_implemented(); diff --git a/src/tools/core/mode/mode_exec.cc b/src/tools/core/mode/mode_exec.cc index b3f130c4ec..f927b637be 100644 --- a/src/tools/core/mode/mode_exec.cc +++ b/src/tools/core/mode/mode_exec.cc @@ -35,6 +35,7 @@ static const char * cts_str[n_cts] = {"RAW", "OBJECT"}; static const char program_name [] = "mode"; static const char * default_config_filename = "MET_BASE/config/MODEConfig_default"; +static const char * default_multivar_config_filename = "MET_BASE/config/MODEMultivarConfig_default"; // took this out of the do_conv_thresh() method static int local_r_index = -1; @@ -143,7 +144,7 @@ void ModeExecutive::clear() /////////////////////////////////////////////////////////////////////// -void ModeExecutive::init(int n_files) +void ModeExecutive::init(int n_files, bool isMultivar) { @@ -152,7 +153,11 @@ void ModeExecutive::init(int n_files) R_index = T_index = 0; // Create the default config file name - default_config_file = replace_path(default_config_filename); + if (isMultivar) { + default_config_file = replace_path(default_multivar_config_filename); + } else { + default_config_file = replace_path(default_config_filename); + } // If the merge config file was not set, use the match config file if(merge_config_file.length() == 0) @@ -226,7 +231,7 @@ void ModeExecutive::init_multivar(GrdFileType ftype, GrdFileType otype) R_index = T_index = 0; // Create the default config file name - default_config_file = replace_path(default_config_filename); + default_config_file = replace_path(default_multivar_config_filename); // If the merge config file was not set, use the match config file if(merge_config_file.length() == 0) diff --git a/src/tools/core/mode/mode_exec.h b/src/tools/core/mode/mode_exec.h index 89d0102d2a..547792c1c6 100644 --- a/src/tools/core/mode/mode_exec.h +++ b/src/tools/core/mode/mode_exec.h @@ -76,7 +76,7 @@ class ModeExecutive { void clear(); - void init(int n_files); + void init(int n_files, bool isMultivar); void init_multivar(GrdFileType ftype, GrdFileType otype); diff --git a/src/tools/core/mode/mode_frontend.cc b/src/tools/core/mode/mode_frontend.cc index 329bcaa0e7..a37bd89b0c 100644 --- a/src/tools/core/mode/mode_frontend.cc +++ b/src/tools/core/mode/mode_frontend.cc @@ -37,7 +37,6 @@ extern const char * const program_name; static ModeExecutive *mode_exec = 0; static int compress_level = -1; - /////////////////////////////////////////////////////////////////////// @@ -78,7 +77,7 @@ int ModeFrontEnd::run(const StringArray & Argv, Processing_t ptype, int field_in process_command_line(Argv, false); - mode_exec->init(n_files); + mode_exec->init(n_files, ptype != SINGLE_VAR); ModeConfInfo & conf = mode_exec->engine.conf_info; if ( field_index >= 0 ) conf.set_field_index(field_index); diff --git a/src/tools/core/mode/multivar_frontend.cc b/src/tools/core/mode/multivar_frontend.cc index 087311dd67..c19a3ad0b0 100644 --- a/src/tools/core/mode/multivar_frontend.cc +++ b/src/tools/core/mode/multivar_frontend.cc @@ -10,7 +10,8 @@ //////////////////////////////////////////////////////////////////////// -static const char mode_default_config [] = "MET_BASE/config/MODEConfig_default"; +// for multivar mode, this is the default file +static const char mode_default_config [] = "MET_BASE/config/MODEMultivarConfig_default"; static const int dir_creation_mode = 0755; @@ -68,6 +69,8 @@ static const char tab [] = " "; static const bool do_clusters = false; +static string default_out_dir = "."; + static ModeConfInfo config; static string mode_path; @@ -394,6 +397,12 @@ void process_command_line(const StringArray & argv) CommandLine cline; + // + // Set the default output directory + // + + outdir = replace_path(default_out_dir); + mode_path = argv[0]; cline.set(argv); @@ -671,9 +680,6 @@ void process_superobjects(ShapeData &f_result, ShapeData &o_result, mode_argv.add(junk); mode_argv.add("-outdir"); mode_argv.add(dir); - // mode_argv.add("-field_index"); - // snprintf(junk, sizeof(junk), "%d", j); - // mode_argv.add(junk); mlog << Debug(1) << "Running superobject mode \n\n";