Skip to content

refactor: unify color/cmap/norm pipeline — CmapParams methods + single continuous-norm#721

Merged
timtreis merged 1 commit into
mainfrom
refactor/issue-699-color-pipeline
Jun 14, 2026
Merged

refactor: unify color/cmap/norm pipeline — CmapParams methods + single continuous-norm#721
timtreis merged 1 commit into
mainfrom
refactor/issue-699-color-pipeline

Conversation

@timtreis

@timtreis timtreis commented Jun 14, 2026

Copy link
Copy Markdown
Member

PRs 1+2 of #699 (color/cmap/norm unification), rebased onto current main (post-#715 utils split / #720). PR3 (image-composite helper) deferred.

Commit — CmapParams gains behavior + one continuous-norm for pixels and colorbar.

  • fresh_norm(): a safe per-element norm copy (applying a Normalize autoscales vmin/vmax in place, leaking one element's range into the next). Replaces the copy(cmap_params.norm) sites.
  • colormap_with_alpha(): public-API replacement for the private cmap._lut[:, -1] = alpha poke in the 1-channel image path; byte-identical body colors, alpha applied to body + bad + under/over, no shared-cmap mutation.
  • _resolve_continuous_norm(values, cmap_params): one resolver called by each pixel-baking site and its colorbar site with the same vector, so they can't diverge; folds the duplicated inline norm blocks (_color_vector_to_rgba, _get_collection_shape — its dead norm param dropped, _map_color_seg, the labels imshow, _append_outline_colorbar, the shapes set_clim). Datashader / image / points / graph paths unchanged (already share their norm).

Behavior note: behavior-preserving for normal (multi-value) renders. One intentional change for constant-valued continuous columns: the old code reset a degenerate vmin == vmax to [0, 1] only on the shapes-fill/outline path (labels already autoscaled to the degenerate range), so the two paths disagreed. The resolver unifies them — a constant-valued shapes column now maps to cmap(0) like labels already did, instead of the colormap top. Visual test_plot_* baselines for any such fixture shift and are regenerated from CI artifacts.

Tests: unit tests for fresh_norm, colormap_with_alpha, and _resolve_continuous_norm; a non-visual test asserting the fill colorbar clim equals the resolved data range.

@timtreis timtreis changed the title refactor: unify color/cmap/norm pipeline — CmapParams methods + single continuous-norm (#699) refactor: unify color/cmap/norm pipeline — CmapParams methods + single continuous-norm Jun 14, 2026
@timtreis timtreis force-pushed the refactor/issue-699-color-pipeline branch 2 times, most recently from b9373c6 to 9995c6f Compare June 14, 2026 21:49
@codecov-commenter

codecov-commenter commented Jun 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.81818% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.96%. Comparing base (bfda2ed) to head (1fd8b48).

Files with missing lines Patch % Lines
src/spatialdata_plot/pl/_color.py 72.72% 4 Missing and 2 partials ⚠️
src/spatialdata_plot/pl/_geometry.py 75.00% 1 Missing ⚠️
src/spatialdata_plot/pl/render.py 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #721      +/-   ##
==========================================
+ Coverage   77.41%   77.96%   +0.54%     
==========================================
  Files          17       17              
  Lines        4486     4465      -21     
  Branches     1014     1003      -11     
==========================================
+ Hits         3473     3481       +8     
+ Misses        658      633      -25     
+ Partials      355      351       -4     
Files with missing lines Coverage Δ
src/spatialdata_plot/pl/_datashader.py 87.42% <100.00%> (-0.04%) ⬇️
src/spatialdata_plot/pl/render_params.py 88.79% <100.00%> (+0.43%) ⬆️
src/spatialdata_plot/pl/_geometry.py 79.35% <75.00%> (+4.35%) ⬆️
src/spatialdata_plot/pl/render.py 88.90% <85.71%> (+0.49%) ⬆️
src/spatialdata_plot/pl/_color.py 59.12% <72.72%> (+1.69%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

… + single continuous-norm (#699)

PRs 1+2 of #699, rebased onto the post-#715 (utils split) / post-#720 main.
PR3 (image-composite helper) deferred.

CmapParams gains behavior:
- fresh_norm(): a safe per-element copy (applying a Normalize autoscales vmin/vmax
  in place, leaking one element's range into the next). Converts the 3 copy(norm)
  sites in render.py.
- cmap_with_alpha() / colormap_with_alpha(): public-API replacement for the private
  cmap._lut[:, -1] = alpha poke in the 1-channel image path; byte-identical body
  colors, no shared-cmap mutation.

Single continuous-norm feeds pixels and colorbar:
- _resolve_continuous_norm(values, cmap_params) in _color.py: one resolver called by
  each pixel-baking site and its matching colorbar site with the same vector, so they
  cannot diverge. Folds the duplicated inline norm blocks in _color_vector_to_rgba and
  _get_collection_shape (now in _geometry.py; its dead `norm` param dropped) and routes
  _map_color_seg + the labels imshow + _append_outline_colorbar + the shapes set_clim
  through it.
- Datashader / image / points / graph paths unchanged (already share their norm).

Behavior-preserving for normal renders; the only unified edge is an all-identical-value
outline column. Adds unit tests for the new CmapParams methods and _resolve_continuous_norm
plus a non-visual colorbar-clim integration test.
@timtreis timtreis force-pushed the refactor/issue-699-color-pipeline branch from 9995c6f to 1fd8b48 Compare June 14, 2026 22:13
@timtreis timtreis merged commit 92d69a0 into main Jun 14, 2026
7 of 8 checks passed
@timtreis timtreis deleted the refactor/issue-699-color-pipeline branch June 14, 2026 22:22
timtreis added a commit that referenced this pull request Jun 15, 2026
…regression)

The resolver returned a plain Normalize, silently linearizing LogNorm/PowerNorm/
SymLogNorm for shapes/points/labels (the old _get_collection_shape used the user
norm directly). Now copies the norm and fills vmin/vmax, keeping the subclass.
Verified: zero baseline shift on the 5 render/colorbar test files (only the
untested non-linear-norm path changes); images are unaffected (norm → imshow).
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.

2 participants