Skip to content

Commit c6b5d8e

Browse files
committed
Merge branch 'main' into feat/hist-bin-params
2 parents 7c4cdc8 + 1e6a373 commit c6b5d8e

10 files changed

+35
-13
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ repos:
77
- id: trailing-whitespace
88

99
- repo: https://github.com/psf/black
10-
rev: 23.12.1
10+
rev: 24.1.1
1111
hooks:
1212
- id: black
1313

@@ -24,7 +24,7 @@ repos:
2424

2525
- repo: https://github.com/astral-sh/ruff-pre-commit
2626
# Ruff version.
27-
rev: 'v0.1.11'
27+
rev: 'v0.2.1'
2828
hooks:
2929
- id: ruff
3030

docs/changelog.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
Changelog
22
=========
3+
2.0.1
4+
-----
5+
Bug fixes
6+
~~~~~~~~~
7+
- Fixed using the ``HistogramWidget`` with layers containing multiscale data.
8+
- Make sure ``HistogramWidget`` uses 100 bins (not 99) when floating point data is
9+
selected.
10+
311
2.0.0
412
-----
513
Changes to custom theming

examples/histogram.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Histograms
33
==========
44
"""
5+
56
import napari
67

78
viewer = napari.Viewer()

examples/scatter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Scatter plots
33
=============
44
"""
5+
56
import napari
67

78
viewer = napari.Viewer()

examples/slice.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
1D slices
33
=========
44
"""
5+
56
import napari
67

78
viewer = napari.Viewer()

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ build-backend = "setuptools.build_meta"
66
write_to = "src/napari_matplotlib/_version.py"
77

88
[tool.pytest.ini_options]
9-
qt_api = "pyqt6"
10-
addopts = "--mpl --mpl-baseline-relative"
119
filterwarnings = [
1210
"error",
11+
"ignore:(?s).*Pyarrow will become a required dependency of pandas",
1312
# Coming from vispy
1413
"ignore:distutils Version classes are deprecated:DeprecationWarning",
1514
"ignore:`np.bool8` is a deprecated alias for `np.bool_`:DeprecationWarning",
1615
]
16+
qt_api = "pyqt6"
17+
addopts = "--mpl --mpl-baseline-relative"
1718

1819
[tool.black]
1920
line-length = 79

src/napari_matplotlib/histogram.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import numpy as np
55
import numpy.typing as npt
66
from matplotlib.container import BarContainer
7+
from napari.layers import Image
8+
from napari.layers._multiscale_data import MultiScaleData
79
from qtpy.QtWidgets import (
810
QAbstractSpinBox,
911
QComboBox,
@@ -31,8 +33,9 @@ def _get_bins(data: npt.NDArray[Any]) -> npt.NDArray[Any]:
3133
step = np.ceil(np.ptp(data) / 100)
3234
return np.arange(np.min(data), np.max(data) + step, step)
3335
else:
34-
# For other data types, just have 99 evenly spaced bins
35-
return np.linspace(np.min(data), np.max(data), 100)
36+
# For other data types, just have 100 evenly spaced bins
37+
# (and 101 bin edges)
38+
return np.linspace(np.min(data), np.max(data), 101)
3639

3740

3841
class HistogramWidget(SingleAxesWidget):
@@ -112,7 +115,7 @@ def on_update_layers(self) -> None:
112115
if not self.layers:
113116
return
114117

115-
# Reset to bin start, stop and step
118+
# Reset the bin start, stop and step values based on new layer data
116119
layer_data = self._get_layer_data(self.layers[0])
117120
self.autoset_widget_bins(data=layer_data)
118121

@@ -189,12 +192,16 @@ def bins_num(self, num: int) -> None:
189192

190193
def _get_layer_data(self, layer: napari.layers.Layer) -> npt.NDArray[Any]:
191194
"""Get the data associated with a given layer"""
192-
if layer.data.ndim - layer.rgb == 3:
195+
data = layer.data
196+
197+
if isinstance(layer.data, MultiScaleData):
198+
data = data[layer.data_level]
199+
200+
if layer.ndim - layer.rgb == 3:
193201
# 3D data, can be single channel or RGB
194-
data = layer.data[self.current_z]
202+
# Slice in z dimension
203+
data = data[self.current_z]
195204
self.axes.set_title(f"z={self.current_z}")
196-
else:
197-
data = layer.data
198205

199206
# Read data into memory if it's a dask array
200207
data = np.asarray(data)
@@ -205,7 +212,7 @@ def draw(self) -> None:
205212
"""
206213
Clear the axes and histogram the currently selected layer/slice.
207214
"""
208-
layer = self.layers[0]
215+
layer: Image = self.layers[0]
209216
data = self._get_layer_data(layer)
210217

211218
# Important to calculate bins after slicing 3D data, to avoid reading
Loading
Loading

src/napari_matplotlib/tests/test_util.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ def test_fallback_if_missing_dimensions(mocker):
6969
test_css = " Flobble { background-color: rgb(0, 97, 163); } "
7070
mocker.patch("napari.qt.get_current_stylesheet").return_value = test_css
7171
with pytest.warns(RuntimeWarning, match="Unable to find DimensionToken"):
72-
assert from_napari_css_get_size_of("Flobble", (1, 2)) == QSize(1, 2)
72+
with pytest.warns(RuntimeWarning, match="Unable to find Flobble"):
73+
assert from_napari_css_get_size_of("Flobble", (1, 2)) == QSize(
74+
1, 2
75+
)
7376

7477

7578
def test_fallback_if_prelude_not_in_css():

0 commit comments

Comments
 (0)