Skip to content

Commit 8dbfdba

Browse files
authored
Merge pull request #191 from dstansby/histogram-data
Don't read full cube into mem for histogramming
2 parents b3f11a8 + 0523d28 commit 8dbfdba

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Diff for: docs/changelog.rst

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
Changelog
22
=========
3+
1.0.2
4+
-----
5+
Bug fixes
6+
~~~~~~~~~
7+
- A full dataset is no longer read into memory when using ``HistogramWidget``.
8+
Only the current slice is loaded.
9+
10+
Changes
11+
~~~~~~~
12+
- Histogram bin limits are now caclualted from the slice being histogrammed, and
13+
not the whole dataset. This is as a result of the above bug fix.
314

415
1.0.1
516
-----

Diff for: src/napari_matplotlib/histogram.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,19 @@ def draw(self) -> None:
3333
Clear the axes and histogram the currently selected layer/slice.
3434
"""
3535
layer = self.layers[0]
36-
bins = np.linspace(np.min(layer.data), np.max(layer.data), 100)
3736

3837
if layer.data.ndim - layer.rgb == 3:
3938
# 3D data, can be single channel or RGB
4039
data = layer.data[self.current_z]
4140
self.axes.set_title(f"z={self.current_z}")
4241
else:
4342
data = layer.data
43+
# Read data into memory if it's a dask array
44+
data = np.asarray(data)
45+
46+
# Important to calculate bins after slicing 3D data, to avoid reading
47+
# whole cube into memory.
48+
bins = np.linspace(np.min(data), np.max(data), 100)
4449

4550
if layer.rgb:
4651
# Histogram RGB channels independently

0 commit comments

Comments
 (0)