Skip to content

Commit

Permalink
Per #2055, adding support for new GRIB2_perc_val configuration option…
Browse files Browse the repository at this point in the history
… to filter records based on the forecast percentile value used by GRIB2 product definition templates 6 and 10. Seth, note that I also included the probability filtering logic tweak we discussed, since it was already present in that same file.
  • Loading branch information
JohnHalleyGotway committed Aug 9, 2022
1 parent 6c04acf commit a863c64
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/Users_Guide/config_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,10 @@ File-format specific settings for the "field" entry:

* The "GRIB2_stat_type" is an integer specifying the statistical
processing type (Table 4.10).

* The "GRIB2_perc_val" is an integer specifying the requested percentile
value (0 to 100) to be used. This applies only to GRIB2 product
definition templates 4.6 and 4.10.

* The "GRIB2_ipdtmpl_index" and "GRIB2_ipdtmpl_val" entries are arrays
of integers which specify the product description template values to
Expand Down
1 change: 1 addition & 0 deletions src/basic/vx_config/config_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ static const char conf_key_GRIB2_process[] = "GRIB2_process";
static const char conf_key_GRIB2_ens_type[] = "GRIB2_ens_type";
static const char conf_key_GRIB2_der_type[] = "GRIB2_der_type";
static const char conf_key_GRIB2_stat_type[] = "GRIB2_stat_type";
static const char conf_key_GRIB2_perc_val[] = "GRIB2_perc_val";
static const char conf_key_GRIB2_ipdtmpl_index[] = "GRIB2_ipdtmpl_index";
static const char conf_key_GRIB2_ipdtmpl_val[] = "GRIB2_ipdtmpl_val";
static const char conf_key_level[] = "level";
Expand Down
13 changes: 11 additions & 2 deletions src/libcode/vx_data2d_grib2/data2d_grib2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,8 @@ void MetGrib2DataFile::find_record_matches( VarInfoGrib2* vinfo,
(!is_bad_data(vinfo->process()) && vinfo->process() != (*it)->Process ) ||
(!is_bad_data(vinfo->ens_type()) && vinfo->ens_type() != (*it)->EnsType ) ||
(!is_bad_data(vinfo->der_type()) && vinfo->der_type() != (*it)->DerType ) ||
(!is_bad_data(vinfo->stat_type()) && vinfo->stat_type() != (*it)->StatType ) ){
(!is_bad_data(vinfo->stat_type()) && vinfo->stat_type() != (*it)->StatType ) ||
(!is_bad_data(vinfo->perc_val()) && vinfo->perc_val() != (*it)->PercVal ) ){
continue;
}

Expand Down Expand Up @@ -523,10 +524,13 @@ void MetGrib2DataFile::find_record_matches( VarInfoGrib2* vinfo,
} // END: if( level match )

