-
Notifications
You must be signed in to change notification settings - Fork 297
Translate text PP save rules into Python #2795
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
488827e
Translate text PP save rules to Python
DPeterK 00d50a7
Update rule function names
DPeterK 8817b84
Plumb in changes
DPeterK d76f996
Changes from running tests
DPeterK 5879f3a
Final test-related changes
DPeterK 4f8941c
Changes to get the tests passing; a review action
DPeterK 4bbaae6
License headers
DPeterK 336cfe4
Reorganisation of pp lbproc_pairs feature. (#12)
pp-mo fe54f04
Remove unneeded lines
DPeterK 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 was deleted.
Oops, something went wrong.
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,48 @@ | ||
| # (C) British Crown Copyright 2017, Met Office | ||
| # | ||
| # This file is part of Iris. | ||
| # | ||
| # Iris is free software: you can redistribute it and/or modify it under | ||
| # the terms of the GNU Lesser General Public License as published by the | ||
| # Free Software Foundation, either version 3 of the License, or | ||
| # (at your option) any later version. | ||
| # | ||
| # Iris is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU Lesser General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU Lesser General Public License | ||
| # along with Iris. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| from __future__ import (absolute_import, division, print_function) | ||
| from six.moves import (filter, input, map, range, zip) # noqa | ||
| import six | ||
|
|
||
| import itertools | ||
|
|
||
|
|
||
| # LBPROC codes and their English equivalents | ||
| LBPROC_PAIRS = ((1, "Difference from another experiment"), | ||
| (2, "Difference from zonal (or other spatial) mean"), | ||
| (4, "Difference from time mean"), | ||
| (8, "X-derivative (d/dx)"), | ||
| (16, "Y-derivative (d/dy)"), | ||
| (32, "Time derivative (d/dt)"), | ||
| (64, "Zonal mean field"), | ||
| (128, "Time mean field"), | ||
| (256, "Product of two fields"), | ||
| (512, "Square root of a field"), | ||
| (1024, "Difference between fields at levels BLEV and BRLEV"), | ||
| (2048, "Mean over layer between levels BLEV and BRLEV"), | ||
| (4096, "Minimum value of field during time period"), | ||
| (8192, "Maximum value of field during time period"), | ||
| (16384, "Magnitude of a vector, not specifically wind speed"), | ||
| (32768, "Log10 of a field"), | ||
| (65536, "Variance of a field"), | ||
| (131072, "Mean over an ensemble of parallel runs")) | ||
|
|
||
| # lbproc_map is dict mapping lbproc->English and English->lbproc | ||
| # essentially a one to one mapping | ||
| LBPROC_MAP = {x: y for x, y in | ||
| itertools.chain(LBPROC_PAIRS, ((y, x) for x, y in LBPROC_PAIRS))} |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think moving these to iris.fileformats.rules is a mistake, as it the information is specific to PP (and FF), whereas iris.fileformats.rules "ought" to be the home for fileformat-independent rules processing.
They aren't specially tied to implementation of text rules anyway.
In any case, "LBPROC_PAIRS" and "lbproc_map" are perfectly reasonable public elements of the API, so you can't just move them anyway.
In an ideal world I think these would be in "iris.fileformats.um_cf_map", and also "lbroc_map" should be capitalised, but it's a bit late for that...
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(from discussion with @dkillick)
The move was introduced because of a circularity problem when
iris.fileformats.ppimportsiris.fileformats.pp_save_rules, which importsiris.fileformats.pp...By putting 'lbproc_map' into
rules, thenpp_save_rulesno longer needed to importpp.Alternative suggestion: Put LBPROC_PAIRS and
lbproc_mapinside pp_save_rules itself.Then to avoid breaking existing API, publish them also in 'pp' by importing them from 'pp_save_rules'.
For better measure, we can fix naming + make them private in pp_save_rules.
Ideally we would "deprecate" this, but I also can't see how?
So, perhaps this really is a suitable case for a major-version breaking change ??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More trouble...
I missed that "lbproc_map" is also used in "pp_rules"
( i.e. "pp_load_rules", perhaps it should now be called that ? )
You can import it there from "pp_save_rules", but that is obviously a rather peculiar dependency ordering.
You cannot import it from 'pp', if 'pp' is to import 'pp_rules' (same circularity problem as before)
In my view, this info really belongs with the other similar stuff in 'um_cf_map'.
To do this properly, we should really put this info into metarelate, and modify
tools/gen_translations.pyto support it, but I really don't think we have time for that.In which case, we should just host this translation info in a separate module.
See : DPeterK#12 for worked suggestion ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #2790.
Agreed 👍 Thanks for spotting this, @pp-mo