Skip to content

Add per-channel norm support for render_images#572

Open
timtreis wants to merge 2 commits intomainfrom
feature/issue-460-per-channel-norm
Open

Add per-channel norm support for render_images#572
timtreis wants to merge 2 commits intomainfrom
feature/issue-460-per-channel-norm

Conversation

@timtreis
Copy link
Copy Markdown
Member

Summary

  • Closes Document how to perform on-the-fly normalization for channels. #460render_images now accepts a list of Normalize objects for per-channel normalization
  • Essential for multi-channel protein/fluorescence data with vastly different intensity ranges per channel
  • The rendering pipeline already read per-channel norms from CmapParams — this change only widens validation and routes per-channel norms into the existing CmapParams creation loop

Changes

  • basic.py: Widen norm type to list[Normalize] | Normalize | None, update docstring, zip norm list with cmap list
  • utils.py: Accept list[Normalize] in validation, reject empty lists and non-Normalize elements
  • test_render_images.py: 5 new tests (per-channel norm, backward compat, length mismatch, empty list, invalid element)

Usage

from matplotlib.colors import Normalize

norms = [
    Normalize(vmin=0, vmax=0.05, clip=True),  # dim channel
    Normalize(vmin=0, vmax=1.0, clip=True),    # full range
    Normalize(vmin=0, vmax=0.5, clip=True),    # medium
]
sdata.pl.render_images(
    channel=[0, 1, 2],
    norm=norms,
    cmap=[plt.cm.gray] * 3,
).pl.show()

Test plan

  • Per-channel norm list renders without error
  • Single Normalize with multiple channels still works (backward compat)
  • Norm list length mismatch → ValueError
  • Empty norm list → ValueError
  • Non-Normalize in list → TypeError
  • Pre-commit (ruff, mypy) passes

🤖 Generated with Claude Code

timtreis and others added 2 commits March 31, 2026 13:53
Accept a list of Normalize objects in render_images so each channel
can be normalized independently — essential for multi-channel protein
data with vastly different intensity ranges.

The rendering pipeline already reads per-channel norms from CmapParams,
so this change only widens the input validation and routes per-channel
norms into the existing CmapParams creation loop.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…s only

- Use resolved per-element cmap for list branching so norm list works
  correctly when cmap is auto-replicated
- Raise ValueError when norm is a list but cmap is not (no silent
  pass-through to _prepare_cmap_norm)
- Restrict list norm validation to element_type="images" only — labels
  has no list-norm support
- Add test for norm list without explicit cmap list

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

Document how to perform on-the-fly normalization for channels.

1 participant