Skip to content

Commit

Permalink
Update to latest nxviz API changes; fix makefile (#233)
Browse files Browse the repository at this point in the history
* apparently tabs are better than spaces; fix makefile

* updates to use latest nxviz API

* update notebooks to match nxviz API

* using head() with a zero length dataframe throws a formatting error in docs

* ignore nxviz API update warnings for docs
  • Loading branch information
MridulS authored Jul 11, 2021
1 parent 0159830 commit 1864bb7
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 69 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ conda:
set -ex
conda env create -f environment.yml
conda activate nams
python setup.py develop
python setup.py develop
python checkenv.py

venv:
Expand All @@ -30,7 +30,7 @@ venv:
virtualenv network
source network/bin/activate && pip install -r requirements.txt
echo "Run 'source network/bin/activate' to begin"
python setup.py develop
python setup.py develop
python checkenv.py

check:
Expand Down
2 changes: 1 addition & 1 deletion nams/solutions/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def plot_path_with_neighbors(G, n1, n2):

g = G.subgraph(nodes)
nv.arc(
g, sort_by="order", node_color_by="order", edge_aes_kwargs={"alpha_scale": 0.5}
g, sort_by="order", node_color_by="order", edge_enc_kwargs={"alpha_scale": 0.5}
)
for n in path:
highlights.arc_node(g, n, sort_by="order")
Expand Down
6 changes: 4 additions & 2 deletions notebooks/01-introduction/03-viz.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"%load_ext autoreload\n",
"%autoreload 2\n",
"%matplotlib inline\n",
"%config InlineBackend.figure_format = 'retina'"
"%config InlineBackend.figure_format = 'retina'\n",
"import warnings\n",
"warnings.filterwarnings('ignore')"
]
},
{
Expand Down Expand Up @@ -365,7 +367,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
"version": "3.8.10"
}
},
"nbformat": 4,
Expand Down
6 changes: 4 additions & 2 deletions notebooks/02-algorithms/01-hubs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"%load_ext autoreload\n",
"%autoreload 2\n",
"%matplotlib inline\n",
"%config InlineBackend.figure_format = 'retina'"
"%config InlineBackend.figure_format = 'retina'\n",
"import warnings\n",
"warnings.filterwarnings('ignore')"
]
},
{
Expand Down Expand Up @@ -614,7 +616,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
"version": "3.8.10"
}
},
"nbformat": 4,
Expand Down
6 changes: 4 additions & 2 deletions notebooks/02-algorithms/02-paths.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"%load_ext autoreload\n",
"%autoreload 2\n",
"%matplotlib inline\n",
"%config InlineBackend.figure_format = 'retina'"
"%config InlineBackend.figure_format = 'retina'\n",
"import warnings\n",
"warnings.filterwarnings('ignore')"
]
},
{
Expand Down Expand Up @@ -479,7 +481,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
"version": "3.8.10"
}
},
"nbformat": 4,
Expand Down
13 changes: 4 additions & 9 deletions notebooks/02-algorithms/03-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"%load_ext autoreload\n",
"%autoreload 2\n",
"%matplotlib inline\n",
"%config InlineBackend.figure_format = 'retina'"
"%config InlineBackend.figure_format = 'retina'\n",
"import warnings\n",
"warnings.filterwarnings('ignore')"
]
},
{
Expand Down Expand Up @@ -718,13 +720,6 @@
"\n",
"print(inspect.getsource(structures))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -743,7 +738,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
"version": "3.8.10"
}
},
"nbformat": 4,
Expand Down
6 changes: 4 additions & 2 deletions notebooks/03-practical/01-io.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"%load_ext autoreload\n",
"%autoreload 2\n",
"%matplotlib inline\n",
"%config InlineBackend.figure_format = 'retina'"
"%config InlineBackend.figure_format = 'retina'\n",
"import warnings\n",
"warnings.filterwarnings('ignore')"
]
},
{
Expand Down Expand Up @@ -657,7 +659,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
"version": "3.8.10"
}
},
"nbformat": 4,
Expand Down
8 changes: 5 additions & 3 deletions notebooks/04-advanced/01-bipartite.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"%load_ext autoreload\n",
"%autoreload 2\n",
"%matplotlib inline\n",
"%config InlineBackend.figure_format = 'retina'"
"%config InlineBackend.figure_format = 'retina'\n",
"import warnings\n",
"warnings.filterwarnings('ignore')"
]
},
{
Expand Down Expand Up @@ -141,7 +143,7 @@
"import matplotlib.pyplot as plt\n",
"\n",
"fig, ax = plt.subplots(figsize=(7, 7))\n",
"nv.circos(G, sort_by=\"degree\", group_by=\"bipartite\", node_color_by=\"bipartite\", node_aes_kwargs={\"size_scale\": 3})"
"nv.circos(G, sort_by=\"degree\", group_by=\"bipartite\", node_color_by=\"bipartite\", node_enc_kwargs={\"size_scale\": 3})"
]
},
{
Expand Down Expand Up @@ -617,7 +619,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
"version": "3.8.10"
}
},
"nbformat": 4,
Expand Down
6 changes: 4 additions & 2 deletions notebooks/04-advanced/02-linalg.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"%load_ext autoreload\n",
"%autoreload 2\n",
"%matplotlib inline\n",
"%config InlineBackend.figure_format = 'retina'"
"%config InlineBackend.figure_format = 'retina'\n",
"import warnings\n",
"warnings.filterwarnings('ignore')"
]
},
{
Expand Down Expand Up @@ -923,7 +925,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
"version": "3.8.10"
}
},
"nbformat": 4,
Expand Down
8 changes: 5 additions & 3 deletions notebooks/04-advanced/03-stats.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"%load_ext autoreload\n",
"%autoreload 2\n",
"%matplotlib inline\n",
"%config InlineBackend.figure_format = 'retina'"
"%config InlineBackend.figure_format = 'retina'\n",
"import warnings\n",
"warnings.filterwarnings('ignore')"
]
},
{
Expand Down Expand Up @@ -398,7 +400,7 @@
"import nxviz as nv\n",
"from nxviz import annotate\n",
"\n",
"nv.circos(G, sort_by=\"degree\", node_color_by=\"degree\", node_aes_kwargs={\"size_scale\": 10})\n",
"nv.circos(G, sort_by=\"degree\", node_color_by=\"degree\", node_enc_kwargs={\"size_scale\": 10})\n",
"annotate.node_colormapping(G, color_by=\"degree\")"
]
},
Expand Down Expand Up @@ -660,7 +662,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
"version": "3.8.10"
}
},
"nbformat": 4,
Expand Down
6 changes: 4 additions & 2 deletions notebooks/05-casestudies/01-gameofthrones.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"import networkx as nx\n",
"import community\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
"import matplotlib.pyplot as plt\n",
"import warnings\n",
"warnings.filterwarnings('ignore')"
]
},
{
Expand Down Expand Up @@ -752,7 +754,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
"version": "3.8.10"
}
},
"nbformat": 4,
Expand Down
60 changes: 21 additions & 39 deletions notebooks/05-casestudies/02-airport.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"import networkx as nx\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np"
"import numpy as np\n",
"import warnings\n",
"warnings.filterwarnings('ignore')"
]
},
{
Expand Down Expand Up @@ -338,7 +340,7 @@
"lat_long\n",
"wanted_nodes = list(pass_2015_network.nodes())\n",
"us_airports = lat_long.query(\"CODE3 in @wanted_nodes\").drop_duplicates(subset=[\"CODE3\"]).set_index(\"CODE3\")\n",
"us_airports\n",
"us_airports.head()\n",
"# us_airports"
]
},
Expand Down Expand Up @@ -385,7 +387,7 @@
"import nxviz as nv\n",
"from nxviz import nodes, plots, edges\n",
"plt.figure(figsize=(20, 9))\n",
"pos = nodes.geo(g, aesthetics_kwargs={\"size_scale\": 1})\n",
"pos = nodes.geo(g, encodings_kwargs={\"size_scale\": 1})\n",
"plots.aspect_equal()\n",
"plots.despine()"
]
Expand All @@ -408,8 +410,8 @@
"import nxviz as nv\n",
"from nxviz import nodes, plots, edges, annotate\n",
"plt.figure(figsize=(20, 9))\n",
"pos = nodes.geo(g, color_by=\"degree\", aesthetics_kwargs={\"size_scale\": 1})\n",
"edges.line(g, pos, aesthetics_kwargs={\"alpha_scale\": 0.1})\n",
"pos = nodes.geo(g, color_by=\"degree\", encodings_kwargs={\"size_scale\": 1})\n",
"edges.line(g, pos, encodings_kwargs={\"alpha_scale\": 0.1})\n",
"annotate.node_colormapping(g, color_by=\"degree\")\n",
"plots.aspect_equal()\n",
"plots.despine()"
Expand Down Expand Up @@ -519,8 +521,9 @@
"G.add_edges_from([(1, 2), (3, 2),\n",
" (4, 2), (5, 2),\n",
" (6, 2), (7, 2)])\n",
"# nx.draw_spring(G, with_labels=True)\n",
"nv.circos(G, node_aes_kwargs={\"size_scale\": 0.3})"
"nx.draw_circular(G, with_labels=True)\n",
"\n",
"# nv.circos(G, node_enc_kwargs={\"size_scale\": 0.3})"
]
},
{
Expand Down Expand Up @@ -559,8 +562,8 @@
"outputs": [],
"source": [
"G.add_edge(5, 6)\n",
"nv.circos(G, node_aes_kwargs={\"size_scale\": 0.3})\n",
"# nx.draw_spring(G, with_labels=True)"
"# nv.circos(G, node_enc_kwargs={\"size_scale\": 0.3})\n",
"nx.draw_circular(G, with_labels=True)"
]
},
{
Expand Down Expand Up @@ -590,7 +593,7 @@
"outputs": [],
"source": [
"G.add_edge(2, 8)\n",
"nv.circos(G, node_aes_kwargs={\"size_scale\": 0.3})"
"nx.draw_circular(G, with_labels=True)"
]
},
{
Expand Down Expand Up @@ -919,9 +922,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The airports 'SSB' and 'SPB' are codes for Seaplanes airports and they have flights to each other so it makes sense that they aren't connected to the larger network of airports.\n",
"The airports `SSB` and `SPB` are codes for Seaplanes airports and they have flights to each other so it makes sense that they aren't connected to the larger network of airports.\n",
"\n",
"The airport is even more weird as it is in a component in itself, i.e there is a flight from AIK to AIK. After investigating further it just seems like an anomaly in this dataset."
"The airport is even more weird as it is in a component in itself, i.e there is a flight from `AIK` to `AIK`. After investigating further it just seems like an anomaly in this dataset."
]
},
{
Expand Down Expand Up @@ -1134,31 +1137,17 @@
},
"outputs": [],
"source": [
"BCE_DEST_2015 = pass_air_data[\n",
" (pass_air_data['YEAR'] == 2015) & \n",
" (pass_air_data['DEST'] == 'BCE')]\n",
"BCE_DEST_2015.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"BCE_ORI_2015 = pass_air_data[\n",
" (pass_air_data['YEAR'] == 2015) & \n",
" (pass_air_data['ORIGIN'] == 'BCE')]\n",
"BCE_ORI_2015.head()"
"bce_2015 = (pass_air_data\n",
" .query('YEAR == 2015')\n",
" .query(\"ORIGIN == 'BCE' or DEST == 'BCE'\"))\n",
"bce_2015"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As we can see above you can fly into 'BCE' but can't fly out, weird indeed. These airport are small airports with one off schedules flights. For the purposes of our analyses we can ignore such airports."
"As we can see above you can fly into `BCE` but can't fly out, weird indeed. These airport are small airports with one off schedules flights. For the purposes of our analyses we can ignore such airports."
]
},
{
Expand Down Expand Up @@ -1412,13 +1401,6 @@
"\n",
"print(inspect.getsource(airport))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -1440,7 +1422,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
"version": "3.8.10"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 1864bb7

Please sign in to comment.