Skip to content

Commit

Permalink
Merge pull request #324 from scipp/docs-tweaks
Browse files Browse the repository at this point in the history
Small docs fixes
  • Loading branch information
nvaytet authored Apr 16, 2024
2 parents c95e375 + 8b5ea7c commit 7c4bb8e
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 17 deletions.
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ filterwarnings = [
'ignore:Passing unrecognized arguments to super:DeprecationWarning',
'ignore:Jupyter is migrating its paths:DeprecationWarning',
'ignore:setDaemon\(\) is deprecated, set the daemon attribute instead:DeprecationWarning',
'ignore:TriCutTool is deprecated::',
'ignore:Cut3dTool is deprecated::',
]

[tool.bandit]
Expand Down
21 changes: 4 additions & 17 deletions src/plopp/graphics/figure.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)

import warnings
from typing import Literal

from .. import backends
from ..core.typing import VisibleDeprecationWarning


def _warn_deprecated(func_name: str, new_func_name: str):
warnings.warn(
f'The function `{func_name}` is deprecated and will be removed in a future '
f'version. Use `{new_func_name}` instead.',
VisibleDeprecationWarning,
stacklevel=2,
)
from ..utils import deprecated


@deprecated('Use ``linefigure`` instead.')
def figure1d(*args, style: Literal['line'] = 'line', **kwargs):
"""
Create a figure to represent one-dimensional data from one or more graph node(s).
Expand Down Expand Up @@ -53,8 +44,6 @@ def figure1d(*args, style: Literal['line'] = 'line', **kwargs):
>>> fig = pp.figure1d(in_node, norm='log')
"""

_warn_deprecated('figure1d', 'linefigure')

if style == 'line':
from .lineview import LineView

Expand All @@ -63,6 +52,7 @@ def figure1d(*args, style: Literal['line'] = 'line', **kwargs):
raise ValueError(f'Unsupported style={style} for figure1d.')


@deprecated('Use ``imagefigure`` instead.')
def figure2d(*args, style: Literal['image'] = 'image', **kwargs):
"""
Create a figure to represent two-dimensional data from a graph node.
Expand Down Expand Up @@ -91,8 +81,6 @@ def figure2d(*args, style: Literal['image'] = 'image', **kwargs):
>>> fig = pp.figure2d(in_node, norm='log')
"""

_warn_deprecated('figure2d', 'imagefigure')

if style == 'image':
from .imageview import ImageView

Expand All @@ -101,6 +89,7 @@ def figure2d(*args, style: Literal['image'] = 'image', **kwargs):
raise ValueError(f'Unsupported style={style} for figure2d.')


@deprecated('Use ``scatter3dfigure`` instead.')
def figure3d(*args, style: Literal['scatter'] = 'scatter', **kwargs):
"""
Create a figure to represent three-dimensional data from a graph node.
Expand Down Expand Up @@ -129,8 +118,6 @@ def figure3d(*args, style: Literal['scatter'] = 'scatter', **kwargs):
>>> fig = pp.figure3d(in_node, norm='log')
"""

_warn_deprecated('figure3d', 'scatter3dfigure')

if style == 'scatter':
from .scatter3dview import Scatter3dView

