Skip to content

Commit

Permalink
typing, v1.23.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hanjinliu committed Sep 5, 2021
1 parent 248a674 commit 39a68ec
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,4 @@ git clone https://github.com/hanjinliu/impy

`impy` is partly dependent on `numba`, `cupy`, `trackpy` and `dask-image`. Please install these packages if needed.

:warning: Image processing algorithms in `ImgArray` are almost stable so that their behavior will not change a lot. However, since `napari` is under development and I'm groping for better UI right now, any functions that currently implemented in `impy` viewer may change or no longer work in the future. Make sure keeping `napari` and `impy` updated when you use.

:warning: Image processing algorithms in `ImgArray` are almost stable so that their behavior will not change a lot. However, since `napari` is under development and I'm groping for better UI right now, any functions that currently implemented in `impy` viewer may change or no longer work in the future. Make sure keeping `napari` and `impy` updated when you use.
2 changes: 1 addition & 1 deletion impy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.22.2"
__version__ = "1.23.0"

import logging
from ._const import Const, SetConst
Expand Down
40 changes: 21 additions & 19 deletions impy/viewer/menus.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import annotations
from warnings import warn
import napari
from napari.utils.notifications import Notification, notification_manager
from napari.utils import history
from napari.layers import Image, Shapes, Points, Labels, Tracks
import magicgui
from functools import wraps
from qtpy.QtWidgets import QFileDialog, QAction
Expand Down Expand Up @@ -40,7 +43,6 @@
"tophat", "rolling_ball"]

def catch_notification(func):
from napari.utils.notifications import Notification, notification_manager
@wraps(func)
def wrapped(*args, **kwargs):
try:
Expand All @@ -58,7 +60,7 @@ def add_imread_menu(viewer:"napari.Viewer"):
@catch_notification
def _(*args):
dlg = QFileDialog()
hist = napari.utils.history.get_open_history()
hist = history.get_open_history()
dlg.setHistory(hist)
filenames, _ = dlg.getOpenFileNames(
parent=viewer.window.qt_viewer,
Expand All @@ -68,7 +70,7 @@ def _(*args):
if filenames != [] and filenames is not None:
img = imread(filenames[0])
add_labeledarray(viewer, img)
napari.utils.history.update_open_history(filenames[0])
history.update_open_history(filenames[0])
return None

viewer.window.file_menu.addAction(action)
Expand All @@ -88,7 +90,7 @@ def _(*args):
raise ValueError("Select only one layer.")

img = layer_to_impy_object(viewer, layers[0])
hist = napari.utils.history.get_save_history()
hist = history.get_save_history()
dlg.setHistory(hist)

if img.dirpath:
Expand All @@ -103,7 +105,7 @@ def _(*args):

if filename:
img.imsave(filename)
napari.utils.history.update_save_history(filename)
history.update_save_history(filename)
return None

viewer.window.file_menu.addAction(action)
Expand All @@ -115,7 +117,7 @@ def add_read_csv_menu(viewer:"napari.Viewer"):
@catch_notification
def _(*args):
dlg = QFileDialog()
hist = napari.utils.history.get_open_history()
hist = history.get_open_history()
dlg.setHistory(hist)
filenames, _ = dlg.getOpenFileNames(
parent=viewer.window.qt_viewer,
Expand All @@ -125,7 +127,7 @@ def _(*args):
if (filenames != []) and (filenames is not None):
path = filenames[0]
read_csv(viewer, path)
napari.utils.history.update_open_history(filenames[0])
history.update_open_history(filenames[0])
return None

viewer.window.file_menu.addAction(action)
Expand All @@ -142,7 +144,7 @@ def _(*args):
if name in viewer.window._dock_widgets.keys():
viewer.window._dock_widgets[name].show()
else:
root = napari.utils.history.get_open_history()[0]
root = history.get_open_history()[0]
ex = Explorer(viewer, root)
viewer.window.add_dock_widget(ex, name="Explorer", area="right", allowed_areas=["right"])
return None
Expand All @@ -159,7 +161,7 @@ def add_duplicate_menu(viewer:"napari.Viewer"):
def _():
layer = get_a_selected_layer(viewer)

if isinstance(layer, (napari.layers.Image, napari.layers.Labels)):
if isinstance(layer, (Image, Labels)):
dlg = DuplicateDialog(viewer, layer)
dlg.exec_()
else:
Expand Down Expand Up @@ -190,19 +192,19 @@ def _():
"opacity": layer.opacity,
"ndim": 2,
"name": f"[Proj]{layer.name}"})
if isinstance(layer, napari.layers.Image):
if isinstance(layer, Image):
if layer.data.ndim < 3:
return None
dlg = ImageProjectionDialog(viewer, layer)
dlg.exec_()

