From 8f7142f88877dc32310161dd7b0c1bfca16d53b3 Mon Sep 17 00:00:00 2001 From: sronilsson Date: Wed, 3 Jul 2024 15:39:25 -0400 Subject: [PATCH] network --- docs/_static/img/graph_flow.html | 164 +++++++++++++++++++++++++++ docs/_static/img/graph_katz.html | 164 +++++++++++++++++++++++++++ docs/_static/img/graph_pagerank.html | 164 +++++++++++++++++++++++++++ simba/mixins/image_mixin.py | 8 +- simba/mixins/network_mixin.py | 16 ++- simba/utils/read_write.py | 10 +- 6 files changed, 510 insertions(+), 16 deletions(-) create mode 100644 docs/_static/img/graph_flow.html create mode 100644 docs/_static/img/graph_katz.html create mode 100644 docs/_static/img/graph_pagerank.html diff --git a/docs/_static/img/graph_flow.html b/docs/_static/img/graph_flow.html new file mode 100644 index 000000000..e9ae4be05 --- /dev/null +++ b/docs/_static/img/graph_flow.html @@ -0,0 +1,164 @@ + + + + + + + + + +
+

+
+ + + + + + +
+

+
+ + + + + +
+ + +
+
+ + + + + + + \ No newline at end of file diff --git a/docs/_static/img/graph_katz.html b/docs/_static/img/graph_katz.html new file mode 100644 index 000000000..0acd1db31 --- /dev/null +++ b/docs/_static/img/graph_katz.html @@ -0,0 +1,164 @@ + + + + + + + + + +
+

+
+ + + + + + +
+

+
+ + + + + +
+ + +
+
+ + + + + + + \ No newline at end of file diff --git a/docs/_static/img/graph_pagerank.html b/docs/_static/img/graph_pagerank.html new file mode 100644 index 000000000..403ddb7f4 --- /dev/null +++ b/docs/_static/img/graph_pagerank.html @@ -0,0 +1,164 @@ + + + + + + + + + +
+

+
+ + + + + + +
+

+
+ + + + + +
+ + +
+
+ + + + + + + \ No newline at end of file diff --git a/simba/mixins/image_mixin.py b/simba/mixins/image_mixin.py index 273c7b0f9..a357ed14a 100644 --- a/simba/mixins/image_mixin.py +++ b/simba/mixins/image_mixin.py @@ -299,19 +299,19 @@ def canny_edge_detection( """ Apply Canny edge detection to the input image. """ - check_if_valid_img(source=f"{ImageMixin.img_moments.__name__}", data=img) + check_if_valid_img(source=f"{ImageMixin.canny_edge_detection.__name__}", data=img) check_int( - name=f"{ImageMixin.img_moments.__name__} threshold_1", + name=f"{ImageMixin.canny_edge_detection.__name__} threshold_1", value=threshold_1, min_value=1, ) check_int( - name=f"{ImageMixin.img_moments.__name__} threshold_2", + name=f"{ImageMixin.canny_edge_detection.__name__} threshold_2", value=threshold_2, min_value=1, ) check_int( - name=f"{ImageMixin.img_moments.__name__} aperture_size", + name=f"{ImageMixin.canny_edge_detection.__name__} aperture_size", value=aperture_size, min_value=1, ) diff --git a/simba/mixins/network_mixin.py b/simba/mixins/network_mixin.py index 861f94c75..1dfc4155e 100644 --- a/simba/mixins/network_mixin.py +++ b/simba/mixins/network_mixin.py @@ -89,11 +89,7 @@ def create_multigraph(data: Dict[Tuple[str, str], List[float]]) -> nx.MultiGraph >>> NetworkMixin().create_multigraph(data=data) """ - check_instance( - source=NetworkMixin.create_multigraph.__name__, - instance=data, - accepted_types=dict, - ) + check_instance(source=NetworkMixin.create_multigraph.__name__, instance=data, accepted_types=dict) results, dict_data, G = {}, [], nx.MultiGraph() for k, v in data.items(): check_instance( @@ -201,6 +197,10 @@ def graph_katz_centrality(graph: nx.Graph, weights: Optional[str] = "weight", al def graph_current_flow_closeness_centrality(graph: nx.Graph, weights: Optional[str] = "weight"): """ + + + + :example: >>> graph = NetworkMixin.create_graph(data={('Animal_1', 'Animal_2'): 1.0, ('Animal_1', 'Animal_3'): 0.2, ('Animal_2', 'Animal_3'): 0.5}) >>> NetworkMixin().graph_current_flow_closeness_centrality(graph=graph) @@ -249,7 +249,7 @@ def girvan_newman( instance=graph, accepted_types=nx.Graph, ) - if levels > G.number_of_nodes(): + if levels > graph.number_of_nodes(): raise CountError( msg=f"Number of nodes ({G.number_of_nodes()}) is less than numer of girvan newman levels ({levels}).", source=NetworkMixin.__class__.__name__, @@ -335,6 +335,9 @@ def visualize(graph: Union[nx.Graph, nx.MultiGraph], .. raw:: html :file: ../docs/_static/img/network_ex.html + .. raw:: html + :file: _static/img/network_ex.html + .. note:: Multi-networks created by ``simba.mixins.network_mixin.create_multigraph`` can be a little messy to look at. Instead, creates seperate objects and files with single edges from each time-point. @@ -383,6 +386,7 @@ def visualize(graph: Union[nx.Graph, nx.MultiGraph], if not multi_graph: network_graph = Network(f"{img_size[0]}px", f"{img_size[1]}px") network_graph.set_edge_smooth(smooth_type) + network_graph.force_atlas_2based() for node_cnt, node_name in enumerate(graph): if isinstance(node_size, dict): node_node_size = node_size[node_name] diff --git a/simba/utils/read_write.py b/simba/utils/read_write.py index 09281bc0c..14aca8421 100644 --- a/simba/utils/read_write.py +++ b/simba/utils/read_write.py @@ -761,12 +761,10 @@ def find_video_of_file(video_dir: Union[str, os.PathLike], return return_path -def find_files_of_filetypes_in_directory( - directory: str, - extensions: list, - raise_warning: Optional[bool] = True, - raise_error: Optional[bool] = False, -) -> List[str]: +def find_files_of_filetypes_in_directory(directory: str, + extensions: list, + raise_warning: Optional[bool] = True, + raise_error: Optional[bool] = False) -> List[str]: """ Find all files in a directory of specified extensions/types.