Skip to content

Commit

Permalink
Merge pull request #252 from dstansby/hist-multiscale
Browse files Browse the repository at this point in the history
Fix HistogramWidget for multiscale data
  • Loading branch information
dstansby authored Jan 23, 2024
2 parents 559e1c1 + 31c8fac commit 87763d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ build-backend = "setuptools.build_meta"
write_to = "src/napari_matplotlib/_version.py"

[tool.pytest.ini_options]
qt_api = "pyqt6"
addopts = "--mpl --mpl-baseline-relative"
filterwarnings = [
"error",
"ignore:(?s).*Pyarrow will become a required dependency of pandas",
# Coming from vispy
"ignore:distutils Version classes are deprecated:DeprecationWarning",
"ignore:`np.bool8` is a deprecated alias for `np.bool_`:DeprecationWarning",
]
qt_api = "pyqt6"
addopts = "--mpl --mpl-baseline-relative"

[tool.black]
line-length = 79
Expand Down
16 changes: 11 additions & 5 deletions src/napari_matplotlib/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import numpy as np
import numpy.typing as npt
from matplotlib.container import BarContainer
from napari.layers import Image
from napari.layers._multiscale_data import MultiScaleData
from qtpy.QtWidgets import (
QComboBox,
QLabel,
Expand Down Expand Up @@ -68,14 +70,18 @@ def draw(self) -> None:
"""
Clear the axes and histogram the currently selected layer/slice.
"""
layer = self.layers[0]
layer: Image = self.layers[0]
data = layer.data

if layer.data.ndim - layer.rgb == 3:
if isinstance(layer.data, MultiScaleData):
data = data[layer.data_level]

if layer.ndim - layer.rgb == 3:
# 3D data, can be single channel or RGB
data = layer.data[self.current_z]
# Slice in z dimension
data = 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)

Expand Down

0 comments on commit 87763d3

Please sign in to comment.