Repository navigation
Attach plot_prediction colorbar to the data mesh - #903
nikhil3495 wants to merge 4 commits into
Conversation
plot_prediction built its shared colorbar from axes[0].collections[0]. cartopy adds coastlines and borders as FeatureArtist collections before plot_on_axis draws the pcolormesh, so the colorbar used the coastline artist's default 0-1 norm and its ticks never matched the plotted data. Use the mesh returned by plot_on_axis instead, as plot_spatial_error already does. The existing test stubs out coastlines and add_feature, which hid this; the new test restores them (creating the artists needs no download). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Open PR #636 replaces the same |
AshNicolus
left a comment
There was a problem hiding this comment.
The fix is right: plot_on_axis returns the data mesh (vis.py:477), the same object plot_spatial_error already passes, so the colorbar can no longer pick up the coastline/border artists or the boundary overlay mesh.
flowchart LR
C["ax.collections =<br/>[coastlines, borders, mesh]"] --> O["collections[0]<br/>(main)"] --> W["norm 0 to 1 ❌"]
M["mesh returned by<br/>plot_on_axis"] --> N["meshes[0]<br/>(this PR)"] --> OK["norm vmin to vmax ✅"]
Optional nit: test_plot_prediction (tests/test_plotting.py:144-147) still reads ax.collections[0].norm. It passes only because the autouse fixture stubs coastlines/add_feature; without the stubs it would check the coastline artist. Picking the QuadMesh out of ax.collections would keep it in step with this fix.
collections[0] is only the data mesh because the autouse fixture stubs out coastlines/add_feature; with real cartopy features it is a FeatureArtist. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@AshNicolus Good catch, confirmed: with real features |
AshNicolus
left a comment
There was a problem hiding this comment.
Verified 41bb114: GeoQuadMesh subclasses QuadMesh, and plot_on_axis draws the data mesh (vis.py:423) before the optional boundary overlay (vis.py:445), so the first QuadMesh in ax.collections is always the data mesh, with or without real coastlines and borders.
flowchart LR
C["ax.collections"] --> F["FeatureArtist<br/>coastlines, borders"]
C --> D["data mesh<br/>first QuadMesh"]
C --> B["boundary overlay<br/>QuadMesh, optional"]
D --> T["norm == vrange ✅"]
|
Thanks for checking 41bb114, @AshNicolus. The failing link-check-job is unrelated to this diff: lychee got transient 503s from github.com for three existing blob/main links in docs/getting-started/installation.md and docs/user-guide/datastores.md, files this PR doesn't touch. The same 503s hit fix/mlflow-end-run-on-finalize and passed on its next run, main is green, and Documentation / Link check passes here. Could someone re-run the job? |
Describe your changes
plot_predictionbuilt its shared colorbar fromaxes[0].collections[0]. Cartopy adds coastlines and borders asFeatureArtistcollections beforeplot_on_axiscallspcolormesh, so the colorbar used the coastline artist's default 0-1 norm. Every example-prediction plot logged during training and evaluation showed 0-1 tick labels instead of the data range. The fix passes the mesh returned byplot_on_axistofig.colorbar, asplot_spatial_erroralready does.The existing
test_plot_predictionstubs outcoastlines/add_feature, which hid the bug. The newtest_plot_prediction_colorbar_uses_data_rangerestores the real methods (creating the artists needs no download) and asserts that the colorbar spansvrange. It fails on unmodified main (colorbar limits(0.0, 1.0), expected(250, 350)) and passes with the fix; I checked both by stashingneural_lam/vis.py. The fulltests/test_plotting.pypasses (28 tests), and thedummydatacases oftests/test_training.pypass. Not run here: themdpcases (local SSL failures downloading the ECMWF test data) and the lychee pre-commit hook (SKIP=lychee, a local hook-config error on this Windows setup).Note: #636 makes the same one-line change as part of its boundary-overlay feature. This PR fixes only the bug, so it can land on its own; either merge order conflicts trivially.
Issue Link
closes #902
Type of change
Checklist before requesting a review
Author checklist after completed review