Skip to content

fix: resolve gathered bscan plotting filename collision - #876

Merged
agianno merged 2 commits into
gprMax:masterfrom
shyamsharmas124-commits:fix-bscan-gather-filename
Oct 6, 2026
Merged

agianno merged 2 commits into
gprMax:masterfrom
shyamsharmas124-commits:fix-bscan-gather-filename

Conversation

@shyamsharmas124-commits

Copy link
Copy Markdown
Contributor

Bug Report: B-scan Gather Overwrites Highest Receiver Plot

Description

When running plot_Bscan.py with the -gather flag, the script collects traces across all receivers into a single gathered matrix. However, it passes nrx (the highest receiver index) as the rxnumber to mpl_plot().

By default, mpl_plot() names its saved output files using a suffix based on rxnumber, i.e., _rx{rxnumber}.png. For a gathered B-scan, this causes the output file to be incorrectly named as ..._rx{nrx}.png. If a user also plots the individual receivers separately (either before or after the gather operation without clearing), the gathered plot will incorrectly overwrite the B-scan plot corresponding to the highest numbered receiver.

Fix

In plot_Bscan.py where -gather invokes mpl_plot(), explicit naming context is provided by passing trace_group="gathered". This overrides the rxnumber derived trace ID inside mpl_plot(), generating output files named cleanly with a _gathered.png suffix, thus resolving the file collision. The unused nrx argument has been replaced with 1.

Tests

A regression test (test_plot_bscan_gather_filename) has been added to tests/toolboxes/test_plotting_outputs.py validating that gathered output produces a _gathered.png output file successfully without raising an exception.

@agianno

agianno commented Oct 6, 2026

Copy link
Copy Markdown
Member

Thanks—the filename correction looks right. The regression test currently calls the plotting function with trace_group="gathered" explicitly, so it does not exercise the changed -gather CLI path and also passes on the unpatched code.

Could you add a CLI-level regression test using an output file with at least two receivers?

  • Generate the normal rx2 plot and record its contents.
  • Run with -gather, using the default output filename.
  • Assert that a separate *_gathered.png is created and that *_rx2.png remains unchanged.
    Please run this headlessly and ensure the test fails before the fix and passes afterwards. The implementation itself looks suitable to merge once that regression coverage is added.

@shyamsharmas124-commits

Copy link
Copy Markdown
Contributor Author

Thanks for the review and the excellent point about exercising the CLI path directly.

I've updated test_plot_bscan_gather_filename to run headlessly as a CLI-level regression test using subprocess.run with MPLBACKEND="Agg".

The test now uses a synthetic output file with two receivers, generates the normal plots, records the rx2 byte contents, and then invokes the -gather CLI command. It asserts that the _gathered.png is correctly created and that _rx2.png remains completely unchanged.

I verified locally that this test reliably fails on the unpatched code and passes cleanly with the trace_group fix applied.

@agianno

agianno commented Oct 6, 2026

Copy link
Copy Markdown
Member

Thanks—the revised test now exercises the actual CLI path and catches the original regression. I independently confirmed that it fails before the fix and passes afterwards, with the individual receiver plot preserved. All checks are green. This is ready to merge.

@agianno
agianno merged commit 06f841d into gprMax:master Oct 6, 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.

3 participants