Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if nx.is_connected(self.G) is False:
print('Warning: Graph is fragmented...\n')
[self.G, _] = prune_disconnected(self.G)
elif self.prune == 2:
print('Pruning to retain only most important nodes...')
[self.G, _] = most_important(self.G)
else:
print('Graph is connected...')
# Get corresponding matrix
self.in_mat = np.array(nx.to_numpy_matrix(self.G))
# Saved pruned
if (self.prune != 0) and (self.prune is not None):
final_mat_path = "%s%s" % (self.est_path.split('.npy')[0], '_pruned_mat')
utils.save_mat(self.in_mat, final_mat_path, self.out_fmt)
print("%s%s" % ('Source File: ', final_mat_path))
else:
print("%s%s" % ('Source File: ', self.est_path))
return self.in_mat, final_mat_path
if nx.is_connected(self.G) is False:
print('Warning: Graph is fragmented...\n')
[self.G, _] = prune_disconnected(self.G)
elif self.prune == 2:
print('Pruning to retain only most important nodes...')
[self.G, _] = most_important(self.G)
else:
print('Graph is connected...')
# Get corresponding matrix
self.in_mat = np.array(nx.to_numpy_matrix(self.G))
# Saved pruned
if (self.prune != 0) and (self.prune is not None):
final_mat_path = "%s%s" % (self.est_path.split('.npy')[0], '_pruned_mat')
utils.save_mat(self.in_mat, final_mat_path, self.out_fmt)
print("%s%s" % ('Source File: ', final_mat_path))
else:
print("%s%s" % ('Source File: ', self.est_path))
return self.in_mat, final_mat_path
and prob (probabilistic).
max_length : int
Maximum fiber length threshold in mm to restrict tracking.
"""
import gc
from pynets.core import utils, thresholding
thr_perc = 100 * float(thr)
if parc is True:
node_size = 'parc'
if np.count_nonzero(conn_matrix) == 0:
raise ValueError('ERROR: Raw connectivity matrix contains only zeros.')
# Save unthresholded
utils.save_mat(conn_matrix, utils.create_raw_path_diff(ID, network, conn_model, roi, dir_path, node_size,
target_samples, track_type, parc, directget, max_length))
if min_span_tree is True:
print('Using local thresholding option with the Minimum Spanning Tree (MST)...\n')
if dens_thresh is False:
print('Ignoring -dt flag since local density thresholding is not currently supported.')
thr_type = 'MST_thr'
edge_threshold = "%s%s" % (str(np.abs(1 - thr_perc)), '%')
[conn_matrix_thr, coords, labels] = thresholding.local_thresholding_prop(conn_matrix, coords, labels, thr)
elif disp_filt is True:
thr_type = 'DISP_alpha'
edge_threshold = "%s%s" % (str(np.abs(1 - thr_perc)), '%')
G1 = thresholding.disparity_filter(nx.from_numpy_array(conn_matrix))
# G2 = nx.Graph([(u, v, d) for u, v, d in G1.edges(data=True) if d['alpha'] < thr])
print('Computing edge disparity significance with alpha = %s' % thr)
print('Filtered graph: nodes = %s, edges = %s' % (G1.number_of_nodes(), G1.number_of_edges()))
print("%s%.2f%s" % ('\nThresholding proportionally at: ', thr_perc, '% ...\n'))
conn_matrix_thr = thresholding.threshold_proportional(conn_matrix, float(thr))
else:
thr_type = 'dens'
edge_threshold = None
print("%s%.2f%s" % ('\nThresholding to achieve density of: ', thr_perc, '% ...\n'))
conn_matrix_thr = thresholding.density_thresholding(conn_matrix, float(thr))
if not nx.is_connected(nx.from_numpy_matrix(conn_matrix_thr)):
print('Warning: Fragmented graph')
# Save thresholded mat
est_path = utils.create_est_path_func(ID, network, conn_model, thr, roi, dir_path, node_size, smooth, c_boot,
thr_type, hpass, parc)
utils.save_mat(conn_matrix_thr, est_path)
gc.collect()
return conn_matrix_thr, edge_threshold, est_path, thr, node_size, network, conn_model, roi, smooth, prune, ID, dir_path, atlas, uatlas, labels, coords, c_boot, norm, binary, hpass
unweighted graph.
hpass : float
High-pass filter values (Hz) to apply to node-extracted time-series.
"""
import gc
from pynets.core import utils, thresholding
thr_perc = 100 * float(thr)
if parc is True:
node_size = 'parc'
if np.count_nonzero(conn_matrix) == 0:
raise ValueError('ERROR: Raw connectivity matrix contains only zeros.')
# Save unthresholded
utils.save_mat(conn_matrix, utils.create_raw_path_func(ID, network, conn_model, roi, dir_path, node_size, smooth,
c_boot, hpass, parc))
if min_span_tree is True:
print('Using local thresholding option with the Minimum Spanning Tree (MST)...\n')
if dens_thresh is False:
print('Ignoring -dt flag since local density thresholding is not currently supported.')
thr_type = 'MST_thr'
edge_threshold = "%s%s" % (str(np.abs(1 - thr_perc)), '%')
[conn_matrix_thr, coords, labels] = thresholding.local_thresholding_prop(conn_matrix, coords, labels, thr)
elif disp_filt is True:
thr_type = 'DISP_alpha'
edge_threshold = "%s%s" % (str(np.abs(1 - thr_perc)), '%')
G1 = thresholding.disparity_filter(nx.from_numpy_array(conn_matrix))
# G2 = nx.Graph([(u, v, d) for u, v, d in G1.edges(data=True) if d['alpha'] < thr])
print('Computing edge disparity significance with alpha = %s' % thr)
print('Filtered graph: nodes = %s, edges = %s' % (G1.number_of_nodes(), G1.number_of_edges()))
print("%s%.2f%s" % ('\nThresholding proportionally at: ', thr_perc, '% ...\n'))
conn_matrix_thr = thresholding.threshold_proportional(conn_matrix, float(thr))
else:
thr_type = 'dens'
edge_threshold = "%s%s" % (str(np.abs(1 - thr_perc)), '%')
print("%s%.2f%s" % ('\nThresholding to achieve density of: ', thr_perc, '% ...\n'))
conn_matrix_thr = thresholding.density_thresholding(conn_matrix, float(thr))
if not nx.is_connected(nx.from_numpy_matrix(conn_matrix_thr)):
print('Warning: Fragmented graph')
# Save thresholded mat
est_path = utils.create_est_path_diff(ID, network, conn_model, thr, roi, dir_path, node_size, target_samples,
track_type, thr_type, parc, directget, max_length)
utils.save_mat(conn_matrix_thr, est_path)
gc.collect()
return conn_matrix_thr, edge_threshold, est_path, thr, node_size, network, conn_model, roi, prune, ID, dir_path, atlas, uatlas, labels, coords, norm, binary, target_samples, track_type, atlas_mni, streams, directget, max_length