Skip to content

Don't read full cube into mem for histogramming #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 26, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Don't read full cube into mem for histogramming
  • Loading branch information
dstansby committed Jul 26, 2023
commit 38fbccd9c6da1d91484a87eba27dadf8fff0b82e
5 changes: 4 additions & 1 deletion src/napari_matplotlib/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def draw(self) -> None:
Clear the axes and histogram the currently selected layer/slice.
"""
layer = self.layers[0]
bins = np.linspace(np.min(layer.data), np.max(layer.data), 100)

if layer.data.ndim - layer.rgb == 3:
# 3D data, can be single channel or RGB
Expand All @@ -42,6 +41,10 @@ def draw(self) -> None:
else:
data = layer.data

# Important to calculate bins after slicing 3D data, to avoid reading
# whole cube into memory.
bins = np.linspace(np.min(layer.data), np.max(layer.data), 100)

if layer.rgb:
# Histogram RGB channels independently
for i, c in enumerate("rgb"):
Expand Down