Skip to content

Commit

Permalink
move napari viewer parameter to end (backwards compatibility breaking…
Browse files Browse the repository at this point in the history
…) and return pandas DataFrames
  • Loading branch information
haesleinhuepf committed May 8, 2022
1 parent e312dd8 commit 246099c
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 60 deletions.
33 changes: 16 additions & 17 deletions demo/handle_timelapse_data.ipynb

Large diffs are not rendered by default.

63 changes: 31 additions & 32 deletions demo/tables.ipynb

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions napari_skimage_regionprops/_regionprops.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import warnings

import numpy as np
import pandas
from napari import Viewer
from napari_tools_menu import register_function
import napari
import math
from ._all_frames import analyze_all_frames

def regionprops(image_layer : napari.layers.Layer, labels_layer: napari.layers.Labels, napari_viewer : Viewer, size : bool = True, intensity : bool = True, perimeter : bool = False, shape : bool = False, position : bool = False, moments : bool = False):
def regionprops(image_layer : napari.layers.Layer, labels_layer: napari.layers.Labels, size : bool = True, intensity : bool = True, perimeter : bool = False, shape : bool = False, position : bool = False, moments : bool = False, napari_viewer : Viewer = None):
warnings.warn("napari_skimage_regionprops.regionprops is deprecated. Use regionprops_table instead.")
image_data = None
if image_layer is not None:
image_data = image_layer.data

regionprops_table(image_data, labels_layer.data, napari_viewer, size, intensity, perimeter, shape, position, moments)

@register_function(menu="Measurement > Regionprops (nsr)")
def regionprops_table(image : napari.types.ImageData, labels: napari.types.LabelsData, napari_viewer : Viewer = None, size : bool = True, intensity : bool = True, perimeter : bool = False, shape : bool = False, position : bool = False, moments : bool = False):
@register_function(menu="Measurement > Regionprops (scikit-image, nsr)")
def regionprops_table(image : napari.types.ImageData, labels: napari.types.LabelsData, size : bool = True, intensity : bool = True, perimeter : bool = False, shape : bool = False, position : bool = False, moments : bool = False, napari_viewer : Viewer = None) -> "pandas.DataFrame":
"""
Adds a table widget to a given napari viewer with quantitative analysis results derived from an image-label pair.
"""
Expand Down Expand Up @@ -71,9 +72,11 @@ def standard_deviation_intensity(region, intensities):
properties = properties + ['solidity', 'extent', 'feret_diameter_max', 'local_centroid']
if len(labels.shape) == 2:
properties = properties + ['major_axis_length', 'minor_axis_length', 'orientation', 'eccentricity']
# we need these two to compute some shape descriptors
if not size:
# we need these two to compute some shape descriptors
properties = properties + ['area', 'perimeter']
properties = properties + ['area']
if not perimeter:
properties = properties + ['perimeter']
else:
properties = properties + ['moments_central']
# euler_number,
Expand Down Expand Up @@ -148,7 +151,8 @@ def standard_deviation_intensity(region, intensities):
from ._table import add_table
add_table(labels_layer, napari_viewer)
else:
return table
import pandas
return pandas.DataFrame(table)

def ellipsoid_axis_lengths(table):
"""Compute ellipsoid major, intermediate and minor axis length.
Expand Down
14 changes: 9 additions & 5 deletions napari_skimage_regionprops/_tests/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def test_regionprops_without_moments(make_napari_viewer):

# analyze everything we can
from napari_skimage_regionprops import regionprops
regionprops(image_layer, labels_layer, viewer, True, True, True, True, True, False)
regionprops(image_layer, labels_layer, size=True, intensity=True, perimeter=True, shape=True, position=True, moments=False, napari_viewer=viewer)

def test_3d_2d(make_napari_viewer):

Expand Down Expand Up @@ -180,7 +180,8 @@ def test_3d_2d(make_napari_viewer):

# analyze everything we can
from napari_skimage_regionprops import regionprops
regionprops(image_layer, labels_layer, viewer, True, True, True, True, True, True)
regionprops(image_layer, labels_layer, size=True, intensity=True, perimeter=True, shape=True, position=True,
moments=True, napari_viewer=viewer)

# there is now a table in the viewer
assert len(viewer.window._dock_widgets) == num_dw + 1
Expand Down Expand Up @@ -222,7 +223,8 @@ def test_3d(make_napari_viewer):

# analyze everything we can
from napari_skimage_regionprops import regionprops
regionprops(image_layer, labels_layer, viewer, True, True, True, True, True, True)
regionprops(image_layer, labels_layer, size=True, intensity=True, perimeter=True, shape=True, position=True,
moments=True, napari_viewer=viewer)

# there is now a table in the viewer
assert len(viewer.window._dock_widgets) == num_dw + 1
Expand Down Expand Up @@ -265,7 +267,8 @@ def test_3d_dask(make_napari_viewer):

# analyze everything we can
from napari_skimage_regionprops import regionprops
regionprops(image_layer, labels_layer, viewer, True, True, True, True, True, True)
regionprops(image_layer, labels_layer, size=True, intensity=True, perimeter=True, shape=True, position=True,
moments=True, napari_viewer=viewer)

# there is now a table in the viewer
assert len(viewer.window._dock_widgets) == num_dw + 1
Expand Down Expand Up @@ -312,7 +315,8 @@ def test_4d_3d(make_napari_viewer):

# analyze everything we can
from napari_skimage_regionprops import regionprops
regionprops(image_layer, labels_layer, viewer, True, True, True, True, True, True)
regionprops(image_layer, labels_layer, size=True, intensity=True, perimeter=True, shape=True, position=True,
moments=True, napari_viewer=viewer)

# there is now a table in the viewer
assert len(viewer.window._dock_widgets) == num_dw + 1
Expand Down

0 comments on commit 246099c

Please sign in to comment.