[Fix #99] Convert wrscatter directions from degrees to radians - #348
Open
dylanpulver wants to merge 1 commit into
Open
[Fix #99] Convert wrscatter directions from degrees to radians#348dylanpulver wants to merge 1 commit into
dylanpulver wants to merge 1 commit into
Conversation
… radians wrscatter negated the direction in degrees and then added pi/2 radians, so a compass bearing landed at an essentially arbitrary angle. The transform the rest of the library uses is theta = radians(90 - direction) (see the `angles` array in WindroseAxes._init_plot); only 0 degrees came out right by coincidence. Regenerates the three scatter image baselines, which encoded the old placement, and adds a numeric test for the direction convention.
dylanpulver
force-pushed
the
fix-wrscatter-degrees
branch
from
September 2, 2026 08:57
85e80db to
f0c790d
Compare
Collaborator
|
I'm not super familiar with the code, but consistency with the other plotting methods is definitely a plus! We would need to mint a new major release though b/c, in a way, it is a breaking change. I'll leave this here to see if we can get more comments from others. If not I plan to take a look using the best of my knowledge of the code and merge. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
wrscatternegates the direction while it is still in degrees and then addsnp.radians(90), so the value handed to the polar axes is not an angle in radians at all:The transform the rest of the library uses is
theta = radians(90 - direction)- that is what theanglesarray inWindroseAxes._init_plotcomputes, and it is whatbar,box,contourandcontourfall plot against. Measured against that convention, onmain:Only 0 degrees is right, by coincidence. This is the same symptom as #99 ("all the polar plots have 0 angle at North, but
wrscatteris drawn like a usual polar plot"): the 2018 fix for that issue added-wd + pi/2, which is the correct expression forwdin radians, butwrscatteris fed degrees. So this finishes that fix rather than changing the intended convention.Also affects
plot_windrose(..., kind="scatter"), sinceD_KIND_PLOT["scatter"]iswrscatter.Three image baselines encoded the old placement and are regenerated:
output/func/test_wrscatter.png,output/df/test_scatter.png,output/df/test_windrose_np_plot_and_pd_plot.png. Before you trust them: regeneratingtest_wrbar.pngfrom unmodifiedmainhere reproduces the committed file with RMS 0.0000, so this machine's rendering matches whatever produced the current baselines, while the committedtest_wrscatter.pngwas already RMS 5.76 away from what unmodifiedmaindraws here, against a tolerance of 10. After this PR that figure regenerates exactly.Added
test_wrscatter_direction_convention, which asserts the plotted theta againstradians(90 - direction)rather than against a picture. Ranpytest -s -rxs -Werror tests/ --mplon Python 3.14 / matplotlib 3.11.1 / macOS: 34 passed before, 35 passed after. Reverting onlywindrose/windrose.pyfails the new test; so does writingradians(direction)without the sign flip. Writing it as-radians(direction) + pi/2is algebraically the same and also passes - I used theradians(90 - d)form because it reads as the library's own convention.Not touched:
WindroseAxes.scatteritself, whichtests/test_windrose_np_mpl_oo.pycalls with raw degrees and no transform — a separate question, and changing it would break anyone already passing radians.AI disclosure: drafted with Claude Opus 5 (
claude-opus-5); the numbers above are from runs on this machine.