Skip to content

Commit

Permalink
Adds handling of a model-id-attr to wxcode-modal (metoppv#1634)
Browse files Browse the repository at this point in the history
* Updates checksums following addition of mosg__model_configuration to wxcode-modal gridded test data

* Adds model-id-attr to wxcode modal

- Adds a test for this
- Updates acceptance tests to use this
- and updates checksums as acceptance test inputs modified so that
  - mosg__model_configuration is set
  - title is consistent with a blended data-set

* Black and flake8

* Debugs new tests to that the new parametrized variable is available where it's needed

* Updates checksums with gridded wxcode-modal attribute update

* Updates checksums with spot wxcode-modal attribute update

* Updates checksums after merging with master

* Updates checksums following reapplication of meta-data using IMPROVER load/save wrappers.

* Updates checksums following recreation of KGO.

* Recreates checksums following rebase of acceptance test branch to hotfix 1.0.3

* Removes useless comment

* Corrects checksums following rebase of acceptance test data branch
  • Loading branch information
MoseleyS authored Jan 18, 2022
1 parent 88249ff commit b85b137
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 79 deletions.
8 changes: 6 additions & 2 deletions improver/cli/wxcode_modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

@cli.clizefy
@cli.with_output
def process(*cubes: cli.inputcube):
def process(*cubes: cli.inputcube, model_id_attr: str = None):
"""Generates a modal weather symbol for the period covered by the input
weather symbol cubes. Where there are different weather codes available
for night and day, the modal code returned is always a day code, regardless
Expand All @@ -46,6 +46,10 @@ def process(*cubes: cli.inputcube):
cubes (iris.cube.CubeList):
A cubelist containing weather symbols cubes that cover the period
over which a modal symbol is desired.
model_id_attr (str):
Name of attribute recording source models that should be
inherited by the output cube. The source models are expected as
a space-separated string.
Returns:
iris.cube.Cube:
Expand All @@ -56,4 +60,4 @@ def process(*cubes: cli.inputcube):
if not cubes:
raise RuntimeError("Not enough input arguments. See help for more information.")

return ModalWeatherCode()(cubes)
return ModalWeatherCode(model_id_attr=model_id_attr)(cubes)
24 changes: 22 additions & 2 deletions improver/wxcode/modal_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,20 @@ class ModalWeatherCode(BasePlugin):
covered by the input files.
"""

def __init__(self):
"""Create an aggregator instance for reuse"""
def __init__(self, model_id_attr: str = None):
"""
Set up plugin and create an aggregator instance for reuse
Args:
model_id_attr:
Name of attribute recording source models that should be
inherited by the output cube. The source models are expected as
a space-separated string.
"""
self.aggregator_instance = Aggregator("mode", self.mode_aggregator)

self.model_id_attr = model_id_attr

# Create the expected cell method for use with single cube inputs
# that do not pass through the aggregator.
self.mode_cell_method = iris.coords.CellMethod("mode", coords="time")
Expand Down Expand Up @@ -205,6 +215,16 @@ def process(self, cubes: CubeList) -> Cube:
result = cube.collapsed("time", self.aggregator_instance)
self._set_blended_times(result)

if self.model_id_attr:
# Update contributing models
contributing_models = set()
for source_cube in cubes:
for model in source_cube.attributes[self.model_id_attr].split(" "):
contributing_models.update([model])
result.attributes[self.model_id_attr] = " ".join(
sorted(list(contributing_models))
)

# Handle any unset points where it was hard to determine a suitable mode
if (result.data == UNSET_CODE_INDICATOR).any():
self._group_codes(result, cube)
Expand Down
Loading

0 comments on commit b85b137

Please sign in to comment.