Skip to content

Commit

Permalink
Feature #2286 grib_lookup (#2288)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnHalleyGotway authored Sep 30, 2022
1 parent 2e40571 commit bbcc08a
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 124 deletions.
4 changes: 2 additions & 2 deletions src/libcode/vx_nc_obs/met_point_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class MetPointData {
StringArray get_var_names();

bool is_same_obs_values(const float obs_arr1[OBS_ARRAY_LEN], const float obs_arr2[OBS_ARRAY_LEN]);
bool is_using_var_id();
bool is_using_var_id() const;

void set_grib_code_or_var_index(float obs_arr[OBS_ARRAY_LEN], int grib_code);
void set_hdr_cnt(int hdr_cnt);
Expand Down Expand Up @@ -165,7 +165,7 @@ inline int MetPointData::get_obs_cnt() { return nobs; }
inline MetPointObsData *MetPointData::get_point_obs_data() { return obs_data; }
inline StringArray MetPointData::get_qty_data() { return obs_data->qty_names; }
inline StringArray MetPointData::get_var_names() { return obs_data->var_names; }
inline bool MetPointData::is_using_var_id() { return use_var_id; }
inline bool MetPointData::is_using_var_id() const { return use_var_id; }
inline void MetPointData::set_grib_code_or_var_index(float obs_arr[OBS_ARRAY_LEN], int grib_code) { obs_arr[1] = grib_code; }
inline void MetPointDataPython::set_use_var_id(bool new_use_var_id) { use_var_id = new_use_var_id; }

Expand Down
2 changes: 1 addition & 1 deletion src/libcode/vx_nc_obs/nc_obs_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ bool is_using_var_id(const char * nc_name) {
return use_var_id;
}

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

bool is_using_var_id(NcFile *nc_file) {
bool use_var_id = false;
Expand Down
60 changes: 0 additions & 60 deletions src/libcode/vx_pointdata_python/pointdata_python.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ void MetPythonPointDataFile::python_init_from_scratch()
{

PythonCommand.clear();
//met_data.clear();

close();

Expand Down Expand Up @@ -123,20 +122,6 @@ return;
}


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

/*
void MetPythonPointDataFile::set_type(const GrdFileType t)
{
Type = t;
return;
}
*/

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


Expand Down Expand Up @@ -216,23 +201,7 @@ void MetPythonPointDataFile::dump(ostream & out, int depth) const
Indent prefix(depth);

out << prefix << "File = ";
/*
if ( Filename.empty() ) out << "(nul)\n";
else out << '\"' << Filename << "\"\n";

if ( Raw_Grid ) {
out << prefix << "Grid:\n";
// Raw_Grid->dump(out, depth + 1);
} else {
out << prefix << "No Grid!\n";
}
*/
//
// done
//

Expand All @@ -243,35 +212,6 @@ return;
}


////////////////////////////////////////////////////////////////////////
/*
bool MetPythonPointDataFile::data_ok(int x, int y) const
{
//const double value = get(x, y);
//return ( !is_bad_data(value) );
return true;
}
////////////////////////////////////////////////////////////////////////
void MetPythonPointDataFile::data_minmax(double & data_min, double & data_max) const
{
//Plane.data_range(data_min, data_max);
return;
}
*/

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


Expand Down
25 changes: 2 additions & 23 deletions src/libcode/vx_pointdata_python/pointdata_python.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
////////////////////////////////////////////////////////////////////////


//class MetPythonPointDataFile : public Met2dDataFile {
class MetPythonPointDataFile {

private:
Expand All @@ -44,10 +43,6 @@ class MetPythonPointDataFile {

MetPointDataPython met_data;

//VarInfoPython VInfo;

//GrdFileType Type; // FileType_Python_Xarray or FileType_Python_Numpy

public:

MetPythonPointDataFile();
Expand All @@ -58,21 +53,11 @@ class MetPythonPointDataFile {
// set stuff
//

//void set_type(const GrdFileType);

//
// get stuff
//

// GrdFileType file_type() const;

// double operator () (int x, int y) const;

//double get (int x, int y) const;

// bool data_ok (int x, int y) const;

// void data_minmax (double & data_min, double & data_max) const;
bool is_using_var_id() const;

//
// do stuff
Expand All @@ -85,21 +70,15 @@ class MetPythonPointDataFile {

void dump (ostream &, int depth = 0) const;

//MetPointData get_met_point_data();
MetPointDataPython *get_met_point_data();

//int data_plane_array(VarInfo &, DataPlaneArray &);

//bool met_point_data(MetPointData &);

};


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


//inline double MetPythonPointDataFile::operator () (int x, int y) const { return ( get(x, y) ); }
//inline GrdFileType MetPythonPointDataFile::file_type () const { return ( Type ); }
inline bool MetPythonPointDataFile::is_using_var_id() const { return(met_data.is_using_var_id()); }


////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions src/libcode/vx_pointdata_python/python_pointdata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ static void set_array_from_python(PyObject *python_data, const char *python_key,
<< "error getting the point data by the key (" << python_key << ") from python object\n\n";
exit (1);
}
else mlog << Debug(3) << method_name
<< "not exists the point data (" << python_key << ") from python object\n";
else mlog << Debug(7) << method_name
<< "point data for " << python_key << " does not exist from python object\n";
}
}

Expand Down
13 changes: 6 additions & 7 deletions src/tools/core/ensemble_stat/ensemble_stat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
// 036 02/20/22 Halley Gotway MET #1259 Write probabilistic statistics.
// 037 07/06/22 Howard Soh METplus-Internal #19 Rename main to met_main.
// 038 09/06/22 Halley Gotway MET #1908 Remove ensemble processing logic.
// 039 09/29/22 Halley Gotway MET #2286 Refine GRIB1 table lookup logic.
//
////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -369,9 +370,6 @@ void process_command_line(int argc, char **argv) {
// Store the input ensemble file type
etype = ens_mtddf->file_type();

// Use a variable index from var_name instead of GRIB code
bool use_var_id = false;

// Observation files are required
if(!grid_obs_flag && !point_obs_flag) {
mlog << Error << "\nprocess_command_line() -> "
Expand All @@ -383,9 +381,6 @@ void process_command_line(int argc, char **argv) {
// Determine the input observation file type
if(point_obs_flag) {
otype = FileType_Gb1;
if(point_obs_file_list.n() > 0) {
use_var_id = is_using_var_id(point_obs_file_list[0].c_str());
}
}
else if(!grid_obs_flag) {
otype = FileType_None;
Expand All @@ -409,7 +404,7 @@ void process_command_line(int argc, char **argv) {

// Process the configuration
conf_info.process_config(etype, otype, grid_obs_flag, point_obs_flag,
use_var_id, &ens_file_list, ctrl_file.nonempty());
&ens_file_list, ctrl_file.nonempty());

// Set output_nc_flag
out_nc_flag = (grid_obs_flag && !conf_info.nc_info.all_false());
Expand Down Expand Up @@ -930,6 +925,7 @@ void process_point_obs(int i_nc) {
}

met_point_obs = met_point_file.get_met_point_data();
use_var_id = met_point_file.is_using_var_id();
}
else {
#endif
Expand All @@ -953,6 +949,9 @@ void process_point_obs(int i_nc) {
}
#endif

// Perform GRIB table lookups, if needed
if(!use_var_id) conf_info.process_grib_codes();

int hdr_count = met_point_obs->get_hdr_cnt();
int obs_count = met_point_obs->get_obs_cnt();

Expand Down
37 changes: 29 additions & 8 deletions src/tools/core/ensemble_stat/ensemble_stat_conf_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void EnsembleStatConfInfo::clear() {

// Initialize values
model.clear();
grib_codes_set = false;
obtype.clear();
vld_ens_thresh = bad_data_double;
vld_data_thresh = bad_data_double;
Expand Down Expand Up @@ -116,7 +117,6 @@ void EnsembleStatConfInfo::read_config(const ConcatString default_file_name,
void EnsembleStatConfInfo::process_config(GrdFileType etype,
GrdFileType otype,
bool grid_vx, bool point_vx,
bool use_var_id,
StringArray * ens_files,
bool use_ctrl) {
int i, j, n_ens_files;
Expand Down Expand Up @@ -276,8 +276,7 @@ void EnsembleStatConfInfo::process_config(GrdFileType etype,

// Process the options for this verification task
vx_opt[i].process_config(etype, i_fdict, otype, i_odict,
rng_ptr, grid_vx, point_vx,
use_var_id, ens_member_ids,
rng_ptr, grid_vx, point_vx, ens_member_ids,
ens_files, use_ctrl, control_id);

// For no point verification, store obtype as the message type
Expand Down Expand Up @@ -306,6 +305,32 @@ void EnsembleStatConfInfo::process_config(GrdFileType etype,

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

void EnsembleStatConfInfo::process_grib_codes() {

// Only needs to be set once
if(grib_codes_set) return;

mlog << Debug(3) << "Processing each \"" << conf_key_obs_field
<< "\" name as a GRIB code abbreviation since the point "
<< "observations are specified as GRIB codes.\n";

Dictionary *odict = conf.lookup_array(conf_key_obs_field);
Dictionary i_odict;

// Add the GRIB code by parsing each observation dictionary
for(int i=0; i<n_vx; i++) {
i_odict = parse_conf_i_vx_dict(odict, i);
vx_opt[i].vx_pd.obs_info->add_grib_code(i_odict);
}

// Flag to prevent processing more than once
grib_codes_set = true;

return;
}

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

void EnsembleStatConfInfo::process_flags() {
int i, j;
bool output_ascii_flag = false;
Expand Down Expand Up @@ -609,8 +634,7 @@ void EnsembleStatVxOpt::clear() {

void EnsembleStatVxOpt::process_config(GrdFileType ftype, Dictionary &fdict,
GrdFileType otype, Dictionary &odict,
gsl_rng *rng_ptr, bool grid_vx,
bool point_vx, bool use_var_id,
gsl_rng *rng_ptr, bool grid_vx, bool point_vx,
StringArray ens_member_ids,
StringArray * ens_files,
bool use_ctrl, ConcatString control_id) {
Expand Down Expand Up @@ -679,9 +703,6 @@ void EnsembleStatVxOpt::process_config(GrdFileType ftype, Dictionary &fdict,
// Set the VarInfo objects
vx_pd.obs_info->set_dict(odict);

// Set the GRIB code for point observations
if(point_vx && !use_var_id) vx_pd.obs_info->add_grib_code(odict);

// Dump the contents of the current VarInfo
if(mlog.verbosity_level() >= 5) {
mlog << Debug(5)
Expand Down
6 changes: 4 additions & 2 deletions src/tools/core/ensemble_stat/ensemble_stat_conf_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class EnsembleStatVxOpt {

void process_config(GrdFileType, Dictionary &,
GrdFileType, Dictionary &,
gsl_rng *, bool, bool, bool,
gsl_rng *, bool, bool,
StringArray, StringArray *,
bool, ConcatString);
void parse_nc_info(Dictionary &);
Expand Down Expand Up @@ -213,6 +213,7 @@ class EnsembleStatConfInfo {
ConcatString control_id; // Control ID

EnsembleStatVxOpt * vx_opt; // Array of vx task options [n_vx] (allocated)
bool grib_codes_set;

double vld_ens_thresh; // Required ratio of valid input files
double vld_data_thresh; // Required ratio of valid data for each point
Expand Down Expand Up @@ -242,8 +243,9 @@ class EnsembleStatConfInfo {
void clear();

void read_config (const ConcatString , const ConcatString);
void process_config(GrdFileType, GrdFileType, bool, bool, bool,
void process_config(GrdFileType, GrdFileType, bool, bool,
StringArray *, bool);
void process_grib_codes();
void process_flags ();
void process_masks (const Grid &);
void set_vx_pd (const IntArray &, int);
Expand Down
Loading

0 comments on commit bbcc08a

Please sign in to comment.