Skip to content
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

Review of functions in nilearn_plotting.py #112

Open
wingedRuslan opened this issue May 30, 2019 · 0 comments
Open

Review of functions in nilearn_plotting.py #112

wingedRuslan opened this issue May 30, 2019 · 0 comments
Assignees

Comments

@wingedRuslan
Copy link
Collaborator

wingedRuslan commented May 30, 2019

While looking through the code in nilearn_plotting.py I've noted which parts of the code do and which parts of the code do not run. Opened this issue to share my findings.

  1. graph_to_nilearn_array runs but would be better to have tests for this function.

  2. plot_connectome_with_nilearn does not run.

  • Besides having tiny typos (while calling graph_to_nilearn_array the parameters passed have different names), the execution of the function leads to the following error.
Error - Only length-1 arrays can be converted to Python scalars
TypeError                                 Traceback (most recent call last)
<ipython-input-17-3468803bff2b> in <module>()
----> 1 plot_connectome_with_nilearn(G)

~/anaconda3/lib/python3.6/site-packages/scona/nilearn_plotting.py in plot_connectome_with_nilearn(G, node_colour_att, node_colour, node_size_att, node_size, edge_attribute, edge_cmap, edge_vmin, edge_vmax, output_file, display_mode, figure, axes, title, annotate, black_bg, alpha, edge_kwargs, node_kwargs, colorbar)
     88         display_mode=display_mode, figure=figure, axes=axes, title=title,
     89         annotate=annotate, black_bg=black_bg, alpha=alpha,
---> 90         edge_kwargs=edge_kwargs, node_kwargs=node_kwargs, colorbar=colorbar)
     91 
     92 

~/anaconda3/lib/python3.6/site-packages/nilearn/plotting/img_plotting.py in plot_connectome(adjacency_matrix, node_coords, node_color, node_size, edge_cmap, edge_vmin, edge_vmax, edge_threshold, output_file, display_mode, figure, axes, title, annotate, black_bg, alpha, edge_kwargs, node_kwargs, colorbar)
   1263                       edge_threshold=edge_threshold,
   1264                       edge_kwargs=edge_kwargs, node_kwargs=node_kwargs,
-> 1265                       colorbar=colorbar)
   1266 
   1267     if output_file is not None:

~/anaconda3/lib/python3.6/site-packages/nilearn/plotting/displays.py in add_graph(self, adjacency_matrix, node_coords, node_color, node_size, edge_cmap, edge_vmin, edge_vmax, edge_threshold, edge_kwargs, node_kwargs, colorbar)
   1389                 ax._add_lines(line_coords, adjacency_matrix_values, edge_cmap,
   1390                               vmin=edge_vmin, vmax=edge_vmax,
-> 1391                               **edge_kwargs)
   1392             # To obtain the brain left view, we simply invert the x axis
   1393             if ax.direction == 'l':

~/anaconda3/lib/python3.6/site-packages/nilearn/plotting/displays.py in _add_lines(self, line_coords, line_values, cmap, vmin, vmax, **kwargs)
    420             this_kwargs.update(kwargs)
    421             xdata, ydata = start_end_point_2d.T
--> 422             line = lines.Line2D(xdata, ydata, **this_kwargs)
    423             self.ax.add_line(line)
    424 

~/anaconda3/lib/python3.6/site-packages/matplotlib/lines.py in __init__(self, xdata, ydata, linewidth, linestyle, color, marker, markersize, markeredgewidth, markeredgecolor, markerfacecolor, markerfacecoloralt, fillstyle, antialiased, dash_capstyle, solid_capstyle, dash_joinstyle, solid_joinstyle, pickradius, drawstyle, markevery, **kwargs)
    396         self.set_linestyle(linestyle)
    397         self.set_drawstyle(drawstyle)
--> 398         self.set_linewidth(linewidth)
    399 
    400         self._color = None

~/anaconda3/lib/python3.6/site-packages/matplotlib/lines.py in set_linewidth(self, w)
   1004         ACCEPTS: float value in points
   1005         """
-> 1006         w = float(w)
   1007 
   1008         if self._linewidth != w:

~/anaconda3/lib/python3.6/site-packages/numpy/ma/core.py in __float__(self)
   4294         """
   4295         if self.size > 1:
-> 4296             raise TypeError("Only length-1 arrays can be converted "
   4297                             "to Python scalars")
   4298         elif self._mask:

TypeError: Only length-1 arrays can be converted to Python scalars

  1. view_connectome_with_nilearn works fine. But while running the following error appears:
Error - iopub_data_rate_limit
IOPub data rate exceeded.
The notebook server will temporarily stop sending output
to the client in order to avoid crashing it.
To change this limit, set the config variable
`--NotebookApp.iopub_data_rate_limit`.

This is a known issue with jupyter notebook - iopub rate limits are too low by default, for visualization-heavy projects. To solve this a user should change jupyter's config variable iopub_data_rate_limit. One possible solution is to run the notebook with the following command (changing the parameter to arbitrary big number):
jupyter notebook --NotebookApp.iopub_data_rate_limit=10000000
After running a notebook as stated above, the function is successfully executed and produces a nice figure.

  1. view_markers_with_nilearn runs and everything is fine.

In order to run the above-mentioned functions, I have used this code from available tutorials to make the required input argument - BrainNetwork Graph:

import numpy as np
import networkx as nx
import scona as scn
import scona.datasets as datasets

# Read in sample data from the NSPN WhitakerVertes PNAS 2016 paper.
df, names, covars, centroids = datasets.NSPN_WhitakerVertes_PNAS2016.import_data()

# calculate residuals of the matrix df for the columns of names
df_res = scn.create_residuals_df(df, names)

# create a correlation matrix over the columns of df_res
M = scn.create_corrmat(df_res, method='pearson')

# Initialise a weighted graph G from the correlation matrix M
G = scn.BrainNetwork(network=M, parcellation=names, centroids=centroids)

For successfully executed functions I have created a jupyter notebook to demonstrate the outputs.

@wingedRuslan wingedRuslan self-assigned this Jun 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant