Skip to content

Commit

Permalink
Merge pull request #60 from wiheto/develop
Browse files Browse the repository at this point in the history
0.3.0
  • Loading branch information
wiheto authored Jun 13, 2023
2 parents 0a9ec9e + 60a66ff commit 7eb3ac1
Show file tree
Hide file tree
Showing 137 changed files with 6,407 additions and 359 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Changelog

## [0.3.0] - in development

### Added

- Changelog added. (wiheto)
- Preliminary BIDS operations that generate edge df from BIDS layout `edges_from_bids()` (wiheto)
- Connectivity matrix as view option (wiheto)
- Rotation of connectivity matrix (wiheto)
- cm_order for connectivity matrix (wiheto)
- Dual colours for positive and negative edges (wiheto)
- Allow dual colors for positive and negative edges (wiheto)
- Some gallery examples (plot_dmn, connectivity matrix) (wiheto)

### Update
- Updated README with network neuroscience reference (wiheto)
- Removed matplotlib deprecated `matplotlib.cm.get_cmap` for `matplotlib.colormaps` (wiheto)
- Rasterization for glass brains (and all template/cms) for faster svg rendering (wiheto)
- Example data is now packaged in ./netplotbrain/example_data to be included in package (wiheto)

### Fixed
- Renaming "legend_tick_fontsize" and "legend_title_fontsize" to be more consistent (wiheto)
- Renaming "highlightlevel" to "highlight_level" to be more consistent (wiheto)
- Correcting some kwarg names in documentation (wiheto)
- A bug with spring layout and node_color when only subset of nodes plotted (wiheto)
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include examples/*
include netplotbrain/example_data/*.tsv
recursive-include netplotbrain/example_data/bids_test/ *
include netplotbrain/profiles/*.json
include netplotbrain/templatesettings/*.json
13 changes: 10 additions & 3 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ edges_df | pd.DataFrame | Allows for passing additional edge information if edge
edge_cmap | str | Matplotlib colormap for node coloring when node_color points to a dataframe. |
edge_alpha | float | Transparency of edges (default: 1).
edgecolumnames | list | Edge columns names in edge dataframe. Default is i and j (specifying nodes).
edge_color | matplotlib coloring | Can be string (default 'black') or list of 3D/4D colors for each edge.
edge_color | matplotlib coloring | Can be string (default 'black') or list of 3D/4D colors for each edge. Can also be a dictionary with keys positive and negative to denote two different colors for positive and negative edges.
edge_weights | str | String that specifies column in edge dataframe that contains weights. If numpy array is edge input, can be True (default) to specify edge weights.
edge_highlightbehaviour | str | Alternatives "both" or "any" or None. Governs edge dimming when highlight_nodes is on. If both, then highlights only edges between highlighted nodes. If any, then only edges connecting any of the nodes are highlighted.
edge_widthscale | int, float | Scale the width of all edges by a factor (default: 1).
Expand All @@ -61,9 +61,16 @@ template_glass_maxalpha | float | Default is 0.01. To make the smokey effect the

### HIGHLIGHTING KWARGS

highlightlevel | float | Intensity of the highlighting (opposite of alpha). Controls both nods and edges together. Value between 0 and 1, if 1, non-highlighted nodes are fully transparent. If 0, non-highlighted nodes are same alpha level as highlighted nodes. Default 0.85.
highlight_level | float | Intensity of the highlighting (opposite of alpha). Controls both nods and edges together. Value between 0 and 1, if 1, non-highlighted nodes are fully transparent. If 0, non-highlighted nodes are same alpha level as highlighted nodes. Default 0.85.

See also nodehighlight* and edgehighlight* kwargs.
See also node_highlight* and edge_highlight* kwargs.

## Connectviity matrix kwargs

| Argument | Type | Description |
| --- | --- | --- |
cm_order | Str | Specify which variable to group and order nodes in connectivity matrix by. Default is "auto". Auto entails that if node_color is a column in the data and if cm_order is unspecified use node_color column. Otherwise if None will plot in list order.
cm_rotate | Bool | If True, rotates the connectivity matrix 45 degrees. Default True.

### LEGENDKWARGS

Expand Down
4 changes: 4 additions & 0 deletions docs/gallery.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@

[![](./gallery/figures/rows1.png)](./two_rows/)

### [Highlight a network](./two_rows/)

[![](./gallery/figures/plot_dmn.png)](./plot_dmn/)


## Integrations

Expand Down
Binary file added docs/gallery/figures/plot_dmn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions docs/gallery/highlevel_size.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "cf30fa87",
"metadata": {},
"source": [
" \n",
"# Node properties: size\n",
"\n",
"Netplotbrain allows for specifying different figure properties by only specifyign the column name.\n",
"\n",
"Below we demonstrate how node_size can change based on different columns in the nodes dataframe.\n",
"\n",
"The key lines of code here are when:\n",
"\n",
"`node_size='centrality_measure1'`\n",
"\n",
"and\n",
"\n",
"`node_size='centrality_measure2'`\n",
"\n",
"These columns could be called anything such as \"module_degree_zscore\" or \"efficiency\""
]
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "-all",
"main_language": "python",
"notebook_metadata_filter": "-all"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
102 changes: 102 additions & 0 deletions docs/gallery/highlight_roi.ipynb

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions docs/gallery/highlight_roi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# # Highlight Parcels
#
# One possble use of netplotbrain is to highlight a seed region used. Here we will highlight two regions of interest.

# +
# Load imports
import netplotbrain
import pandas as pd
import numpy as np

# Get 100 node atlas from templateflow
node_dict = {'atlas': 'Schaefer2018',
'desc': '100Parcels7Networks',
'extension': '.nii.gz',
'resolution': 1}

# pyton index of atlas rois.
# this will start at 0 but atlas starts at 1.
# So below select node 15 and 66 in atlas.
seeds = [14, 65]

# Create dataframe of 100 rois
nodeinfo = np.zeros(100)
nodeinfo[seeds] = 1

node_color = ['gray'] * 100
node_color[seeds[0]] = 'cornflowerblue'
node_color[seeds[1]] = 'salmon'
nodes_df = pd.DataFrame({'seed': nodeinfo, 'color': node_color})


fig, _ = netplotbrain.plot(template = 'MNI152NLin2009cAsym',
nodes = node_dict,
nodes_df = nodes_df,
node_type = 'parcels',
view = 'preset-3',
node_color = 'color',
highlight_nodes = 'seed',
highlighlevel = 1,
node_alpha = 0.4,
save_name='/home/xthowi/scratch/sham.png',
figdpi=300)
24 changes: 12 additions & 12 deletions docs/gallery/infant.ipynb

Large diffs are not rendered by default.

70 changes: 35 additions & 35 deletions docs/gallery/nbs.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/gallery/nbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ def generate_group_cm(nodes, subjects, community_size, community_str, scale=0.25
view=['LSR'],
title='NBS integration',
node_type='circles',
highlightlevel=0.5)
highlight_level=0.5)

# + [markdown]
"""
The amount of highlight is governed by the highlightlevel argument.
The amount of highlight is governed by the highlight_level argument.
Increasing it highlights the significant edges more.
"""
133 changes: 55 additions & 78 deletions docs/gallery/node_cmap.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/gallery/node_cmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
# See [example about colors for different way the color columns in the dataframe can be specified](https://www.netplotbrain.org/gallery/specifying_node_color/)
#
# There are two different ways to specify colormaps. This holds for both nodes (node_cmap) edges (edge_cmap)
#
#
# The first way entails that you specify a matplotlib colormap (e.g. Set1, Inferno, (see options [here](https://matplotlib.org/stable/tutorials/colors/colormaps.html))
#
#
# The second way is to provide a list of matplotlib colors to create your own colormap (see named color options [here](https://matplotlib.org/stable/gallery/color/named_colors.html))
#
# This notebook will shows an example of each of these. We will use 100 ROIs from the Schaefer atlas and color the 7 Yeo networks
Expand Down
61 changes: 29 additions & 32 deletions docs/gallery/node_styles.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "9bede4b0",
"id": "8e6ed0ff",
"metadata": {},
"source": [
" \n",
Expand All @@ -17,13 +17,13 @@
{
"cell_type": "code",
"execution_count": 1,
"id": "4057c752",
"id": "5e1ec81d",
"metadata": {
"execution": {
"iopub.execute_input": "2022-11-30T20:31:52.276511Z",
"iopub.status.busy": "2022-11-30T20:31:52.276110Z",
"iopub.status.idle": "2022-11-30T20:31:55.776855Z",
"shell.execute_reply": "2022-11-30T20:31:55.776256Z"
"iopub.execute_input": "2023-06-13T13:17:07.104406Z",
"iopub.status.busy": "2023-06-13T13:17:07.103988Z",
"iopub.status.idle": "2023-06-13T13:17:14.858186Z",
"shell.execute_reply": "2023-06-13T13:17:14.857190Z"
}
},
"outputs": [],
Expand All @@ -36,13 +36,13 @@
{
"cell_type": "code",
"execution_count": 2,
"id": "996d6191",
"id": "b788f413",
"metadata": {
"execution": {
"iopub.execute_input": "2022-11-30T20:31:55.779394Z",
"iopub.status.busy": "2022-11-30T20:31:55.779192Z",
"iopub.status.idle": "2022-11-30T20:31:55.790470Z",
"shell.execute_reply": "2022-11-30T20:31:55.790066Z"
"iopub.execute_input": "2023-06-13T13:17:14.863126Z",
"iopub.status.busy": "2023-06-13T13:17:14.862797Z",
"iopub.status.idle": "2023-06-13T13:17:14.889825Z",
"shell.execute_reply": "2023-06-13T13:17:14.888442Z"
}
},
"outputs": [
Expand All @@ -63,21 +63,20 @@
{
"cell_type": "code",
"execution_count": 3,
"id": "b9744a4c",
"id": "07b3b71c",
"metadata": {
"execution": {
"iopub.execute_input": "2022-11-30T20:31:55.792359Z",
"iopub.status.busy": "2022-11-30T20:31:55.792228Z",
"iopub.status.idle": "2022-11-30T20:32:01.172438Z",
"shell.execute_reply": "2022-11-30T20:32:01.171980Z"
"iopub.execute_input": "2023-06-13T13:17:14.894600Z",
"iopub.status.busy": "2023-06-13T13:17:14.894284Z",
"iopub.status.idle": "2023-06-13T13:17:24.425742Z",
"shell.execute_reply": "2023-06-13T13:17:24.424831Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"(<Figure size 432x288 with 1 Axes>,\n",
" [<Axes3DSubplot: title={'center': 'Circles'}>])"
"(<Figure size 432x288 with 1 Axes>, [<Axes3D: title={'center': 'Circles'}>])"
]
},
"execution_count": 3,
Expand Down Expand Up @@ -106,21 +105,20 @@
{
"cell_type": "code",
"execution_count": 4,
"id": "57047813",
"id": "b6a3fdf9",
"metadata": {
"execution": {
"iopub.execute_input": "2022-11-30T20:32:01.174659Z",
"iopub.status.busy": "2022-11-30T20:32:01.174502Z",
"iopub.status.idle": "2022-11-30T20:32:06.880092Z",
"shell.execute_reply": "2022-11-30T20:32:06.879719Z"
"iopub.execute_input": "2023-06-13T13:17:24.430107Z",
"iopub.status.busy": "2023-06-13T13:17:24.429752Z",
"iopub.status.idle": "2023-06-13T13:17:36.029369Z",
"shell.execute_reply": "2023-06-13T13:17:36.028719Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"(<Figure size 432x288 with 2 Axes>,\n",
" [<Axes3DSubplot: title={'center': 'Spheres'}>])"
"(<Figure size 432x288 with 2 Axes>, [<Axes3D: title={'center': 'Spheres'}>])"
]
},
"execution_count": 4,
Expand Down Expand Up @@ -148,21 +146,20 @@
{
"cell_type": "code",
"execution_count": 5,
"id": "9f41ada0",
"id": "4b819641",
"metadata": {
"execution": {
"iopub.execute_input": "2022-11-30T20:32:06.881811Z",
"iopub.status.busy": "2022-11-30T20:32:06.881699Z",
"iopub.status.idle": "2022-11-30T20:32:14.208952Z",
"shell.execute_reply": "2022-11-30T20:32:14.208530Z"
"iopub.execute_input": "2023-06-13T13:17:36.033350Z",
"iopub.status.busy": "2023-06-13T13:17:36.033132Z",
"iopub.status.idle": "2023-06-13T13:17:52.479938Z",
"shell.execute_reply": "2023-06-13T13:17:52.479320Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"(<Figure size 432x288 with 3 Axes>,\n",
" [<Axes3DSubplot: title={'center': 'Parcels'}>])"
"(<Figure size 432x288 with 3 Axes>, [<Axes3D: title={'center': 'Parcels'}>])"
]
},
"execution_count": 5,
Expand Down
45 changes: 45 additions & 0 deletions docs/gallery/plot_connectivitymatrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#
# # Visualizing a single network
#
# [Open interactive notebook in Binder](https://mybinder.org/v2/gh/wiheto/netplotbrain/main?filepath=docs/gallery/plot_connectivitymatrix.ipynb)
#
# ## Goal
# Here we are plot the nodes on the brain from the Schaefer atlas and plot the connectivity matrix next to it
#

# +
# Import packages
import templateflow.api as tf
import netplotbrain
import pandas as pd

# +
# Get template information
template = 'MNI152NLin2009cAsym'
atlas = 'Schaefer2018'
atlas_desc = '100Parcels7Networks'

# +
# Get and load the tsv file (information about the atlas)
atlas_path = tf.get(atlas=atlas,
template=template,
desc=atlas_desc,
extension='.tsv')
atlas_df = pd.read_csv(atlas_path, sep='\t')
atlas_df.head()

#+
# Create a column called "network" by extracting the relevant information from the column "name"
atlas_df['network'] = list(map(lambda x: x.split('_')[2], atlas_df.name.values))
atlas_df.head()

# +
# Nodes in connectivity will automatically be organized by node_color, unless cm_order is specified.
netplotbrain.plot(nodes={'atlas': atlas,
'desc': atlas_desc,
'resolution': 1},
view='LSc',
node_type='parcels',
nodes_df=atlas_df,
node_color='network',
node_cmap='Set2')
Loading

0 comments on commit 7eb3ac1

Please sign in to comment.