Skip to content
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

Refactor weather code plugins and CLIs #1944

Merged
merged 28 commits into from
Nov 14, 2023

Conversation

MoseleyS
Copy link
Contributor

@MoseleyS MoseleyS commented Sep 22, 2023

Time spent on this ticket should be charged to a specific code. Ask @MoseleyS.

As Enhancing Post Processing Science Lead, I want the IMPROVER weather code plugin to be refactored so that I can run a precipitation type code configuration.

The essential changes are around metadata. The output cube name and categorical attributes are now derived from the decision tree, which has been updated as a result and is now also a required input to the modal categories plugin.

To achieve this, I have done some refactoring:

  • code and acceptance test data moved to directories named categorical
  • CLI names changed:
    • wxcode -> categorical
    • wxcode-modal -> categorical-modes
  • Both these CLIs now require the decision tree, with the key name changing from wxtree to decision-tree
  • Plugin names changed:
    • WeatherSymbols -> ApplyDecisionTree
    • ModalWeatherCode -> ModalCategory
  • Several internal variable names and comments have been updated to be more generic.
  • Meta data definitions of the cube name, attribute names and contents have moved out of the code and into the decision tree.
  • Grouping and day -> night mapping have moved out of the code and into the decision tree.

Acceptance test data updates in metoppv/improver_test_data#28

For reviewing, I recommend looking in two parts:

  1. Most of the refactoring is in the first four commits: aaf3ae6...5734e30
  2. Then everything else: 5734e30...99f6802

This PR MUST be merged with the accompanying suite PR: (https://github.com/MetOffice/improver_suite/pull/1823)

Testing:

  • Ran tests and they passed OK
  • Added new tests for the new feature(s)

- CLI renamed from wxcode to categorical
- WeatherSymbols plugin renamed to ApplyDecisionTree
- Code moved from wxcode directory to categorical
- Comments and variable names replaced with more agnostic definitions
- acceptance test data locations
- extended docs locations
- Includes method for mapping day and night symbols
- Includes extended documentation
@codecov
Copy link

codecov bot commented Sep 22, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (aaf3ae6) 98.38% compared to head (01af03c) 98.40%.
Report is 17 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1944      +/-   ##
==========================================
+ Coverage   98.38%   98.40%   +0.01%     
==========================================
  Files         123      124       +1     
  Lines       11795    12028     +233     
==========================================
+ Hits        11605    11836     +231     
- Misses        190      192       +2     
Files Coverage Δ
improver/categorical/decision_tree.py 99.30% <100.00%> (ø)
improver/categorical/modal_code.py 100.00% <100.00%> (ø)
improver/categorical/utilities.py 100.00% <100.00%> (ø)
improver/developer_tools/metadata_interpreter.py 99.05% <100.00%> (ø)

... and 16 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MoseleyS MoseleyS self-assigned this Sep 22, 2023
@MoseleyS MoseleyS marked this pull request as ready for review September 22, 2023 15:43
@MoseleyS MoseleyS removed their assignment Sep 22, 2023
Copy link
Contributor

@mspelman07 mspelman07 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Stephen. A few comments mostly around clarifying some docstrings but otherwise this looks good.

improver/categorical/decision_tree.py Outdated Show resolved Hide resolved
improver/categorical/decision_tree.py Outdated Show resolved Hide resolved
improver/categorical/decision_tree.py Outdated Show resolved Hide resolved
improver/categorical/modal_code.py Outdated Show resolved Hide resolved
improver/cli/categorical.py Outdated Show resolved Hide resolved
@mspelman07 mspelman07 assigned MoseleyS and unassigned mspelman07 Sep 27, 2023
@MoseleyS
Copy link
Contributor Author

MoseleyS commented Oct 3, 2023

improver.categorical.utilities.categorical_attributes improver.developer_tools.metadata_interpreter.MOMetadataInterpreter (in function run)

The categorical utilities just has a few variables called wx_keys which probably wants updating but I'm not sure about the developer_tools one?

I've updated the variable names in both files. This allows us to add other categorical data to the metadata interpreter in the future, if required.

@MoseleyS MoseleyS assigned mspelman07 and unassigned MoseleyS Oct 3, 2023
mspelman07
mspelman07 previously approved these changes Oct 3, 2023
@mspelman07 mspelman07 removed their assignment Oct 3, 2023
@gavinevans gavinevans self-assigned this Oct 20, 2023
Copy link
Contributor

@gavinevans gavinevans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @MoseleyS 👍

I've added some very minor comments.

improver/categorical/decision_tree.py Outdated Show resolved Hide resolved
improver/categorical/decision_tree.py Show resolved Hide resolved
improver/categorical/decision_tree.py Show resolved Hide resolved
improver/categorical/utilities.py Outdated Show resolved Hide resolved
improver/categorical/utilities.py Outdated Show resolved Hide resolved
improver/categorical/utilities.py Outdated Show resolved Hide resolved
improver_tests/categorical/test_utilities.py Outdated Show resolved Hide resolved
@gavinevans gavinevans assigned MoseleyS and unassigned gavinevans Oct 20, 2023
@MoseleyS MoseleyS assigned gavinevans and unassigned MoseleyS Nov 1, 2023
Copy link
Contributor

@gavinevans gavinevans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates, @MoseleyS 👍

I've added one trivial comment.

improver/categorical/modal_code.py Outdated Show resolved Hide resolved
@gavinevans gavinevans assigned MoseleyS and unassigned gavinevans Nov 2, 2023
@MoseleyS MoseleyS assigned gavinevans and unassigned MoseleyS Nov 2, 2023
@gavinevans gavinevans assigned MoseleyS and unassigned gavinevans Nov 2, 2023
@MoseleyS MoseleyS merged commit 3eee0a9 into metoppv:master Nov 14, 2023
10 checks passed
@MoseleyS MoseleyS deleted the refactor_wxcode branch November 14, 2023 13:14
MoseleyS added a commit to MoseleyS/improver that referenced this pull request Aug 22, 2024
* Refactors wxcode to be more agnostic

- CLI renamed from wxcode to categorical
- WeatherSymbols plugin renamed to ApplyDecisionTree
- Code moved from wxcode directory to categorical
- Comments and variable names replaced with more agnostic definitions

* Fixes failing tests following refactor

* isort

* More refactoring

- acceptance test data locations
- extended docs locations

* Updates testing decision tree and check_tree method and tests

* Updates categorical attribute generation and tests, and day_night functionality.

* categorical utilities tests now all pass

* Updates tests for create_categorical_cube

* Updates ApplyDecisionTree and tests

- Includes method for mapping day and night symbols
- Includes extended documentation

* Updates ModalWeatherCode which now needs the decision_tree to get the day-night and groupings info.

* Renames ModalWeatherCode as ModalCategory and adds decision_tree to the CLI.

* Updates checksums

* Removes obsolete KeyError trap

* Updates checksums

* Tests bare category error in check tree

* Adds test for day_night_map

* Adds checks to make sure that leaf nodes meet these criteria

- Each leaf has a unique value
- "if_night" values do not point to leaves that have "if_night" values

* isort

* Adds test for case where a leaf is unreachable and isn't declared as such.

* Adds "is_unreachable" to decision tree documentation

* Updates following review.

* Removes `wx` from variable names in categorical_attributes

* Removes `wx` from variable names in metadata_interpreter.py

* Simple review updates (non-functional)

* Moves simple is_decision_node method into utilities and reuses it in another utility. Adds test.

* Simplifies test to one line

* Uses is_decision_node in another place

* Grammar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants