Skip to content

Refactoring cf-plot to remove duplication and add more pythonic internal structure, include contour animation#123

Open
bnlawrence wants to merge 76 commits into
NCAS-CMS:mainfrom
bnlawrence:main
Open

Refactoring cf-plot to remove duplication and add more pythonic internal structure, include contour animation#123
bnlawrence wants to merge 76 commits into
NCAS-CMS:mainfrom
bnlawrence:main

Conversation

@bnlawrence
Copy link
Copy Markdown

Overall Summary:

  • Completes major contour/runtime refactor and removes legacy internal dependencies. The overall functionality from a developer perspective is described in UML in a new docs/dev section. This is intended as a precursor for a new o-o based API (to supplement the legacy API).
  • Leaves existing unit tests (which should be deprecated) and all new and revised functionality is now handled using pytest.
  • Adds contour animation support, with partial documentation support.
  • All current pytest tests pass, though 2 are skipped which needs investigation.
  • Image validation has been done by eye with a new reference set of images provided, though the old ones are left for now as it is not always obvious whether things are right or wrong, and many differences just look like tiny pixel shifts.

Major Technical Changes

  • Refactored contour rendering into dedicated runtime/state modules.
  • Expanded runtime architecture: map/layout/rotated/state ownership centralised.
  • Migrated utility logic out of legacy locations; reduced coupling to old monolithic paths.
  • Removed deprecated internal packages and duplicated legacy implementations.
  • Rationalised plot/state synchronisation behaviour.
  • Added contour animation hooks and frame update behaviour.
  • Added animation API and limited animation testing.

Bryan Lawrence added 30 commits May 14, 2026 07:35
- Use os.path.splitext() instead of string slicing for extension detection
- Prevents double .png suffix (.png.png) when file is configured with extension
- Example 4 now correctly writes gen_fig_4.png instead of gen_fig_4.png.png
…ookup

- Example 6: switch from ggap.nc[3] to ggap_file['geopotential']
- Example 9: switch from ggap.nc[0] to ggap_file['air_temperature']
- Eliminates positional index dependency for all ggap-based tests
- Add /generated-example-images/ to .gitignore
- Remove generated-example-images from git index (keep local files)
@bnlawrence bnlawrence marked this pull request as ready for review May 28, 2026 07:40
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR is a major refactor of cf-plot that restructures the monolithic cfplot.py into modular runtime components (layout_runtime, map_runtime, rotated_runtime, state), introduces an object-oriented contour rendering pipeline, removes legacy internal subpackages (graphic, parameters, calculate, utils), migrates testing from unittest to pytest with a new tests/ tree, and adds preliminary contour animation support.

Changes:

  • Replaces monolithic state/graphic/parameters modules with state.py, layout_runtime.py, map_runtime.py, rotated_runtime.py, and an OO contour pipeline; rewrites vector, trajectory, line, stipple, and adds stream.
  • Introduces contour animation hooks (animation, animation_axis, animation_title_template, reusable map background) with new unit/integration tests.
  • Reorganises tests under tests/unit and tests/integration with image comparison against a new reference set; replaces setup.py with a pyproject.toml build configuration and adds extensive developer architecture docs.

Reviewed changes

Copilot reviewed 49 out of 167 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pyproject.toml New PEP 621 metadata; setuptools package list only includes top-level cfplot.
setup.py Removed; build configuration moves to pyproject.toml.
README.md Documents new animation parameters for cfp.con.
pytest.ini Adds pytest config with integration/image markers.
cfplot/init.py Rewrites public surface around new modules; adds version resolution and reset/rgaxes/_mapaxis wrappers.
cfplot/state.py New shared state object with grouped dataclasses, defaults, reset helper.
cfplot/layout_runtime.py New figure/session lifecycle, gset/gpos/gclose/gopen, axis helpers, autosave.
cfplot/map_runtime.py New centralised map setup/axes/title/feature helpers.
cfplot/rotated_runtime.py New rotated-pole rendering and grid axes.
cfplot/contour.py Major contour pipeline rewrite (dataclass + renderer classes + animation hooks).
cfplot/blockfill.py / colorbar.py New helpers extracted from the legacy monolith.
cfplot/colour/* Colour helpers moved/restructured; new colourmaps subpackage.
cfplot/vector.py / trajectory.py / line.py / stipple.py / stream.py Reworked to use new runtime/state modules.
cfplot/{graphic,parameters,calculate,utils}/* Legacy modules deleted/emptied.
cfplot/test/test_examples.py Migrated from unittest to pytest.
tests/conftest.py Adds repo root to sys.path.
tests/test_canari.py Specific regression test; imports a private helper across test packages.
tests/integration/* New integration tests for contour, advanced plots, animation, examples.
tests/unit/* New unit tests for mapaxis, levels, gopen/gclose, state sync, contour boundary, trajectory labels, animation titles.
docs/dev/* New architecture, simplification plan, merge playbook, UML diagrams.
.gitignore Adds .vscode, .DS_Store, generated-example-images.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pyproject.toml
Comment thread tests/integration/test_advanced_plot_examples.py Outdated
Comment thread tests/test_canari.py Outdated
@bnlawrence
Copy link
Copy Markdown
Author

Note there may be some legacy unit tests (and hence legacy behaviour) which have not been migrated and tested, we should check those ...

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.

2 participants