Skip to content

Commit

Permalink
Merge pull request #191 from dstansby/histogram-data
Browse files Browse the repository at this point in the history
Don't read full cube into mem for histogramming
  • Loading branch information
dstansby authored Jul 26, 2023
2 parents b3f11a8 + 0523d28 commit 8dbfdba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 11 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
Changelog
=========
1.0.2
-----
Bug fixes
~~~~~~~~~
- A full dataset is no longer read into memory when using ``HistogramWidget``.
Only the current slice is loaded.

Changes
~~~~~~~
- Histogram bin limits are now caclualted from the slice being histogrammed, and
not the whole dataset. This is as a result of the above bug fix.

1.0.1
-----
Expand Down
7 changes: 6 additions & 1 deletion src/napari_matplotlib/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,19 @@ 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
data = layer.data[self.current_z]
self.axes.set_title(f"z={self.current_z}")
else:
data = layer.data
# Read data into memory if it's a dask array
data = np.asarray(data)

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

if layer.rgb:
# Histogram RGB channels independently
Expand Down

0 comments on commit 8dbfdba

Please sign in to comment.