Repository navigation
Anchor antenna pattern dB rings at the 0 dB peak - #883
Merged
Merged
Conversation
plot_fields built the radial rings with np.arange(minimum_db, ring_step_db, ring_step_db) and then relabelled the last tick "0 dB". That only works when minimum_db is an exact multiple of ring_step_db. For any other combination exposed through the --minimum-db and --ring-step-db options (for example the default -72 dB floor with a 10 dB ring step) the last tick lies above 0 dB, matplotlib expands the radial limit to reach it, and the "0 dB" label marks that outer ring while the real peak circle is drawn unlabelled inside it. Generate the rings as multiples of ring_step_db measured down from the 0 dB peak and restricted to the displayed [minimum_db, 0] range, apply the radial limits after the ticks so they stay authoritative, and reject non-positive ring steps and non-negative floors with a ValueError instead of a ZeroDivisionError or IndexError.
Member
|
Thanks for fixing this |
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.
Summary
plot_fields.plot_patterngenerated its radial dB rings withnp.arange(minimum_db, ring_step_db, ring_step_db)and relabelled the last tick "0 dB". That is only correct whenminimum_dbis an exact multiple ofring_step_db. For any other--minimum-db/--ring-step-dbcombination (e.g. the default -72 dB floor with a 10 dB step) the final tick sits above 0 dB, matplotlib expands the radial limit to reach it, the "0 dB" label ends up on that outer ring, and the actual peak circle is drawn unlabelled inside it. Non-positive ring steps also crashed withZeroDivisionErrororIndexError.Fixes #882
What changed
gprMax/toolboxes/AntennaPatterns/plot_fields.pyring_ticks(minimum_db, ring_step_db)helper returns rings at multiples of the ring step measured down from the 0 dB peak, restricted to the displayed[minimum_db, 0]range, with the "0 dB" label on the tick at 0.minimum_dbmust be finite and negative,ring_step_dbfinite and positive, otherwiseValueError.set_ylim(minimum_db, 0)is now applied afterset_yticks, so the radial limits stay authoritative.(-72, 12)plot is unchanged.tests/toolboxes/test_antenna_patterns.pytest_plot_pattern_rings_stay_within_display_range(parametrised over(-72, 12),(-72, 10),(-80, 12),(-50, 12),(-60, 20)) captures the figure and asserts the ticks are within range, spaced by the ring step, end at 0 with the "0 dB" label, and thatylim == (minimum_db, 0).test_plot_pattern_rejects_invalid_ring_settingsassertsValueErrorfor zero/negative steps, non-negative floors and infinite values.How tested
Before the fix: 7 failed, 5 passed (the
(-72, 10),(-80, 12),(-50, 12)ring cases plus the four finite invalid-input cases; the invalid cases failed withZeroDivisionError/IndexErrorinstead ofValueError).After the fix: 12 passed.
black --line-length 100andisort --profile black --line-length 100(the pre-commit settings) are clean on both files.Notes
-72/12constants from the legacyuser_libsscript masked this; the bug became reachable when the values were exposed as CLI options in the toolbox modernisation.pyproject.tomldeclaresline-length = 120for black while.pre-commit-config.yamlpasses--line-length 100; I followed the pre-commit setting. The pre-existingprint(...)calls at the end ofplot_patternare not black-120 clean, which is unrelated to this change and left as is.plot_fields.mainlets aValueErrorfromplot_patternpropagate as a traceback rather than routing it throughparser.error, consistent with the module's other validation errors.