Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 1993 grid_mask #1994

Merged
merged 2 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 42 additions & 10 deletions met/src/tools/other/gen_vx_mask/gen_vx_mask.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
// 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.
// 010 08/30/21 Halley Gotway MET #1891 fix input and mask fields.
// 010 08/30/21 Halley Gotway MET#1891 Fix input and mask fields.
// 011 12/13/21 Halley Gotway MET#1993 Fix -type grid.
//
////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -163,26 +164,26 @@ void process_command_line(int argc, char **argv) {

void process_input_grid(DataPlane &dp) {

// Parse info.name as a white-space separated string
// Parse the input grid as a white-space separated string
StringArray sa;
sa.parse_wsss(input_gridname);

// Search for a named grid
if(sa.n() == 1 && find_grid_by_name(sa[0].c_str(), grid)) {
mlog << Debug(3)
<< "Use the grid named \"" << input_gridname << "\".\n";
<< "Use input grid named \"" << input_gridname << "\".\n";
}
// Parse grid definition
else if(sa.n() > 1 && parse_grid_def(sa, grid)) {
mlog << Debug(3)
<< "Use the grid defined by string \"" << input_gridname
<< "Use input grid defined by string \"" << input_gridname
<< "\".\n";
}
// Extract the grid from a gridded data file
else {

mlog << Debug(3)
<< "Use the grid defined by file \"" << input_gridname
<< "Use input grid defined by file \"" << input_gridname
<< "\".\n";

// Read the input grid and data plane, if requested
Expand Down Expand Up @@ -249,13 +250,44 @@ void process_mask_file(DataPlane &dp) {
mask_type == MaskType_Lon) {
}

// Otherwise, process the mask file as a gridded data file
// Otherwise, process the mask file as a named grid, grid specification
// string or gridded data file
else {

// Read the mask grid and data plane, if requested
get_data_plane(mask_filename, mask_field_str,
mask_type == MaskType_Data,
dp, grid_mask);
// For the grid mask type, support named grids and grid
// specification strings
if(mask_type == MaskType_Grid) {

// Parse the mask file as a white-space separated string
StringArray sa;
sa.parse_wsss(mask_filename);

// Search for a named grid
if(sa.n() == 1 && find_grid_by_name(sa[0].c_str(), grid_mask)) {
mlog << Debug(3)
<< "Use mask grid named \"" << mask_filename << "\".\n";
}
// Parse grid definition
else if(sa.n() > 1 && parse_grid_def(sa, grid_mask)) {
mlog << Debug(3)
<< "Use mask grid defined by string \"" << mask_filename
<< "\".\n";
}
}

// Parse as a gridded data file if not already set
if(grid_mask.nxy() == 0) {

// Extract the grid from a gridded data file
mlog << Debug(3)
<< "Use mask grid defined by file \"" << mask_filename
<< "\".\n";

// Read the mask grid and data plane, if requested
get_data_plane(mask_filename, mask_field_str,
mask_type == MaskType_Data,
dp, grid_mask);
}

mlog << Debug(2)
<< "Parsed Mask Grid:\t" << grid_mask.name()
Expand Down
35 changes: 35 additions & 0 deletions test/xml/unit_gen_vx_mask.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,41 @@
</output>
</test>

<!-- -->
<!-- GRID: named grids -->
<!-- -->

<test name="gen_vx_mask_GRID_NAMED_GRIDS">
<exec>&MET_BIN;/gen_vx_mask</exec>
<param> \
G004 G130 \
&OUTPUT_DIR;/gen_vx_mask/GRID_NAMED_GRIDS_mask.nc \
-type grid -name G130_grid \
-v 1
</param>
<output>
<grid_nc>&OUTPUT_DIR;/gen_vx_mask/GRID_NAMED_GRIDS_mask.nc</grid_nc>
</output>
</test>

<!-- -->
<!-- GRID: grid specification strings -->
<!-- -->

<test name="gen_vx_mask_GRID_SPEC_STRINGS">
<exec>&MET_BIN;/gen_vx_mask</exec>
<param> \
"latlon 720 361 -90 0 0.5 0.5" \
"latlon 200 100 -40 -50 0.5 0.5" \
&OUTPUT_DIR;/gen_vx_mask/GRID_SPEC_STRINGS_mask.nc \
-type grid -name grid_spec \
-v 1
</param>
<output>
<grid_nc>&OUTPUT_DIR;/gen_vx_mask/GRID_SPEC_STRINGS_mask.nc</grid_nc>
</output>
</test>

<!-- -->
<!-- CIRCLE: compute minimum distances rather than a mask -->
<!-- -->
Expand Down