Skip to content

Commit

Permalink
Feature 1792 gen_vx_mask (#1816)
Browse files Browse the repository at this point in the history
* Per issue #1792, Change -type from optional to required. Set default_mask_type to MaskType_None. Added a check on mask_type to see if it's set and print error message accordingly.

* Update test_gen_vx_mask.sh

* For the first test, added -type poly, since the masking type is now required. SL

* For all of the Poly unit tests added -type poly to the command line. The mask type is now required. SL

* Modified document to indicate that -type string (masking type) is now required on the command line for gen_vx_mask. SL

* Update met/docs/Users_Guide/masking.rst

Co-authored-by: johnhg <johnhg@ucar.edu>

* Update met/src/tools/other/gen_vx_mask/gen_vx_mask.cc

Co-authored-by: johnhg <johnhg@ucar.edu>

Co-authored-by: Seth Linden <linden@kiowa.rap.ucar.edu>
Co-authored-by: johnhg <johnhg@ucar.edu>
  • Loading branch information
3 people committed Jun 4, 2021
1 parent b6bb5e7 commit d3cd134
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 19 deletions.
8 changes: 4 additions & 4 deletions met/docs/Users_Guide/masking.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The usage statement for the Gen-Vx-Mask tool is shown below:
input_grid
mask_file
out_file
[-type str]
-type str
[-input_field string]
[-mask_field string]
[-complement]
Expand All @@ -36,7 +36,7 @@ The usage statement for the Gen-Vx-Mask tool is shown below:
[-v level]
[-compress level]
gen_vx_mask has three required arguments and can take optional ones.
gen_vx_mask has four required arguments and can take optional ones. Note, -type string (masking type) was previously optional but is now required.

Required arguments for gen_vx_mask
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -57,11 +57,11 @@ Required arguments for gen_vx_mask

3. The **out_file** argument is the output NetCDF mask file to be written.

4. The **-type string** is required to set the masking type. The application will give an error message and exit if "-type string" is not specified on the command line. See description of supported types below.

Optional arguments for gen_vx_mask
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

4. The **-type string** option can be used to override the default masking type (poly). See description of supported types below.

5. The **-input_field string** option can be used to read existing mask data from “input_file”.

6. The **-mask_field string** option can be used to define the field from “mask_file” to be used for “data” masking.
Expand Down
3 changes: 2 additions & 1 deletion met/scripts/examples/test_gen_vx_mask.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ echo "*** Running Gen-Vx-Mask to generate a polyline mask file for the Continent
gen_vx_mask \
../data/sample_fcst/2005080700/wrfprs_ruc13_24.tm00_G212 \
$MET_BASE/poly/CONUS.poly \
${TEST_OUT_DIR}/gen_vx_mask/CONUS_poly.nc -v 2
${TEST_OUT_DIR}/gen_vx_mask/CONUS_poly.nc \
-type poly -v 2

echo
echo "*** Running Gen-Vx-Mask to generate a circle mask file ***"
Expand Down
2 changes: 1 addition & 1 deletion met/scripts/mk/gen_vx_mask.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ gen_vx_mask: ${GEN_VX_MASK_EXEC}
${GEN_VX_MASK_EXEC} \
../data/sample_fcst/2005080700/wrfprs_ruc13_24.tm00_G212 \
../data/poly/CONUS.poly \
${TEST_OUT_DIR}/gen_vx_mask/CONUS_poly.nc -v 2
${TEST_OUT_DIR}/gen_vx_mask/CONUS_poly.nc -type poly -v 2
@
echo
echo "*** Running Gen-Vx-Mask to generate a circle mask file ***"
Expand Down
22 changes: 17 additions & 5 deletions met/src/tools/other/gen_vx_mask/gen_vx_mask.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
// 006 07/09/18 Bullock Add shapefile masking type.
// 007 04/08/19 Halley Gotway Add percentile thresholds.
// 008 04/06/20 Halley Gotway Generalize input_grid option.
// 009 06/01/21 Seth Linden Change -type from optional to required
//
////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -138,6 +139,17 @@ void process_command_line(int argc, char **argv) {
mask_filename = cline[1];
out_filename = cline[2];

// Check for the mask type (from -type string)
if(mask_type == MaskType_None) {
mlog << Error << "\n" << program_name << " -> "
<< "the -type command line requirement must be set to a specific masking type!\n"
<< "\t\t \"poly\", \"box\", \"circle\", \"track\", \"grid\", "
<< "\"data\", \"solar_alt\", \"solar_azi\", \"lat\", \"lon\" "
<< "or \"shape\""
<< "\n\n";
exit(1);
}

// List the input files
mlog << Debug(1)
<< "Input Grid:\t\t" << input_gridname << "\n"
Expand Down Expand Up @@ -1340,7 +1352,7 @@ void usage() {
<< "\tinput_grid\n"
<< "\tmask_file\n"
<< "\tout_file\n"
<< "\t[-type string]\n"
<< "\t-type string\n"
<< "\t[-input_field string]\n"
<< "\t[-mask_field string]\n"
<< "\t[-complement]\n"
Expand Down Expand Up @@ -1380,12 +1392,12 @@ void usage() {
<< "\t\t\"out_file\" is the output NetCDF mask file to be "
<< "written (required).\n"

<< "\t\t\"-type string\" overrides the default masking type ("
<< masktype_to_string(default_mask_type) << ") (optional)\n"
<< "\t\t\"-type string\" specify the masking type "
<< "(required).\n"
<< "\t\t \"poly\", \"box\", \"circle\", \"track\", \"grid\", "
<< "\"data\", \"solar_alt\", \"solar_azi\", \"lat\", \"lon\" "
<< "or \"shape\"\n"

<< "\t\t\"-input_field string\" reads existing mask data from "
<< "the \"input_grid\" gridded data file (optional).\n"

Expand Down Expand Up @@ -1446,7 +1458,7 @@ void usage() {
void set_type(const StringArray & a) {
if(type_is_set) {
mlog << Error << "\n" << program_name << " -> "
<< "the -type command line option can only be used once!\n"
<< "the -type command line requirement can only be used once!\n"
<< "To apply multiple masks, run this tool multiple times "
<< "using the output of one run as the input to the next."
<< "\n\n";
Expand Down
7 changes: 4 additions & 3 deletions met/src/tools/other/gen_vx_mask/gen_vx_mask.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// 000 12/09/14 Halley Gotway New
// 001 06/02/16 Halley Gotway Add box masking type.
// 002 11/15/16 Halley Gotway Add solar masking types.
// 003 06/03/21 Seth Linden Changed default mask type to MaskType_None
//
////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -75,7 +76,7 @@ extern const char * masktype_to_string(MaskType);
//
////////////////////////////////////////////////////////////////////////

static const MaskType default_mask_type = MaskType_Poly;
static const MaskType default_mask_type = MaskType_None;
static const double default_mask_val = 1.0;

////////////////////////////////////////////////////////////////////////
Expand All @@ -86,10 +87,10 @@ static const double default_mask_val = 1.0;

// Input data file, mask file, and output NetCDF file
static ConcatString input_gridname, mask_filename, out_filename;

// Optional arguments
static MaskType mask_type = default_mask_type;
static bool type_is_set = false;

// Optional arguments
static ConcatString input_field_str, mask_field_str;
static SetLogic set_logic = SetLogic_None;
static bool complement = false;
Expand Down
10 changes: 5 additions & 5 deletions test/xml/unit_gen_vx_mask.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
&DATA_DIR_MODEL;/grib1/gfs/gfs_2012040900_F012.grib \
&MET_BASE;/poly/CONUS.poly \
&OUTPUT_DIR;/gen_vx_mask/POLY_GFS_LATLON_CONUS_mask.nc \
-v 1
-type poly -v 1
</param>
<output>
<grid_nc>&OUTPUT_DIR;/gen_vx_mask/POLY_GFS_LATLON_CONUS_mask.nc</grid_nc>
Expand All @@ -48,7 +48,7 @@
&DATA_DIR_MODEL;/grib1/gfs/gfs_2012040900_F012_g008.grib \
&MET_BASE;/poly/CONUS.poly \
&OUTPUT_DIR;/gen_vx_mask/POLY_GFS_MERCATOR_CONUS_mask.nc \
-v 1
-type poly -v 1
</param>
<output>
<grid_nc>&OUTPUT_DIR;/gen_vx_mask/POLY_GFS_MERCATOR_CONUS_mask.nc</grid_nc>
Expand All @@ -65,7 +65,7 @@
&DATA_DIR_MODEL;/grib1/nam/nam_2012040900_F012.grib \
&MET_BASE;/poly/CONUS.poly \
&OUTPUT_DIR;/gen_vx_mask/POLY_NAM_LAMBERT_CONUS_mask.nc \
-v 1
-type poly -v 1
</param>
<output>
<grid_nc>&OUTPUT_DIR;/gen_vx_mask/POLY_NAM_LAMBERT_CONUS_mask.nc</grid_nc>
Expand All @@ -82,7 +82,7 @@
&DATA_DIR_MODEL;/grib1/arw-tom-gep0/arw-tom-gep0_2012040900_F012.grib \
&MET_BASE;/poly/NWC.poly \
&OUTPUT_DIR;/gen_vx_mask/POLY_HMT_STEREO_NWC_mask.nc \
-v 1
-type poly -v 1
</param>
<output>
<grid_nc>&OUTPUT_DIR;/gen_vx_mask/POLY_HMT_STEREO_NWC_mask.nc</grid_nc>
Expand All @@ -100,7 +100,7 @@
&DATA_DIR_MODEL;/grib1/gfs/gfs_2012040900_F012.grib \
&MET_BASE;/poly/NAK.poly \
&OUTPUT_DIR;/gen_vx_mask/POLY_GFS_LATLON_NAK_mask.nc \
-v 1
-type poly -v 1
</param>
<output>
<grid_nc>&OUTPUT_DIR;/gen_vx_mask/POLY_GFS_LATLON_NAK_mask.nc</grid_nc>
Expand Down

0 comments on commit d3cd134

Please sign in to comment.