From a39d796ecae4a8a1972282a236ddd706cd04a028 Mon Sep 17 00:00:00 2001 From: Carter Francis Date: Wed, 2 Dec 2026 22:05:01 -0600 Subject: [PATCH 1/2] Add Plot2D.reset_tile_band, to re-derive the tile band when the dataset changes Tile mode encodes pixels to 8 bits over a band fixed from the first frame and then held, so a contrast change is a LUT re-window. Every later frame on a tiled plot keeps that band, a smaller one too. When a host switches the plot to a different dataset that is wrong: SpyDE's detector binned 4 x 4 has 16 times the counts, every pixel clipped to the top code, and the display window set for the binned frames drew them black. reset_tile_band() clears the band; the next set_data or update_tile_source derives it from the new frame through the existing _ensure_tile_band. Tile mode, the zoom and the detail tile are kept. A no-op off tile mode. SpyDE can then stop calling _disable_tile(). --- anyplotlib/plot2d/_plot2d.py | 16 +++++++++ .../tests/test_plot2d/test_tiled_imshow.py | 36 +++++++++++++++++++ .../+reset-tile-band.new_feature.rst | 1 + 3 files changed, 53 insertions(+) create mode 100644 upcoming_changes/+reset-tile-band.new_feature.rst diff --git a/anyplotlib/plot2d/_plot2d.py b/anyplotlib/plot2d/_plot2d.py index d329f133d..4279fd843 100644 --- a/anyplotlib/plot2d/_plot2d.py +++ b/anyplotlib/plot2d/_plot2d.py @@ -834,6 +834,22 @@ def set_tile_band(self, vmin: float, vmax: float) -> None: # pushes — so the band and the bytes it describes ship together. self.update_tile_source() + def reset_tile_band(self) -> None: + """Forget the band the tile bytes are encoded over, so the next frame + (``set_data`` or ``update_tile_source``) derives it from its own range. + + The band is fixed from the first frame and then held, which is what keeps + a contrast change to a LUT re-window. That is right while frames come from + one source, and wrong when the source changes underneath the plot: a + detector binned 4 x 4 has 16 times the counts, so over the held band every + pixel clips to the top code, and a display window set for the new frames + draws them black. Call this when the plot starts showing a different + dataset; tile mode, the zoom and the detail tile are kept. A no-op off + tile mode.""" + if not self._tile_on: + return + self._state["raw_min"], self._state["raw_max"] = None, None + def _tile_quant_clim(self): """The FIXED quantisation band (raw_min/raw_max) the tile bytes are encoded over, so a contrast change re-windows in the LUT without re-encoding pixels. diff --git a/anyplotlib/tests/test_plot2d/test_tiled_imshow.py b/anyplotlib/tests/test_plot2d/test_tiled_imshow.py index da33bc04a..7aa5ee093 100644 --- a/anyplotlib/tests/test_plot2d/test_tiled_imshow.py +++ b/anyplotlib/tests/test_plot2d/test_tiled_imshow.py @@ -582,3 +582,39 @@ def test_injected_detail_tile_renders_crisp_when_zoomed(self, interact_page): assert info["right"] > info["left"] + 30, ( f"detail tile split not visible over the overview: {info}") assert info["left"] > 100, f"tile not shown — base(0.3~77) leaked: {info}" + + +class TestResetTileBand: + """`reset_tile_band` — forget the held band when the plot starts showing a + different dataset, so its frames are encoded over their own range. Without it + a binned view (16 times the counts) clipped to the top code everywhere and a + display window set for it drew black (SpyDE's "binning turns the signal + black").""" + + @staticmethod + def _tiled(scale=1000.0): + frame = np.random.RandomState(0).rand(2048, 2048).astype(np.float32) * scale + return apl.subplots(1, 1)[1].imshow(frame) + + def test_without_a_reset_a_brighter_dataset_keeps_the_old_band(self): + p = self._tiled() + band = (p._state["raw_min"], p._state["raw_max"]) + p.set_data(np.random.RandomState(1).rand(2048, 2048).astype(np.float32) * 16000.0) + assert (p._state["raw_min"], p._state["raw_max"]) == band + + @pytest.mark.parametrize("side", [2048, 512]) + def test_after_a_reset_the_next_frame_brings_its_own_band(self, side): + p = self._tiled() + before = base64.b64decode(p.resolve_pixel_tokens(p.to_state_dict())["image_b64"]) + p.reset_tile_band() + p.set_data(np.random.RandomState(1).rand(side, side).astype(np.float32) * 16000.0) + lo, hi = p._state["raw_min"], p._state["raw_max"] + assert lo is not None and hi is not None and hi > 4000.0, (lo, hi) + assert p._tile_on, "tile mode, the zoom and the detail tile are kept" + after = base64.b64decode(p.resolve_pixel_tokens(p.to_state_dict())["image_b64"]) + assert after != before + + def test_is_a_no_op_off_tile_mode(self): + p = apl.subplots(1, 1)[1].imshow(np.zeros((64, 64), np.float32)) + p.reset_tile_band() + assert not p._tile_on diff --git a/upcoming_changes/+reset-tile-band.new_feature.rst b/upcoming_changes/+reset-tile-band.new_feature.rst new file mode 100644 index 000000000..5a9975eb9 --- /dev/null +++ b/upcoming_changes/+reset-tile-band.new_feature.rst @@ -0,0 +1 @@ +:meth:`Plot2D.reset_tile_band` forgets the band tile-mode pixels are encoded over, so the next frame brings its own: for a plot that starts showing a different dataset, whose range the held band would clip (a binned view drew black). From 4d69d48ce0453e57be2e759990ee912bf8aa51e6 Mon Sep 17 00:00:00 2001 From: Carter Francis Date: Wed, 2 Dec 2026 22:11:09 -0600 Subject: [PATCH 2/2] Run the Playwright jobs on ubuntu-24.04, where Playwright 1.58 installs Chromium ubuntu-latest became Ubuntu 26.04, and `playwright install chromium --with-deps` (Playwright 1.58.0) refuses it: "Playwright does not support chromium on ubuntu26.04-x64". Every Linux test job and the docs build failed at that step before a test ran. Pinning the runners that install Playwright keeps the browser and the screenshot baselines as they are; lift the pin when a Playwright release supports 26.04. --- .github/workflows/ci.yml | 3 ++- .github/workflows/docs.yml | 6 ++++-- .github/workflows/tests.yml | 6 ++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b7e206c1..3c209c6da 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,8 @@ on: jobs: test: - runs-on: ubuntu-latest + # ubuntu-24.04, not -latest: Playwright 1.58 cannot install Chromium on 26.04. + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 861d01c3f..bc4a72127 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -29,7 +29,8 @@ jobs: # broken cross-references and bad docstrings are caught before merge. build: name: Build docs - runs-on: ubuntu-latest + # ubuntu-24.04, not -latest: Playwright 1.58 cannot install Chromium on 26.04. + runs-on: ubuntu-24.04 steps: - name: Checkout repository @@ -90,7 +91,8 @@ jobs: deploy: name: Deploy docs needs: build - runs-on: ubuntu-latest + # ubuntu-24.04, not -latest: Playwright 1.58 cannot install Chromium on 26.04. + runs-on: ubuntu-24.04 # Skip deployment for pull requests. if: github.event_name != 'pull_request' diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 32cbf627b..be9553ee5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -17,7 +17,8 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-latest] + # ubuntu-24.04, not -latest: Playwright 1.58 cannot install Chromium on 26.04. + os: [ubuntu-24.04, macos-latest, windows-latest] python-version: ["3.10", "3.11", "3.12", "3.13"] exclude: - os: macos-latest @@ -55,7 +56,8 @@ jobs: minimum-deps: name: Minimum deps (Python 3.10 / ubuntu) - runs-on: ubuntu-latest + # ubuntu-24.04, not -latest: Playwright 1.58 cannot install Chromium on 26.04. + runs-on: ubuntu-24.04 steps: - name: Checkout repository