Skip to content

Anchor antenna pattern dB rings at the 0 dB peak - #883

Merged
agianno merged 1 commit into
gprMax:masterfrom
SajalDevX:fix/antenna-pattern-ring-ticks
Oct 9, 2026
Merged

agianno merged 1 commit into
gprMax:masterfrom
SajalDevX:fix/antenna-pattern-ring-ticks

Conversation

@SajalDevX

Copy link
Copy Markdown
Contributor

Summary

plot_fields.plot_pattern generated its radial dB rings with np.arange(minimum_db, ring_step_db, ring_step_db) and relabelled the last tick "0 dB". That is only correct when minimum_db is an exact multiple of ring_step_db. For any other --minimum-db / --ring-step-db combination (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 with ZeroDivisionError or IndexError.

Fixes #882

What changed

  • gprMax/toolboxes/AntennaPatterns/plot_fields.py
    • New ring_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.
    • Validates the inputs: minimum_db must be finite and negative, ring_step_db finite and positive, otherwise ValueError.
    • set_ylim(minimum_db, 0) is now applied after set_yticks, so the radial limits stay authoritative.
    • The default (-72, 12) plot is unchanged.
  • tests/toolboxes/test_antenna_patterns.py
    • test_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 that ylim == (minimum_db, 0).
    • test_plot_pattern_rejects_invalid_ring_settings asserts ValueError for zero/negative steps, non-negative floors and infinite values.

How tested

pytest tests/toolboxes/test_antenna_patterns.py

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 with ZeroDivisionError / IndexError instead of ValueError).
After the fix: 12 passed.

black --line-length 100 and isort --profile black --line-length 100 (the pre-commit settings) are clean on both files.

Notes

  • The original hard-coded -72/12 constants from the legacy user_libs script masked this; the bug became reachable when the values were exposed as CLI options in the toolbox modernisation.
  • pyproject.toml declares line-length = 120 for black while .pre-commit-config.yaml passes --line-length 100; I followed the pre-commit setting. The pre-existing print(...) calls at the end of plot_pattern are not black-120 clean, which is unrelated to this change and left as is.
  • Possible adjacent follow-up (not changed here): plot_fields.main lets a ValueError from plot_pattern propagate as a traceback rather than routing it through parser.error, consistent with the module's other validation errors.

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.
@agianno
agianno merged commit e68d228 into gprMax:master Oct 9, 2026
14 checks passed
@agianno

agianno commented Oct 9, 2026

Copy link
Copy Markdown
Member

Thanks for fixing this

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.

AntennaPatterns plot_fields mislabels the dB rings when the floor is not a multiple of the ring step

2 participants