Skip to content

Extract channel→colormap mapping to _colormaps.py (PR1 of #7)#11

Merged
ferrinm merged 1 commit into
mainfrom
refactor/extract-colormaps
May 19, 2026
Merged

Extract channel→colormap mapping to _colormaps.py (PR1 of #7)#11
ferrinm merged 1 commit into
mainfrom
refactor/extract-colormaps

Conversation

@ferrinm

@ferrinm ferrinm commented May 19, 2026

Copy link
Copy Markdown
Owner

Summary

  • New src/pyphenix/_colormaps.py exposes channel_color(name, idx), the single source of truth for channel→display-color used by the napari widget, the drag-and-drop reader, and the upcoming plate overview (Plate overview images (parent tracking issue) #7).
  • _widget.py and _reader.py both delete their inline dicts and call the helper.
  • 19 new unit tests cover known names, the idx-fallback for unknown names (with wrap-around), case-insensitive substring matching, and the first-match precedence rule.

User-visible change

The two old dicts had drifted. The reader used to map DAPI → blue and mCherry → red and was missing Brightfield, EGFP, mStrawberry, Cy3, and Alexa 568. After this PR the reader matches the widget: DAPI → cyan, mCherry → magenta, etc. This is the explicit point of the refactor — the wishlist for #7 requires the plate overview to use "the colormaps suggested per-channel by the napari widget" — but it does mean anyone relying on the old drag-and-drop colors will see them shift.

Widget behavior is unchanged.

Also in this PR

The shared design docs the rest of #7 references:

  • CONTEXT.md — ubiquitous language (plate, well, field, channel combo, plate-wide contrast limits, field choice)
  • docs/adr/0001-plate-wide-contrast-on-downsampled-pixels.md — the single non-obvious overview trade-off worth recording

Test plan

  • pytest tests/test_colormaps.py — 19/19 pass
  • Full suite — 42/42 pass (19 new + 23 existing)
  • Drag-and-drop a Phenix directory into napari; confirm DAPI now shows cyan and mCherry now shows magenta
  • Load an experiment via the widget; confirm colors are unchanged

Closes #8. Part of #7.

🤖 Generated with Claude Code

The same channel-name → display-color rule was duplicated in
_widget.py (used by the napari widget) and _reader.py (used by the
drag-and-drop napari reader). The two copies had drifted: the reader
mapped DAPI→blue and mCherry→red and was missing Brightfield, EGFP,
mStrawberry, Cy3, and Alexa 568 entirely.

Both call sites now use the new pyphenix._colormaps.channel_color()
helper. The unified mapping follows the widget's (more complete) set,
per the wishlist's requirement that the upcoming plate overview match
"the colormaps suggested per-channel by the napari widget" (#7, #8).

User-visible effect: drag-and-drop reader colors shift for DAPI
(blue → cyan) and mCherry (red → magenta), matching what the widget
already shows. Widget behavior is unchanged.

Also lands the shared design docs the rest of #7 references:
- CONTEXT.md (ubiquitous language for plate / well / field / channel
  combo / plate-wide contrast limits)
- docs/adr/0001-plate-wide-contrast-on-downsampled-pixels.md

Closes #8.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ferrinm
ferrinm merged commit 8d4abb4 into main May 19, 2026
13 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.

PR1: Extract channel→colormap mapping to _colormaps.py

1 participant