Skip to content

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

Closed

Description

@SajalDevX

Describe the bug

gprMax.toolboxes.AntennaPatterns.plot_fields.plot_pattern builds the radial dB rings with

ticks = np.arange(minimum_db, ring_step_db, ring_step_db)
labels = [f"{tick:g}" for tick in ticks]
labels[-1] = "0 dB"

This only produces a 0 dB ring when minimum_db is an exact multiple of ring_step_db (the defaults, -72 and 12, happen to be). Both values are user options (--minimum-db, --ring-step-db), and for any other combination the last tick lands above 0 dB. Because set_yticks runs after set_ylim, matplotlib then expands the radial limit to include that tick, so the plot ends up with:

  • an outer ring drawn above 0 dB (e.g. at +8 dB) that carries the "0 dB" label,
  • the true 0 dB peak circle drawn unlabelled inside it, and
  • all intermediate rings at odd values (-62, -52, ...) instead of multiples of the ring step.

Since every pattern is normalised to its peak, the "0 dB" ring is the reference the reader uses to judge the pattern level, so the mislabelled plot is misleading rather than just untidy.

Non-positive ring steps are not rejected either: ring_step_db=0 raises ZeroDivisionError from np.arange and a negative step raises IndexError from labels[-1].

To Reproduce

  1. Process any pattern run with python -m gprMax.toolboxes.AntennaPatterns.initial_save <output>.h5 (or build a small .npz as in the snippet below).
  2. Plot it with a 10 dB ring step: python -m gprMax.toolboxes.AntennaPatterns.plot_fields <output>.npz --ring-step-db 10
  3. Open the PDF: the outer ring is labelled "0 dB" but the radial axis now runs from -72 dB to +8 dB and the peak circle is unmarked.

Code snippets

import numpy as np
from gprMax.toolboxes.AntennaPatterns import plot_fields

captured = []
plot_fields.plt.close = captured.append
data = {
    "patterns": np.array([[1.0, 0.5, 0.1]]),
    "radii": np.array([0.1]),
    "theta_degrees": np.array([0.0, 90.0, 180.0]),
    "pattern": np.array("E"),
    "relative_permittivity": np.array(np.nan),
    "relative_permeability": np.array(1.0),
    "centre_frequency": np.array(1e9),
    "antenna_dimension": np.array(0.06),
}
for minimum_db, ring_step_db in [(-72, 12), (-72, 10), (-80, 12), (-50, 12)]:
    plot_fields.plot_pattern(data, "pattern.png", minimum_db=minimum_db, ring_step_db=ring_step_db)
    axes = captured[-1].axes[0]
    print(minimum_db, ring_step_db, list(axes.get_yticks()),
          [t.get_text() for t in axes.get_yticklabels()], axes.get_ylim())

Actual output:

-72 12 [-60, -48, -36, -24, -12, 0] ['-60', '-48', '-36', '-24', '-12', '0 dB'] (-72.0, 0.0)
-72 10 [-62, -52, -42, -32, -22, -12, -2, 8] ['-62', ..., '-2', '0 dB'] (-72.0, 8.0)
-80 12 [-68, -56, -44, -32, -20, -8, 4] ['-68', ..., '-8', '0 dB'] (-80.0, 4.0)
-50 12 [-38, -26, -14, -2, 10] ['-38', '-26', '-14', '-2', '0 dB'] (-50.0, 10.0)

Expected: rings at multiples of the ring step measured down from the 0 dB peak, all inside [minimum_db, 0], the "0 dB" label on the tick at 0, and the radial limits unchanged at (minimum_db, 0). For (-72, 10) that is [-70, -60, ..., -10, 0]. ring_step_db <= 0 or minimum_db >= 0 should raise a ValueError.

OS

Linux (also reproducible on macOS; pure matplotlib behaviour)

Python version

Python 3.12.3 (numpy 2.5.3, matplotlib 3.11.2)

gprMax version

gprMax v4.0.1 (master, b7e1c3b)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions