Skip to content

invalidate nan locations when downsampling image#3368

Merged
j9ac9k merged 1 commit intopyqtgraph:masterfrom
pijyoi:fix-stale-nanlocs
Oct 2, 2025
Merged

invalidate nan locations when downsampling image#3368
j9ac9k merged 1 commit intopyqtgraph:masterfrom
pijyoi:fix-stale-nanlocs

Conversation

@pijyoi
Copy link
Copy Markdown
Contributor

@pijyoi pijyoi commented Sep 11, 2025

The ImageItem downsampling factors to use are automatically re-calculated as the user makes changes to the view transform. E.g. zooming, changing window dimensions.
This means that any cached nan locations need to be invalidated.

May fix #3138

MWE that demonstrates the issue. The image dimensions used will trigger auto downsampling.

import numpy as np
import pyqtgraph as pg

rng = np.random.default_rng(0)
data = rng.random(size=(500, 32768), dtype=np.float32)
yval = np.linspace(-1, 1, data.shape[0], endpoint=True)[:, None]
xval = np.linspace(-1, 1, data.shape[1], endpoint=True)
mask = ((yval**2) + xval**2) > 1
data[mask] = np.nan

pg.mkQApp()
win = pg.PlotWidget()
img = pg.ImageItem(data, axisOrder='row-major')
win.addItem(img)
win.show()
pg.exec()

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Oct 2, 2025

Thanks for the fix @pijyoi

I'm going to close #3138 saying this PR has fixed it, and hope the issue is re-opened if it's still a problem.

@j9ac9k j9ac9k merged commit d61f7e2 into pyqtgraph:master Oct 2, 2025
36 checks passed
@pijyoi pijyoi deleted the fix-stale-nanlocs branch October 2, 2025 05:46
@oyvindlr
Copy link
Copy Markdown
Contributor

oyvindlr commented Oct 2, 2025

Yes, sorry I never got around to testing this. You know how things are. Instead I just disabled autodownsampling, even for large images. I haven't really noticed any performance degradation from this. I'm confident @pijyoi has fixed the issue though.

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.

Intermittent exception thrown trying to update ImageItem

3 participants