-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
bugSomething isn't workingSomething isn't working
Description
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
- Create an XYImageItem with non-uniform x/y coordinates
- Add it to a plot
- Activate the ImageStatsTool
- Draw a rectangle over the image
- Expected: Statistics should be displayed in the rectangle
- 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, andIExportROIImageItemTypetoXYImageItem.__implements__ - Add
IExportROIImageItemTypetoMaskedXYImageItem.__implements__ - Add
IExportROIImageItemTypetoMaskedImageItem.__implements__
Files to Modify
plotpy/items/image/standard.py- XYImageItem.types() and implementsplotpy/items/image/masked.py- MaskedXYImageItem.implements and MaskedImageItem.implements
Additional Context
- Regular
ImageItemworks correctly because it inherits fromRawImageItemwhich inherits fromBaseImageItem, andBaseImageItem.types()includesIExportROIImageItemType - 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
Labels
bugSomething isn't workingSomething isn't working