Skip to content

Feature request: Public API for setting channel names/labels #223

@hongquanli

Description

@hongquanli

Summary

Currently, there's no public API to set custom channel names/labels in the ArrayViewer. The only way to customize channel labels is through the private _lut_controllers API, which requires polling with QTimer to wait for initialization.

Use Case

When displaying multi-channel microscopy data (e.g., OME-TIFF with channel metadata), it's desirable to show meaningful channel names like "DAPI", "GFP", "RFP" instead of numeric indices "0", "1", "2".

Current Workaround

# Must poll because _lut_controllers isn't available immediately
def _update_labels():
    controllers = getattr(viewer, "_lut_controllers", None)
    if controllers:
        for i, name in enumerate(channel_names):
            if i in controllers:
                controllers[i].key = name
                controllers[i].synchronize()
    else:
        QTimer.singleShot(100, _update_labels)  # Retry

QTimer.singleShot(100, _update_labels)

This approach:

  • Relies on private API (_lut_controllers)
  • Requires polling with arbitrary delays
  • May break if internal API changes

Proposed Solutions (any of these would help)

Option 1: Constructor parameter

viewer = ndv.ArrayViewer(data, channel_names=["DAPI", "GFP", "RFP"])

Option 2: Public method

viewer = ndv.ArrayViewer(data)
viewer.set_channel_names(["DAPI", "GFP", "RFP"])

Option 3: Signal when ready

viewer = ndv.ArrayViewer(data)
viewer.ready.connect(lambda: update_labels(viewer))

Context

This came up while implementing channel name display in hongquanli/ndviewer_light#6, a lightweight viewer for microscopy data that uses NDV as its backend.

Thank you for considering this enhancement!


🤖 This issue was generated with Claude Code while working on hongquanli/ndviewer_light#6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions