Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/metkit/grib2mars/mappings/rules/extract.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "metkit/grib2mars/mappings/rules/activity.h"
#include "metkit/grib2mars/mappings/rules/anoffset.h"
#include "metkit/grib2mars/mappings/rules/channel.h"
#include "metkit/grib2mars/mappings/rules/chem.h"
#include "metkit/grib2mars/mappings/rules/class.h"
#include "metkit/grib2mars/mappings/rules/dataset.h"
#include "metkit/grib2mars/mappings/rules/date.h"
Expand Down Expand Up @@ -60,6 +61,7 @@ const std::unordered_map<std::string, MarsExtractor<MarsDict, MiscDict>>& extrac
{"type", extractType<MarsDict, MiscDict>},
{"expver", extractExpver<MarsDict, MiscDict>},
{"param", extractParam<MarsDict, MiscDict>},
{"chem", extractChem<MarsDict, MiscDict>},
{"levtype", extractLevtype<MarsDict, MiscDict>},
{"levelist", extractLevelist<MarsDict, MiscDict>},
{"frequency", extractFrequency<MarsDict, MiscDict>},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,20 @@ std::size_t compositionMatcher(const MarsDict_t& mars, const OptDict_t& opt) {
return static_cast<std::size_t>(CompositionType::Chem);
}
}
else if (matchAny(param, 435000, 435002, 436000, 436002, 437000, 437002)) {
if (matchAny(chem, 25)) {
return static_cast<std::size_t>(CompositionType::Chem);
}
}
else if (matchAny(param, 479000)) {
if (matchAny(chem, 404)) {
return static_cast<std::size_t>(CompositionType::Chem);
}
}
else if (matchAny(param, 469000)) {
if (matchAny(chem, 2, 5, 9, 10, 12, 16, 18, 19, 42, range(45, 48), 52, 99, 100, 129, 224, 226, 233, 311,
933, 934)) {
if (matchAny(chem, 2, 5, 9, 10, 12, 16, 18, 19, 25, 31, 42, range(45, 49), 52, range(98, 100), 124, 126,
129, 199, 224, 226, 233, 311, 334, 404, range(431, 433), range(438, 441), range(443, 446),
922, 930, 933, 934, 948, 951)) {
return static_cast<std::size_t>(CompositionType::ChemicalSource);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,20 @@ std::size_t pointInTimeMatcher(const MarsDict_t& mars, const OptDict_t& opt) {
return static_cast<std::size_t>(PointInTimeType::Default);
}

// Chemical products which have not been mapped
if (matchAny(param, range(228083, 228085))) {
return static_cast<std::size_t>(PointInTimeType::Default);
}

// Chemical products
if (matchAny(param, range(228083, 228085), range(400000, 499999))) {
if (matchAny(param, range(400000, 499999))) {
if (param % 10 != 0) {
throw utils::exceptions::Mars2GribMatcherException(
"Chemical param " + std::to_string(param) + " with last digit " + std::to_string(param % 10) +
" is not a point-in-time product. Last digit must be 0 for point-in-time products in "
"400000 - 499999 param range.",
Here());
}
return static_cast<std::size_t>(PointInTimeType::Default);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,35 @@ std::size_t statisticsMatcher(const MarsDict_t& mars, const OptDict_t& opt) {
return static_cast<std::size_t>(StatisticsType::StandardDeviation);
}

// Chemical products
// Chemical products which have not been mapped
if (matchAny(param, range(228080, 228082), range(233032, 233035), range(235062, 235064))) {
return static_cast<std::size_t>(StatisticsType::Accumulation);
}

// Chemical products
// Note: In range 4xxxxy the following typeOfStatisticalProduct can be derived from the last digit:
// y == 1 -> mean; 2 -> accumulation; 3 -> maximum; 4 -> minimum; 5 -> standard deviation
// If the last digit is 0, the param is point-in-time.
if (matchAny(param, range(400000, 499999))) {
switch (param % 10) {
case 1:
return static_cast<std::size_t>(StatisticsType::Average);
case 2:
return static_cast<std::size_t>(StatisticsType::Accumulation);
case 3:
return static_cast<std::size_t>(StatisticsType::Maximum);
case 4:
return static_cast<std::size_t>(StatisticsType::Minimum);
case 5:
return static_cast<std::size_t>(StatisticsType::StandardDeviation);
default:
throw utils::exceptions::Mars2GribMatcherException(
"No typeOfStatisticalProcessing defined for chemical param " + std::to_string(param) +
" with last digit " + std::to_string(param % 10),
Here());
}
}

// TODO: Don't handle products with timespan as non-statistical if they are not handled above!
// if (has(mars, "timespan")) {
// throw utils::exceptions::Mars2GribMatcherException("MARS contains `timespan` but
Expand Down
62 changes: 62 additions & 0 deletions src/metkit/mars2mars/mappings/rules/chemical.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,32 @@ inline void convertChemical(const InDict_t& in, OutDict_t& out, eckit::LocalConf
return setParamChem(out, 400000, 930);
case 210074:
return setParamChem(out, 400000, 931);
case 210080:
return setParamChem(out, 469000, 25);
case 210081:
return setParamChem(out, 469000, 2);
case 210082:
return setParamChem(out, 469000, 404);
case 210083:
return setParamChem(out, 469000, 334);
case 210084:
return setParamChem(out, 469000, 199);
case 210085:
return setParamChem(out, 469000, 129);
case 210086:
return setParamChem(out, 469000, 31);
case 210087:
return setParamChem(out, 469000, 930);
case 210088:
return setParamChem(out, 469000, 922);
case 210089:
return setParamChem(out, 469000, 948);
case 210090:
return setParamChem(out, 469000, 934);
case 210091:
return setParamChem(out, 469000, 933);
case 210092:
return setParamChem(out, 469000, 951);
case 210102:
return setParamChem(out, 469000, 233);
case 210103:
Expand All @@ -133,8 +151,18 @@ inline void convertChemical(const InDict_t& in, OutDict_t& out, eckit::LocalConf
return setParamChem(out, 469000, 48);
case 210108:
return setParamChem(out, 469000, 16);
case 210109:
return setParamChem(out, 469000, 49);
case 210110:
return setParamChem(out, 469000, 99);
case 210111:
return setParamChem(out, 469000, 124);
case 210112:
return setParamChem(out, 469000, 126);
case 210113:
return setParamChem(out, 469000, 5);
case 210114:
return setParamChem(out, 469000, 98);
case 210115:
return setParamChem(out, 469000, 52);
case 210116:
Expand Down Expand Up @@ -217,6 +245,28 @@ inline void convertChemical(const InDict_t& in, OutDict_t& out, eckit::LocalConf
return setParamChemWavelength(out, 457000, 922, 1640.0);
case 210230:
return setParamChemWavelength(out, 457000, 922, 2130.0);
case 210231:
return setParamChem(out, 469000, 431);
case 210232:
return setParamChem(out, 469000, 432);
case 210233:
return setParamChem(out, 469000, 433);
case 210234:
return setParamChem(out, 469000, 439);
case 210235:
return setParamChem(out, 469000, 440);
case 210236:
return setParamChem(out, 469000, 441);
case 210237:
return setParamChem(out, 469000, 443);
case 210238:
return setParamChem(out, 469000, 438);
case 210239:
return setParamChem(out, 469000, 444);
case 210240:
return setParamChem(out, 469000, 445);
case 210241:
return setParamChem(out, 469000, 446);
case 210247:
return setParamChem(out, 402000, 912);
case 210248:
Expand Down Expand Up @@ -1221,6 +1271,18 @@ inline void convertChemical(const InDict_t& in, OutDict_t& out, eckit::LocalConf
return setParamChem(out, 444000, 17);
case 223033:
return setParamChem(out, 444000, 33);
case 228080:
return setParamChem(out, 435002, 25);
case 228081:
return setParamChem(out, 436002, 25);
case 228082:
return setParamChem(out, 437002, 25);
case 228083:
return setParamChem(out, 435000, 25);
case 228084:
return setParamChem(out, 436000, 25);
case 228085:
return setParamChem(out, 437000, 25);

default:
break;
Expand Down
Loading