nettracer3d 0.7.3__py3-none-any.whl → 0.7.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of nettracer3d might be problematic. Click here for more details.
- nettracer3d/community_extractor.py +17 -39
- nettracer3d/modularity.py +41 -264
- nettracer3d/nettracer.py +31 -99
- nettracer3d/nettracer_gui.py +506 -271
- nettracer3d/network_analysis.py +0 -178
- nettracer3d/segmenter.py +84 -724
- nettracer3d/segmenter_GPU.py +1286 -0
- nettracer3d/simple_network.py +2 -150
- {nettracer3d-0.7.3.dist-info → nettracer3d-0.7.5.dist-info}/METADATA +8 -7
- nettracer3d-0.7.5.dist-info/RECORD +21 -0
- {nettracer3d-0.7.3.dist-info → nettracer3d-0.7.5.dist-info}/WHEEL +1 -1
- nettracer3d-0.7.3.dist-info/RECORD +0 -20
- {nettracer3d-0.7.3.dist-info → nettracer3d-0.7.5.dist-info}/entry_points.txt +0 -0
- {nettracer3d-0.7.3.dist-info → nettracer3d-0.7.5.dist-info}/licenses/LICENSE +0 -0
- {nettracer3d-0.7.3.dist-info → nettracer3d-0.7.5.dist-info}/top_level.txt +0 -0
nettracer3d/nettracer.py
CHANGED
|
@@ -2913,6 +2913,7 @@ class Network_3D:
|
|
|
2913
2913
|
|
|
2914
2914
|
if file_path is not None:
|
|
2915
2915
|
self._node_centroids = network_analysis.read_centroids_to_dict(file_path)
|
|
2916
|
+
self._node_centroids = self.clear_null(self._node_centroids)
|
|
2916
2917
|
print("Succesfully loaded node centroids")
|
|
2917
2918
|
return
|
|
2918
2919
|
|
|
@@ -2922,10 +2923,12 @@ class Network_3D:
|
|
|
2922
2923
|
if item == 'node_centroids.xlsx' or item == 'node_centroids.csv':
|
|
2923
2924
|
if directory is not None:
|
|
2924
2925
|
self._node_centroids = network_analysis.read_centroids_to_dict(f'{directory}/{item}')
|
|
2926
|
+
self._node_centroids = self.clear_null(self._node_centroids)
|
|
2925
2927
|
print("Succesfully loaded node centroids")
|
|
2926
2928
|
return
|
|
2927
2929
|
else:
|
|
2928
2930
|
self._node_centroids = network_analysis.read_centroids_to_dict(item)
|
|
2931
|
+
self._node_centroids = self.clear_null(self._node_centroids)
|
|
2929
2932
|
print("Succesfully loaded node centroids")
|
|
2930
2933
|
return
|
|
2931
2934
|
|
|
@@ -2941,6 +2944,7 @@ class Network_3D:
|
|
|
2941
2944
|
|
|
2942
2945
|
if file_path is not None:
|
|
2943
2946
|
self._node_identities = network_analysis.read_excel_to_singval_dict(file_path)
|
|
2947
|
+
self._node_identities = self.clear_null(self._node_identities)
|
|
2944
2948
|
print("Succesfully loaded node identities")
|
|
2945
2949
|
return
|
|
2946
2950
|
|
|
@@ -2950,10 +2954,12 @@ class Network_3D:
|
|
|
2950
2954
|
if item == 'node_identities.xlsx' or item == 'node_identities.csv':
|
|
2951
2955
|
if directory is not None:
|
|
2952
2956
|
self._node_identities = network_analysis.read_excel_to_singval_dict(f'{directory}/{item}')
|
|
2957
|
+
self._node_identities = self.clear_null(self._node_identities)
|
|
2953
2958
|
print("Succesfully loaded node identities")
|
|
2954
2959
|
return
|
|
2955
2960
|
else:
|
|
2956
2961
|
self._node_identities = network_analysis.read_excel_to_singval_dict(item)
|
|
2962
|
+
self._node_identities = self.clear_null(self._node_identities)
|
|
2957
2963
|
print("Succesfully loaded node identities")
|
|
2958
2964
|
return
|
|
2959
2965
|
|
|
@@ -2968,7 +2974,8 @@ class Network_3D:
|
|
|
2968
2974
|
"""
|
|
2969
2975
|
|
|
2970
2976
|
if file_path is not None:
|
|
2971
|
-
self.
|
|
2977
|
+
self._communities = network_analysis.read_excel_to_singval_dict(file_path)
|
|
2978
|
+
self._communities = self.clear_null(self._communities)
|
|
2972
2979
|
print("Succesfully loaded communities")
|
|
2973
2980
|
return
|
|
2974
2981
|
|
|
@@ -2978,15 +2985,23 @@ class Network_3D:
|
|
|
2978
2985
|
if item == 'node_communities.xlsx' or item == 'node_communities.csv':
|
|
2979
2986
|
if directory is not None:
|
|
2980
2987
|
self._communities = network_analysis.read_excel_to_singval_dict(f'{directory}/{item}')
|
|
2988
|
+
self._communities = self.clear_null(self._communities)
|
|
2981
2989
|
print("Succesfully loaded communities")
|
|
2982
2990
|
return
|
|
2983
2991
|
else:
|
|
2984
2992
|
self._communities = network_analysis.read_excel_to_singval_dict(item)
|
|
2993
|
+
self._communities = self.clear_null(self._communities)
|
|
2985
2994
|
print("Succesfully loaded communities")
|
|
2986
2995
|
return
|
|
2987
2996
|
|
|
2988
2997
|
print("Could not find communities. They must be in the specified directory and named 'node_communities.xlsx'")
|
|
2989
2998
|
|
|
2999
|
+
def clear_null(self, some_dict):
|
|
3000
|
+
|
|
3001
|
+
if some_dict == {}:
|
|
3002
|
+
some_dict = None
|
|
3003
|
+
return some_dict
|
|
3004
|
+
|
|
2990
3005
|
def load_edge_centroids(self, directory = None, file_path = None):
|
|
2991
3006
|
"""
|
|
2992
3007
|
Can be called on a Network_3D object to load a .xlsx into the edge_centroids property as a dictionary. It will look for a file called 'edge_centroids.xlsx' in the specified directory,
|
|
@@ -2997,6 +3012,7 @@ class Network_3D:
|
|
|
2997
3012
|
|
|
2998
3013
|
if file_path is not None:
|
|
2999
3014
|
self._edge_centroids = network_analysis.read_centroids_to_dict(file_path)
|
|
3015
|
+
self._edge_centroids = self.clear_null(self._edge_centroids)
|
|
3000
3016
|
print("Succesfully loaded edge centroids")
|
|
3001
3017
|
return
|
|
3002
3018
|
|
|
@@ -3006,10 +3022,12 @@ class Network_3D:
|
|
|
3006
3022
|
if item == 'edge_centroids.xlsx' or item == 'edge_centroids.csv':
|
|
3007
3023
|
if directory is not None:
|
|
3008
3024
|
self._edge_centroids = network_analysis.read_centroids_to_dict(f'{directory}/{item}')
|
|
3025
|
+
self._edge_centroids = self.clear_null(self._edge_centroids)
|
|
3009
3026
|
print("Succesfully loaded edge centroids")
|
|
3010
3027
|
return
|
|
3011
3028
|
else:
|
|
3012
3029
|
self._edge_centroids = network_analysis.read_centroids_to_dict(item)
|
|
3030
|
+
self._edge_centroids = self.clear_null(self._edge_centroids)
|
|
3013
3031
|
print("Succesfully loaded edge centroids")
|
|
3014
3032
|
return
|
|
3015
3033
|
|
|
@@ -3427,10 +3445,11 @@ class Network_3D:
|
|
|
3427
3445
|
self.calculate_search_region(search, GPU = GPU, fast_dil = fast_dil, GPU_downsample = GPU_downsample)
|
|
3428
3446
|
#self._nodes = None # I originally put this here to micromanage RAM a little bit (it writes it to disk so I wanted to purge it from mem briefly but now idt thats necessary and I'd rather give it flexibility when lacking write permissions)
|
|
3429
3447
|
search = None
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3448
|
+
if directory is not None:
|
|
3449
|
+
try:
|
|
3450
|
+
self.save_search_region(directory)
|
|
3451
|
+
except:
|
|
3452
|
+
pass
|
|
3434
3453
|
|
|
3435
3454
|
self.calculate_edges(edges, diledge = diledge, inners = inners, hash_inner_edges = hash_inners, search = search, remove_edgetrunk = remove_trunk, GPU = GPU, fast_dil = fast_dil, skeletonized = skeletonize)
|
|
3436
3455
|
del edges
|
|
@@ -3545,12 +3564,12 @@ class Network_3D:
|
|
|
3545
3564
|
|
|
3546
3565
|
#Some methods that may be useful:
|
|
3547
3566
|
|
|
3548
|
-
def community_partition(self, weighted = False, style = 0, dostats = True):
|
|
3567
|
+
def community_partition(self, weighted = False, style = 0, dostats = True, seed = None):
|
|
3549
3568
|
"""
|
|
3550
3569
|
Sets the communities attribute by splitting the network into communities
|
|
3551
3570
|
"""
|
|
3552
3571
|
|
|
3553
|
-
self._communities, self.normalized_weights, stats = modularity.community_partition(self._network_lists, weighted = weighted, style = style, dostats = dostats)
|
|
3572
|
+
self._communities, self.normalized_weights, stats = modularity.community_partition(self._network_lists, weighted = weighted, style = style, dostats = dostats, seed = seed)
|
|
3554
3573
|
|
|
3555
3574
|
return stats
|
|
3556
3575
|
|
|
@@ -4008,66 +4027,6 @@ class Network_3D:
|
|
|
4008
4027
|
self._communities, self.normalized_weights = modularity.show_communities_flex(self._network, self._network_lists, self.normalized_weights, geo_info = [self._node_centroids, self._nodes.shape], geometric = geometric, directory = directory, weighted = weighted, partition = partition, style = style)
|
|
4009
4028
|
|
|
4010
4029
|
|
|
4011
|
-
def show_communities(self, geometric = False, directory = None):
|
|
4012
|
-
"""
|
|
4013
|
-
Shows the network property, and some basic stats, as a graph where nodes are labelled by colors representing the community they belong to as determined by a label propogation algorithm. Does not support viewing edge weights.
|
|
4014
|
-
:param geoemtric: (Optional - Val = False; boolean). If False, node placement in the graph will be random. If True, nodes
|
|
4015
|
-
will be placed in their actual spatial location (from the original node segmentation) along the XY plane, using node_centroids.
|
|
4016
|
-
The node size will then represent the nodes Z location, with smaller nodes representing a larger Z value. If False, nodes will be placed randomly.
|
|
4017
|
-
:param directory: (Optional – Val = None; string). An optional string path to a directory to save the network plot image to. If not set, nothing will be saved.
|
|
4018
|
-
"""
|
|
4019
|
-
|
|
4020
|
-
if not geometric:
|
|
4021
|
-
|
|
4022
|
-
simple_network.show_community_network(self._network_lists, directory = directory)
|
|
4023
|
-
|
|
4024
|
-
else:
|
|
4025
|
-
simple_network.show_community_network(self._network_lists, geometric = True, geo_info = [self._node_centroids, self._nodes.shape], directory = directory)
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
def show_communities_louvain(self, geometric = False, directory = None):
|
|
4029
|
-
"""
|
|
4030
|
-
Shows the network property as a graph, and some basic stats, where nodes are labelled by colors representing the community they belong to as determined by a louvain algorithm. Supports viewing edge weights.
|
|
4031
|
-
:param geoemtric: (Optional - Val = False; boolean). If False, node placement in the graph will be random. If True, nodes
|
|
4032
|
-
will be placed in their actual spatial location (from the original node segmentation) along the XY plane, using node_centroids.
|
|
4033
|
-
The node size will then represent the nodes Z location, with smaller nodes representing a larger Z value. If False, nodes will be placed randomly.
|
|
4034
|
-
"""
|
|
4035
|
-
|
|
4036
|
-
if not geometric:
|
|
4037
|
-
|
|
4038
|
-
modularity.louvain_mod(self._network_lists, directory = directory)
|
|
4039
|
-
else:
|
|
4040
|
-
modularity.louvain_mod(self._network_lists, geometric = True, geo_info = [self._node_centroids, self._nodes.shape], directory = directory)
|
|
4041
|
-
|
|
4042
|
-
def louvain_modularity(self, solo_mod = False):
|
|
4043
|
-
"""
|
|
4044
|
-
Shows some basic stats of the network, including modularity (essentially strength of community structure), using a louvain algorithm that accounts for edge weights.
|
|
4045
|
-
:param solo_mod: (Optional - Val = False; boolean). If True, will return a singular modularity for the network, taking into
|
|
4046
|
-
account all disconnected components as pieces of a network. If False, will return the modularity of each singular disconnected component of the network with the number of nodes in the component as a key
|
|
4047
|
-
and the modularity of the component as a value.
|
|
4048
|
-
:returns: A dictionary containing the modularity for each disconnected component in the network, key-indexed by that component's node count, or a single modularity value accounting for all disconnected components of the network if the solo_mod param is True.
|
|
4049
|
-
"""
|
|
4050
|
-
|
|
4051
|
-
if not solo_mod:
|
|
4052
|
-
mod = modularity._louvain_mod(self._network)
|
|
4053
|
-
else:
|
|
4054
|
-
mod = modularity._louvain_mod_solo(self._network)
|
|
4055
|
-
|
|
4056
|
-
return mod
|
|
4057
|
-
|
|
4058
|
-
def modularity(self, solo_mod = False):
|
|
4059
|
-
"""
|
|
4060
|
-
Shows some basic stats of the network, including modularity (essentially strength of community structure), using a label propogation algorithm that does not consider edge weights.
|
|
4061
|
-
:param solo_mod: (Optional - Val = False; boolean). If True, will return a singular modularity for the network, taking into
|
|
4062
|
-
account all disconnected components as pieces of a network. If False, will return the modularity of each singular disconnected component of the network with the number of nodes in the component as a key
|
|
4063
|
-
and the modularity of the component as a value.
|
|
4064
|
-
:returns: A dictionary containing the modularity for each disconnected component in the network, key-indexed by that component's node count, or a single modularity value accounting for all disconnected components of the network if the solo_mod param is True.
|
|
4065
|
-
"""
|
|
4066
|
-
|
|
4067
|
-
modularity = simple_network.modularity(self._network, solo_mod = solo_mod)
|
|
4068
|
-
|
|
4069
|
-
return modularity
|
|
4070
|
-
|
|
4071
4030
|
|
|
4072
4031
|
def show_identity_network(self, geometric = False, directory = None):
|
|
4073
4032
|
"""
|
|
@@ -4130,7 +4089,7 @@ class Network_3D:
|
|
|
4130
4089
|
return G
|
|
4131
4090
|
|
|
4132
4091
|
|
|
4133
|
-
def isolate_mothers(self, directory = None, down_factor = 1,
|
|
4092
|
+
def isolate_mothers(self, directory = None, down_factor = 1, ret_nodes = False, called = False):
|
|
4134
4093
|
|
|
4135
4094
|
"""
|
|
4136
4095
|
Method to isolate 'mother' nodes of a network (in this case, this means nodes that exist betwixt communities), also generating overlays that relate this information to the 3D structure.
|
|
@@ -4144,7 +4103,7 @@ class Network_3D:
|
|
|
4144
4103
|
"""
|
|
4145
4104
|
|
|
4146
4105
|
if ret_nodes:
|
|
4147
|
-
mothers = community_extractor.extract_mothers(None, self._network,
|
|
4106
|
+
mothers = community_extractor.extract_mothers(None, self._network, self._communities, ret_nodes = True, called = called)
|
|
4148
4107
|
return mothers
|
|
4149
4108
|
else:
|
|
4150
4109
|
|
|
@@ -4153,9 +4112,9 @@ class Network_3D:
|
|
|
4153
4112
|
for item in self._node_centroids:
|
|
4154
4113
|
centroids[item] = np.round((self._node_centroids[item]) / down_factor)
|
|
4155
4114
|
nodes = downsample(self._nodes, down_factor)
|
|
4156
|
-
mothers, overlay = community_extractor.extract_mothers(nodes, self._network, directory = directory, centroid_dic = centroids,
|
|
4115
|
+
mothers, overlay = community_extractor.extract_mothers(nodes, self._network, self._communities, directory = directory, centroid_dic = centroids, called = called)
|
|
4157
4116
|
else:
|
|
4158
|
-
mothers, overlay = community_extractor.extract_mothers(self._nodes, self._network, centroid_dic = self._node_centroids, directory = directory,
|
|
4117
|
+
mothers, overlay = community_extractor.extract_mothers(self._nodes, self._network, self._communities, centroid_dic = self._node_centroids, directory = directory, called = called)
|
|
4159
4118
|
return mothers, overlay
|
|
4160
4119
|
|
|
4161
4120
|
|
|
@@ -4167,7 +4126,7 @@ class Network_3D:
|
|
|
4167
4126
|
|
|
4168
4127
|
hub_img = np.isin(self._nodes, hubs) * self._nodes
|
|
4169
4128
|
else:
|
|
4170
|
-
|
|
4129
|
+
hub_img = None
|
|
4171
4130
|
|
|
4172
4131
|
return hubs, hub_img
|
|
4173
4132
|
|
|
@@ -4229,33 +4188,6 @@ class Network_3D:
|
|
|
4229
4188
|
|
|
4230
4189
|
|
|
4231
4190
|
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
def extract_communities_louvain(self, directory = None, down_factor = 1, color_code = True):
|
|
4235
|
-
"""
|
|
4236
|
-
Method to generate overlays that relate community detection in a network to the 3D structure.
|
|
4237
|
-
Overlays include a grayscale image where nodes are assigned a grayscale value corresponding to their community, a numerical index where numbers are drawn at nodes corresponding to their community, and a
|
|
4238
|
-
color coded overlay where a nodes color corresponds to its community. Community detection will be done with louvain algorithm.
|
|
4239
|
-
These will be saved to the active directory if none is specified.
|
|
4240
|
-
:param directory: (Optional - Val = None; string). A path to a directory to save outputs.
|
|
4241
|
-
:param down_factor: (Optional - Val = 1; int). A factor to downsample nodes by while drawing overlays. Note this option REQUIRES node_centroids to already be set.
|
|
4242
|
-
:param color code: (Optional - Val = True; boolean). If set to False, the color-coded overlay will not be drawn.
|
|
4243
|
-
:returns: A dictionary where nodes are grouped by community.
|
|
4244
|
-
"""
|
|
4245
|
-
|
|
4246
|
-
if down_factor > 1:
|
|
4247
|
-
centroids = self._node_centroids.copy()
|
|
4248
|
-
for item in self._node_centroids:
|
|
4249
|
-
centroids[item] = np.round((self._node_centroids[item]) / down_factor)
|
|
4250
|
-
nodes = downsample(self._nodes, down_factor)
|
|
4251
|
-
partition = network_analysis.community_partition(nodes, self._network_lists, directory = directory, centroids = centroids, color_code = color_code)
|
|
4252
|
-
|
|
4253
|
-
else:
|
|
4254
|
-
partition = network_analysis.community_partition(self._nodes, self._network_lists, directory = directory, centroids = self._node_centroids, color_code = color_code)
|
|
4255
|
-
|
|
4256
|
-
return partition
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
4191
|
#Methods related to analysis:
|
|
4260
4192
|
|
|
4261
4193
|
def radial_distribution(self, radial_distance, directory = None):
|