Skip to content

Commit 0fea2b6

Browse files
committed
MUL-283: Simplify MARS2GRIB mapping
Removed special handling for levtype al and spherical harmonics
1 parent 4166faa commit 0fea2b6

File tree

2 files changed

+40
-109
lines changed

2 files changed

+40
-109
lines changed

src/multio/mars2grib/Rules.cc

Lines changed: 39 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,9 @@ auto makeGridRule(dm::Repres repres, std::int64_t num) {
181181
}
182182

183183
auto gridRules() {
184-
return exclusiveRuleList(makeGridRule(dm::Repres::GG, 40), makeGridRule(dm::Repres::LL, 0));
184+
return exclusiveRuleList(makeGridRule(dm::Repres::LL, 0), makeGridRule(dm::Repres::GG, 40),
185+
makeGridRule(dm::Repres::SH, 50));
185186
}
186-
auto gridRuleSH() {
187-
return exclusiveRuleList(makeGridRule(dm::Repres::SH, 50));
188-
}
189-
190187

191188
auto localSectionRules() {
192189
return exclusiveRuleList( //
@@ -199,22 +196,18 @@ auto localSectionRules() {
199196

200197
auto processTypesRules() {
201198
return exclusiveRuleList( //
202-
rule(all(Missing{dm::NUMBER}, Missing{dm::HDATE})), rule(all(Has{dm::NUMBER}, Missing{dm::HDATE}), ensemble()),
203-
rule(all(Has{dm::NUMBER}, Has{dm::HDATE}), reforecast(), ensemble()));
204-
}
205-
206-
auto processTypesRulesAl() {
207-
return exclusiveRuleList( //
208-
rule(all(Has{dm::NUMBER}), largeEnsemble()));
199+
rule(all(NoneOf{dm::LEVTYPE, {dm::LevType::AL}}, Missing{dm::NUMBER}, Missing{dm::HDATE})),
200+
rule(all(NoneOf{dm::LEVTYPE, {dm::LevType::AL}}, Has{dm::NUMBER}, Missing{dm::HDATE}), ensemble()),
201+
rule(all(NoneOf{dm::LEVTYPE, {dm::LevType::AL}}, Has{dm::NUMBER}, Has{dm::HDATE}), reforecast(), ensemble()),
202+
rule(all(matchLevType(dm::LevType::AL), Has{dm::NUMBER}, Missing{dm::HDATE}), largeEnsemble()),
203+
rule(all(matchLevType(dm::LevType::AL), Has{dm::NUMBER}, Has{dm::HDATE}), reforecast(), largeEnsemble()));
209204
}
210205

211206

212207
auto packingRules() {
213-
return exclusiveRuleList( //
214-
rule(OneOf{dm::PACKING, {"simple"}}, dataRepres(0)), rule(OneOf{dm::PACKING, {"ccsds"}}, dataRepres(42)));
215-
}
216-
auto packingRulesSH() {
217-
return exclusiveRuleList( //
208+
return exclusiveRuleList( //
209+
rule(OneOf{dm::PACKING, {"simple"}}, dataRepres(0)), //
210+
rule(OneOf{dm::PACKING, {"ccsds"}}, dataRepres(42)), //
218211
rule(OneOf{dm::PACKING, {"complex"}}, dataRepres(51)));
219212
}
220213

@@ -589,25 +582,16 @@ auto paramHLRules() {
589582
//-----------------------------------------------------------------------------
590583

591584
auto paramMLRules() {
592-
return exclusiveRuleList( //
593-
rule(matchParams(75, 76, 133, 203, 246, 247, 248, 260290), //
594-
pointInTime(), //
595-
typeOfLevel(TOL::Hybrid)), //
596-
rule(matchParams(paramRange(162100, 162113)), //
597-
timeRange(TimeRangeType::SinceLastPostProcessingStep, TOSP::Accumulation), //
598-
typeOfLevel(TOL::Hybrid)) //
599-
);
600-
}
601-
602-
auto paramMLRulesSH() {
603-
return exclusiveRuleList( //
604-
rule(matchParams(77, 129, 130, 131, 132, 135, 138, 152, 155), //
605-
pointInTime(), //
606-
typeOfLevel(TOL::Hybrid)) //
585+
return exclusiveRuleList( //
586+
rule(matchParams(75, 76, 77, paramRange(129, 133), 135, 138, 152, 155, 203, 246, 247, 248, 260290), //
587+
pointInTime(), //
588+
typeOfLevel(TOL::Hybrid)), //
589+
rule(matchParams(paramRange(162100, 162113)), //
590+
timeRange(TimeRangeType::SinceLastPostProcessingStep, TOSP::Accumulation), //
591+
typeOfLevel(TOL::Hybrid)) //
607592
);
608593
}
609594

610-
611595
//-----------------------------------------------------------------------------
612596
// PL
613597
//-----------------------------------------------------------------------------
@@ -630,23 +614,13 @@ auto plLevelRules(MkTail&& mkTail) {
630614

631615
auto paramPLRules() {
632616
return plLevelRules([]() {
633-
return exclusiveRuleList( //
634-
rule(matchParams(60, 75, 76, paramRange(129, 135), 203, 246, 247, 248, 157, 260290), //
635-
pointInTime()), //
636-
rule(matchParams(235100, paramRange(235129, 235133), 235135, 235157, 235203, 235246), //
637-
timeRange(TimeRangeType::SinceLastPostProcessingStep, TOSP::Average)) //
638-
);
639-
});
640-
}
641-
642-
auto paramPLRulesSH() {
643-
return plLevelRules([]() {
644-
return exclusiveRuleList( //
645-
rule(matchParams(1, 2, paramRange(129, 135), 138, 152, 155, 157), //
646-
pointInTime()), //
647-
rule(matchParams(235129, 235130, 235138, 235152, 235155, 263107), //
648-
timeRange(TimeRangeType::SinceLastPostProcessingStep, TOSP::Average)) //
649-
);
617+
return exclusiveRuleList( //
618+
rule(matchParams(1, 2, 60, 75, 76, paramRange(129, 135), 138, 152, 155, 157, 203, 246, 247, 248, 157,
619+
260290),
620+
pointInTime()),
621+
rule(matchParams(235100, paramRange(235129, 235133), 235135, 235138, 235152, 235155, 235157, 235203, 235246,
622+
263107),
623+
timeRange(TimeRangeType::SinceLastPostProcessingStep, TOSP::Average)));
650624
});
651625
}
652626

@@ -676,29 +650,14 @@ auto paramPTRules() {
676650
);
677651
}
678652

679-
auto paramPTRulesSH() {
680-
return exclusiveRuleList( //
681-
rule(matchParams(53, 54, 131, 132, 133, 138, 155), //
682-
pointInTime(), //
683-
typeOfLevel(TOL::Theta)) //
684-
);
685-
}
686653

687654
//-----------------------------------------------------------------------------
688655
// PV
689656
//-----------------------------------------------------------------------------
690657

691658
auto paramPVRules() {
692-
return exclusiveRuleList( //
693-
rule(matchParams(3, 54, 129, 131, 132, 133, 203), //
694-
pointInTime(), //
695-
typeOfLevel(TOL::PotentialVorticity)) //
696-
);
697-
}
698-
699-
auto paramPVRulesSH() {
700659
return exclusiveRuleList( //
701-
rule(matchParams(3, 54, 129), //
660+
rule(matchParams(3, 54, 129, 131, 132, 133, 203), //
702661
pointInTime(), //
703662
typeOfLevel(TOL::PotentialVorticity)), //
704663
rule(matchParams(235098, 235269), //
@@ -765,17 +724,8 @@ auto paramRules() {
765724
chainedRuleList(rule(matchLevType(dm::LevType::PL)), paramPLRules()), //
766725
chainedRuleList(rule(matchLevType(dm::LevType::PT)), paramPTRules()), //
767726
chainedRuleList(rule(matchLevType(dm::LevType::PV)), paramPVRules()), //
768-
chainedRuleList(rule(matchLevType(dm::LevType::SOL)), paramSOLRules()) //
769-
);
770-
}
771-
772-
773-
auto paramRulesSH() {
774-
return exclusiveRuleList( //
775-
chainedRuleList(rule(matchLevType(dm::LevType::ML)), paramMLRulesSH()), //
776-
chainedRuleList(rule(matchLevType(dm::LevType::PL)), paramPLRulesSH()), //
777-
chainedRuleList(rule(matchLevType(dm::LevType::PT)), paramPTRulesSH()), //
778-
chainedRuleList(rule(matchLevType(dm::LevType::PV)), paramPVRulesSH()) //
727+
chainedRuleList(rule(matchLevType(dm::LevType::SOL)), paramSOLRules()), //
728+
chainedRuleList(rule(matchLevType(dm::LevType::AL)), paramAlRules()) //
779729
);
780730
}
781731

@@ -784,37 +734,18 @@ auto paramRulesSH() {
784734
// Big rule tree...
785735
//-----------------------------------------------------------------------------
786736

787-
const ExclusiveRuleList& allRules() {
788-
static auto all_ = exclusiveRuleList(
789-
// Branch for grids
790-
chainedRuleList( //
791-
rule(all(Has{dm::GRID}, NoneOf{dm::LEVTYPE, {dm::LevType::AL}})), //
792-
gridRules(), //
793-
localSectionRules(), //
794-
processTypesRules(), //
795-
paramRules(), //
796-
packingRules() //
797-
),
798-
799-
// Branch for spherical harmonics
800-
chainedRuleList( //
801-
rule(all(Has{dm::TRUNCATION}, NoneOf{dm::LEVTYPE, {dm::LevType::AL}})), //
802-
gridRuleSH(), //
803-
localSectionRules(), //
804-
processTypesRules(), //
805-
paramRulesSH(), //
806-
packingRulesSH() //
807-
),
808-
809-
// Branch for abstract level
810-
chainedRuleList( //
811-
rule(matchLevType(dm::LevType::AL)), //
812-
gridRules(), //
813-
localSectionRules(), //
814-
processTypesRulesAl(), //
815-
paramAlRules(), //
816-
packingRules() //
817-
));
737+
const ChainedRuleList& allRules() {
738+
static auto all_ =
739+
// General branch for grids & spherical harmanics
740+
chainedRuleList( //
741+
rule(all(NoneOf{dm::LEVTYPE, {dm::LevType::AL}})), //
742+
gridRules(), //
743+
localSectionRules(), //
744+
processTypesRules(), //
745+
paramRules(), //
746+
packingRules() //
747+
);
748+
818749
return all_;
819750
}
820751

src/multio/mars2grib/Rules.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
namespace multio::mars2grib::rules {
1919
using namespace rules;
2020

21-
const ExclusiveRuleList& allRules();
21+
const ChainedRuleList& allRules();
2222

2323
SectionsConf buildEncoderConf(const dm::FullMarsRecord&);
2424

0 commit comments

Comments
 (0)