napari.utils#
Classes
Colormap that relates intensity values to colors. |
|
Color cycle with a background value. |
|
Colormap using a direct mapping from labels to color using a dict. |
|
Display a napari screenshot in a jupyter notebook. |
|
This class inherits from progress, providing the additional ability to cancel expensive executions. |
|
This class inherits from tqdm and provides an interface for progress bars in the napari viewer. |
Functions
- napari.utils.nbscreenshot(viewer, *, canvas_only=False, alt_text=None) NotebookScreenshot[source]#
Display a napari screenshot in a Jupyter notebook.
This is a convenience wrapper around NotebookScreenshot for the common use case of returning a rich display object directly from a notebook cell.
- Parameters:
viewer (napari.Viewer) – The napari viewer.
canvas_only (bool, optional) – If False include the napari viewer frame in the screenshot, and if True then take screenshot of just the image display canvas. By default, False.
alt_text (str, optional) – Image description alternative text, for screenreader accessibility. Good alt-text describes the image and any text within the image in no more than three short, complete sentences. By default, None.
- Returns:
A rich display object that renders as a PNG in notebook frontends.
- Return type:
Examples
>>> import napari >>> from napari.utils import nbscreenshot >>> from skimage.data import chelsea
>>> viewer = napari.Viewer() >>> viewer.add_image(chelsea(), name='chelsea-the-cat') >>> nbscreenshot(viewer) >>> # screenshot just the canvas without the napari viewer framing it >>> nbscreenshot(viewer, canvas_only=True)
- napari.utils.progrange(*args: Any, **kwargs: Any) progress[source]#
Shorthand for
progress(range(*args), **kwargs).Adds tqdm based progress bar to napari viewer, if it exists, and returns the wrapped range object.
- Returns:
wrapped range object
- Return type:
- napari.utils.resize_dask_cache(nbytes: int | None = None, mem_fraction: float | None = None) Cache[source]#
Create or resize the dask cache used for opportunistic caching.
The cache object is an instance of a
Cache, (which wraps acachey.Cache).See Dask opportunistic caching
- Parameters:
nbytes (int, optional) – The desired size of the cache, in bytes. If
None, the cache size will autodetermined as fraction of the total memory in the system, usingmem_fraction. Ifnbytesis 0. The cache is turned off. by default, cache size is autodetermined usingmem_fraction.mem_fraction (float, optional) – The fraction (from 0 to 1) of total memory to use for the dask cache.
- Returns:
dask_cache – An instance of a Dask Cache
- Return type:
dask.cache.Cache
Examples
>>> from napari.utils import resize_dask_cache >>> cache = resize_dask_cache() # use 25% of total memory by default
>>> # dask.Cache wraps cachey.Cache >>> assert isinstance(cache.cache, cachey.Cache)
>>> # useful attributes >>> cache.cache.available_bytes # full size of cache >>> cache.cache.total_bytes # currently used bytes