Skip to content

Commit

Permalink
Per #1471, defined a parse_grid_string() function in the vx_statistic…
Browse files Browse the repository at this point in the history
…s library and then updated vx_data2d_python to call that function. However, this creates a circular dependency because vx_data2d_python now depends on vx_statistics.
  • Loading branch information
JohnHalleyGotway committed Mar 9, 2021
1 parent 40b57af commit 697f362
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
24 changes: 22 additions & 2 deletions met/src/libcode/vx_data2d_python/dataplane_from_numpy_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "string.h"

#include "vx_python3_utils.h"
#include "vx_statistics.h"
#include "check_endian.h"

#include "data_plane.h"
Expand Down Expand Up @@ -219,9 +220,28 @@ dp_out.set_accum(t);

////////////////////

PyObject * py_grid = attrs.lookup_dict("grid");
//
// attempt to parse "grid" as a string
//

s = attrs.lookup_string("grid");

if ( s.nonempty() ) {

grid_out = parse_grid_string(s.c_str());

}
else {

grid_from_python_dict(Python3_Dict(py_grid), grid_out);
//
// otherwise, parse "grid" as a dictionary
//

PyObject * py_grid = attrs.lookup_dict("grid");

grid_from_python_dict(Python3_Dict(py_grid), grid_out);

}

////////////////////

Expand Down
45 changes: 45 additions & 0 deletions met/src/libcode/vx_statistics/apply_mask.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,51 @@ Grid parse_vx_grid(const RegridInfo info, const Grid *fgrid, const Grid *ogrid)

////////////////////////////////////////////////////////////////////////

Grid parse_grid_string(const char *grid_str) {
Grid grid;
StringArray sa;

// Parse as a white-space separated string
sa.parse_wsss(grid_str);

// 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 \""
<< grid_str << "\".\n";
}
// Parse grid definition
else if(sa.n() > 1 && parse_grid_def(sa, grid)) {
mlog << Debug(3) << "Use the grid defined by string \""
<< grid_str << "\".\n";
}
// Extract the grid from a gridded data file
else {
mlog << Debug(3) << "Use the grid defined by file \""
<< grid_str << "\".\n";

Met2dDataFileFactory m_factory;
Met2dDataFile *met_ptr = (Met2dDataFile *) 0;

// Open the data file
if(!(met_ptr = m_factory.new_met_2d_data_file(grid_str))) {
mlog << Error << "\nparse_grid_string() -> "
<< "can't open file \"" << grid_str
<< "\"\n\n";
exit(1);
}

// Store the grid
grid = met_ptr->grid();

// Cleanup
if(met_ptr) { delete met_ptr; met_ptr = 0; }
}

return(grid);
}

////////////////////////////////////////////////////////////////////////

void parse_grid_weight(const Grid &grid, const GridWeightType t,
DataPlane &wgt_dp) {
int x, y;
Expand Down
2 changes: 2 additions & 0 deletions met/src/libcode/vx_statistics/apply_mask.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ static const char poly_str_delim[] = "{}";

extern Grid parse_vx_grid(const RegridInfo, const Grid *, const Grid *);

extern Grid parse_grid_string(const char *);

extern void parse_grid_weight(const Grid &, const GridWeightType,
DataPlane &);

Expand Down

0 comments on commit 697f362

Please sign in to comment.