Skip to content

Plot all non-negative FFT bins for zero A-scan traces - #879

Merged
agianno merged 1 commit into
gprMax:masterfrom
SajalDevX:fix/ascan-fft-odd-zero-range
Oct 7, 2026
Merged

agianno merged 1 commit into
gprMax:masterfrom
SajalDevX:fix/ascan-fft-odd-zero-range

Conversation

@SajalDevX

Copy link
Copy Markdown
Contributor

Summary

plot_Ascan -fft on an all-zero trace with an odd number of samples leaves out the highest non-negative frequency bin. fft_plot_range falls back to len(freqs) // 2 when no positive-frequency power value is finite, but an odd-length fftfreq has (n + 1) // 2 non-negative bins. This is the same off-by-one that #875 fixed in plot_source_wave.

Fixes #878

What changed

  • gprMax/toolboxes/Plotting/plot_Ascan.py: the all-non-finite fallback in fft_plot_range now returns np.s_[0 : positive[-1] + 1], the same upper bound the non-fallback path already uses. Even lengths give the same result as before (n // 2 == positive[-1] + 1), and n = 1 still gives 0:1.
  • tests/toolboxes/test_plotting_outputs.py:
    • test_fft_plot_range_handles_zero_signal now runs for 8, 9 and 1 samples (before, it only covered n = 8).
    • New test_plot_ascan_fft_of_zero_trace_plots_all_nonnegative_bins runs mpl_plot(..., fft=True) end to end on 9- and 10-sample zero traces. It checks that the plotted frequencies equal fftfreq(n)[fftfreq(n) >= 0], in the same way as the Use the solver's iteration count for plot_source_wave time windows #875 test for plot_source_wave.

How tested

  • Without the fix: test_fft_plot_range_handles_zero_signal[9-5] (slice(0, 4) != slice(0, 5)) and test_plot_ascan_fft_of_zero_trace_plots_all_nonnegative_bins[9] fail. The even-length and n = 1 cases pass.
  • With the fix: tests/toolboxes/test_plotting_outputs.py gives 13 passed. Together with test_physical_trace_consumers.py, test_matlab_h5_tools.py and tests/utilities/test_toolbox_namespace.py: 57 passed, 1 skipped (MATLAB not installed).
  • black/isort (line length 100, profile black) are clean on the changed lines and on the test file.

Notes

  • plot_Ascan.py already had black/isort differences before this change (import order near the top, and the multi-line ax.set_xlim([...]) call in the multi-output branch). I left them alone so this diff stays focused. I can add a separate formatting commit if you'd like.
  • The positive.size == 0 branch in fft_plot_range can't be reached for output from fftfreq, because bin 0 is always 0 Hz. It does no harm, so I didn't change it.

When every power value is -inf (an all-zero trace), fft_plot_range
fell back to len(freqs) // 2, which drops the highest non-negative
frequency bin for odd-length signals. Use the last non-negative bin
index instead, matching the non-fallback path.
@agianno
agianno merged commit c91bdf7 into gprMax:master Oct 7, 2026
14 checks passed
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.

plot_Ascan -fft drops the highest non-negative frequency bin for odd-length all-zero traces

2 participants