// if seeking a probabilistic field, check the prob info
if( (rec_match_ex || rec_match_rn) && vinfo->p_flag() && (*it)->ProbFlag ){
if( (rec_match_ex || rec_match_rn) && vinfo->p_flag()) {

rec_match_ex = rec_match_rn = false;

// no match unless the data contains probabilities
if( !(*it)->ProbFlag ) { break; }

SingleThresh v_thr_lo = vinfo->p_thresh_lo();
SingleThresh v_thr_hi = vinfo->p_thresh_hi();

Expand Down Expand Up @@ -821,6 +825,11 @@ void MetGrib2DataFile::read_grib2_record_list() {
rec->StatType = gfld->ipdtmpl[23];
}

// percentile value for templates 6 and 10
if( 6 == gfld->ipdtnum || 10 == gfld->ipdtnum ){
rec->PercVal = gfld->ipdtmpl[15];
}

// depending on the template number, determine the reference times
if( 8 <= gfld->ipdtnum && 12 >= gfld->ipdtnum ){

Expand Down
1 change: 1 addition & 0 deletions src/libcode/vx_data2d_grib2/data2d_grib2.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ typedef struct {
int EnsNumber;
int DerType;
int StatType;
int PercVal;
IntArray IPDTmpl;
} Grib2Record;

Expand Down
13 changes: 12 additions & 1 deletion src/libcode/vx_data2d_grib2/var_info_grib2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ void VarInfoGrib2::assign(const VarInfoGrib2 &v) {
EnsType = v.EnsType;
DerType = v.DerType;
StatType = v.StatType;
PercVal = v.PercVal;

IPDTmplIndex = v.IPDTmplIndex;
IPDTmplVal = v.IPDTmplVal;
Expand All @@ -134,6 +135,7 @@ void VarInfoGrib2::clear() {
EnsType = bad_data_int;
DerType = bad_data_int;
StatType = bad_data_int;
PercVal = bad_data_int;

IPDTmplIndex.clear();
IPDTmplVal.clear();
Expand All @@ -157,7 +159,8 @@ void VarInfoGrib2::dump(ostream &out) const {
<< " Process = " << Process << "\n"
<< " EnsType = " << EnsType << "\n"
<< " DerType = " << DerType << "\n"
<< " StatType = " << StatType << "\n";
<< " StatType = " << StatType << "\n"
<< " PercVal = " << PercVal << "\n";
out << " IPDTmplIndex:\n";
IPDTmplIndex.dump(out);
out << " IPDTmplVal:\n";
Expand Down Expand Up @@ -245,6 +248,13 @@ void VarInfoGrib2::set_stat_type(int v) {

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

void VarInfoGrib2::set_perc_val(int v) {
PercVal = v;
return;
}

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

void VarInfoGrib2::set_ipdtmpl_index(const IntArray &v) {
IPDTmplIndex = v;
return;
Expand Down Expand Up @@ -280,6 +290,7 @@ void VarInfoGrib2::set_dict(Dictionary & dict) {
EnsType = dict.lookup_int (conf_key_GRIB2_ens_type, false);
DerType = dict.lookup_int (conf_key_GRIB2_der_type, false);
StatType = dict.lookup_int (conf_key_GRIB2_stat_type, false);
PercVal = dict.lookup_int (conf_key_GRIB2_perc_val, false);

IPDTmplIndex = dict.lookup_int_array(conf_key_GRIB2_ipdtmpl_index, false);
IPDTmplVal = dict.lookup_int_array(conf_key_GRIB2_ipdtmpl_val, false);
Expand Down
4 changes: 4 additions & 0 deletions src/libcode/vx_data2d_grib2/var_info_grib2.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class VarInfoGrib2 : public VarInfo
int EnsType; // Type of Ensemble Forecast (Table 4.6)
int DerType; // Derived Forecast (Table 4.7)
int StatType; // Statistical Processing Type (Table 4.10)
int PercVal; // Percentile Value (Octet 35 for Templates 4.6 and 4.10)

IntArray IPDTmplIndex; // Index into the GRIB2 ipdtmpl array
IntArray IPDTmplVal; // Corresponding GRIB2 ipdtmpl value
Expand Down Expand Up @@ -88,6 +89,7 @@ class VarInfoGrib2 : public VarInfo
int ens_type() const;
int der_type() const;
int stat_type() const;
int perc_val() const;

int n_ipdtmpl() const;
int ipdtmpl_index(int) const;
Expand All @@ -110,6 +112,7 @@ class VarInfoGrib2 : public VarInfo
void set_ens_type(int);
void set_der_type(int);
void set_stat_type(int);
void set_perc_val(int);
void set_ipdtmpl_index(const IntArray &);
void set_ipdtmpl_val(const IntArray &);

Expand Down Expand Up @@ -143,6 +146,7 @@ inline int VarInfoGrib2::process() const { return(Process); }
inline int VarInfoGrib2::ens_type() const { return(EnsType); }
inline int VarInfoGrib2::der_type() const { return(DerType); }
inline int VarInfoGrib2::stat_type() const { return(StatType); }
inline int VarInfoGrib2::perc_val() const { return(PercVal); }
inline int VarInfoGrib2::n_ipdtmpl() const {
return(IPDTmplIndex.n()); }
inline int VarInfoGrib2::ipdtmpl_index(int i) const {
Expand Down

0 comments on commit a863c64

Please sign in to comment.