Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to make nx Graph from Skeleton #224

Merged
merged 22 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,9 @@ skan = [
[tool.setuptools_scm]
write_to = 'src/skan/_version.py'

[tool.pytest.ini_options]
minversion = "7.4.2"
addopts = "-W ignore"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you add this? (ie what warnings are we ignoring here and is that wise 😅)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently its our own deprecation warnings that were recently added for the removal of _.

src/skan/test/test_csr.py:407
  /home/neil/work/git/hub/ns-rse/skan/src/skan/test/test_csr.py:407: VisibleDeprecationWarning: separator in column name will change to _ in version 0.13; to silence this warning, use `separator='-'` to maintain current behavior and use `separator='_'` to switch to the new default behavior.
    csr.summarize(csr.Skeleton(skeleton1)),

Happy to remove this though I only added it so it was easier to read test output whilst writing them.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave it for now and make an issue to either wrap those in pytest.warns or pass the separator arg.


[project.entry-points.'napari.manifest']
skan-napari = 'skan:napari.yaml'
52 changes: 50 additions & 2 deletions src/skan/_testdata.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import networkx as nx
import numpy as np

from skimage.draw import random_shapes
from skimage.morphology import skeletonize

tinycycle = np.array([[0, 1, 0],
[1, 0, 1],
[0, 1, 0]], dtype=bool)


tinyline = np.array([0, 1, 1, 1, 0], dtype=bool)
tinyline = np.array([[0, 1, 1, 1, 0]], dtype=bool)


skeleton0 = np.array([[0, 0, 0, 1, 0, 0, 0],
Expand Down Expand Up @@ -71,3 +73,49 @@
[3, 0, 0, 1, 0, 0, 0],
[3, 0, 0, 0, 1, 1, 1],
[0, 3, 0, 0, 0, 1, 0]], dtype=int)

# Generate a random skeletons, first is a skeleton with a closed loop with side branches
kwargs = {"image_shape": (128, 128),
"max_shapes": 20,
"channel_axis": None,
"shape": None,
"rng": 1,
"allow_overlap": True,
"min_size": 20}
# Skeleton with loop to be retained and side-branches
random_images, _ = random_shapes(**kwargs)
mask = np.where(random_images != 255, 1, 0)
skeleton_loop1 = skeletonize(mask)
# Skeleton with loop to be retained and side-branches
kwargs["rng"] = 165103
kwargs["min_size"] = 60
random_images, _ = random_shapes(**kwargs)
mask = np.where(random_images != 255, 1, 0)
skeleton_loop2 = skeletonize(mask)
# Linear skeleton with lots of large side-branches, some forked
kwargs["rng"] = 13588686514
kwargs["min_size"] = 20
random_images, _ = random_shapes(**kwargs)
mask = np.where(random_images != 255, 1, 0)
skeleton_linear1 = skeletonize(mask)
# Linear Skeleton with simple fork at one end
kwargs["rng"] = 21
kwargs["min_size"] = 20
random_images, _ = random_shapes(**kwargs)
mask = np.where(random_images != 255, 1, 0)
skeleton_linear2 = skeletonize(mask)
# Linear Skeletons (i.e. multiple) with branches
kwargs["rng"] = 894632511
kwargs["min_size"] = 20
random_images, _ = random_shapes(**kwargs)
mask = np.where(random_images != 255, 1, 0)
skeleton_linear3 = skeletonize(mask)

## Sample NetworkX Graphs...
# ...with no edge attributes
nx_graph = nx.Graph()
nx_graph.add_nodes_from([1, 2, 3])
# ...with edge attributes
nx_graph_edges = nx.Graph()
nx_graph_edges.add_nodes_from([1, 2, 3])
nx_graph_edges.add_edge(1, 2, **{"path": np.asarray([[4, 4]])})
Loading
Loading