elif isinstance(layer, napari.layers.Labels):
elif isinstance(layer, Labels):
if layer.data.ndim < 3:
return None
dlg = LabelProjectionDialog(viewer, layer)
dlg.exec_()

elif isinstance(layer, napari.layers.Shapes):
elif isinstance(layer, Shapes):
data = [d[:,-2:] for d in data]

if layer.nshapes > 0:
Expand All @@ -214,7 +216,7 @@ def _():
kwargs["shape_type"] = layer.shape_type
viewer.add_shapes(data, **kwargs)

elif isinstance(layer, napari.layers.Points):
elif isinstance(layer, Points):
data = data[:, -2:]
for k in ["face_color", "edge_color", "size", "symbol"]:
kwargs[k] = getattr(layer, k, None)
Expand All @@ -224,7 +226,7 @@ def _():
kwargs["ndim"] = 2
viewer.add_points(data, **kwargs)

elif isinstance(layer, napari.layers.Tracks):
elif isinstance(layer, Tracks):
data = data[:, [0, -2, -1]] # p, y, x axes
viewer.add_tracks(data, **kwargs)

Expand Down Expand Up @@ -375,7 +377,7 @@ def add_time_stamper_menu(viewer:"napari.Viewer"):
@catch_notification
def _(*args):
layer = get_a_selected_layer(viewer)
if not isinstance(layer, napari.layers.Image):
if not isinstance(layer, Image):
raise TypeError("Select an image layer.")
layer.data.axisof("t") # check image axes here.
dlg = TimeStamper(viewer, layer)
Expand All @@ -402,7 +404,7 @@ def _(*args):
layer.current_properties = {"1": np.array([""], dtype="<U32")}
layer.properties = {"1": np.array([""]*ndata, dtype="<U32")}
widget = TableWidget(viewer, layer.properties, name=name)
if isinstance(layer, (napari.layers.Points, napari.layers.Shapes)):
if isinstance(layer, (Points, Shapes)):
widget.linked_layer = layer
viewer.window.add_dock_widget(widget, area="right", name=name)

Expand Down Expand Up @@ -488,7 +490,7 @@ def _(*args):
if len(selected) != 1:
raise ValueError("No layer selected")
selected = selected[0]
if not isinstance(selected, napari.layers.Image):
if not isinstance(selected, Image):
raise TypeError("Selected layer is not an image layer")
img = selected.data
if hasattr(img, "labels"):
Expand Down Expand Up @@ -573,7 +575,7 @@ def _(*args):
template={"label": "temp",
"tooltip": "Template image. This image will move."},
ndim={"choices": [2, 3]})
def template_matcher(img:napari.layers.Image, template:napari.layers.Image, ndim=2):
def template_matcher(img:Image, template:Image, ndim=2):
step = viewer.dims.current_step[:-min(ndim, img.ndim)]
img_ = img.data[step]
template_ = template.data[step]
Expand Down Expand Up @@ -724,7 +726,7 @@ def _iter_args_and_kwargs(string:str):



def _get_property(layer, i):
def _get_property(layer:Shapes|Points, i):
try:
prop = layer.properties["text"][i]
except (KeyError, IndexError):
Expand Down

0 comments on commit 39a68ec

Please sign in to comment.