Skip to content

Commit

Permalink
#2231 Support unstructured grid
Browse files Browse the repository at this point in the history
  • Loading branch information
Howard Soh committed Sep 12, 2023
1 parent 9043e99 commit 6a3710f
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/tools/core/grid_stat/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ grid_stat_LDADD = -lvx_stat_out \
-lvx_data2d_nc_pinterp \
$(PYTHON_LIBS) \
-lvx_data2d_nccf \
-lvx_data2d_ugrid -latlas -leckit -leckit_mpi -leckit_geometry \
-lvx_statistics \
-lvx_data2d \
-lvx_seeps \
-lvx_seeps \
-lvx_nc_util \
-lvx_regrid \
-lvx_grid \
Expand Down
9 changes: 8 additions & 1 deletion src/tools/core/grid_stat/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,17 @@ LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MET_ATLAS = @MET_ATLAS@
MET_ATLASINC = @MET_ATLASINC@
MET_ATLASLIB = @MET_ATLASLIB@
MET_BUFR = @MET_BUFR@
MET_BUFRLIB = @MET_BUFRLIB@
MET_CAIRO = @MET_CAIRO@
MET_CAIROINC = @MET_CAIROINC@
MET_CAIROLIB = @MET_CAIROLIB@
MET_ECKIT = @MET_ECKIT@
MET_ECKITINC = @MET_ECKITINC@
MET_ECKITLIB = @MET_ECKITLIB@
MET_FREETYPE = @MET_FREETYPE@
MET_FREETYPEINC = @MET_FREETYPEINC@
MET_FREETYPELIB = @MET_FREETYPELIB@
Expand Down Expand Up @@ -336,9 +342,10 @@ grid_stat_LDADD = -lvx_stat_out \
-lvx_data2d_nc_pinterp \
$(PYTHON_LIBS) \
-lvx_data2d_nccf \
-lvx_data2d_ugrid -latlas -leckit -leckit_mpi -leckit_geometry \
-lvx_statistics \
-lvx_data2d \
-lvx_seeps \
-lvx_seeps \
-lvx_nc_util \
-lvx_regrid \
-lvx_grid \
Expand Down
33 changes: 29 additions & 4 deletions src/tools/core/grid_stat/grid_stat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@
//
////////////////////////////////////////////////////////////////////////

using namespace std;

#include <cstdio>
#include <cstdlib>
#include <ctype.h>
Expand All @@ -127,8 +125,6 @@ using namespace std;
#include <sys/types.h>

#include <netcdf>
using namespace netCDF;

#include "main.h"
#include "handle_openmp.h"

Expand All @@ -140,8 +136,19 @@ using namespace netCDF;
#include "vx_log.h"
#include "seeps.h"

#include "vx_data2d_ugrid.h"

using namespace std;
using namespace netCDF;


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

static ConcatString ugrid_nc;

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


static void process_command_line(int, char **);
static void setup_first_pass (const DataPlane &);

Expand Down Expand Up @@ -184,6 +191,7 @@ static void clean_up();
static void usage();
static void set_outdir(const StringArray &);
static void set_compress(const StringArray &);
static void set_ugrid_nc(const StringArray &);
static bool read_data_plane(VarInfo* info, DataPlane& dp, Met2dDataFile* mtddf,
const ConcatString &filename);