Expand Down
14 changes: 14 additions & 0 deletions src/plopp/graphics/imageview.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@ def imagefigure(*args, **kwargs):
Create a figure to represent two-dimensional data from one or more graph node(s).
.. versionadded:: 24.04.0
Examples
--------
Create an input node and attach an ``imagefigure`` as a view:
>>> da = pp.data.data2d()
>>> in_node = pp.Node(da)
>>> fig = pp.imagefigure(in_node)
With a customization argument to make the color scale logarithmic:
>>> da = pp.data.data2d()
>>> in_node = pp.Node(da)
>>> fig = pp.imagefigure(in_node, norm='log')
"""

return backends.figure2d(ImageView, *args, **kwargs)
22 changes: 22 additions & 0 deletions src/plopp/graphics/lineview.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,28 @@ def linefigure(*args, **kwargs):
Create a figure to represent one-dimensional data from one or more graph node(s).
.. versionadded:: 24.04.0
Examples
--------
Create an input node and attach a ``linefigure`` as a view:
>>> da = pp.data.data1d()
>>> in_node = pp.Node(da)
>>> fig = pp.linefigure(in_node)
Visualize two data arrays on the same figure:
>>> a = pp.data.data1d()
>>> b = 3 * a
>>> a_node = pp.Node(a)
>>> b_node = pp.Node(b)
>>> fig = pp.linefigure(a_node, b_node)
With a customization argument to make the vertical scale logarithmic:
>>> da = pp.data.data1d()
>>> in_node = pp.Node(da)
>>> fig = pp.linefigure(in_node, norm='log')
"""

return backends.figure2d(LineView, *args, **kwargs)
14 changes: 14 additions & 0 deletions src/plopp/graphics/scatter3dview.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,20 @@ def scatter3dfigure(*args, **kwargs):
Create a figure to represent three-dimensional data from one or more graph node(s).
.. versionadded:: 24.04.0
Examples
--------
Create an input node and attach a ``scatter3dfigure`` as a view:
>>> da = pp.data.scatter()
>>> in_node = pp.Node(da)
>>> fig = pp.scatter3dfigure(in_node)
With a customization argument to make the color scale logarithmic:
>>> da = pp.data.scatter()
>>> in_node = pp.Node(da)
>>> fig = pp.scatter3dfigure(in_node, norm='log')
"""

return backends.figure3d(Scatter3dView, *args, **kwargs)
14 changes: 14 additions & 0 deletions src/plopp/graphics/scatterview.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ def scatterfigure(*args, **kwargs):
Create a figure to represent scatter data from one or more graph node(s).
.. versionadded:: 24.04.0
Examples
--------
Create an input node and attach a ``scatterfigure`` as a view:
>>> da = pp.data.scatter()
>>> in_node = pp.Node(da)
>>> fig = pp.scatterfigure(in_node)
A scatter figure with a color bar (using the data values for the color scale):
>>> da = pp.data.scatter()
>>> in_node = pp.Node(da)
>>> fig = pp.scatterfigure(in_node, cbar=True)
"""

return backends.figure2d(ScatterView, *args, **kwargs)
27 changes: 27 additions & 0 deletions src/plopp/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2024 Scipp contributors (https://github.com/scipp)

import functools
import warnings
from typing import Callable

from .core.typing import VisibleDeprecationWarning


def deprecated(message: str = '') -> Callable:
def decorator(function: Callable) -> Callable:
@functools.wraps(function)
def wrapper(*args, **kwargs):
warnings.warn(
f'{function.__name__} is deprecated. {message}',
VisibleDeprecationWarning,
stacklevel=2,
)
return function(*args, **kwargs)

return wrapper

return decorator


__all__ = ['deprecated']
5 changes: 5 additions & 0 deletions src/plopp/widgets/cut3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
import scipp as sc

from ..core import View, node
from ..utils import deprecated
from .debounce import debounce
from .style import BUTTON_LAYOUT
from .tools import PlusMinusTool


@deprecated("Use ``Clip3dTool`` instead.")
class Cut3dTool(ipw.HBox):
"""
A tool that provides a slider to extract a plane of points in a three-dimensional
Expand Down Expand Up @@ -220,11 +222,14 @@ def decrease_thickness(self):
self._add_cut()


@deprecated("Use ``ClippingPlanes`` instead.")
class TriCutTool(ipw.HBox):
"""
A collection of :class:`Cut3dTool` to make spatial cuts in the X, Y, and Z
directions on a three-dimensional scatter plot.
.. deprecated:: v24.04.0
Parameters
----------
fig:
Expand Down

0 comments on commit 7c4bb8e

Please sign in to comment.