Skip to content

Commit

Permalink
Docstring and typing fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jni committed Jul 7, 2024
1 parent de4bb80 commit 77bf7ed
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
11 changes: 3 additions & 8 deletions napari/_qt/qt_main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -1662,21 +1662,16 @@ def export_figure(
This function finds a tight boundary around the data, resets the view
around that boundary (and, when scale=1, such that 1 captured pixel is
equivalent to one data pixel), takes a screenshot, then restores the
previous zoom and canvas sizes. For example with one image layer with
an image of 256 x 256 pixels and layer.scale=[1,1], with scale=1 the
size of the resulting figure will be 256 x 256 pixels. If layer.scale
for both dimensions is set to 0.5, it will be 128 x 128 pixels. Currently,
only works when 2 dimensions are displayed.
previous zoom and canvas sizes. Currently, only works when 2 dimensions
are displayed.
Parameters
----------
path : str, optional
Filename for saving screenshot image.
scale : float
Scale factor used to increase resolution of canvas for the
screenshot. By default, a scale of 1. A scale
of 1 corresponds to 1 data pixel per screenshot pixel if all displayed
layers have layer.scale for each displayed dimension set to 1.
screenshot. By default, a scale of 1.
flash : bool
Flag to indicate whether flash animation should be shown after
the screenshot was captured.
Expand Down
45 changes: 25 additions & 20 deletions napari/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from weakref import WeakSet

import magicgui as mgui
import numpy as np

from napari.components.viewer_model import ViewerModel
from napari.utils import _magicgui
Expand Down Expand Up @@ -94,36 +95,40 @@ def export_figure(
*,
scale_factor: float = 1,
flash: bool = True,
):
) -> np.ndarray:
"""Export an image of the full extent of the displayed layer data.
This function finds a tight boundary around the data, resets the view around
that boundary, takes a screenshot for which each pixel is equal to the pixel
resolution of the data and then restores the previous zoom and canvas sizes.
The pixel resolution can be upscaled or downscaled by passing an integer value
to the scale parameter different from 1. For example with one image layer with
an image of 256 x 256 pixels and layer.scale=[15,15] (pixel resolution of for
x and y of 15), with scale=2 the size of the resulting figure will be
512 x 512 pixels (the interpolation mode of the layer will be used to upscale).
If scale is set to 0.5, it will be 128 x 128 pixels. If having layers with a
different layer.scale, the resolution of each screenshot pixel will be equal
to the largest value of layer.scale for each dimension across the layers.
Currently, only works when 2 dimensions are displayed.
This function finds a tight boundary around the data, resets the view
around that boundary, takes a screenshot for which each pixel is equal
to the pixel resolution of the data, then restores the previous zoom
and canvas sizes.
The pixel resolution can be upscaled or downscaled by the given
`scale_factor`. For example, an image with 800 x 600 pixels with
scale_factor 1 will be saved as 800 x 600, or 1200 x 900 with
scale_factor 1.5.
For anisotropic images, the resolution is set by the highest-resolution
dimension. For an anisotropic 800 x 600 image with scale set to
[0.25, 0.5], the screenshot will be 800 x 1200, or 1200 x 1800 with a
scale_factor of 1.5.
Upscaling will be done using the interpolation mode set on each layer.
Parameters
----------
path : str, optional
Filename for saving screenshot image.
scale_factor : float
By default, the zoom will export approximately 1 pixel per smallest-scale
pixel on the viewer. For example, if a layer has scale 0.004nm/pixel and
another has scale 1µm/pixel, the exported figure will have 0.004nm/pixel.
Upscaling by 2 will produce a figure with 0.002nm/pixel through the
interpolation mode set on each layer.
By default, the zoom will export approximately 1 pixel per
smallest-scale pixel on the viewer. For example, if a layer has
scale 0.004nm/pixel and another has scale 1µm/pixel, the exported
figure will have 0.004nm/pixel. Upscaling by 2 will produce a
figure with 0.002nm/pixel through the interpolation mode set on
each layer.
flash : bool
Flag to indicate whether flash animation should be shown after
the screenshot was captured.
By default, True.
the screenshot was captured. By default, True.
Returns
-------
Expand Down

0 comments on commit 77bf7ed

Please sign in to comment.