From 357bd511bfb422ae2bc810ac65809a96ac094453 Mon Sep 17 00:00:00 2001
From: George McCabe <23407799+georgemccabe@users.noreply.github.com>
Date: Tue, 16 Jan 2024 16:54:02 -0700
Subject: [PATCH] per #2547, added unit tests to process WRF out data with
 plot_data_plane and grid_stat

---
 .../test_unit/config/GridStatConfig_WRF_pres  | 288 ++++++++++++++++++
 internal/test_unit/xml/unit_grid_stat.xml     |  17 ++
 .../test_unit/xml/unit_plot_data_plane.xml    |  84 +++++
 3 files changed, 389 insertions(+)
 create mode 100644 internal/test_unit/config/GridStatConfig_WRF_pres

diff --git a/internal/test_unit/config/GridStatConfig_WRF_pres b/internal/test_unit/config/GridStatConfig_WRF_pres
new file mode 100644
index 0000000000..3468aa110c
--- /dev/null
+++ b/internal/test_unit/config/GridStatConfig_WRF_pres
@@ -0,0 +1,288 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// Grid-Stat configuration file.
+//
+// For additional information, please see the MET User's Guide.
+//
+////////////////////////////////////////////////////////////////////////////////
+
+//
+// Output model name to be written
+//
+model = "FCST";
+
+//
+// Output description to be written
+// May be set separately in each "obs.field" entry
+//
+desc = "NA";
+
+//
+// Output observation type to be written
+//
+obtype = "ANALYS";
+
+////////////////////////////////////////////////////////////////////////////////
+
+//
+// Verification grid
+// May be set separately in each "field" entry
+//
+regrid = {
+   to_grid    = NONE;
+   method     = NEAREST;
+   width      = 1;
+   vld_thresh = 0.5;
+   shape      = SQUARE;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+//
+// May be set separately in each "field" entry
+//
+censor_thresh       = [];
+censor_val          = [];
+mpr_column          = [];
+mpr_thresh          = [];
+cat_thresh          = [];
+cnt_thresh          = [ NA ];
+cnt_logic           = UNION;
+wind_thresh         = [ NA ];
+wind_logic          = UNION;
+eclv_points         = 0.05;
+nc_pairs_var_name   = "";
+nc_pairs_var_suffix = "";
+hss_ec_value        = NA;
+rank_corr_flag      = FALSE;
+
+//
+// Forecast and observation fields to be verified
+//
+fcst = {
+
+   field = [
+      {
+        name       = "U_PL";
+        level      = [ "(0,2,*,*)" ];
+        cat_thresh = [ >=0.0, >=2.5 ];
+      }
+   ];
+
+}
+obs = {
+
+   field = [
+      {
+        name       = "U_PL";
+        level      = [ "(0,@50000,*,*)" ];
+        cat_thresh = [ >=0.0, >=2.5 ];
+      }
+   ];
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+//
+// Climatology data
+//
+climo_mean = {
+
+   file_name = [];
+   field     = [];
+
+   regrid = {
+      method     = NEAREST;
+      width      = 1;
+      vld_thresh = 0.5;
+      shape      = SQUARE;
+   }
+
+   time_interp_method = DW_MEAN;
+   day_interval       = 31;
+   hour_interval      = 6;
+}
+
+climo_stdev = climo_mean;
+climo_stdev = {
+   file_name = [];
+}
+
+//
+// May be set separately in each "obs.field" entry
+//
+climo_cdf = {
+   cdf_bins    = 1;
+   center_bins = FALSE;
+   write_bins  = TRUE;
+   direct_prob = FALSE;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+//
+// Verification masking regions
+// May be set separately in each "obs.field" entry
+//
+mask = {
+   grid = [ "FULL" ];
+   poly = [];
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+//
+// Confidence interval settings
+// May be set separately in each "obs.field" entry
+//
+ci_alpha  = [ 0.05 ];
+
+boot = {
+   interval = PCTILE;
+   rep_prop = 1.0;
+   n_rep    = 0;
+   rng      = "mt19937";
+   seed     = "";
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+//
+// Data smoothing methods
+// May be set separately in each "obs.field" entry
+//
+interp = {
+   field      = BOTH;
+   vld_thresh = 1.0;
+   shape      = SQUARE;
+
+   type = [
+      {
+         method = NEAREST;
+         width  = 1;
+      }
+   ];
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+//
+// Neighborhood methods
+// May be set separately in each "obs.field" entry
+//
+nbrhd = {
+   field      = BOTH;
+   vld_thresh = 1.0;
+   shape      = SQUARE;
+   width      = [ 1 ];
+   cov_thresh = [ >=0.5 ];
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+//
+// Fourier decomposition
+// May be set separately in each "obs.field" entry
+//
+fourier = {
+   wave_1d_beg = [];
+   wave_1d_end = [];
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+//
+// Gradient statistics
+// May be set separately in each "obs.field" entry
+//
+gradient = {
+   dx = [ 1 ];
+   dy = [ 1 ];
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+//
+// Distance Map statistics
+// May be set separately in each "obs.field" entry
+//
+distance_map = {
+   baddeley_p        = 2;
+   baddeley_max_dist = NA;
+   fom_alpha         = 0.1;
+   zhu_weight        = 0.5;
+   beta_value(n)     = n * n / 2.0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+//
+// Threshold for SEEPS p1 (Probability of being dry)
+//
+seeps_p1_thresh = >=0.1&&<=0.85;
+
+////////////////////////////////////////////////////////////////////////////////
+
+//
+// Statistical output types
+// May be set separately in each "obs.field" entry
+//
+output_flag = {
+   fho    = STAT;
+   ctc    = STAT;
+   cts    = STAT;
+   mctc   = STAT;
+   mcts   = STAT;
+   cnt    = STAT;
+   sl1l2  = STAT;
+   sal1l2 = NONE;
+   vl1l2  = NONE;
+   val1l2 = NONE;
+   vcnt   = NONE;
+   pct    = NONE;
+   pstd   = NONE;
+   pjc    = NONE;
+   prc    = NONE;
+   eclv   = NONE;
+   nbrctc = NONE;
+   nbrcts = NONE;
+   nbrcnt = NONE;
+   grad   = NONE;
+   dmap   = NONE;
+   seeps  = NONE;
+}
+
+//
+// NetCDF matched pairs output file
+// May be set separately in each "obs.field" entry
+//
+nc_pairs_flag = {
+   latlon       = TRUE;
+   raw          = TRUE;
+   diff         = TRUE;
+   climo        = TRUE;
+   climo_cdp    = FALSE;
+   seeps        = FALSE;
+   weight       = FALSE;
+   nbrhd        = FALSE;
+   fourier      = FALSE;
+   gradient     = FALSE;
+   distance_map = FALSE;
+   apply_mask   = TRUE;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+ugrid_dataset = "";
+ugrid_max_distance_km = 30;
+ugrid_coordinates_file = "";
+
+////////////////////////////////////////////////////////////////////////////////
+
+grid_weight_flag = NONE;
+tmp_dir          = "/tmp";
+output_prefix    = "${OUTPUT_PREFIX}";
+version          = "V12.0.0";
+
+////////////////////////////////////////////////////////////////////////////////
diff --git a/internal/test_unit/xml/unit_grid_stat.xml b/internal/test_unit/xml/unit_grid_stat.xml
index 204e934230..f70f53ad22 100644
--- a/internal/test_unit/xml/unit_grid_stat.xml
+++ b/internal/test_unit/xml/unit_grid_stat.xml
@@ -311,4 +311,21 @@
     </output>
   </test>
 
+  <test name="grid_stat_WRF_pres">
+    <exec>&MET_BIN;/grid_stat</exec>
+    <env>
+      <pair><name>OUTPUT_PREFIX</name>   <value>WRF_pres</value></pair>
+    </env>
+    <param> \
+      &DATA_DIR_MODEL;/wrf/wrfout_solarwind_d02_2019-08-31_12:00:00 \
+      &DATA_DIR_MODEL;/wrf/wrfout_solarwind_d02_2019-08-31_12:00:00 \
+      &CONFIG_DIR;/GridStatConfig_WRF_pres \
+      -outdir &OUTPUT_DIR;/grid_stat -v 1
+    </param>
+    <output>
+      <stat>&OUTPUT_DIR;/grid_stat/grid_stat_WRF_pres_120000L_20190831_120000V.stat</stat>
+      <grid_nc>&OUTPUT_DIR;/grid_stat/grid_stat_WRF_pres_120000L_20190831_120000V_pairs.nc</grid_nc>
+    </output>
+  </test>
+
 </met_test>
diff --git a/internal/test_unit/xml/unit_plot_data_plane.xml b/internal/test_unit/xml/unit_plot_data_plane.xml
index e9e5ae965f..3e72dbca35 100644
--- a/internal/test_unit/xml/unit_plot_data_plane.xml
+++ b/internal/test_unit/xml/unit_plot_data_plane.xml
@@ -564,4 +564,88 @@
     </output>
   </test>
 
+  <test name="plot_data_plane_WRF_west_east_stag">
+    <exec>&MET_BIN;/plot_data_plane</exec>
+    <param> \
+      &DATA_DIR_MODEL;/wrf/wrfout_solarwind_d02_2019-08-31_12:00:00 \
+      &OUTPUT_DIR;/plot_data_plane/wrf_west_east_stag.ps \
+      'name="U"; level="(0,0,*,*)";' \
+      -title "X-wind component (staggered)" \
+      -v 1
+    </param>
+    <output>
+      <ps>&OUTPUT_DIR;/plot_data_plane/wrf_west_east_stag.ps</ps>
+    </output>
+  </test>
+
+  <test name="plot_data_plane_WRF_south_north_stag">
+    <exec>&MET_BIN;/plot_data_plane</exec>
+    <param> \
+      &DATA_DIR_MODEL;/wrf/wrfout_solarwind_d02_2019-08-31_12:00:00 \
+      &OUTPUT_DIR;/plot_data_plane/wrf_south_north_stag.ps \
+      'name="V"; level="(0,0,*,*)";' \
+      -title "Y-wind component (staggered)" \
+      -v 1
+    </param>
+    <output>
+      <ps>&OUTPUT_DIR;/plot_data_plane/wrf_south_north_stag.ps</ps>
+    </output>
+  </test>
+
+  <test name="plot_data_plane_WRF_num_press_levels_stag">
+    <exec>&MET_BIN;/plot_data_plane</exec>
+    <param> \
+      &DATA_DIR_MODEL;/wrf/wrfout_solarwind_d02_2019-08-31_12:00:00 \
+      &OUTPUT_DIR;/plot_data_plane/wrf_num_press_levels_stag.ps \
+      'name="RH_PL"; level="(0,@50000,*,*)";' \
+      -title "Relative Humidity P50000 (num_press_levels_stag)" \
+      -v 1
+    </param>
+    <output>
+      <ps>&OUTPUT_DIR;/plot_data_plane/wrf_num_press_levels_stag.ps</ps>
+    </output>
+  </test>
+
+  <test name="plot_data_plane_WRF_num_z_levels_stag">
+    <exec>&MET_BIN;/plot_data_plane</exec>
+    <param> \
+      &DATA_DIR_MODEL;/wrf/wrfout_solarwind_d02_2019-08-31_12:00:00 \
+      &OUTPUT_DIR;/plot_data_plane/wrf_num_z_levels_stag.ps \
+      'name="RH_ZL"; level="(0,0,*,*)";' \
+      -title "Relative Humidity Z-level (num_z_levels_stag)" \
+      -v 1
+    </param>
+    <output>
+      <ps>&OUTPUT_DIR;/plot_data_plane/wrf_num_z_levels_stag.ps</ps>
+    </output>
+  </test>
+
+  <test name="plot_data_plane_WRF_bottom_top">
+    <exec>&MET_BIN;/plot_data_plane</exec>
+    <param> \
+      &DATA_DIR_MODEL;/wrf/wrfout_solarwind_d02_2019-08-31_12:00:00 \
+      &OUTPUT_DIR;/plot_data_plane/wrf_bottom_top.ps \
+      'name="T"; level="(0,0,*,*)";' \
+      -title "perturbation potential temperature theta-t0 (bottom_top)" \
+      -v 1
+    </param>
+    <output>
+      <ps>&OUTPUT_DIR;/plot_data_plane/wrf_bottom_top.ps</ps>
+    </output>
+  </test>
+
+  <test name="plot_data_plane_WRF_bottom_top_stag">
+    <exec>&MET_BIN;/plot_data_plane</exec>
+    <param> \
+      &DATA_DIR_MODEL;/wrf/wrfout_solarwind_d02_2019-08-31_12:00:00 \
+      &OUTPUT_DIR;/plot_data_plane/wrf_bottom_top_stag.ps \
+      'name="PH"; level="(0,0,*,*)";' \
+      -title "perturbation geopotential (bottom_top_stag)" \
+      -v 1
+    </param>
+    <output>
+      <ps>&OUTPUT_DIR;/plot_data_plane/wrf_bottom_top_stag.ps</ps>
+    </output>
+  </test>
+
 </met_test>