-
Notifications
You must be signed in to change notification settings - Fork 14
Regression fixes for MTG2 conversion and encoding logic #238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tweska
wants to merge
28
commits into
develop
Choose a base branch
from
fix/grib2mars
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
6b58f97
mars2mars: Fix wrong param conversion for 141
tweska 40b987e
grib2mars: Set bitmapPresent as boolean
tweska 83e87fa
grib2mars: Default initialStep to 0, and timeIncrementInSeconds to 3600
tweska 6b50b3b
grib2mars: Read and set laplacianOperator as double
tweska 19a6b38
mars2mars: Fix typo SFC -> sfc
tweska 53353bf
mars2grib: Skip explicit level setting for isothermal fields
tweska 0522024
mars2mars: Add misc param mappings lost during porting
tweska 0431d76
grib2mars: Add extractors for iteration and coeffindex
tweska 8c2df96
mars2mars: Add incremental param mappings lost during porting
tweska 44413ce
grib2mars: Add extractor for typeOfProcessedData
tweska a8890dc
Run clang-format
tweska 232fd37
grib2mars: Add extractor for numberOfComponents and modelErrorType
tweska 5f04929
grib2mars: Simplify extraction of number and ensemble related keys
tweska 26705bb
grib2mars,mars2grib: Support FourierCoefficients
tweska 460942e
Apply suggestions from code review
tweska e76e6f3
grib1-to-grib2 tool: Add extra options needed for MTG2 conversion tasks
tweska 1ea819a
mars2grib: Support scaleValuesBy and offsetValuesBy in encoder
tweska ca01c24
grib2mars,mars2grib: Remove laplacianOperator
tweska d4f24f3
grib1-to-grib2 tool: Detect discipline 192 based on paramId for GRIB1
tweska a6fa2d6
mars2grib: Fix level encoding of param 129172
tweska 3c5f80a
grib2mars: Simplify step extraction
tweska 4781488
grib2mars: Reintroduce logic to conditionally extract numberOfForecas…
tweska 86b6da0
mars2mars: Convert stream waef to enfo
tweska 662b570
mars2mars: Remove number from MARS dict for type=me
tweska 4aee9a9
Run clang-format
tweska befc9e1
grib2mars,mars2mars: Support step ranges, and convert to step + timespan
tweska b627ab5
mars2mars: Set timespan to 0 for statistical fields as instant fields…
tweska 19a7e8d
mars2mars: Avoid reading step with the wrong type
tweska File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #pragma once | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "metkit/codes/api/CodesAPI.h" | ||
|
|
||
| #include "metkit/grib2mars/utils/dictionary_traits/dictionary_access_traits.h" | ||
| #include "metkit/grib2mars/utils/grib2marsExceptions.h" | ||
|
|
||
| namespace metkit::grib2mars::rules::impl { | ||
|
|
||
| template <class MarsDict, class MiscDict> | ||
| void extractCoeffindex(const std::string& keyword, const metkit::codes::CodesHandle& grib, MarsDict& mars, | ||
| MiscDict& misc) { | ||
| using metkit::grib2mars::utils::dict_traits::set_or_throw; | ||
| using metkit::grib2mars::utils::exceptions::Grib2MarsGenericException; | ||
|
|
||
| try { | ||
| if (!grib.has(keyword)) { | ||
| throw Grib2MarsGenericException( | ||
| "Missing GRIB key `" + keyword + "` required to extract MARS keyword `" + keyword + "`", Here()); | ||
| } | ||
|
|
||
| const long value = grib.getLong(keyword); | ||
| set_or_throw<long>(mars, keyword, value); | ||
|
|
||
| if (grib.has("numberOfFourierCoefficients")) { | ||
| const long numberOfFourierCoefficients = grib.getLong("numberOfFourierCoefficients"); | ||
| misc.set("numberOfFourierCoefficients", numberOfFourierCoefficients); | ||
| } | ||
| } | ||
| catch (...) { | ||
| std::throw_with_nested(Grib2MarsGenericException("Failed to extract MARS keyword `" + keyword + "`", Here())); | ||
| } | ||
| } | ||
|
|
||
| } // namespace metkit::grib2mars::rules::impl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #pragma once | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "metkit/codes/api/CodesAPI.h" | ||
|
|
||
| #include "metkit/grib2mars/utils/dictionary_traits/dictionary_access_traits.h" | ||
| #include "metkit/grib2mars/utils/grib2marsExceptions.h" | ||
|
|
||
| namespace metkit::grib2mars::rules::impl { | ||
|
|
||
| template <class MarsDict, class MiscDict> | ||
| void extractIteration(const std::string& keyword, const metkit::codes::CodesHandle& grib, MarsDict& mars, | ||
| MiscDict& misc) { | ||
| using metkit::grib2mars::utils::dict_traits::set_or_throw; | ||
| using metkit::grib2mars::utils::exceptions::Grib2MarsGenericException; | ||
|
|
||
| try { | ||
| if (!grib.has(keyword)) { | ||
| throw Grib2MarsGenericException( | ||
| "Missing GRIB key `" + keyword + "` required to extract MARS keyword `" + keyword + "`", Here()); | ||
| } | ||
|
|
||
| const long value = grib.getLong(keyword); | ||
| set_or_throw<long>(mars, keyword, value); | ||
|
|
||
| if (grib.getString("type") == "4i" && grib.has("totalNumberOfIterations")) { | ||
| const long totalNumberOfIterations = grib.getLong("totalNumberOfIterations"); | ||
| misc.set("totalNumberOfIterations", totalNumberOfIterations); | ||
| } | ||
| } | ||
| catch (...) { | ||
| std::throw_with_nested(Grib2MarsGenericException("Failed to extract MARS keyword `" + keyword + "`", Here())); | ||
| } | ||
| } | ||
|
|
||
| } // namespace metkit::grib2mars::rules::impl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,68 +15,36 @@ void extractNumber(const std::string& keyword, const metkit::codes::CodesHandle& | |
| using metkit::grib2mars::utils::exceptions::Grib2MarsGenericException; | ||
|
|
||
| try { | ||
| if (!grib.has("type")) { | ||
| if (!grib.has(keyword)) { | ||
| throw Grib2MarsGenericException( | ||
| "Missing GRIB key `type` required to extract MARS keyword `" + keyword + "`", Here()); | ||
| "Missing GRIB key `" + keyword + "` required to extract MARS keyword `" + keyword + "`", Here()); | ||
| } | ||
|
|
||
| const std::string type = grib.getString("type"); | ||
|
|
||
| if (type == "es" || type == "em") { | ||
| if (!grib.has("numberOfForecastsInEnsemble")) { | ||
| throw Grib2MarsGenericException( | ||
| "Missing GRIB key `numberOfForecastsInEnsemble` required " | ||
| "for derived ensemble forecast", | ||
| Here()); | ||
| } | ||
| const long value = grib.getLong(keyword); | ||
| set_or_throw<long>(mars, keyword, value); | ||
|
|
||
| if (grib.has("numberOfForecastsInEnsemble")) { | ||
| const long numberOfForecastsInEnsemble = grib.getLong("numberOfForecastsInEnsemble"); | ||
|
|
||
| misc.set("numberOfForecastsInEnsemble", numberOfForecastsInEnsemble); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| if (!grib.has("number") || !grib.has("numberOfForecastsInEnsemble")) { | ||
| return; | ||
| } | ||
|
|
||
| const long number = grib.getLong("number"); | ||
| const long numberOfForecastsInEnsemble = grib.getLong("numberOfForecastsInEnsemble"); | ||
|
|
||
| if (number != 0 && numberOfForecastsInEnsemble == 0) { | ||
| throw Grib2MarsGenericException("The value for key `numberOfForecastsInEnsemble` must not be 0", Here()); | ||
| } | ||
|
|
||
| if (numberOfForecastsInEnsemble == 0) { | ||
| return; | ||
| } | ||
|
|
||
| set_or_throw<long>(mars, keyword, number); | ||
|
|
||
| misc.set("numberOfForecastsInEnsemble", numberOfForecastsInEnsemble); | ||
|
|
||
| if (grib.has("class")) { | ||
| const std::string klass = grib.getString("class"); | ||
|
|
||
| if (klass == "ai") { | ||
| // Handled in the encoder, matching the original tool logic. | ||
| return; | ||
| if (numberOfForecastsInEnsemble != 0) { | ||
| misc.set("numberOfForecastsInEnsemble", numberOfForecastsInEnsemble); | ||
|
|
||
| if (grib.getString("class") != "ai") { | ||
| if (grib.has("typeOfEnsembleForecast")) { | ||
| const long typeOfEnsembleForecast = grib.getLong("typeOfEnsembleForecast"); | ||
| misc.set("typeOfEnsembleForecast", typeOfEnsembleForecast); | ||
| } | ||
| else if (grib.has("eps")) { | ||
| const long typeOfEnsembleForecast = grib.getLong("eps"); | ||
| misc.set("typeOfEnsembleForecast", typeOfEnsembleForecast); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (grib.has("typeOfEnsembleForecast")) { | ||
| const long typeOfEnsembleForecast = grib.getLong("typeOfEnsembleForecast"); | ||
|
|
||
| misc.set("typeOfEnsembleForecast", typeOfEnsembleForecast); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| if (grib.has("eps")) { | ||
| const long eps = grib.getLong("eps"); | ||
|
|
||
| misc.set("typeOfEnsembleForecast", eps); | ||
| else if (grib.getString("type") != "me") { | ||
| throw Grib2MarsGenericException( | ||
| "Missing GRIB key `numberOfForecastsInEnsemble` required to extract MARS keyword `" + keyword + "`", | ||
| Here()); | ||
| } | ||
| } | ||
|
Comment on lines
17
to
49
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that |
||
| catch (...) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.