From a863c640aceef9f05d2032d9d80816297f333fe1 Mon Sep 17 00:00:00 2001 From: John Halley Gotway Date: Tue, 9 Aug 2022 16:30:20 -0600 Subject: [PATCH] Per #2055, adding support for new GRIB2_perc_val configuration option 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. --- docs/Users_Guide/config_options.rst | 4 ++++ src/basic/vx_config/config_constants.h | 1 + src/libcode/vx_data2d_grib2/data2d_grib2.cc | 13 +++++++++++-- src/libcode/vx_data2d_grib2/data2d_grib2.h | 1 + src/libcode/vx_data2d_grib2/var_info_grib2.cc | 13 ++++++++++++- src/libcode/vx_data2d_grib2/var_info_grib2.h | 4 ++++ 6 files changed, 33 insertions(+), 3 deletions(-) diff --git a/docs/Users_Guide/config_options.rst b/docs/Users_Guide/config_options.rst index 5e4ae8fdbe..e93c0e18c0 100644 --- a/docs/Users_Guide/config_options.rst +++ b/docs/Users_Guide/config_options.rst @@ -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 diff --git a/src/basic/vx_config/config_constants.h b/src/basic/vx_config/config_constants.h index c51577ee4f..3cc2fe14e2 100644 --- a/src/basic/vx_config/config_constants.h +++ b/src/basic/vx_config/config_constants.h @@ -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"; diff --git a/src/libcode/vx_data2d_grib2/data2d_grib2.cc b/src/libcode/vx_data2d_grib2/data2d_grib2.cc index 03d57b5d86..c3ac911dc4 100644 --- a/src/libcode/vx_data2d_grib2/data2d_grib2.cc +++ b/src/libcode/vx_data2d_grib2/data2d_grib2.cc @@ -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; } @@ -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(); @@ -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 ){ diff --git a/src/libcode/vx_data2d_grib2/data2d_grib2.h b/src/libcode/vx_data2d_grib2/data2d_grib2.h index 0f371c758a..b4538cd11f 100644 --- a/src/libcode/vx_data2d_grib2/data2d_grib2.h +++ b/src/libcode/vx_data2d_grib2/data2d_grib2.h @@ -61,6 +61,7 @@ typedef struct { int EnsNumber; int DerType; int StatType; + int PercVal; IntArray IPDTmpl; } Grib2Record; diff --git a/src/libcode/vx_data2d_grib2/var_info_grib2.cc b/src/libcode/vx_data2d_grib2/var_info_grib2.cc index 6fc0d45759..a78eb38885 100644 --- a/src/libcode/vx_data2d_grib2/var_info_grib2.cc +++ b/src/libcode/vx_data2d_grib2/var_info_grib2.cc @@ -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; @@ -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(); @@ -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"; @@ -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; @@ -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); diff --git a/src/libcode/vx_data2d_grib2/var_info_grib2.h b/src/libcode/vx_data2d_grib2/var_info_grib2.h index beca6c3b07..a6bf0fcd5e 100644 --- a/src/libcode/vx_data2d_grib2/var_info_grib2.h +++ b/src/libcode/vx_data2d_grib2/var_info_grib2.h @@ -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 @@ -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; @@ -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 &); @@ -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 {