Expand Down Expand Up @@ -236,6 +244,7 @@ void process_command_line(int argc, char **argv) {
// Add the options function calls
cline.add(set_outdir, "-outdir", 1);
cline.add(set_compress, "-compress", 1);
cline.add(set_ugrid_nc, "-ugrid", 1);

// Parse the command line
cline.parse();
Expand Down Expand Up @@ -263,6 +272,7 @@ void process_command_line(int argc, char **argv) {
// Get the forecast and observation file types from config, if present
ftype = parse_conf_file_type(conf_info.conf.lookup_dictionary(conf_key_fcst));
otype = parse_conf_file_type(conf_info.conf.lookup_dictionary(conf_key_obs));
if (ftype == FileType_None && 0 < ugrid_nc.length()) ftype = FileType_UGrid;

// Read forecast file
if(!(fcst_mtddf = mtddf_factory.new_met_2d_data_file(fcst_file.c_str(), ftype))) {
Expand All @@ -285,6 +295,10 @@ void process_command_line(int argc, char **argv) {
// Process the configuration
conf_info.process_config(ftype, otype);

if (FileType_UGrid == ftype) {
((MetUGridDataFile *)fcst_mtddf)->open_metadata(ugrid_nc.c_str());
}

// For python types read the first field to set the grid
if(is_python_grdfiletype(ftype)) {
if(!fcst_mtddf->data_plane(*conf_info.vx_opt[0].fcst_info, dp)) {
Expand Down Expand Up @@ -3026,6 +3040,7 @@ void usage() {
<< "\tfcst_file\n"
<< "\tobs_file\n"
<< "\tconfig_file\n"
<< "\t[-ugrid ugrid_file]\n"
<< "\t[-outdir path]\n"
<< "\t[-log file]\n"
<< "\t[-v level]\n"
Expand All @@ -3040,6 +3055,9 @@ void usage() {
<< "\t\t\"config_file\" is a GridStatConfig file containing "
<< "the desired configuration settings (required).\n"

<< "\t\t\"-ugrid ugrid_file\" is the metadata file for unstructured grid "
<< " (only required for unstructured grid data).\n"

<< "\t\t\"-outdir path\" overrides the default output directory "
<< "(" << out_dir << ") (optional).\n"

Expand Down Expand Up @@ -3069,6 +3087,13 @@ void set_compress(const StringArray & a) {

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

void set_ugrid_nc(const StringArray & a)
{
ugrid_nc = a[0];
}

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

bool read_data_plane(VarInfo* info, DataPlane& dp, Met2dDataFile* mtddf,
const ConcatString &filename) {

Expand Down
2 changes: 1 addition & 1 deletion src/tools/core/grid_stat/grid_stat_conf_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class GridStatConfInfo {

GridStatVxOpt * vx_opt; // Array of vx task options [n_vx] (allocated)

map<ConcatString,MaskPlane> mask_map; // Mapping of mask names to MaskPlanes
std::map<ConcatString,MaskPlane> mask_map; // Mapping of mask names to MaskPlanes

GridWeightType grid_weight_flag; // Grid weighting flag
ConcatString tmp_dir; // Directory for temporary files
Expand Down
9 changes: 8 additions & 1 deletion src/tools/core/point_stat/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,17 @@ LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
MET_ATLAS = @MET_ATLAS@
MET_ATLASINC = @MET_ATLASINC@
MET_ATLASLIB = @MET_ATLASLIB@
MET_BUFR = @MET_BUFR@
MET_BUFRLIB = @MET_BUFRLIB@
MET_CAIRO = @MET_CAIRO@
MET_CAIROINC = @MET_CAIROINC@
MET_CAIROLIB = @MET_CAIROLIB@
MET_ECKIT = @MET_ECKIT@
MET_ECKITINC = @MET_ECKITINC@
MET_ECKITLIB = @MET_ECKITLIB@
MET_FREETYPE = @MET_FREETYPE@
MET_FREETYPEINC = @MET_FREETYPEINC@
MET_FREETYPELIB = @MET_FREETYPELIB@
Expand Down Expand Up @@ -335,10 +341,11 @@ point_stat_LDADD = -lvx_stat_out \
-lvx_data2d_grib $(GRIB2_LIBS) \
-lvx_data2d_nc_pinterp \
-lvx_data2d_nccf \
-lvx_data2d_ugrid -latlas -leckit -leckit_mpi -leckit_geometry \
$(PYTHON_LIBS) \
-lvx_data2d \
-lvx_nc_obs \
-lvx_seeps \
-lvx_seeps \
-lvx_nc_util \
-lvx_regrid \
-lvx_grid \
Expand Down
29 changes: 25 additions & 4 deletions src/tools/core/point_stat/point_stat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@
//
////////////////////////////////////////////////////////////////////////

using namespace std;

#include <cstdio>
#include <cstdlib>
#include <ctype.h>
Expand All @@ -119,7 +117,6 @@ using namespace std;
#include <unistd.h>

#include <netcdf>
using namespace netCDF;

#include "main.h"
#include "point_stat.h"
Expand All @@ -133,14 +130,19 @@ using namespace netCDF;
#include "nc_obs_util.h"
#include "nc_point_obs_in.h"

#include "vx_data2d_ugrid.h"

#ifdef WITH_PYTHON
#include "data2d_nc_met.h"
#include "pointdata_python.h"
#endif

////////////////////////////////////////////////////////////////////////
using namespace std;
using namespace netCDF;

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

static ConcatString ugrid_nc;

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

Expand Down Expand Up @@ -177,6 +179,7 @@ static void set_ncfile(const StringArray &);
static void set_obs_valid_beg_time(const StringArray &);
static void set_obs_valid_end_time(const StringArray &);
static void set_outdir(const StringArray &);
static void set_ugrid_nc(const StringArray &);

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

Expand Down Expand Up @@ -240,6 +243,7 @@ void process_command_line(int argc, char **argv) {
cline.add(set_obs_valid_beg_time, "-obs_valid_beg", 1);
cline.add(set_obs_valid_end_time, "-obs_valid_end", 1);
cline.add(set_outdir, "-outdir", 1);
cline.add(set_ugrid_nc, "-ugrid", 1);

// Parse the command line
cline.parse();
Expand Down Expand Up @@ -280,6 +284,7 @@ void process_command_line(int argc, char **argv) {

// Get the forecast file type from config, if present
ftype = parse_conf_file_type(conf_info.conf.lookup_dictionary(conf_key_fcst));
if (ftype == FileType_None && 0 < ugrid_nc.length()) ftype = FileType_UGrid;

// Read forecast file
if(!(fcst_mtddf = mtddf_factory.new_met_2d_data_file(fcst_file.c_str(), ftype))) {
Expand All @@ -297,6 +302,10 @@ void process_command_line(int argc, char **argv) {
// Set the model name
shc.set_model(conf_info.model.c_str());

if (FileType_UGrid == ftype) {
((MetUGridDataFile *)fcst_mtddf)->open_metadata(ugrid_nc.c_str());
}

// Use the first verification task to set the random number generator
// and seed value for bootstrap confidence intervals
rng_set(rng_ptr,
Expand Down Expand Up @@ -2164,6 +2173,7 @@ void usage() {
<< "\t[-point_obs file]\n"
<< "\t[-obs_valid_beg time]\n"
<< "\t[-obs_valid_end time]\n"
<< "\t[-ugrid ugrid_file]\n"
<< "\t[-outdir path]\n"
<< "\t[-log file]\n"
<< "\t[-v level]\n\n"
Expand All @@ -2189,6 +2199,9 @@ void usage() {
<< "\t\t\"-outdir path\" overrides the default output "
<< "directory (" << out_dir << ") (optional).\n"

<< "\t\t\"-ugrid ugrid_file\" is the metadata file for unstructured grid "
<< " (only required for unstructured grid data).\n"

<< "\t\t\"-log file\" outputs log messages to the specified "
<< "file (optional).\n"

Expand Down Expand Up @@ -2234,3 +2247,11 @@ void set_outdir(const StringArray & a)
}

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

void set_ugrid_nc(const StringArray & a)
{
ugrid_nc = a[0];
}

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

5 changes: 3 additions & 2 deletions src/tools/core/point_stat/point_stat_conf_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

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

using namespace std;

#include <dirent.h>
#include <iostream>
#include <unistd.h>
Expand All @@ -23,6 +21,9 @@ using namespace std;
#include "vx_data2d.h"
#include "vx_log.h"

using namespace std;


////////////////////////////////////////////////////////////////////////
//
// Code for class PointStatConfInfo
Expand Down
8 changes: 4 additions & 4 deletions src/tools/core/point_stat/point_stat_conf_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class PointStatVxOpt {
SingleThresh seeps_p1_thresh; // SEESP p1 threshold

// Vector of MaskLatLon objects defining Lat/Lon Point masks
vector<MaskLatLon> mask_llpnt;
std::vector<MaskLatLon> mask_llpnt;

StringArray mask_name; // Masking names

Expand Down Expand Up @@ -235,13 +235,13 @@ class PointStatConfInfo {
SingleThresh topo_interp_fcst_thresh;

// Message type groups that should be processed together
map<ConcatString,StringArray> msg_typ_group_map;
std::map<ConcatString,StringArray> msg_typ_group_map;

// Mapping of mask names to DataPlanes
map<ConcatString,MaskPlane> mask_area_map;
std::map<ConcatString,MaskPlane> mask_area_map;

// Mapping of mask names to Station ID lists
map<ConcatString,StringArray> mask_sid_map;
std::map<ConcatString,StringArray> mask_sid_map;

ConcatString tmp_dir; // Directory for temporary files
ConcatString output_prefix; // String to customize output file name
Expand Down

0 comments on commit 6a3710f

Please sign in to comment.