Skip to content

Commit 3de2dc8

Browse files
committed
GRIB2: PDT selection for probability forecasts
1 parent 22fd24d commit 3de2dc8

File tree

9 files changed

+269
-122
lines changed

9 files changed

+269
-122
lines changed

definitions/grib2/section.1.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ meta is_chemical_srcsink g2_chemical(productDefinitionTemplateNumber, stepType,
105105
meta is_aerosol g2_aerosol(productDefinitionTemplateNumber, stepType, 0);
106106
meta is_aerosol_optical g2_aerosol(productDefinitionTemplateNumber, stepType, 1);
107107

108+
meta is_probability_fcst g2_probability(productDefinitionTemplateNumber, stepType);
109+
108110
transient setCalendarId = 0 ;
109111
transient deleteCalendarId = 0 ;
110112
alias calendarIdPresent = false;

src/eccodes/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ list( APPEND eccodes_src_files
273273
accessor/DataRunLengthPacking.cc
274274
accessor/GridSpec.cc
275275
accessor/G2ParamConceptFilename.cc
276+
accessor/G2Probability.cc
276277

277278
grib_jasper_encoding.cc
278279
grib_openjpeg_encoding.cc

src/eccodes/accessor/Concept.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,7 @@ static int rectify_concept_apply(grib_handle* h, const char* key)
242242
{ "constituentType", { "is_chemical", 1 } },
243243
{ "sourceSinkChemicalPhysicalProcess", { "is_chemical_srcsink", 1 } },
244244
{ "randomFieldNumber", { "productDefinitionTemplateNumber", 143 } },
245-
// TODO(masn): Add a new key e.g. is_probability_forecast
246-
{ "probabilityType", { "productDefinitionTemplateNumber", 5 } }
245+
{ "probabilityType", { "is_probability_fcst", 1 } }
247246
};
248247
const auto mapIter = keyMap.find(key);
249248
if (mapIter != keyMap.end()) {
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* (C) Copyright 2005- ECMWF.
3+
*
4+
* This software is licensed under the terms of the Apache Licence Version 2.0
5+
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6+
*
7+
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
8+
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
9+
*/
10+
11+
#include "G2Probability.h"
12+
13+
eccodes::accessor::G2Probability _grib_accessor_g2_probability;
14+
eccodes::Accessor* grib_accessor_g2_probability = &_grib_accessor_g2_probability;
15+
16+
namespace eccodes::accessor
17+
{
18+
19+
void G2Probability::init(const long l, grib_arguments* c)
20+
{
21+
Unsigned::init(l, c);
22+
grib_handle* hand = get_enclosing_handle();
23+
int n = 0;
24+
25+
productDefinitionTemplateNumber_ = c->get_name(hand, n++);
26+
stepType_ = c->get_name(hand, n++);
27+
}
28+
29+
int G2Probability::unpack_long(long* val, size_t* len)
30+
{
31+
long productDefinitionTemplateNumber = 0;
32+
grib_get_long(get_enclosing_handle(), productDefinitionTemplateNumber_, &productDefinitionTemplateNumber);
33+
*val = (productDefinitionTemplateNumber == 5 || productDefinitionTemplateNumber == 9);
34+
35+
return GRIB_SUCCESS;
36+
}
37+
38+
int G2Probability::pack_long(const long* val, size_t* len)
39+
{
40+
grib_handle* hand = get_enclosing_handle();
41+
long productDefinitionTemplateNumber = -1;
42+
long productDefinitionTemplateNumberNew = -1;
43+
char stepType[15] = {0,};
44+
size_t slen = 15;
45+
int isInstant = 0;
46+
int ret = 0;
47+
48+
if (grib_get_long(hand, productDefinitionTemplateNumber_, &productDefinitionTemplateNumber) != GRIB_SUCCESS)
49+
return GRIB_SUCCESS;
50+
51+
ret = grib_get_string(hand, stepType_, stepType, &slen);
52+
ECCODES_ASSERT(ret == GRIB_SUCCESS);
53+
54+
// long eps = grib_is_defined(hand, "perturbationNumber");
55+
56+
if (!strcmp(stepType, "instant"))
57+
isInstant = 1;
58+
59+
if (isInstant) {
60+
productDefinitionTemplateNumberNew = 5;
61+
}
62+
else {
63+
productDefinitionTemplateNumberNew = 9;
64+
}
65+
66+
if (productDefinitionTemplateNumber != productDefinitionTemplateNumberNew) {
67+
grib_set_long(hand, productDefinitionTemplateNumber_, productDefinitionTemplateNumberNew);
68+
}
69+
70+
return 0;
71+
}
72+
73+
int G2Probability::value_count(long* count)
74+
{
75+
*count = 1;
76+
return 0;
77+
}
78+
79+
} // namespace eccodes::accessor
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* (C) Copyright 2005- ECMWF.
3+
*
4+
* This software is licensed under the terms of the Apache Licence Version 2.0
5+
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6+
*
7+
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
8+
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
9+
*/
10+
11+
#pragma once
12+
13+
#include "Unsigned.h"
14+
15+
namespace eccodes::accessor
16+
{
17+
18+
class G2Probability : public Unsigned
19+
{
20+
public:
21+
G2Probability() :
22+
Unsigned() { class_name_ = "g2_probability"; }
23+
grib_accessor* create_empty_accessor() override { return new G2Probability{}; }
24+
int pack_long(const long* val, size_t* len) override;
25+
int unpack_long(long* val, size_t* len) override;
26+
int value_count(long*) override;
27+
void init(const long, grib_arguments*) override;
28+
29+
private:
30+
const char* productDefinitionTemplateNumber_ = nullptr;
31+
const char* stepType_ = nullptr;
32+
};
33+
34+
} // namespace eccodes::accessor

src/eccodes/grib_accessor_class.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ extern grib_accessor* grib_accessor_g2_concept_dir;
9292
extern grib_accessor* grib_accessor_g2_eps;
9393
extern grib_accessor* grib_accessor_g2_mars_labeling;
9494
extern grib_accessor* grib_accessor_g2_param_concept_filename;
95+
extern grib_accessor* grib_accessor_g2_probability;
9596
extern grib_accessor* grib_accessor_g2bitmap;
9697
extern grib_accessor* grib_accessor_g2bitmap_present;
9798
extern grib_accessor* grib_accessor_g2date;

0 commit comments

Comments
 (0)