-
-
Notifications
You must be signed in to change notification settings - Fork 411
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
graph layer #5861
Open
JoOkuma
wants to merge
148
commits into
napari:main
Choose a base branch
from
JoOkuma:napari-graph-2023
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
graph layer #5861
Changes from 96 commits
Commits
Show all changes
148 commits
Select commit
Hold shift + click to select a range
5ba80f3
starting graph layer implementation from points
JoOkuma e95b3d0
added _basepoints class
JoOkuma c45d2ec
1st replacement of self.data to self._points_data on _BasePoints
JoOkuma 92d9dd9
init graph layer implementation
JoOkuma a3efea3
Merge branch 'main' into napari-graph-2023
JoOkuma 891217b
graph slicing request / response and vispy visuals
JoOkuma 37ddd96
add graph layer testing
JoOkuma 89fb3cf
add add_graph example description
JoOkuma b5a0b94
refactored graph class to always operate on the cluster directly
JoOkuma d278b5a
add new delaunay graph example
JoOkuma 9c8a390
update add_graph to follow other examples
JoOkuma fb0cb59
Merge branch 'main' into napari-graph-2023
JoOkuma 66057a4
graph slicing bug fix
JoOkuma 149c0d8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] dc4ff25
Merge branch 'main' into napari-graph-2023
JoOkuma 6836979
Merge branch 'napari-graph-2023' of github.com:JoOkuma/napari into na…
JoOkuma a6564c7
fix change from precommit
JoOkuma cc8ff0f
Merge branch 'main' into napari-graph-2023
JoOkuma 3c97c56
updated graphdata type
JoOkuma 4a6a08c
replaced edges_ of points and graph layer with border_
JoOkuma 7b12d4b
fixed basegraph typing when napari-graph is not installed
JoOkuma 7ba748e
fixed mypy new type error
JoOkuma 28ce0c8
Merge branch 'main' into napari-graph-2023
JoOkuma 4cf0931
Update napari/layers/graph/graph.py
JoOkuma bbe6d46
minor fixes
JoOkuma 3d5370c
Merge branch 'main' into napari-graph-2023
JoOkuma c43ecd8
Merge branch 'main' into napari-graph-2023
JoOkuma fef8077
removed predefined buffers size and fixed properties arguments
JoOkuma e1a0d32
fixing typing
JoOkuma 9bbef0c
Merge branch 'main' into napari-graph-2023
JoOkuma 05b9aa2
add deprecation warning to edge -> border points arguments
JoOkuma eb8a90e
Update examples/add_graph.py
JoOkuma d07aa40
Update napari/layers/graph/graph.py
JoOkuma 62519a5
Merge branch 'main' into napari-graph-2023
JoOkuma f36c8bf
updated edge -> border deprecation version
JoOkuma 05fe4b4
add deprecated points edge_ events warning
JoOkuma a910ca9
warning on warningemitter connecti
JoOkuma 42bdb18
jni minor comments
JoOkuma 90f80f9
Merge branch 'main' into napari-graph-2023
JoOkuma f04520f
testing deprecated property with property func
JoOkuma 81e9884
fixed bug by replacing instance method with class method
JoOkuma 6e97eb5
fixed deprecation warning event test
JoOkuma 3775280
improving nuclei segmentation graph example
JoOkuma d2036b0
replaced a few o private napari-graph class
JoOkuma 981bd70
Merge branch 'main' into napari-graph-2023
JoOkuma 3c9c33d
update docs
JoOkuma f68f4b3
add networkx support
JoOkuma 6b3ef25
Merge branch 'main' into napari-graph-2023
JoOkuma 6d8eb92
add since_version
JoOkuma bf509a8
using to_napari_graph API
JoOkuma 2e16e74
using to_napari_graph API
JoOkuma c907ce0
Merge branch 'main' into napari-graph-2023
JoOkuma 98adf82
improving graph nodes removal
JoOkuma 1f066bf
Merge branch 'main' into napari-graph-2023
JoOkuma 761c05e
fixed bug from merge with main
JoOkuma fd531c4
updating to new graph API
JoOkuma c747c74
Merge branch 'main' into napari-graph-2023
JoOkuma 41eb555
fixing magicgui tests
JoOkuma b1a3482
fixed viewer and types tests
JoOkuma 78cc0bc
fixing typing
JoOkuma 3012731
Merge branch 'main' into napari-graph-2023
JoOkuma 3f4cfd8
testing CI with numba>=0.57.0
JoOkuma 9cd8395
added removed napari-graph install from python=3.11 and made napari-g…
JoOkuma 0b289ee
downgranding numpy constraints
JoOkuma b7c1888
updated npe2 requirement
JoOkuma 29063c9
Merge branch 'napari-graph-2023' of github.com:JoOkuma/napari into na…
JoOkuma c225c80
Merge branch 'main' into napari-graph-2023
JoOkuma ba3beca
removed napari graph not optional
JoOkuma 6fa5c54
Apply suggestions from Juan's code review
JoOkuma 6adaa7d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 08f6f3a
rolling back numpy constaints downgrade
JoOkuma ed52d96
Merge branch 'napari-graph-2023' of github.com:JoOkuma/napari into na…
JoOkuma f4ea067
fixing typing
JoOkuma 1a7123f
fixed napari-graph numba warning
JoOkuma ad70173
Fixing 6016 errors
JoOkuma a580c0a
Merge branch 'main' into fix-6016
jni 6b576a4
updated requirements
JoOkuma b2321ae
Merge branch 'fix-6016' of github.com:JoOkuma/napari into fix-6016
JoOkuma e363e96
Merge branch 'main' into napari-graph-2023
JoOkuma 3731322
fix requirements
JoOkuma 715ae5d
Merge branch 'main' into fix-6016
JoOkuma f23afd2
Merge branch 'fix-6016' into napari-graph-2023
JoOkuma 0b39ce5
minor comments fix
JoOkuma cf1f40e
fixing czaki and jni comments
JoOkuma 540636f
Merge branch 'main' into napari-graph-2023
JoOkuma b34884f
fixed tests
JoOkuma 3b91999
Merge branch 'main' into napari-graph-2023
JoOkuma 998d9f9
Final merge fixes
jni 5cc814c
Only compute Delaunay graph in 2D
jni ff6ac5c
Add example of adding a networkx spatial graph directly
jni 1f94fe9
Merge branch 'main' into napari-graph-2023
JoOkuma 69ebbc4
fixing rolledback changes from 'border' -> 'edge' refactor
JoOkuma bef7d9e
Add networkx graph to graph layer test matrix
jni d608af6
Merge branch 'main' into napari-graph-2023
JoOkuma d466def
Merge branch 'main' into napari-graph-2023
JoOkuma ea2ac8c
converting networkx graph to napari-graph before testing
JoOkuma 5315af3
Merge branch 'main' into napari-graph-2023
JoOkuma f969d6c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6f9e718
fix add point bug
jamesyan-git b548030
add events to add/remove graph nodes
jamesyan-git b5c03fe
tidy up
jamesyan-git 7f2e917
consistent use of vertex indices
jamesyan-git 00dc63c
fix formatting
jamesyan-git 2848ebb
change vertex indices from slected to -1
jamesyan-git 7cb291d
Merge pull request #31 from jamesyan-git/fix_add
JoOkuma 8ac802d
Merge main
DragaDoncila 68ad317
pass through projection mode
DragaDoncila d055ceb
use indices instead of self.selected_data
jamesyan-git b30dc39
Something kinda working
DragaDoncila bbace5b
Remove spurious delete
DragaDoncila 4f158af
Fix count of added nodes
jamesyan-git 1901fd9
Merge branch 'napari-graph-2023' into fix-events
jamesyan-git bcabf32
more testing
jamesyan-git 535ceca
More test
jamesyan-git 458c338
fixt test
jamesyan-git ac460ee
Fixing tests after merge - tests passing
DragaDoncila 4235019
add test for removing nodes
jamesyan-git 6b80268
add remove_selected test
jamesyan-git b4ea210
clean up tests
jamesyan-git 43a3bbd
Add selected_data setting
jamesyan-git 9246384
address comments
jamesyan-git 76cb651
Merge pull request #32 from jamesyan-git/fix-events
JoOkuma a367dba
Merge branch 'napari-graph-2023' of https://github.com/jookuma/napari…
DragaDoncila ef6e1a6
Actually working thick slices
DragaDoncila 83755da
Merge main
DragaDoncila e03887a
Fix labels
DragaDoncila 451b87b
Merge branch 'main' into napari-graph-2023
DragaDoncila efd0408
Merge main and fix some typing
DragaDoncila 16b3a37
Fix tests and typing
DragaDoncila d8d8d21
More typing ignore
DragaDoncila e28e0c0
More typing fix
DragaDoncila 9791e34
More typing fix
DragaDoncila 758b2f5
Merge main...
b5b2472
More merging...?
34725fc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e1998eb
Bring back napari graph dep
fec6bbb
Fix points layer
05395f6
Bring back og example
c2ded23
Merge branch 'napari-graph-2023' of https://github.com/JoOkuma/napari…
bc60ce3
Fixing conflicts
DragaDoncila 6c21fc8
Fix points tests
DragaDoncila 31b5703
Use node attribute to create node
ClementCaporal 565934b
Rename _visual to node for GraphVisual
ClementCaporal 6369a31
Update points.py to allow VispyPointsLayer.node access
ClementCaporal 83ec8d5
Fix node point layer typing issue
ClementCaporal cebfffc
Fix graph node typing issue
ClementCaporal 2f348fc
Merge pull request #40 from ClementCaporal/patch-1
JoOkuma 5d5830a
fix typo
DragaDoncila File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
""" | ||
Add networkx graph | ||
================== | ||
|
||
Add a networkx graph directly to napari. This works as long as nodes | ||
have a "pos" attribute with the node coordinate. | ||
|
||
.. tags:: visualization-basic | ||
""" | ||
|
||
import networkx as nx | ||
|
||
import napari | ||
|
||
hex_grid = nx.hexagonal_lattice_graph(5, 5, with_positions=True) | ||
# below conversion not needed after napari/napari-graph#11 is released | ||
hex_grid_ints = nx.convert_node_labels_to_integers(hex_grid) | ||
|
||
viewer = napari.Viewer() | ||
layer = viewer.add_graph(hex_grid_ints, size=1) | ||
|
||
if __name__ == "__main__": | ||
napari.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
""" | ||
Add graph | ||
=================== | ||
|
||
Display a random undirected graph using the graph layer. | ||
|
||
.. tags:: visualization-basic | ||
""" | ||
|
||
import numpy as np | ||
import pandas as pd | ||
from napari_graph import UndirectedGraph | ||
|
||
import napari | ||
|
||
|
||
def build_graph(n_nodes: int, n_neighbors: int) -> UndirectedGraph: | ||
neighbors = np.random.randint(n_nodes, size=(n_nodes * n_neighbors)) | ||
edges = np.stack([np.repeat(np.arange(n_nodes), n_neighbors), neighbors], axis=1) | ||
|
||
nodes_df = pd.DataFrame( | ||
400 * np.random.uniform(size=(n_nodes, 4)), | ||
columns=["t", "z", "y", "x"], | ||
) | ||
graph = UndirectedGraph(edges=edges, coords=nodes_df) | ||
|
||
return graph | ||
|
||
|
||
graph = build_graph(n_nodes=1_000_000, n_neighbors=5) | ||
|
||
viewer = napari.Viewer() | ||
layer = viewer.add_graph(graph, out_of_slice_display=True) | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
napari.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
""" | ||
Nuclei Segmentation Graph | ||
=============== | ||
|
||
Creates a delaunay graph from maxima of cell nuclei. | ||
|
||
.. tags:: visualization-nD | ||
""" | ||
from itertools import combinations | ||
|
||
import numpy as np | ||
from napari_graph import UndirectedGraph | ||
from scipy.spatial import Delaunay | ||
from skimage import data, feature, filters | ||
|
||
import napari | ||
|
||
|
||
def delaunay_edges(points: np.ndarray) -> np.ndarray: | ||
delaunay = Delaunay(points) | ||
edges = set() | ||
for simplex in delaunay.simplices: | ||
# each simplex is represented as a list of four points. | ||
# we add all edges between the points to the edge list | ||
edges |= set(combinations(simplex, 2)) | ||
|
||
return np.asarray(list(edges)) | ||
|
||
|
||
cells = data.cells3d() | ||
|
||
nuclei = cells[:, 1] | ||
smooth = filters.gaussian(nuclei, sigma=10) | ||
nodes_coords = feature.peak_local_max(smooth) | ||
edges = delaunay_edges(nodes_coords[:, 1:]) | ||
graph = UndirectedGraph(edges, nodes_coords) | ||
viewer, image_layer = napari.imshow( | ||
cells, channel_axis=1, name=['membranes', 'nuclei'], ndisplay=3 | ||
) | ||
graph_layer = viewer.add_graph(graph) | ||
viewer.camera.angles = (10, -20, 130) | ||
|
||
if __name__ == '__main__': | ||
napari.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from napari._qt.layer_controls.qt_points_controls import QtPointsControls | ||
|
||
|
||
class QtGraphControls(QtPointsControls): | ||
pass | ||
JoOkuma marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should rename to
add_graph_networkx.py
to group together with other graph examples