From 48b52e78d63a476d505f3a2c4e80fe181a55bc28 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Wed, 27 Mar 2024 18:29:43 +0000 Subject: [PATCH 01/22] #2842 Removed UGrid related setting --- data/config/GridStatConfig_default | 9 ++++++--- data/config/PointStatConfig_default | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/data/config/GridStatConfig_default b/data/config/GridStatConfig_default index adbb9a214b..4c1e18f0e7 100644 --- a/data/config/GridStatConfig_default +++ b/data/config/GridStatConfig_default @@ -263,10 +263,13 @@ nc_pairs_flag = { } //////////////////////////////////////////////////////////////////////////////// +// Followings are optional. User should set them to use the unstructued grid. +// The unstructued grid is an optional feature. +// -ugrid_dataset = ""; -ugrid_max_distance_km = 30; -ugrid_coordinates_file = ""; +//ugrid_dataset = ""; +//ugrid_max_distance_km = 30; +//ugrid_coordinates_file = ""; //////////////////////////////////////////////////////////////////////////////// diff --git a/data/config/PointStatConfig_default b/data/config/PointStatConfig_default index 9a8132dccc..65c4a9b147 100644 --- a/data/config/PointStatConfig_default +++ b/data/config/PointStatConfig_default @@ -298,10 +298,13 @@ output_flag = { } //////////////////////////////////////////////////////////////////////////////// +// Followings are optional. User should set them to use the unstructued grid. +// which The unstructued grid is an optional feature. +// -ugrid_dataset = ""; -ugrid_max_distance_km = 30; -ugrid_coordinates_file = ""; +//ugrid_dataset = ""; +//ugrid_max_distance_km = 30; +//ugrid_coordinates_file = ""; //////////////////////////////////////////////////////////////////////////////// From 9feae3db6c31fc90d65f5a5a07ddce5a4c2bc0b5 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Wed, 27 Mar 2024 18:31:48 +0000 Subject: [PATCH 02/22] #2842 Corrected vertical level for data_plane_array --- src/libcode/vx_data2d_ugrid/data2d_ugrid.cc | 23 +-------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/src/libcode/vx_data2d_ugrid/data2d_ugrid.cc b/src/libcode/vx_data2d_ugrid/data2d_ugrid.cc index 25e5f3ef6f..7b9ea3b25f 100644 --- a/src/libcode/vx_data2d_ugrid/data2d_ugrid.cc +++ b/src/libcode/vx_data2d_ugrid/data2d_ugrid.cc @@ -322,27 +322,6 @@ int MetUGridDataFile::data_plane_array(VarInfo &vinfo, mlog << Error << "\n" << method_name << "LevelType_Time for unstructured grid is not enabled\n\n"; exit(1); - /* Not enabled - const int debug_level = 7; - LongArray time_offsets = collect_time_offsets(vinfo); - if (0 < time_offsets.n_elements()) { - for (int idx=0; idx= debug_level) { - for (int idx=0; idx< time_offsets.n_elements(); idx++ ) { - mlog << Debug(debug_level) << method_name << "time: " - << unix_to_yyyymmdd_hhmmss(_file->ValidTime[time_offsets[idx]]) - << " from index " << time_offsets[idx] << "\n"; - } - } - } - */ } else if (level.type() == LevelType_Pres) { if (nullptr == data_vinfo) { @@ -353,7 +332,7 @@ int MetUGridDataFile::data_plane_array(VarInfo &vinfo, if (vlevel >= lvl_lower && vlevel <= lvl_upper) { vinfo.set_req_name(vinfo_list[idx]->name.c_str()); if (data_plane(vinfo, plane, vinfo_list[idx])) { - plane_array.add(plane, lvl_lower, lvl_upper); + plane_array.add(plane, vlevel, vlevel); n_rec++; } mlog << Debug(5) << method_name From 01ae422b711906a136948c8e42582558a754ceae Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Wed, 27 Mar 2024 18:32:44 +0000 Subject: [PATCH 03/22] #2842 Do not allow the time range --- src/libcode/vx_data2d_ugrid/var_info_ugrid.cc | 55 ------------------- 1 file changed, 55 deletions(-) diff --git a/src/libcode/vx_data2d_ugrid/var_info_ugrid.cc b/src/libcode/vx_data2d_ugrid/var_info_ugrid.cc index 45c1cbdfbc..8fd52d4240 100644 --- a/src/libcode/vx_data2d_ugrid/var_info_ugrid.cc +++ b/src/libcode/vx_data2d_ugrid/var_info_ugrid.cc @@ -231,61 +231,6 @@ void VarInfoUGrid::set_magic(const ConcatString &nstr, const ConcatString &lstr) Level.set_is_offset(as_offset); } } - // Check for a range of times - else if ((ptr3 = strchr(ptr2, ':')) != nullptr) { - // Check if a range has already been supplied - if (Dimension.has(range_flag)) { - mlog << Error << "\n" << method_name - << "only one dimension can have a range for NetCDF variable \"" - << MagicStr << "\".\n\n"; - exit(1); - } - else { - int increment = 1; - // Store the dimension of the range and limits - *ptr3++ = 0; - char *ptr_inc = strchr(ptr3, ':'); - if (ptr_inc != nullptr) *ptr_inc++ = 0; - mlog << Debug(7) << method_name - << " start: " << ptr2 << ", end: " << ptr3 << "\n"; - - bool datestring_start = is_datestring(ptr2); - bool datestring_end = is_datestring(ptr3); - if (datestring_start != datestring_end) { - mlog << Error << "\n" << method_name - << "the time value and an index/offset can not be mixed for NetCDF variable \"" - << MagicStr << "\".\n\n"; - exit(1); - } - if (datestring_start && datestring_end) as_offset = false; - - unixtime time_lower = datestring_start - ? timestring_to_unix(ptr2) - : (as_offset ? atoi(ptr2) : atof(ptr2)); - unixtime time_upper = datestring_end - ? timestring_to_unix(ptr3) - : (as_offset ? atoi(ptr3) : atof(ptr3)); - if (ptr_inc != nullptr) { - if (as_offset) increment = atoi(ptr_inc); - else { - increment = is_float(ptr_inc) - ? atof(ptr_inc) : timestring_to_sec(ptr_inc); - mlog << Debug(7) << method_name - << " increment: \"" << ptr_inc << "\" to " - << increment << " seconds.\n"; - } - } - - add_dimension(range_flag, as_offset); - Level.set_lower(time_lower); - Level.set_upper(time_upper); - Level.set_increment(increment); - - // Assume time level type for a range of levels - Level.set_type(LevelType_Time); - Level.set_is_offset(as_offset); - } - } else { // Single level int level = 0; From 1b43102a674b393614d252164944131b5fbdbb51 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Wed, 27 Mar 2024 18:34:15 +0000 Subject: [PATCH 04/22] #2842 The UGridConfig file can be passed as ugrid_dataset --- src/libcode/vx_data2d_ugrid/ugrid_file.cc | 30 ++++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/libcode/vx_data2d_ugrid/ugrid_file.cc b/src/libcode/vx_data2d_ugrid/ugrid_file.cc index f85a6ea0ea..5fec54d735 100644 --- a/src/libcode/vx_data2d_ugrid/ugrid_file.cc +++ b/src/libcode/vx_data2d_ugrid/ugrid_file.cc @@ -958,25 +958,32 @@ void UGridFile::read_netcdf_grid() void UGridFile::set_dataset(ConcatString _dataset_name) { - const char *ugrid_config_name = nullptr; + ConcatString ugrid_config_name; + const string method_nmame = "UGridFile::set_dataset() "; if (0 == _dataset_name.length()) { - mlog << Error << "\nUGridFile::set_dataset()" - << " The \"" << conf_key_ugrid_dataset + mlog << Error << "\n" << method_nmame + << "The \"" << conf_key_ugrid_dataset << "\" is not defined at the configuration file.\n\n"; exit(1); } dataset_name = _dataset_name; - ConcatString dataset_config(def_config_prefix); - dataset_config.add(dataset_name); - if (!file_exists(dataset_config.c_str())) { - dataset_config = def_config_prefix2; + if (file_exists(dataset_name.c_str())) { + /* UGridConfig file was passed as the ugrid_dataset */ + ugrid_config_name = dataset_name; + } + else { + ConcatString dataset_config(def_config_prefix); dataset_config.add(dataset_name); - dataset_config = replace_path(dataset_config.c_str()); + if (!file_exists(dataset_config.c_str())) { + dataset_config = def_config_prefix2; + dataset_config.add(dataset_name); + dataset_config = replace_path(dataset_config.c_str()); + } + ugrid_config_name = dataset_config; } - ugrid_config_name = dataset_config.c_str(); - if (file_exists(ugrid_config_name)) { - read_config(ugrid_config_name); + if (file_exists(ugrid_config_name.c_str())) { + read_config(ugrid_config_name.c_str()); } else { mlog << Error << "\nUGridFile::set_dataset()" @@ -984,7 +991,6 @@ void UGridFile::set_dataset(ConcatString _dataset_name) { << ugrid_config_name << "\".\n\n"; exit(1); } - } //////////////////////////////////////////////////////////////////////// From 334b2a840a156f12b84a5818719b0f1fef2aa110 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Wed, 27 Mar 2024 18:36:05 +0000 Subject: [PATCH 05/22] #2842 Changed -config option to -ugrid_config --- src/tools/core/grid_stat/grid_stat.cc | 28 +++++++++++++---- src/tools/core/grid_stat/grid_stat.h | 2 +- .../core/grid_stat/grid_stat_conf_info.cc | 28 ++++++++++------- .../core/grid_stat/grid_stat_conf_info.h | 5 +++- src/tools/core/point_stat/point_stat.cc | 28 ++++++++++++----- src/tools/core/point_stat/point_stat.h | 2 +- .../core/point_stat/point_stat_conf_info.cc | 30 ++++++++++++------- .../core/point_stat/point_stat_conf_info.h | 5 +++- 8 files changed, 90 insertions(+), 38 deletions(-) diff --git a/src/tools/core/grid_stat/grid_stat.cc b/src/tools/core/grid_stat/grid_stat.cc index 9ff348ec1d..7e5e88e6b6 100644 --- a/src/tools/core/grid_stat/grid_stat.cc +++ b/src/tools/core/grid_stat/grid_stat.cc @@ -192,11 +192,13 @@ static void finish_txt_files(); static void clean_up(); static void usage(); -static void set_config(const StringArray &); static void set_outdir(const StringArray &); static void set_compress(const StringArray &); static bool read_data_plane(VarInfo* info, DataPlane& dp, Met2dDataFile* mtddf, const ConcatString &filename); +#ifdef WITH_UGRID +static void set_ugrid_config(const StringArray &); +#endif //////////////////////////////////////////////////////////////////////// @@ -248,6 +250,9 @@ void process_command_line(int argc, char **argv) { // Add the options function calls cline.add(set_outdir, "-outdir", 1); cline.add(set_compress, "-compress", 1); +#ifdef WITH_UGRID + cline.add(set_ugrid_config, "-ugrid_config", 1); +#endif // Parse the command line cline.parse(); @@ -271,7 +276,9 @@ void process_command_line(int argc, char **argv) { // Read the config files conf_info.read_config(default_config_file.c_str(), config_file.c_str()); - conf_info.read_configs(config_files); +#ifdef WITH_UGRID + conf_info.read_ugrid_configs(ugrid_config_files, config_file.c_str()); +#endif // Get the forecast and observation file types from config, if present ftype = parse_conf_file_type(conf_info.conf.lookup_dictionary(conf_key_fcst)); @@ -301,6 +308,8 @@ void process_command_line(int argc, char **argv) { if (FileType_UGrid == ftype || FileType_UGrid == otype) { #ifdef WITH_UGRID ConcatString ugrid_dataset = conf_info.ugrid_dataset; + if (0 < ugrid_dataset.length()) { + } if (0 < ugrid_dataset.length()) { double max_distance_km = conf_info.ugrid_max_distance_km; ConcatString ugrid_nc = conf_info.ugrid_nc; @@ -3094,6 +3103,9 @@ void usage() { << "\tfcst_file\n" << "\tobs_file\n" << "\tconfig_file\n" +#ifdef WITH_UGRID + << "\t[-ugrid_config config_file]\n" +#endif << "\t[-outdir path]\n" << "\t[-log file]\n" << "\t[-v level]\n" @@ -3108,8 +3120,10 @@ void usage() { << "\t\t\"config_file\" is a GridStatConfig file containing " << "the desired configuration settings (required).\n" - << "\t\t\"-config config_file\" specifies additional PointStatConfig file containing " - << "the configuration settings for unstructured grid (optional).\n" +#ifdef WITH_UGRID + << "\t\t\"-ugrid_config ugrid_config_file\" is a UGridConfig file containing " + << "the desired configuration settings for unstructured grid (required only for UGrid)\n" +#endif << "\t\t\"-outdir path\" overrides the default output directory " << "(" << out_dir << ") (optional).\n" @@ -3128,10 +3142,12 @@ void usage() { //////////////////////////////////////////////////////////////////////// -void set_config(const StringArray & a) +#ifdef WITH_UGRID +void set_ugrid_config(const StringArray & a) { - config_files.add(a[0]); + ugrid_config_files.add(a[0]); } +#endif //////////////////////////////////////////////////////////////////////// diff --git a/src/tools/core/grid_stat/grid_stat.h b/src/tools/core/grid_stat/grid_stat.h index b5db513b57..ccd85c82ac 100644 --- a/src/tools/core/grid_stat/grid_stat.h +++ b/src/tools/core/grid_stat/grid_stat.h @@ -113,7 +113,7 @@ static ConcatString obs_file; // Input Config file static ConcatString config_file; -static StringArray config_files; +static StringArray ugrid_config_files; static GridStatConfInfo conf_info; // Optional arguments diff --git a/src/tools/core/grid_stat/grid_stat_conf_info.cc b/src/tools/core/grid_stat/grid_stat_conf_info.cc index 0643888a96..c967fc21f7 100644 --- a/src/tools/core/grid_stat/grid_stat_conf_info.cc +++ b/src/tools/core/grid_stat/grid_stat_conf_info.cc @@ -49,6 +49,7 @@ void GridStatConfInfo::init_from_scratch() { // Initialize pointers vx_opt = (GridStatVxOpt *) nullptr; + ignore_ugrid_dataset = false; clear(); return; @@ -69,7 +70,7 @@ void GridStatConfInfo::clear() { version.clear(); #ifdef WITH_UGRID ugrid_nc.clear(); - ugrid_dataset.clear(); + if (!ignore_ugrid_dataset) ugrid_dataset.clear(); ugrid_map_config.clear(); ugrid_max_distance_km = bad_data_double; #endif @@ -109,18 +110,25 @@ void GridStatConfInfo::read_config(const char *default_file_name, //////////////////////////////////////////////////////////////////////// -void GridStatConfInfo::read_configs(StringArray user_file_names) { - - const char *file_name; - for (int i=0; i " - << "The configuration file \"" << user_file_names[i]<< "\" does not exist.\n\n"; +#ifdef WITH_UGRID +void GridStatConfInfo::read_ugrid_configs(StringArray ugrid_config_names, const char * user_config) { + + ConcatString file_name; + for (int i=0; i " + << "The configuration file \"" << ugrid_config_names[i]<< "\" does not exist.\n\n"; } + if (file_exists(user_config)) conf.read(user_config); /* to avoid overriding by ugrid_config_names */ return; } +#endif //////////////////////////////////////////////////////////////////////// @@ -154,7 +162,7 @@ void GridStatConfInfo::process_config(GrdFileType ftype, #ifdef WITH_UGRID // Conf: ugrid_dataset - ugrid_dataset = parse_conf_ugrid_dataset(&conf); + if (!ignore_ugrid_dataset) ugrid_dataset = parse_conf_ugrid_dataset(&conf); // Conf: ugrid_nc ugrid_nc = parse_conf_ugrid_coordinates_file(&conf); diff --git a/src/tools/core/grid_stat/grid_stat_conf_info.h b/src/tools/core/grid_stat/grid_stat_conf_info.h index c2efe1cd54..51e480f02a 100644 --- a/src/tools/core/grid_stat/grid_stat_conf_info.h +++ b/src/tools/core/grid_stat/grid_stat_conf_info.h @@ -284,6 +284,7 @@ class GridStatConfInfo { ConcatString output_prefix; // String to customize output file name ConcatString version; // Config file version #ifdef WITH_UGRID + bool ignore_ugrid_dataset; ConcatString ugrid_nc; // NetCDF for coordinate variables of unstructured grid ConcatString ugrid_dataset; // UGRid dataset name (mpas, lfric etc) ConcatString ugrid_map_config; // User's configuration file which contains ugrid metadata mapping @@ -299,7 +300,9 @@ class GridStatConfInfo { void clear(); void read_config (const char *, const char *); - void read_configs (StringArray user_file_names); +#ifdef WITH_UGRID + void read_ugrid_configs(StringArray ugrid_config_names, const char * user_config); +#endif void process_config(GrdFileType, GrdFileType); void process_flags (); void process_masks (const Grid &); diff --git a/src/tools/core/point_stat/point_stat.cc b/src/tools/core/point_stat/point_stat.cc index d950486015..b5460f9a01 100644 --- a/src/tools/core/point_stat/point_stat.cc +++ b/src/tools/core/point_stat/point_stat.cc @@ -175,12 +175,14 @@ static void finish_txt_files(); static void clean_up(); static void usage(); -static void set_config(const StringArray &); static void set_point_obs(const StringArray &); static void set_ncfile(const StringArray &); static void set_obs_valid_beg_time(const StringArray &); static void set_obs_valid_end_time(const StringArray &); static void set_outdir(const StringArray &); +#ifdef WITH_UGRID +static void set_ugrid_config(const StringArray &); +#endif //////////////////////////////////////////////////////////////////////// @@ -240,7 +242,9 @@ void process_command_line(int argc, char **argv) { cline.set_usage(usage); // Add the options function calls - cline.add(set_config, "-config", 1); +#ifdef WITH_UGRID + cline.add(set_ugrid_config, "-ugrid_config", 1); +#endif cline.add(set_point_obs, "-point_obs", 1); cline.add(set_ncfile, "-ncfile", 1); cline.add(set_obs_valid_beg_time, "-obs_valid_beg", 1); @@ -283,7 +287,9 @@ void process_command_line(int argc, char **argv) { // Read the config files conf_info.read_config(default_config_file.c_str(), config_file.c_str()); - conf_info.read_configs(config_files); +#ifdef WITH_UGRID + conf_info.read_ugrid_configs(ugrid_config_files, config_file.c_str()); +#endif // Get the forecast file type from config, if present ftype = parse_conf_file_type(conf_info.conf.lookup_dictionary(conf_key_fcst)); @@ -2203,7 +2209,9 @@ void usage() { << "\tfcst_file\n" << "\tobs_file\n" << "\tconfig_file\n" - << "\t[-config config_file]\n" +#ifdef WITH_UGRID + << "\t[-ugrid_config config_file]\n" +#endif << "\t[-point_obs file]\n" << "\t[-obs_valid_beg time]\n" << "\t[-obs_valid_end time]\n" @@ -2220,8 +2228,10 @@ void usage() { << "\t\t\"config_file\" is a PointStatConfig file containing " << "the desired configuration settings (required).\n" - << "\t\t\"-config config_file\" specifies additional PointStatConfig file containing " - << "the configuration settings for unstructured grid (optional).\n" +#ifdef WITH_UGRID + << "\t\t\"-ugrid_config ugrid_config_file\" is a UGridConfig file containing " + << "the desired configuration settings for unstructured grid (required only for UGrid)\n" +#endif << "\t\t\"-point_obs file\" specifies additional NetCDF point " << "observation files to be used (optional).\n" @@ -2246,10 +2256,12 @@ void usage() { //////////////////////////////////////////////////////////////////////// -void set_config(const StringArray & a) +#ifdef WITH_UGRID +void set_ugrid_config(const StringArray & a) { - config_files.add(a[0]); + ugrid_config_files.add(a[0]); } +#endif //////////////////////////////////////////////////////////////////////// diff --git a/src/tools/core/point_stat/point_stat.h b/src/tools/core/point_stat/point_stat.h index 7d69a62b62..0804650b0a 100644 --- a/src/tools/core/point_stat/point_stat.h +++ b/src/tools/core/point_stat/point_stat.h @@ -108,7 +108,7 @@ static StringArray obs_file; // Input Config file static ConcatString config_file; -static StringArray config_files; +static StringArray ugrid_config_files; static PointStatConfInfo conf_info; // Optional arguments diff --git a/src/tools/core/point_stat/point_stat_conf_info.cc b/src/tools/core/point_stat/point_stat_conf_info.cc index 8066da726a..668a4a37e3 100644 --- a/src/tools/core/point_stat/point_stat_conf_info.cc +++ b/src/tools/core/point_stat/point_stat_conf_info.cc @@ -49,6 +49,7 @@ void PointStatConfInfo::init_from_scratch() { // Initialize pointers vx_opt = (PointStatVxOpt *) nullptr; + ignore_ugrid_dataset = false; clear(); return; @@ -73,7 +74,7 @@ void PointStatConfInfo::clear() { version.clear(); #ifdef WITH_UGRID ugrid_nc.clear(); - ugrid_dataset.clear(); + if (!ignore_ugrid_dataset) ugrid_dataset.clear(); ugrid_map_config.clear(); ugrid_max_distance_km = bad_data_double; #endif @@ -105,18 +106,26 @@ void PointStatConfInfo::read_config(const char *default_file_name, //////////////////////////////////////////////////////////////////////// -void PointStatConfInfo::read_configs(StringArray user_file_names) { - - const char *file_name; - for (int i=0; i " - << "The configuration file \"" << user_file_names[i]<< "\" does not exist.\n\n"; +#ifdef WITH_UGRID +void PointStatConfInfo::read_ugrid_configs(StringArray ugrid_config_names, const char * user_config) { + + ConcatString file_name; + for (int i=0; i " + << "The configuration file \"" << ugrid_config_names[i]<< "\" does not exist.\n\n"; } + if (file_exists(user_config)) conf.read(user_config); /* to avoid overriding by ugrid_config_names */ return; } +#endif //////////////////////////////////////////////////////////////////////// @@ -143,7 +152,8 @@ void PointStatConfInfo::process_config(GrdFileType ftype) { #ifdef WITH_UGRID // Conf: ugrid_dataset - ugrid_dataset = parse_conf_ugrid_dataset(&conf); +cout << " DEBUG ===== ignore_ugrid_dataset = " << ignore_ugrid_dataset << " ugrid_dataset=" << ugrid_dataset<< "==========================\n"; + if (!ignore_ugrid_dataset) ugrid_dataset = parse_conf_ugrid_dataset(&conf); // Conf: ugrid_nc ugrid_nc = parse_conf_ugrid_coordinates_file(&conf); diff --git a/src/tools/core/point_stat/point_stat_conf_info.h b/src/tools/core/point_stat/point_stat_conf_info.h index 365f9c64fc..2385f66b84 100644 --- a/src/tools/core/point_stat/point_stat_conf_info.h +++ b/src/tools/core/point_stat/point_stat_conf_info.h @@ -247,6 +247,7 @@ class PointStatConfInfo { ConcatString output_prefix; // String to customize output file name ConcatString version; // Config file version #ifdef WITH_UGRID + bool ignore_ugrid_dataset; ConcatString ugrid_nc; // NetCDF for coordinate variables of unstructured grid ConcatString ugrid_dataset; // UGRid dataset name (mpas, lfric etc) ConcatString ugrid_map_config; // User's configuration file which contains ugrid metadata mapping @@ -261,7 +262,9 @@ class PointStatConfInfo { void clear(); void read_config(const char *, const char *); - void read_configs(StringArray user_file_names); +#ifdef WITH_UGRID + void read_ugrid_configs(StringArray ugrid_config_names, const char * user_config); +#endif void process_config(GrdFileType); void process_grib_codes(); From b9ca329d83a61f34149d39849f6fa0264328e80d Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Thu, 28 Mar 2024 20:34:22 +0000 Subject: [PATCH 06/22] #2842 Deleted UGrid configurations --- data/config/GridStatConfig_default | 9 --------- data/config/PointStatConfig_default | 9 --------- 2 files changed, 18 deletions(-) diff --git a/data/config/GridStatConfig_default b/data/config/GridStatConfig_default index 4c1e18f0e7..4bec5ecf4b 100644 --- a/data/config/GridStatConfig_default +++ b/data/config/GridStatConfig_default @@ -262,15 +262,6 @@ nc_pairs_flag = { apply_mask = TRUE; } -//////////////////////////////////////////////////////////////////////////////// -// Followings are optional. User should set them to use the unstructued grid. -// The unstructued grid is an optional feature. -// - -//ugrid_dataset = ""; -//ugrid_max_distance_km = 30; -//ugrid_coordinates_file = ""; - //////////////////////////////////////////////////////////////////////////////// grid_weight_flag = NONE; diff --git a/data/config/PointStatConfig_default b/data/config/PointStatConfig_default index 65c4a9b147..d4b277c6a3 100644 --- a/data/config/PointStatConfig_default +++ b/data/config/PointStatConfig_default @@ -297,15 +297,6 @@ output_flag = { seeps_mpr = NONE; } -//////////////////////////////////////////////////////////////////////////////// -// Followings are optional. User should set them to use the unstructued grid. -// which The unstructued grid is an optional feature. -// - -//ugrid_dataset = ""; -//ugrid_max_distance_km = 30; -//ugrid_coordinates_file = ""; - //////////////////////////////////////////////////////////////////////////////// tmp_dir = "/tmp"; From 7f25cf8b43bac0360fa7819dbe49314121673f28 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Tue, 2 Apr 2024 14:00:30 +0000 Subject: [PATCH 07/22] 2842 Fix a compile error when UGrid is disabled --- src/tools/core/grid_stat/grid_stat_conf_info.cc | 2 ++ src/tools/core/point_stat/point_stat_conf_info.cc | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tools/core/grid_stat/grid_stat_conf_info.cc b/src/tools/core/grid_stat/grid_stat_conf_info.cc index c967fc21f7..0cfe6e9e48 100644 --- a/src/tools/core/grid_stat/grid_stat_conf_info.cc +++ b/src/tools/core/grid_stat/grid_stat_conf_info.cc @@ -49,7 +49,9 @@ void GridStatConfInfo::init_from_scratch() { // Initialize pointers vx_opt = (GridStatVxOpt *) nullptr; +#ifdef WITH_UGRID ignore_ugrid_dataset = false; +#endif clear(); return; diff --git a/src/tools/core/point_stat/point_stat_conf_info.cc b/src/tools/core/point_stat/point_stat_conf_info.cc index 668a4a37e3..eb26b0cb3e 100644 --- a/src/tools/core/point_stat/point_stat_conf_info.cc +++ b/src/tools/core/point_stat/point_stat_conf_info.cc @@ -49,7 +49,9 @@ void PointStatConfInfo::init_from_scratch() { // Initialize pointers vx_opt = (PointStatVxOpt *) nullptr; +#ifdef WITH_UGRID ignore_ugrid_dataset = false; +#endif clear(); return; @@ -116,7 +118,6 @@ void PointStatConfInfo::read_ugrid_configs(StringArray ugrid_config_names, const conf.read(file_name.c_str()); ugrid_dataset = file_name; ignore_ugrid_dataset = true; -cout << " DEBUG ignore_ugrid_dataset = " << ignore_ugrid_dataset << " ugrid_dataset = " << ugrid_dataset<< "==========================\n"; } else mlog << Warning << "\nPointStatConfInfo::read_ugrid_configs(StringArray) -> " << "The configuration file \"" << ugrid_config_names[i]<< "\" does not exist.\n\n"; @@ -152,7 +153,6 @@ void PointStatConfInfo::process_config(GrdFileType ftype) { #ifdef WITH_UGRID // Conf: ugrid_dataset -cout << " DEBUG ===== ignore_ugrid_dataset = " << ignore_ugrid_dataset << " ugrid_dataset=" << ugrid_dataset<< "==========================\n"; if (!ignore_ugrid_dataset) ugrid_dataset = parse_conf_ugrid_dataset(&conf); // Conf: ugrid_nc From 8293c53014c1a06469bfa86bc86bc1029d7bddb7 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Tue, 2 Apr 2024 14:03:35 +0000 Subject: [PATCH 08/22] #2842 Cleanup --- src/tools/core/grid_stat/grid_stat.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/tools/core/grid_stat/grid_stat.cc b/src/tools/core/grid_stat/grid_stat.cc index 7e5e88e6b6..21bed55d81 100644 --- a/src/tools/core/grid_stat/grid_stat.cc +++ b/src/tools/core/grid_stat/grid_stat.cc @@ -308,8 +308,6 @@ void process_command_line(int argc, char **argv) { if (FileType_UGrid == ftype || FileType_UGrid == otype) { #ifdef WITH_UGRID ConcatString ugrid_dataset = conf_info.ugrid_dataset; - if (0 < ugrid_dataset.length()) { - } if (0 < ugrid_dataset.length()) { double max_distance_km = conf_info.ugrid_max_distance_km; ConcatString ugrid_nc = conf_info.ugrid_nc; From 816c12c3153777d67733c386303d3ef7d43d844a Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Mon, 8 Apr 2024 20:46:46 +0000 Subject: [PATCH 09/22] #2842 Added an unittest point_stat_ugrid_mpas_config --- internal/test_unit/xml/unit_ugrid.xml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/internal/test_unit/xml/unit_ugrid.xml b/internal/test_unit/xml/unit_ugrid.xml index a77d95d886..80211fdc2f 100644 --- a/internal/test_unit/xml/unit_ugrid.xml +++ b/internal/test_unit/xml/unit_ugrid.xml @@ -111,4 +111,30 @@ + + &MET_BIN;/point_stat + + BEG_DS -1800 + END_DS 1800 + OUTPUT_PREFIX UGRID_MPAS_CFG_OUT_TEMP + CONFIG_DIR &CONFIG_DIR; + + \ + &DATA_DIR_UGRID;/mpas/mpasout.2012-04-09_12.00.00_reduced.nc \ + &OUTPUT_DIR;/pb2nc/gdas1.20120409.t12z.prepbufr.nc \ + &CONFIG_DIR;/PointStatConfig_ugrid_no_dataset \ + -ugrid_config ${MET_BASE}/config/UGridConfig_mpas \ + -outdir &OUTPUT_DIR;/point_stat_ugrid -v 1 + + + &OUTPUT_DIR;/point_stat_ugrid/point_stat_UGRID_MPAS_CFG_OUT_TEMP_000000L_20120409_120000V.stat + &OUTPUT_DIR;/point_stat_ugrid/point_stat_UGRID_MPAS_CFG_OUT_TEMP_000000L_20120409_120000V_fho.txt + &OUTPUT_DIR;/point_stat_ugrid/point_stat_UGRID_MPAS_CFG_OUT_TEMP_000000L_20120409_120000V_ctc.txt + &OUTPUT_DIR;/point_stat_ugrid/point_stat_UGRID_MPAS_CFG_OUT_TEMP_000000L_20120409_120000V_cts.txt + &OUTPUT_DIR;/point_stat_ugrid/point_stat_UGRID_MPAS_CFG_OUT_TEMP_000000L_20120409_120000V_cnt.txt + &OUTPUT_DIR;/point_stat_ugrid/point_stat_UGRID_MPAS_CFG_OUT_TEMP_000000L_20120409_120000V_eclv.txt + &OUTPUT_DIR;/point_stat_ugrid/point_stat_UGRID_MPAS_CFG_OUT_TEMP_000000L_20120409_120000V_mpr.txt + + + From 613035c60cd982bd38479cec41bfd749ba930ac5 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Mon, 8 Apr 2024 20:47:51 +0000 Subject: [PATCH 10/22] #2842 Added a PointStatConfig without UGrid dataset. --- .../config/PointStatConfig_ugrid_no_dataset | 167 ++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 internal/test_unit/config/PointStatConfig_ugrid_no_dataset diff --git a/internal/test_unit/config/PointStatConfig_ugrid_no_dataset b/internal/test_unit/config/PointStatConfig_ugrid_no_dataset new file mode 100644 index 0000000000..e70a3af9ee --- /dev/null +++ b/internal/test_unit/config/PointStatConfig_ugrid_no_dataset @@ -0,0 +1,167 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Point-Stat configuration file. +// +// For additional information, please see the MET User's Guide. +// +//////////////////////////////////////////////////////////////////////////////// + +model = "WRF"; + +// +// Output description to be written +// May be set separately in each "obs.field" entry +// +desc = "NA"; + +//////////////////////////////////////////////////////////////////////////////// + +regrid = { + to_grid = NONE; + method = NEAREST; + width = 1; +} + +//////////////////////////////////////////////////////////////////////////////// + +obs_window = { + beg = ${BEG_DS}; + end = ${END_DS}; +} + +//////////////////////////////////////////////////////////////////////////////// + +mpr_column = []; +mpr_thresh = []; +cnt_thresh = [ NA ]; +cnt_logic = UNION; +wind_thresh = [ NA ]; +wind_logic = UNION; +eclv_points = 0.05; + + +fcst = { + sid_inc = []; + sid_exc = []; + obs_quality_inc = []; + obs_quality_exc = []; + + field = [ + { name = "theta"; level = "L2"; message_type = "ADPSFC"; } + ]; + +} + +obs = { + sid_inc = []; + sid_exc = []; + obs_quality_inc = []; + obs_quality_exc = []; + + field = [ + { name = "TMP"; level = "P1000-500"; message_type = "ADPSFC"; } + ]; + +} + +//////////////////////////////////////////////////////////////////////////////// + +climo_mean = obs; +climo_mean = { + file_name = []; +} + +//////////////////////////////////////////////////////////////////////////////// + +mask = { + grid = []; + poly = []; + sid = []; + llpnt = [{ name = "ALLLATLON"; lat_thresh = NA; lon_thresh = NA; }]; +} + +//////////////////////////////////////////////////////////////////////////////// + +ci_alpha = [ 0.05 ]; + +boot = { + interval = PCTILE; + rep_prop = 1.0; + n_rep = 200; + rng = "mt19937"; + seed = "1"; +} + +//////////////////////////////////////////////////////////////////////////////// + +interp = { + vld_thresh = 1.0; + + type = [ + { + method = NEAREST; + width = 1; + } + ]; +} + +//////////////////////////////////////////////////////////////////////////////// + +hira = { + flag = FALSE; + width = [ 2, 3, 4, 5 ]; + vld_thresh = 1.0; + cov_thresh = [ ==0.25 ]; + shape = SQUARE; + prob_cat_thresh = []; +} + +//////////////////////////////////////////////////////////////////////////////// + +output_flag = { + fho = BOTH; + ctc = BOTH; + cts = BOTH; + mctc = NONE; + mcts = NONE; + cnt = BOTH; + sl1l2 = NONE; + sal1l2 = NONE; + vl1l2 = NONE; + val1l2 = NONE; + vcnt = BOTH; + pct = NONE; + pstd = NONE; + pjc = NONE; + prc = NONE; + ecnt = NONE; + orank = NONE; + rps = NONE; + eclv = BOTH; + mpr = BOTH; + seeps = NONE; + seeps_mpr = NONE; +} + +//////////////////////////////////////////////////////////////////////////////// +// Threshold for SEEPS p1 (Probability of being dry) + +seeps_p1_thresh = NA; + +//////////////////////////////////////////////////////////////////////////////// +// Unstructured Grid (optional ecept ugrid_dataset) + +//ugrid_dataset = "mpas"; +ugrid_max_distance_km = 35; +//ugrid_map_config = ""; +ugrid_coordinates_file = "${MET_TEST_INPUT}/ugrid_data/mpas/static.40962_reduced.nc"; + +//////////////////////////////////////////////////////////////////////////////// + +duplicate_flag = NONE; +rank_corr_flag = TRUE; +tmp_dir = "/tmp"; +output_prefix = "${OUTPUT_PREFIX}"; +version = "V12.0.0"; + +//////////////////////////////////////////////////////////////////////////////// From 42f65bd125f7e3f11096cc54c44e487ef7c18448 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Wed, 17 Apr 2024 19:56:17 +0000 Subject: [PATCH 11/22] #2842 Corrected ty[po at the variable name --- src/libcode/vx_data2d_ugrid/ugrid_file.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libcode/vx_data2d_ugrid/ugrid_file.cc b/src/libcode/vx_data2d_ugrid/ugrid_file.cc index 5fec54d735..637d9c4422 100644 --- a/src/libcode/vx_data2d_ugrid/ugrid_file.cc +++ b/src/libcode/vx_data2d_ugrid/ugrid_file.cc @@ -959,10 +959,10 @@ void UGridFile::read_netcdf_grid() void UGridFile::set_dataset(ConcatString _dataset_name) { ConcatString ugrid_config_name; - const string method_nmame = "UGridFile::set_dataset() "; + const string method_name = "UGridFile::set_dataset() "; if (0 == _dataset_name.length()) { - mlog << Error << "\n" << method_nmame + mlog << Error << "\n" << method_name << "The \"" << conf_key_ugrid_dataset << "\" is not defined at the configuration file.\n\n"; exit(1); @@ -986,8 +986,8 @@ void UGridFile::set_dataset(ConcatString _dataset_name) { read_config(ugrid_config_name.c_str()); } else { - mlog << Error << "\nUGridFile::set_dataset()" - << " The UGrid dataset \"" << dataset_name << "\" is not supported. Please add \"" + mlog << Error << "\n" << method_name + << "The UGrid dataset \"" << dataset_name << "\" is not supported. Please add \"" << ugrid_config_name << "\".\n\n"; exit(1); } From 0974159c8605e0b37f3478b7df276ccd877421a3 Mon Sep 17 00:00:00 2001 From: Daniel Adriaansen Date: Thu, 18 Apr 2024 18:41:56 +0000 Subject: [PATCH 12/22] Switched from time_centered to time_instant. I think time_centered is the center of the forecast lead window and time_instant is the time the forecast is valid (end of forecast window). --- data/config/UGridConfig_lfric | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/config/UGridConfig_lfric b/data/config/UGridConfig_lfric index 7c5e164643..26a6f25777 100644 --- a/data/config/UGridConfig_lfric +++ b/data/config/UGridConfig_lfric @@ -24,7 +24,7 @@ ugrid_metadata_map = [ { key = "lon_edge"; val = "Mesh2d_edge_x"; }, { key = "lat_node"; val = "Mesh2d_node_y"; }, { key = "lon_node"; val = "Mesh2d_node_x"; }, - { key = "time"; val = "time_centered"; } + { key = "time"; val = "time_instant"; } ]; ugrid_max_distance_km = 30; From 7933a7e048f03907d305d843f0992d0b8dff2020 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Fri, 19 Apr 2024 20:30:01 +0000 Subject: [PATCH 13/22] #2842 Removed ugrid_max_distance_km and unused metadata names --- data/config/UGridConfig_lfric | 15 +++------------ data/config/UGridConfig_mpas | 15 +++------------ 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/data/config/UGridConfig_lfric b/data/config/UGridConfig_lfric index 7c5e164643..e8d0714a3d 100644 --- a/data/config/UGridConfig_lfric +++ b/data/config/UGridConfig_lfric @@ -2,7 +2,7 @@ // // Unstructured grid configuration file. // -// UGridConfig_lfric at the current working directory overrides the settings here. +// UGridConfig_lfric at the current working directory replaces the settings here. // For additional or updated information, please see the MET User's Guide. // //////////////////////////////////////////////////////////////////////////////// @@ -12,23 +12,14 @@ // ugrid_metadata_map = [ { key = "dim_face"; val = "nMesh2d_face"; }, - { key = "dim_node"; val = "nMesh2d_node"; }, - { key = "dim_edge"; val = "nMesh2d_edge"; }, { key = "dim_time"; val = "time_counter"; }, - { key = "dim_vert"; val = "nVertLevels"; }, - { key = "cell_id"; val = "indexToCellID"; }, + { key = "dim_vert"; val = ""; }, // optional { key = "lat_face"; val = "Mesh2d_face_y"; }, { key = "lon_face"; val = "Mesh2d_face_x"; }, - { key = "vert_face"; val = "zCell"; }, - { key = "lat_edge"; val = "Mesh2d_edge_y"; }, - { key = "lon_edge"; val = "Mesh2d_edge_x"; }, - { key = "lat_node"; val = "Mesh2d_node_y"; }, - { key = "lon_node"; val = "Mesh2d_node_x"; }, + { key = "vert_face"; val = ""; }, // optional { key = "time"; val = "time_centered"; } ]; -ugrid_max_distance_km = 30; - //////////////////////////////////////////////////////////////////////////////// version = "V12.0.0"; diff --git a/data/config/UGridConfig_mpas b/data/config/UGridConfig_mpas index 803daf6767..70fca86f98 100644 --- a/data/config/UGridConfig_mpas +++ b/data/config/UGridConfig_mpas @@ -2,7 +2,7 @@ // // Unstructured grid configuration file. // -// UGridConfig_mpas at the current working directory overrides the settings here. +// UGridConfig_mpas at the current working directory replaces the settings here. // For additional or updated information, please see the MET User's Guide. // //////////////////////////////////////////////////////////////////////////////// @@ -12,23 +12,14 @@ // ugrid_metadata_map = [ { key = "dim_face"; val = "nCells"; }, - { key = "dim_node"; val = "nVertices"; }, - { key = "dim_edge"; val = "nEdges"; }, { key = "dim_time"; val = "Time"; }, - { key = "dim_vert"; val = "nVertLevels"; }, - { key = "cell_id"; val = "indexToCellID"; }, + { key = "dim_vert"; val = "nVertLevels"; }, // optional { key = "lat_face"; val = "latCell"; }, { key = "lon_face"; val = "lonCell"; }, - { key = "vert_face"; val = "zCell"; }, - { key = "lat_edge"; val = "latEdge"; }, - { key = "lon_edge"; val = "lonEdge"; }, - { key = "lat_node"; val = "latVertex"; }, - { key = "lon_node"; val = "lonVertex"; }, + { key = "vert_face"; val = "zCell"; }, // optional { key = "time"; val = "xtime"; } ]; -ugrid_max_distance_km = 30; - //////////////////////////////////////////////////////////////////////////////// version = "V12.0.0"; From a253d1e73125b4e9e85208e2ffd495a518a676d7 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Fri, 19 Apr 2024 20:45:40 +0000 Subject: [PATCH 14/22] #2842 Restored time variable time_instant for LFric --- data/config/UGridConfig_lfric | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/config/UGridConfig_lfric b/data/config/UGridConfig_lfric index e8d0714a3d..8b12f429f5 100644 --- a/data/config/UGridConfig_lfric +++ b/data/config/UGridConfig_lfric @@ -17,7 +17,7 @@ ugrid_metadata_map = [ { key = "lat_face"; val = "Mesh2d_face_y"; }, { key = "lon_face"; val = "Mesh2d_face_x"; }, { key = "vert_face"; val = ""; }, // optional - { key = "time"; val = "time_centered"; } + { key = "time"; val = "time_instant"; } ]; //////////////////////////////////////////////////////////////////////////////// From 3c168529392125cd3775e86006965a8efe49a7c4 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Tue, 23 Apr 2024 16:41:11 +0000 Subject: [PATCH 15/22] #2842 Adjust lon between -180 and 180 --- src/libcode/vx_grid/unstructured_grid.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libcode/vx_grid/unstructured_grid.cc b/src/libcode/vx_grid/unstructured_grid.cc index 9af740a233..1c698798cb 100644 --- a/src/libcode/vx_grid/unstructured_grid.cc +++ b/src/libcode/vx_grid/unstructured_grid.cc @@ -151,6 +151,8 @@ void UnstructuredGrid::xy_to_latlon(double x, double y, double &lat, double &lon lat = Data.pointLonLat[x].y(); lon = Data.pointLonLat[x].x(); + if (lon >= 180.0) long -= 360.0; + else if (lon < -180.0) long += 360.0; if(mlog.verbosity_level() >= UGRID_DEBUG_LEVEL) mlog << Debug(UGRID_DEBUG_LEVEL) << "UnstructuredGrid::xy_to_latlon() " From 2472b84423393010b47ad9d5102d99ed475c86d1 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Tue, 23 Apr 2024 16:44:59 +0000 Subject: [PATCH 16/22] #2842 Adjust lon between -180 and 180 --- src/libcode/vx_grid/unstructured_grid.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcode/vx_grid/unstructured_grid.cc b/src/libcode/vx_grid/unstructured_grid.cc index 1c698798cb..ccc13292c0 100644 --- a/src/libcode/vx_grid/unstructured_grid.cc +++ b/src/libcode/vx_grid/unstructured_grid.cc @@ -151,8 +151,8 @@ void UnstructuredGrid::xy_to_latlon(double x, double y, double &lat, double &lon lat = Data.pointLonLat[x].y(); lon = Data.pointLonLat[x].x(); - if (lon >= 180.0) long -= 360.0; - else if (lon < -180.0) long += 360.0; + if (lon >= 180.0) long = long - 360.0; + else if (lon < -180.0) long = long + 360.0; if(mlog.verbosity_level() >= UGRID_DEBUG_LEVEL) mlog << Debug(UGRID_DEBUG_LEVEL) << "UnstructuredGrid::xy_to_latlon() " From 9dfc8bfb84c7d9749ef26ebaa9d1acbda0472c5a Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Tue, 23 Apr 2024 16:45:57 +0000 Subject: [PATCH 17/22] #2842 Adjust lon between -180 and 180 --- src/libcode/vx_grid/unstructured_grid.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcode/vx_grid/unstructured_grid.cc b/src/libcode/vx_grid/unstructured_grid.cc index ccc13292c0..346bea9023 100644 --- a/src/libcode/vx_grid/unstructured_grid.cc +++ b/src/libcode/vx_grid/unstructured_grid.cc @@ -151,8 +151,8 @@ void UnstructuredGrid::xy_to_latlon(double x, double y, double &lat, double &lon lat = Data.pointLonLat[x].y(); lon = Data.pointLonLat[x].x(); - if (lon >= 180.0) long = long - 360.0; - else if (lon < -180.0) long = long + 360.0; + if (lon >= 180.0) lon = lon - 360.0; + else if (lon < -180.0) lon = lon + 360.0; if(mlog.verbosity_level() >= UGRID_DEBUG_LEVEL) mlog << Debug(UGRID_DEBUG_LEVEL) << "UnstructuredGrid::xy_to_latlon() " From fd426405021ebf6576b678144029bf5f4cca104a Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Tue, 23 Apr 2024 17:57:58 +0000 Subject: [PATCH 18/22] #2842 Adjusted lon to between -180 to 180 --- src/libcode/vx_regrid/vx_regrid.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libcode/vx_regrid/vx_regrid.cc b/src/libcode/vx_regrid/vx_regrid.cc index 7abfee78b4..6e5f295ea3 100644 --- a/src/libcode/vx_regrid/vx_regrid.cc +++ b/src/libcode/vx_regrid/vx_regrid.cc @@ -133,8 +133,9 @@ to_data.set_accum (from_data.accum()); // // copy data // - +cout << " DEBUG HS met_regrid_generic() to_grid.nx()=" << to_grid.nx() << ", to_grid.ny()=" << to_grid.ny()<< "\n"; for (xt=0; xt<(to_grid.nx()); ++xt) { +cout << " DEBUG HS met_regrid_generic() xt=" << xt<< "\n"; for (yt=0; yt<(to_grid.ny()); ++yt) { @@ -160,6 +161,7 @@ for (xt=0; xt<(to_grid.nx()); ++xt) { } // for yt } // for xt +cout << " DEBUG HS met_regrid_generic() to_grid.nx()=" << to_grid.nx() << ", to_grid.ny()=" << to_grid.ny()<< " -- Done\n"; // // done From 50d6e4a85b58fabb01406a4ad368b05255e13370 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Tue, 23 Apr 2024 18:20:11 +0000 Subject: [PATCH 19/22] #2842 Changed variable names --- src/libcode/vx_grid/grid_base.cc | 22 +++--- src/libcode/vx_grid/unstructured_grid.cc | 81 ++++++++++---------- src/libcode/vx_grid/unstructured_grid_defs.h | 8 +- 3 files changed, 56 insertions(+), 55 deletions(-) diff --git a/src/libcode/vx_grid/grid_base.cc b/src/libcode/vx_grid/grid_base.cc index f9f7c63317..d144aa3490 100644 --- a/src/libcode/vx_grid/grid_base.cc +++ b/src/libcode/vx_grid/grid_base.cc @@ -321,8 +321,8 @@ void UnstructuredData::clear() { void UnstructuredData::clear_data() { - Nface = Nnode = Nedge = 0; - pointLonLat.clear(); + n_face = n_node = n_edge = 0; + point_lonlat.clear(); lat_checksum = lon_checksum = 0.; if (kdtree) { delete kdtree; kdtree = nullptr; } @@ -337,7 +337,7 @@ void UnstructuredData::dump() const { mlog << Debug(grid_debug_level) << "\nUnstructured Grid Data:\n" - << " Nface: " << Nface << "\n" + << " n_face: " << n_face << "\n" << " lat_checksum: " << lat_checksum << "\n" << " lon_checksum: " << lon_checksum << "\n" << " max_distance_km: " << max_distance_km << "\n" @@ -761,10 +761,10 @@ clear(); UnstructuredData *D = new UnstructuredData; -D->Nedge = data.Nedge; -D->Nnode = data.Nnode; +D->n_edge = data.n_edge; +D->n_node = data.n_node; D->max_distance_km = data.max_distance_km; -D->set_points(data.Nface, data.pointLonLat); +D->set_points(data.n_face, data.point_lonlat); us = D; D = (UnstructuredData *)nullptr; @@ -1690,11 +1690,11 @@ bool is_eq(const UnstructuredData * us1, const UnstructuredData * us2) bool status = false; if (us1 && us2) { if (us1 == us2) status = true; - else status = us1->Nface == us2->Nface - && us1->Nnode == us2->Nnode - && us1->Nedge == us2->Nedge - && us1->pointLonLat[0] == us2->pointLonLat[0] - && (us1->Nface > 0 && us1->pointLonLat[us1->Nface-1] == us2->pointLonLat[us2->Nface-1]) + else status = us1->n_face == us2->n_face + && us1->n_node == us2->n_node + && us1->n_edge == us2->n_edge + && us1->point_lonlat[0] == us2->point_lonlat[0] + && (us1->n_face > 0 && us1->point_lonlat[us1->n_face-1] == us2->point_lonlat[us2->n_face-1]) && is_eq(us1->lat_checksum, us2->lat_checksum) && is_eq(us1->lon_checksum, us2->lon_checksum); } diff --git a/src/libcode/vx_grid/unstructured_grid.cc b/src/libcode/vx_grid/unstructured_grid.cc index 346bea9023..83bdd76c26 100644 --- a/src/libcode/vx_grid/unstructured_grid.cc +++ b/src/libcode/vx_grid/unstructured_grid.cc @@ -96,14 +96,14 @@ void UnstructuredGrid::set_from_data(const UnstructuredData &data) { clear(); if (data.name) Name = data.name; - Nx = data.Nface; + Nx = data.n_face; - Data.Nface = Nx; - Data.Nedge = data.Nedge; - Data.Nnode = data.Nnode; + Data.n_face = Nx; + Data.n_edge = data.n_edge; + Data.n_node = data.n_node; Data.max_distance_km = data.max_distance_km; - Data.set_points(Nx, data.pointLonLat); + Data.set_points(Nx, data.point_lonlat); } @@ -120,9 +120,11 @@ void UnstructuredGrid::set_max_distance_km(double max_distance) { void UnstructuredGrid::latlon_to_xy(double lat, double lon, double &x, double &y) const { - PointLonLat _pointLonLat(lon, lat); + if (lon >= 180.0) lon -= 360.0; + else if (lon < -180.0) lon += 360.0; + PointLonLat _point_lonlat(lon, lat); - IndexKDTree::ValueList neighbor = Data.kdtree->closestPoints(_pointLonLat, 1); + IndexKDTree::ValueList neighbor = Data.kdtree->closestPoints(_point_lonlat, 1); size_t index(neighbor[0].payload()); double distance_km(neighbor[0].distance()/1000.); bool in_distance = Data.is_in_distance(distance_km); @@ -130,16 +132,12 @@ void UnstructuredGrid::latlon_to_xy(double lat, double lon, double &x, double &y x = in_distance ? index : -1.0; y = 0; - //PointLonLat r_lonlat; - //if(_distance > 180.0) atlas_geometry.xyz2lonlat(neighbor[0].point(), r_lonlat); - //else r_lonlat.assign(neighbor[0].point()[0], neighbor[0].point()[1]); - if(mlog.verbosity_level() >= UGRID_DEBUG_LEVEL) mlog << Debug(UGRID_DEBUG_LEVEL) << "UnstructuredGrid::latlon_to_xy() " << "input=(" << lon << ", " << lat << ") ==> (" << x << ", " << y << ") == (" - << Data.pointLonLat[index].x() << ", " << Data.pointLonLat[index].y() + << Data.point_lonlat[index].x() << ", " << Data.point_lonlat[index].y() << ") distance= " << distance_km << "km, " - << _pointLonLat.distance(Data.pointLonLat[index]) + << _point_lonlat.distance(Data.point_lonlat[index]) << " degree" << (in_distance ? " " : ", rejected") << "\n"; } @@ -149,10 +147,10 @@ void UnstructuredGrid::latlon_to_xy(double lat, double lon, double &x, double &y void UnstructuredGrid::xy_to_latlon(double x, double y, double &lat, double &lon) const { - lat = Data.pointLonLat[x].y(); - lon = Data.pointLonLat[x].x(); - if (lon >= 180.0) lon = lon - 360.0; - else if (lon < -180.0) lon = lon + 360.0; + lat = Data.point_lonlat[x].y(); + lon = Data.point_lonlat[x].x(); + if (lon >= 180.0) lon -= 360.0; + else if (lon < -180.0) lon += 360.0; if(mlog.verbosity_level() >= UGRID_DEBUG_LEVEL) mlog << Debug(UGRID_DEBUG_LEVEL) << "UnstructuredGrid::xy_to_latlon() " @@ -215,7 +213,7 @@ else out << "(nul)\n"; out << '\n'; -out << prefix << "Nface = " << Nx << "\n"; +out << prefix << "n_face = " << Nx << "\n"; // // done @@ -236,7 +234,7 @@ ConcatString a; a << "Projection: UnstructuredGrid" << sep; -a << "Nface: " << Nx << sep; +a << "n_face: " << Nx << sep; // // done // @@ -354,13 +352,16 @@ void UnstructuredData::build_tree() { atlas::idx_t n = 0; kdtree = new IndexKDTree(atlas_geometry); - kdtree->reserve(Nface); - for (int i=0; ireserve(n_face); + for (int i=0; i= 180.0) lon -= 360.0; + else if (lon < -180.0) lon += 360.0; + PointLonLat pointLL(lon, point_lonlat[i].y()); pointLL.normalise(); kdtree->insert(pointLL, n++); - lat_checksum += (i+1) * pointLonLat[i].y(); - lon_checksum += (i+1) * pointLonLat[i].x(); + lat_checksum += (i+1) * point_lonlat[i].y(); + lon_checksum += (i+1) * point_lonlat[i].x(); } kdtree->build(); @@ -370,18 +371,18 @@ void UnstructuredData::build_tree() { //////////////////////////////////////////////////////////////////////// void UnstructuredData::copy_from(const UnstructuredData &us_data) { - set_points(us_data.Nface, us_data.pointLonLat); - Nedge = us_data.Nedge; - Nnode = us_data.Nnode; + set_points(us_data.n_face, us_data.point_lonlat); + n_edge = us_data.n_edge; + n_node = us_data.n_node; max_distance_km = us_data.max_distance_km; } //////////////////////////////////////////////////////////////////////// void UnstructuredData::copy_from(const UnstructuredData *us_data) { - set_points(us_data->Nface, us_data->pointLonLat); - Nedge = us_data->Nedge; - Nnode = us_data->Nnode; + set_points(us_data->n_face, us_data->point_lonlat); + n_edge = us_data->n_edge; + n_node = us_data->n_node; max_distance_km = us_data->max_distance_km; } @@ -402,15 +403,15 @@ void UnstructuredData::set_points(int count, double *_lon, double *_lat) { clear_data(); - Nface = count; - pointLonLat.reserve(count); + n_face = count; + point_lonlat.reserve(count); for (int i=0; i= UGRID_DEBUG_LEVEL) mlog << Debug(UGRID_DEBUG_LEVEL) << "UnstructuredData::set_points(int, double *, double *) first (" - << pointLonLat[0].x() << ", " << pointLonLat[0].y() << ") and last (" - << pointLonLat[count-1].x() << ", " << pointLonLat[count-1].y() << ") from (" + << point_lonlat[0].x() << ", " << point_lonlat[0].y() << ") and last (" + << point_lonlat[count-1].x() << ", " << point_lonlat[count-1].y() << ") from (" << _lon[0] << ", " << _lat[0] << ") and (" << _lon[count-1] << ", " << _lat[count-1] << ")\n"; @@ -424,15 +425,15 @@ void UnstructuredData::set_points(int count, const std::vector &ptL clear_data(); - Nface = count; - pointLonLat.reserve(count); + n_face = count; + point_lonlat.reserve(count); for (int i=0; i= UGRID_DEBUG_LEVEL) mlog << Debug(UGRID_DEBUG_LEVEL) << "UnstructuredData::set_points(std::vector &) first: (" - << pointLonLat[0].x() << ", " << pointLonLat[0].y() << ") and last (" - << pointLonLat[count-1].x() << ", " << pointLonLat[count-1].y() << ") from (" + << point_lonlat[0].x() << ", " << point_lonlat[0].y() << ") and last (" + << point_lonlat[count-1].x() << ", " << point_lonlat[count-1].y() << ") from (" << ptLonLat[0].x() << ", " << ptLonLat[0].y() << ") and (" << ptLonLat[count-1].x() << ", " << ptLonLat[count-1].y() << ")\n"; diff --git a/src/libcode/vx_grid/unstructured_grid_defs.h b/src/libcode/vx_grid/unstructured_grid_defs.h index a363bbab6d..68456d0d35 100644 --- a/src/libcode/vx_grid/unstructured_grid_defs.h +++ b/src/libcode/vx_grid/unstructured_grid_defs.h @@ -36,14 +36,14 @@ struct UnstructuredData { const char * name; // not allocated - int Nface; - int Nedge; - int Nnode; + int n_face; + int n_edge; + int n_node; double max_distance_km; // This should be set after calling set_points() double lat_checksum; double lon_checksum; - std::vector pointLonLat; + std::vector point_lonlat; atlas::util::IndexKDTree *kdtree; UnstructuredData(); From f6202069201f2ae810f9e7b74de83fba9a9dd595 Mon Sep 17 00:00:00 2001 From: John Halley Gotway Date: Wed, 24 Apr 2024 09:38:14 -0600 Subject: [PATCH 20/22] Per #2842, switch from degrees east to west right when the longitudes are read. --- src/libcode/vx_data2d_ugrid/ugrid_file.cc | 3 +++ src/libcode/vx_grid/unstructured_grid.cc | 11 ++--------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/libcode/vx_data2d_ugrid/ugrid_file.cc b/src/libcode/vx_data2d_ugrid/ugrid_file.cc index 637d9c4422..66adc71b34 100644 --- a/src/libcode/vx_data2d_ugrid/ugrid_file.cc +++ b/src/libcode/vx_data2d_ugrid/ugrid_file.cc @@ -940,6 +940,9 @@ void UGridFile::read_netcdf_grid() } } + // Convert longitude from degrees east to west + for (int idx=0; idx= 180.0) lon -= 360.0; - else if (lon < -180.0) lon += 360.0; PointLonLat _point_lonlat(lon, lat); IndexKDTree::ValueList neighbor = Data.kdtree->closestPoints(_point_lonlat, 1); @@ -149,8 +147,6 @@ void UnstructuredGrid::xy_to_latlon(double x, double y, double &lat, double &lon lat = Data.point_lonlat[x].y(); lon = Data.point_lonlat[x].x(); - if (lon >= 180.0) lon -= 360.0; - else if (lon < -180.0) lon += 360.0; if(mlog.verbosity_level() >= UGRID_DEBUG_LEVEL) mlog << Debug(UGRID_DEBUG_LEVEL) << "UnstructuredGrid::xy_to_latlon() " @@ -354,10 +350,7 @@ void UnstructuredData::build_tree() { kdtree = new IndexKDTree(atlas_geometry); kdtree->reserve(n_face); for (int i=0; i= 180.0) lon -= 360.0; - else if (lon < -180.0) lon += 360.0; - PointLonLat pointLL(lon, point_lonlat[i].y()); + PointLonLat pointLL(point_lonlat[i].x(), point_lonlat[i].y()); pointLL.normalise(); kdtree->insert(pointLL, n++); lat_checksum += (i+1) * point_lonlat[i].y(); @@ -431,7 +424,7 @@ void UnstructuredData::set_points(int count, const std::vector &ptL point_lonlat[i] = {(ptLonLat)[i].x(), (ptLonLat)[i].y()}; } if(mlog.verbosity_level() >= UGRID_DEBUG_LEVEL) mlog - << Debug(UGRID_DEBUG_LEVEL) << "UnstructuredData::set_points(std::vector &) first: (" + << Debug(UGRID_DEBUG_LEVEL) << "UnstructuredData::set_points(int, std::vector &) first: (" << point_lonlat[0].x() << ", " << point_lonlat[0].y() << ") and last (" << point_lonlat[count-1].x() << ", " << point_lonlat[count-1].y() << ") from (" << ptLonLat[0].x() << ", " << ptLonLat[0].y() << ") and (" From f25dd196a8fd50e75ead9e6fb1b9954022100457 Mon Sep 17 00:00:00 2001 From: Howard Soh Date: Wed, 24 Apr 2024 16:19:22 +0000 Subject: [PATCH 21/22] #2842, switch from degrees east to west right when the longitudes are read --- src/libcode/vx_data2d_ugrid/ugrid_file.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcode/vx_data2d_ugrid/ugrid_file.cc b/src/libcode/vx_data2d_ugrid/ugrid_file.cc index 66adc71b34..d157f75f0c 100644 --- a/src/libcode/vx_data2d_ugrid/ugrid_file.cc +++ b/src/libcode/vx_data2d_ugrid/ugrid_file.cc @@ -941,7 +941,7 @@ void UGridFile::read_netcdf_grid() } // Convert longitude from degrees east to west - for (int idx=0; idx Date: Thu, 25 Apr 2024 19:59:21 +0000 Subject: [PATCH 22/22] #2842 Cleanup debug messages --- src/libcode/vx_regrid/vx_regrid.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/libcode/vx_regrid/vx_regrid.cc b/src/libcode/vx_regrid/vx_regrid.cc index 6e5f295ea3..5fcc970601 100644 --- a/src/libcode/vx_regrid/vx_regrid.cc +++ b/src/libcode/vx_regrid/vx_regrid.cc @@ -133,9 +133,7 @@ to_data.set_accum (from_data.accum()); // // copy data // -cout << " DEBUG HS met_regrid_generic() to_grid.nx()=" << to_grid.nx() << ", to_grid.ny()=" << to_grid.ny()<< "\n"; for (xt=0; xt<(to_grid.nx()); ++xt) { -cout << " DEBUG HS met_regrid_generic() xt=" << xt<< "\n"; for (yt=0; yt<(to_grid.ny()); ++yt) { @@ -161,7 +159,6 @@ cout << " DEBUG HS met_regrid_generic() xt=" << xt<< "\n"; } // for yt } // for xt -cout << " DEBUG HS met_regrid_generic() to_grid.nx()=" << to_grid.nx() << ", to_grid.ny()=" << to_grid.ny()<< " -- Done\n"; // // done