Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_autofix(x, thr, cp):
x[1][1] = np.inf
x[2][1] = np.nan
s = thresholding.autofix(x)
assert (np.nan not in s) and (np.inf not in s)
self.conn_model = conn_model
self.est_path = est_path
self.prune = prune
self.norm = norm
self.out_fmt = out_fmt
self.in_mat = None
self._est_path_fmt = "%s%s" % ('.', self.est_path.split('.')[-1])
# Load and threshold matrix
if self._est_path_fmt == '.txt':
self.in_mat_raw = np.array(np.genfromtxt(self.est_path))
else:
self.in_mat_raw = np.array(np.load(self.est_path))
# De-diagnal and remove nan's and inf's, ensure edge weights are positive
self.in_mat = np.array(np.abs(np.array(thresholding.autofix(self.in_mat_raw))))
# Load numpy matrix as networkx graph
self.G = nx.from_numpy_matrix(self.in_mat)
self.conn_model = conn_model
self.est_path = est_path
self.prune = prune
self.norm = norm
self.out_fmt = out_fmt
self.in_mat = None
self._est_path_fmt = "%s%s" % ('.', self.est_path.split('.')[-1])
# Load and threshold matrix
if self._est_path_fmt == '.txt':
self.in_mat_raw = np.array(np.genfromtxt(self.est_path))
else:
self.in_mat_raw = np.array(np.load(self.est_path))
# De-diagnal and remove nan's and inf's, ensure edge weights are positive
self.in_mat = np.array(np.abs(np.array(thresholding.autofix(self.in_mat_raw))))
# Load numpy matrix as networkx graph
self.G = nx.from_numpy_matrix(self.in_mat)
else:
# Save coords to pickle
coord_path = "%s%s" % (namer_dir, '/coords_plotting.pkl')
with open(coord_path, 'wb') as f:
pickle.dump(coords, f, protocol=2)
# Save labels to pickle
labels_path = "%s%s" % (namer_dir, '/labelnames_plotting.pkl')
with open(labels_path, 'wb') as f:
pickle.dump(labels, f, protocol=2)
connectome = niplot.plot_connectome(np.zeros(shape=(1, 1)), [(0, 0, 0)], node_size=0.0001, black_bg=True)
connectome.add_overlay(ch2better_loc, alpha=0.45, cmap=plt.cm.gray)
#connectome.add_overlay(ch2better_loc, alpha=0.35, cmap=plt.cm.gray)
conn_matrix = np.array(np.array(thresholding.autofix(conn_matrix)))
[z_min, z_max] = -np.abs(conn_matrix).max(), np.abs(conn_matrix).max()
if node_size == 'parc':
node_size_plot = int(6)
else:
node_size_plot = int(node_size)
if len(coords) != conn_matrix.shape[0]:
raise RuntimeWarning('\nWARNING: Number of coordinates does not match conn_matrix dimensions. If you are '
'using disparity filtering, try relaxing the α threshold.')
else:
color_theme = 'Blues'
#color_theme = 'Greens'
#color_theme = 'Reds'
node_color = 'auto'
connectome.add_graph(conn_matrix, coords, edge_threshold=edge_threshold, edge_cmap=color_theme,
edge_vmax=float(z_max), edge_vmin=float(z_min), node_size=node_size_plot,
node_color='auto')
pickle.dump(labels, f, protocol=2)
else:
# Save coords to pickle
coord_path = "%s%s" % (namer_dir, '/coords_plotting.pkl')
with open(coord_path, 'wb') as f:
pickle.dump(coords, f, protocol=2)
# Save labels to pickle
labels_path = "%s%s" % (namer_dir, '/labelnames_plotting.pkl')
with open(labels_path, 'wb') as f:
pickle.dump(labels, f, protocol=2)
connectome = niplot.plot_connectome(np.zeros(shape=(1, 1)), [(0, 0, 0)], node_size=0.0001, black_bg=True)
connectome.add_overlay(ch2better_loc, alpha=0.45, cmap=plt.cm.gray)
#connectome.add_overlay(ch2better_loc, alpha=0.35, cmap=plt.cm.gray)
conn_matrix = np.array(np.array(thresholding.autofix(conn_matrix)))
[z_min, z_max] = -np.abs(conn_matrix).max(), np.abs(conn_matrix).max()
if node_size == 'parc':
node_size_plot = int(6)
else:
node_size_plot = int(node_size)
if len(coords) != conn_matrix.shape[0]:
raise RuntimeWarning('\nWARNING: Number of coordinates does not match conn_matrix dimensions.')
else:
norm = colors.Normalize(vmin=-1, vmax=1)
clust_pal = sns.color_palette("Blues_r", conn_matrix.shape[0])
clust_colors = colors.to_rgba_array(clust_pal)
fa_path = dir_path + '/../reg_dmri/dmri_tmp/DSN/Warped.nii.gz'
if os.path.isfile(fa_path):
connectome.add_overlay(img=fa_path,
threshold=0.01, alpha=0.25, cmap=plt.cm.copper)