From b027ac31d2de2337f5f1df1c366dd18517c52840 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Thu, 18 May 2023 11:04:04 +0100 Subject: [PATCH 1/9] Add some more intersphinx links --- docs/conf.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/conf.py b/docs/conf.py index 2c04f853..c73766e1 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -56,7 +56,9 @@ automodapi_inheritance_diagram = False intersphinx_mapping = { + "python": ("https://docs.python.org/3/", None), "napari": ("https://napari.org/", None), + "numpy": ("https://numpy.org/doc/stable/", None), "matplotlib": ("https://matplotlib.org/", None), } From 7ac9f522e7c2b4dbf10516eb894378d1c871cc52 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Thu, 18 May 2023 11:04:19 +0100 Subject: [PATCH 2/9] Keep going when encountering errors on build --- docs/Makefile | 2 +- docs/make.bat | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/Makefile b/docs/Makefile index b50c24dc..5117fbf5 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -3,7 +3,7 @@ # You can set these variables from the command line, and also # from the environment for the first two. -SPHINXOPTS ?= -W +SPHINXOPTS ?= -W --keep-going SPHINXBUILD ?= sphinx-build SOURCEDIR = . BUILDDIR = _build diff --git a/docs/make.bat b/docs/make.bat index 32bb2452..4b78115a 100644 --- a/docs/make.bat +++ b/docs/make.bat @@ -7,6 +7,9 @@ REM Command file for Sphinx documentation if "%SPHINXBUILD%" == "" ( set SPHINXBUILD=sphinx-build ) +if "%SPHINXOPTS%" == "" ( + set SPHINXOPTS="--keep-going" +) set SOURCEDIR=. set BUILDDIR=_build From ef7fd037235d07adce85a67fa21223bd60094939 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Thu, 18 May 2023 11:04:44 +0100 Subject: [PATCH 3/9] Add ScatterBaseWidget to API docs --- src/napari_matplotlib/scatter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/napari_matplotlib/scatter.py b/src/napari_matplotlib/scatter.py index 405b7b09..94408124 100644 --- a/src/napari_matplotlib/scatter.py +++ b/src/napari_matplotlib/scatter.py @@ -8,7 +8,7 @@ from .base import NapariMPLWidget from .util import Interval -__all__ = ["ScatterWidget", "FeaturesScatterWidget"] +__all__ = ["ScatterBaseWidget", "ScatterWidget", "FeaturesScatterWidget"] class ScatterBaseWidget(NapariMPLWidget): From 8cef781dbf38edfc025dbae2ddc9cb4020d7692d Mon Sep 17 00:00:00 2001 From: David Stansby Date: Thu, 18 May 2023 11:09:32 +0100 Subject: [PATCH 4/9] Enable nitpicky mode Clean up conf.py --- docs/conf.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/conf.py b/docs/conf.py index c73766e1..efff247a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -60,8 +60,14 @@ "napari": ("https://napari.org/", None), "numpy": ("https://numpy.org/doc/stable/", None), "matplotlib": ("https://matplotlib.org/", None), + "PyQT6": ("https://www.riverbankcomputing.com/static/Docs/PyQt6/", None), } +nitpicky = True +# Can't work out how to link this properley using intersphinx and the PyQT6 docs. +# TODO: fix at some point +nitpick_ignore = [("py:class", "PyQt6.QtWidgets.QWidget")] + # Add any paths that contain templates here, relative to this directory. templates_path = ["_templates"] From 77470b5a94afc182485c7262c894d2bec05c5752 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Thu, 18 May 2023 11:17:23 +0100 Subject: [PATCH 5/9] Clean up basewidget docs/api --- src/napari_matplotlib/base.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/napari_matplotlib/base.py b/src/napari_matplotlib/base.py index b69d0310..fc8fa17f 100644 --- a/src/napari_matplotlib/base.py +++ b/src/napari_matplotlib/base.py @@ -22,11 +22,12 @@ class NapariMPLWidget(QWidget): """ - Base Matplotlib canvas. Widget that can be embedded as a napari widget. + Widget containing a Matplotlib canvas and toolbar. - This creates a single FigureCanvas, which contains a single Figure. - It is not responsible for creating any Axes, because different widgets - may want to implement different subplot layouts. + This creates a single FigureCanvas, which contains a single + `~matplotlib.figure.Figure`, and an associated toolbar. + It is not responsible for creating any Axes, because different + widgets may want to implement different subplot layouts. This class also handles callbacks to automatically update figures when the layer selection or z-step is changed in the napari viewer. To take @@ -60,12 +61,12 @@ def __init__(self, napari_viewer: napari.viewer.Viewer): self.layout().addWidget(self.toolbar) self.layout().addWidget(self.canvas) - self.setup_callbacks() + self._setup_callbacks() self.layers: List[napari.layers.Layer] = [] - # Accept any number of input layers by default + #: Number of layers taken as input n_layers_input = Interval(None, None) - # Accept any type of input layer by default + #: Type of layer taken as input input_layer_types: Tuple[napari.layers.Layer, ...] = (napari.layers.Layer,) @property @@ -83,17 +84,17 @@ def n_selected_layers(self) -> int: @property def current_z(self) -> int: """ - Current z-step of the viewer. + Current z-step of the napari viewer. """ return self.viewer.dims.current_step[0] - def setup_callbacks(self) -> None: + def _setup_callbacks(self) -> None: """ Sets up callbacks. - Sets up callbacks for: - - Layer selection changing - - z-step changing + Sets up callbacks for when: + - Layer selection is changed + - z-step is changed """ # z-step changed in viewer self.viewer.dims.events.current_step.connect(self._draw) @@ -102,7 +103,7 @@ def setup_callbacks(self) -> None: def update_layers(self, event: napari.utils.events.Event) -> None: """ - Update the layers attribute with currently selected layers and re-draw. + Update the ``layers`` attribute with currently selected layers and re-draw. """ self.layers = list(self.viewer.layers.selection) self._on_update_layers() @@ -145,7 +146,7 @@ def add_single_axes(self) -> None: @staticmethod def apply_napari_colorscheme(ax: Axes) -> None: - """Apply napari-compatible colorscheme to an axes object.""" + """Apply napari-compatible colorscheme to an Axes.""" # changing color of axes background to transparent ax.set_facecolor("none") From 8573b0b60201f3023572153df37032881b8080f7 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Thu, 18 May 2023 11:20:59 +0100 Subject: [PATCH 6/9] Improve x/y axis key doc --- src/napari_matplotlib/scatter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/napari_matplotlib/scatter.py b/src/napari_matplotlib/scatter.py index 94408124..af7c180a 100644 --- a/src/napari_matplotlib/scatter.py +++ b/src/napari_matplotlib/scatter.py @@ -127,7 +127,7 @@ def __init__(self, napari_viewer: napari.viewer.Viewer): @property def x_axis_key(self) -> Optional[str]: """ - Key to access x axis data from the FeaturesTable. + Key for the x-axis data. """ return self._x_axis_key @@ -139,7 +139,7 @@ def x_axis_key(self, key: Optional[str]) -> None: @property def y_axis_key(self) -> Optional[str]: """ - Key to access y axis data from the FeaturesTable. + Key for the y-axis data. """ return self._y_axis_key From bdb81dcdea116e50cdc2da88f15418f0bf4a2f14 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Thu, 18 May 2023 11:21:53 +0100 Subject: [PATCH 7/9] Add Interval repr add typing to repr Add repr docstring --- src/napari_matplotlib/util.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/napari_matplotlib/util.py b/src/napari_matplotlib/util.py index 4ae8ca19..17965caf 100644 --- a/src/napari_matplotlib/util.py +++ b/src/napari_matplotlib/util.py @@ -28,6 +28,12 @@ def __init__(self, lower_bound: Optional[int], upper_bound: Optional[int]): self.lower = lower_bound self.upper = upper_bound + def __repr__(self) -> str: + """ + Get string representation. + """ + return f"Interval({self.lower}, {self.upper})" + def __contains__(self, val: int) -> bool: """ Return True if val is in the current interval. From 654f005ead7d24b37fe9db76a2e8906665dbe27b Mon Sep 17 00:00:00 2001 From: David Stansby Date: Thu, 18 May 2023 11:27:15 +0100 Subject: [PATCH 8/9] Improve scatter docstring --- src/napari_matplotlib/scatter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/napari_matplotlib/scatter.py b/src/napari_matplotlib/scatter.py index af7c180a..858a42a8 100644 --- a/src/napari_matplotlib/scatter.py +++ b/src/napari_matplotlib/scatter.py @@ -68,7 +68,7 @@ def _get_data(self) -> Tuple[npt.NDArray[Any], npt.NDArray[Any], str, str]: class ScatterWidget(ScatterBaseWidget): """ - Widget to display scatter plot of two similarly shaped image layers. + Scatter data in two similarly shaped layers. If there are more than 500 data points, a 2D histogram is displayed instead of a scatter plot, to avoid too many scatter points. From ec8a90b6a4025640c88a5cfa84feb21ed468644c Mon Sep 17 00:00:00 2001 From: David Stansby Date: Thu, 18 May 2023 11:27:34 +0100 Subject: [PATCH 9/9] Tidy up public API for slicing --- src/napari_matplotlib/slice.py | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/napari_matplotlib/slice.py b/src/napari_matplotlib/slice.py index 4e22bad8..c29fff5c 100644 --- a/src/napari_matplotlib/slice.py +++ b/src/napari_matplotlib/slice.py @@ -50,7 +50,7 @@ def __init__(self, napari_viewer: napari.viewer.Viewer): self.update_layers(None) @property - def layer(self) -> napari.layers.Layer: + def _layer(self) -> napari.layers.Layer: """ Layer being plotted. """ @@ -73,28 +73,19 @@ def current_dim_index(self) -> int: return _dims[::-1].index(self.current_dim) @property - def selector_values(self) -> Dict[str, int]: + def _selector_values(self) -> Dict[str, int]: """ Values of the slice selectors. """ return {d: self.slice_selectors[d].value() for d in _dims_sel} - def update_slice_selectors(self) -> None: - """ - Update range and enabled status of the slice selectors, and the value - of the z slice selector. - """ - # Update min/max - for i, dim in enumerate(_dims_sel): - self.slice_selectors[dim].setRange(0, self.layer.data.shape[i]) - - def get_xy(self) -> Tuple[npt.NDArray[Any], npt.NDArray[Any]]: + def _get_xy(self) -> Tuple[npt.NDArray[Any], npt.NDArray[Any]]: """ Get data for plotting. """ - x = np.arange(self.layer.data.shape[self.current_dim_index]) + x = np.arange(self._layer.data.shape[self.current_dim_index]) - vals = self.selector_values + vals = self._selector_values vals.update({"z": self.current_z}) slices = [] @@ -109,7 +100,7 @@ def get_xy(self) -> Tuple[npt.NDArray[Any], npt.NDArray[Any]]: # Reverse since z is the first axis in napari slices = slices[::-1] - y = self.layer.data[tuple(slices)].ravel() + y = self._layer.data[tuple(slices)].ravel() return x, y @@ -123,8 +114,8 @@ def draw(self) -> None: """ Clear axes and draw a 1D plot. """ - x, y = self.get_xy() + x, y = self._get_xy() self.axes.plot(x, y) self.axes.set_xlabel(self.current_dim) - self.axes.set_title(self.layer.name) + self.axes.set_title(self._layer.name) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy