Repository navigation
Plot all non-negative FFT bins for zero A-scan traces - #879
Merged
Merged
Conversation
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.
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_Ascan -ffton an all-zero trace with an odd number of samples leaves out the highest non-negative frequency bin.fft_plot_rangefalls back tolen(freqs) // 2when no positive-frequency power value is finite, but an odd-lengthfftfreqhas(n + 1) // 2non-negative bins. This is the same off-by-one that #875 fixed inplot_source_wave.Fixes #878
What changed
gprMax/toolboxes/Plotting/plot_Ascan.py: the all-non-finite fallback infft_plot_rangenow returnsnp.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), andn = 1still gives0:1.tests/toolboxes/test_plotting_outputs.py:test_fft_plot_range_handles_zero_signalnow runs for 8, 9 and 1 samples (before, it only coveredn = 8).test_plot_ascan_fft_of_zero_trace_plots_all_nonnegative_binsrunsmpl_plot(..., fft=True)end to end on 9- and 10-sample zero traces. It checks that the plotted frequencies equalfftfreq(n)[fftfreq(n) >= 0], in the same way as the Use the solver's iteration count for plot_source_wave time windows #875 test forplot_source_wave.How tested
test_fft_plot_range_handles_zero_signal[9-5](slice(0, 4) != slice(0, 5)) andtest_plot_ascan_fft_of_zero_trace_plots_all_nonnegative_bins[9]fail. The even-length andn = 1cases pass.tests/toolboxes/test_plotting_outputs.pygives 13 passed. Together withtest_physical_trace_consumers.py,test_matlab_h5_tools.pyandtests/utilities/test_toolbox_namespace.py: 57 passed, 1 skipped (MATLAB not installed).Notes
plot_Ascan.pyalready had black/isort differences before this change (import order near the top, and the multi-lineax.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.positive.size == 0branch infft_plot_rangecan't be reached for output fromfftfreq, because bin 0 is always 0 Hz. It does no harm, so I didn't change it.