Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'

Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions anyplotlib/plot2d/_plot2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
36 changes: 36 additions & 0 deletions anyplotlib/tests/test_plot2d/test_tiled_imshow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions upcoming_changes/+reset-tile-band.new_feature.rst
Original file line number Diff line number Diff line change
@@ -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).
Loading