Skip to content

Fixed ImageStatsTool displaying "No available data" for XYImageItem and MaskedXYImageItem #50

@PierreRaybaut

Description

@PierreRaybaut

Description

Problem

The ImageStatsTool displays "No available data" instead of showing statistics when used on XYImageItem or MaskedXYImageItem objects (images with non-uniform coordinates).

Steps to Reproduce

  1. Create an XYImageItem with non-uniform x/y coordinates
  2. Add it to a plot
  3. Activate the ImageStatsTool
  4. Draw a rectangle over the image
  5. Expected: Statistics should be displayed in the rectangle
  6. Actual: "No available data" is shown

Minimal Example

import numpy as np
from plotpy.builder import make
from plotpy.plot import PlotDialog
from plotpy.tools import ImageStatsTool

# Create test data
data = np.random.rand(100, 100)
x = np.linspace(0, 10, 100)
y = np.linspace(0, 20, 100)

# Create an XY image item (non-uniform coordinates)
image = make.xyimage(x, y, data, title="Test XY Image")

# Create a plot with the image
win = PlotDialog(edit=False, toolbar=True)
plot = win.manager.get_plot()
plot.add_item(image)

# Add ImageStatsTool
tool = ImageStatsTool(win.manager)
win.manager.add_tool(tool)

win.exec()

Root Cause

The ImageStatsRectangle.get_info() method calls get_items_in_rectangle() which filters items by calling plot.get_items(item_type=IExportROIImageItemType). This method checks if item_type in item.types().

XYImageItem.types() was missing IExportROIImageItemType, causing XY images to be filtered out during the search, resulting in no items being found and the "No available data" message.

Solution

Add IExportROIImageItemType to the tuple returned by XYImageItem.types().

Additionally, update __implements__ tuples for consistency:

  • Add IHistDataSource, IVoiImageItemType, and IExportROIImageItemType to XYImageItem.__implements__
  • Add IExportROIImageItemType to MaskedXYImageItem.__implements__
  • Add IExportROIImageItemType to MaskedImageItem.__implements__

Files to Modify

  • plotpy/items/image/standard.py - XYImageItem.types() and implements
  • plotpy/items/image/masked.py - MaskedXYImageItem.implements and MaskedImageItem.implements

Additional Context

  • Regular ImageItem works correctly because it inherits from RawImageItem which inherits from BaseImageItem, and BaseImageItem.types() includes IExportROIImageItemType
  • XYImageItem overrides types() but was missing this interface type
  • The underlying methods (get_closest_index_rect(), export_roi()) work correctly for XY images; only the interface declaration was missing

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions