Skip to content

Commit

Permalink
Per #2966, update logic to fix using data masking twice, add a unit t…
Browse files Browse the repository at this point in the history
…est to demonstrate, and update the mask_type attribute to include the magic string for the gridded data used for data masking.
  • Loading branch information
JohnHalleyGotway committed Nov 6, 2024
1 parent 42ff3cf commit 4ff2c26
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
21 changes: 21 additions & 0 deletions internal/test_unit/xml/unit_gen_vx_mask.xml
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,27 @@
</output>
</test>

<!-- -->
<!-- DATA/DATA/LAT/LON: freezing western hemisphere land points -->
<!-- -->

<test name="gen_vx_mask_DATA_DATA_LAT_LON">
<exec>&MET_BIN;/gen_vx_mask</exec>
<param> \
&DATA_DIR_MODEL;/grib2/gfs/gfs_2012040900_F012.grib2 \
&DATA_DIR_MODEL;/grib2/gfs/gfs_2012040900_F012.grib2 \
&OUTPUT_DIR;/gen_vx_mask/DATA_DATA_LAT_LON_mask.nc \
-type data,data,lat,lon \
-mask_field 'name="LAND"; level="L0";' \
-mask_field 'name="TMP"; level="L0";' \
-thresh eq1,lt273,gt0,lt0 \
-intersection -v 5
</param>
<output>
<grid_nc>&OUTPUT_DIR;/gen_vx_mask/DATA_DATA_LAT_LON_mask.nc</grid_nc>
</output>
</test>

<!-- -->
<!-- SHAPE: shapefile masking -->
<!-- -->
Expand Down
17 changes: 12 additions & 5 deletions src/tools/other/gen_vx_mask/gen_vx_mask.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,13 @@ int met_main(int argc, char *argv[]) {
// Process each -type setting
for(int i=0; i<mask_type_opts.size(); i++) {

// Re-initialize the mask grid for each iteration
grid_mask.clear();

// Set the current mask type
mask_type = mask_type_opts[i];

// Set the current mask field_
// Set the current mask field
if(mask_field_opts.n() == 1) {
mask_field_str = mask_field_opts[0];
}
Expand All @@ -110,15 +113,16 @@ int met_main(int argc, char *argv[]) {
thresh.clear();
}

// Process the mask file
static DataPlane dp_cur;
process_mask_file(dp_cur);

// Build mask type description string
if(i>0) mask_type_desc_cs << " " << setlogic_to_abbr(set_logic) << " ";
mask_type_desc_cs << masktype_to_string(mask_type);
if(mask_type == MaskType::Data) mask_type_desc_cs << "(" << data_desc_cs << ")";
if(thresh.get_type() != thresh_na) mask_type_desc_cs << thresh.get_str();

// Process the mask file
static DataPlane dp_cur;
process_mask_file(dp_cur);

// Combine with prior masks
if(dp_mask.nxy() == 0) dp_mask = dp_cur;
else dp_mask = combine(dp_mask, dp_cur, set_logic);
Expand Down Expand Up @@ -507,6 +511,9 @@ static void get_data_plane(const ConcatString &file_name,
// Store the units string if no threhsold was specified
if(thresh.get_type() == thresh_na) units_cs = vi_ptr->units();

// Store the description of the data
data_desc_cs = vi_ptr->magic_str();

// Clean up
if(vi_ptr) { delete vi_ptr; vi_ptr = (VarInfo *) nullptr; }

Expand Down
4 changes: 3 additions & 1 deletion src/tools/other/gen_vx_mask/gen_vx_mask.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ static bool have_input_data = true;
static ConcatString input_field_str;
static StringArray mask_field_opts;
static ConcatString mask_field_str;
static ConcatString data_desc_cs;
static SetLogic set_logic = SetLogic::None;
static bool complement = false;
static ThreshArray thresh_opts;
Expand All @@ -122,7 +123,8 @@ static std::vector<ShpPolyRecord> shape_recs;
static MaskPoly poly_mask;

// Grid on which the data field resides
static Grid grid, grid_mask;
static Grid grid;
static Grid grid_mask;

// Configuration object for reading config strings
static MetConfig global_config;
Expand Down

0 comments on commit 4ff2c26

Please sign in to comment.