Skip to content

Commit

Permalink
Merge pull request #15 from lowe-lab-ucl/initial-tracking-widget
Browse files Browse the repository at this point in the history
  • Loading branch information
dpshelio authored Mar 16, 2022
2 parents eee509b + 5004d8e commit 9323552
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 66 deletions.
5 changes: 0 additions & 5 deletions napari_btrack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,3 @@
from ._version import version as __version__
except ImportError:
__version__ = "unknown"



from ._dock_widget import napari_experimental_provide_dock_widget

41 changes: 0 additions & 41 deletions napari_btrack/_dock_widget.py

This file was deleted.

20 changes: 5 additions & 15 deletions napari_btrack/_tests/test_dock_widget.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
from napari_btrack import napari_experimental_provide_dock_widget
import pytest
from ..track import track

"""
# this is your plugin name declared in your napari.plugins entry point
MY_PLUGIN_NAME = "napari-btrack"
# the name of your widget(s)
MY_WIDGET_NAMES = ["Example Q Widget", "example_magic_widget"]

@pytest.mark.parametrize("widget_name", MY_WIDGET_NAMES)
def test_something_with_viewer(widget_name, make_napari_viewer):
def test_add_widget(make_napari_viewer):
viewer = make_napari_viewer()
num_dw = len(viewer.window._dock_widgets)
viewer.window.add_plugin_dock_widget(
plugin_name=MY_PLUGIN_NAME, widget_name=widget_name
)
assert len(viewer.window._dock_widgets) == num_dw + 1
"""
num_dw = len(list(viewer.window._dock_widgets))
viewer.window.add_function_widget(function=track)
assert len(list(viewer.window._dock_widgets)) == num_dw + 1
10 changes: 10 additions & 0 deletions napari_btrack/napari.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: napari-btrack
schema_version: 0.1.0
contributions:
commands:
- id: napari-btrack.track
title: Create Track
python_name: napari_btrack.track:track
widgets:
- command: napari-btrack.track
display_name: Track
53 changes: 53 additions & 0 deletions napari_btrack/track.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import btrack
import napari

from btrack.utils import segmentation_to_objects
from magicgui import magicgui
from magicgui.widgets import FunctionGui
from pathlib import Path
from typing import Optional


def run_tracker(objects, config_file_path):
with btrack.BayesianTracker() as tracker:
# configure the tracker using a config file
tracker.configure_from_file(config_file_path)
tracker.max_search_radius = 50

# append the objects to be tracked
tracker.append(objects)

# set the volume
tracker.volume = ((0, 1600), (0, 1200), (-1e5, 64.0))

# track them (in interactive mode)
tracker.track_interactive(step_size=100)

# generate hypotheses and run the global optimizer
tracker.optimize()

# get the tracks in a format for napari visualization
data, properties, graph = tracker.to_napari(ndim=2)
return data, properties, graph


def track() -> FunctionGui:
@magicgui(
call_button=True,
persist=True,
config_file_path=dict(value=Path.home()),
reset_button=dict(widget_type="PushButton", text="Reset defaults"),
)
def widget(
viewer: napari.Viewer,
segmentation: napari.layers.Image,
config_file_path: Optional[Path],
reset_button,
):
segmented_objects = segmentation_to_objects(segmentation.data[:100, ...])
data, properties, graph = run_tracker(segmented_objects, config_file_path)
viewer.add_tracks(
data=data, properties=properties, graph=graph, name=f"{segmentation}_btrack"
)

return widget
11 changes: 7 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ url = https://github.com/quantumjot/napari-btrack
description = A plugin to use btrack from napari
long_description = file: README.md
long_description_content_type = text/markdown
classifiers =
classifiers =
Development Status :: 2 - Pre-Alpha
Intended Audience :: Developers
Framework :: napari
Expand All @@ -30,7 +30,10 @@ install_requires =
numpy
btrack>=0.4.1


[options.entry_points]
napari.plugin =
napari-btrack = napari_btrack
napari.manifest =
napari-btrack = napari_btrack:napari.yaml

[options.package_data]
napari_btrack = napari.yaml

1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-
from setuptools import setup


# https://github.com/pypa/setuptools_scm
use_scm = {"write_to": "napari_btrack/_version.py"}

Expand Down

0 comments on commit 9323552

Please sign in to comment.