Skip to content

Commit fdac184

Browse files
authored
Merge pull request #5 from gjbex/development
Additions
2 parents 0f5301c + f00573b commit fdac184

18 files changed

+3268
-19
lines changed

environment.yml

+3
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ dependencies:
77
- folium
88
- geopandas
99
- holoviews
10+
- ipywidgets
1011
- jupyter
1112
- jupyterlab
1213
- matplotlib
1314
- networkx
15+
- nodejs
1416
- pandas
1517
- python=3.7
1618
- scipy
1719
- seaborn
1820
- shapely
1921
- sqlalchemy
22+
- xarray
2023
- xlrd

python_for_data_science_linux64_conda_specs.txt

+21-18
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ https://repo.anaconda.com/pkgs/main/linux-64/_libgcc_mutex-0.1-main.conda
66
https://repo.anaconda.com/pkgs/main/linux-64/blas-1.0-mkl.conda
77
https://repo.anaconda.com/pkgs/main/linux-64/ca-certificates-2019.11.27-0.tar.bz2
88
https://repo.anaconda.com/pkgs/main/linux-64/intel-openmp-2019.4-243.conda
9+
https://repo.anaconda.com/pkgs/main/linux-64/ld_impl_linux-64-2.33.1-h53a641e_7.conda
910
https://repo.anaconda.com/pkgs/main/linux-64/libgfortran-ng-7.3.0-hdf63c60_0.conda
1011
https://repo.anaconda.com/pkgs/main/linux-64/libstdcxx-ng-9.1.0-hdf63c60_0.conda
1112
https://repo.anaconda.com/pkgs/main/linux-64/poppler-data-0.4.9-0.conda
@@ -20,19 +21,20 @@ https://repo.anaconda.com/pkgs/main/linux-64/gmp-6.1.2-h6c8ec71_1.conda
2021
https://repo.anaconda.com/pkgs/main/linux-64/icu-58.2-h9c2bf20_1.conda
2122
https://repo.anaconda.com/pkgs/main/linux-64/jpeg-9b-h024ee3a_2.conda
2223
https://repo.anaconda.com/pkgs/main/linux-64/json-c-0.13.1-h1bed415_0.conda
23-
https://repo.continuum.io/pkgs/main/linux-64/libffi-3.2.1-hd88cf55_4.tar.bz2
24+
https://repo.anaconda.com/pkgs/main/linux-64/libffi-3.2.1-hd88cf55_4.conda
2425
https://repo.anaconda.com/pkgs/main/linux-64/libsodium-1.0.16-h1bed415_0.conda
2526
https://repo.anaconda.com/pkgs/main/linux-64/libspatialindex-1.9.3-he6710b0_0.tar.bz2
2627
https://repo.anaconda.com/pkgs/main/linux-64/libuuid-1.0.3-h1bed415_2.conda
2728
https://repo.anaconda.com/pkgs/main/linux-64/libxcb-1.13-h1bed415_1.conda
2829
https://repo.anaconda.com/pkgs/main/linux-64/lz4-c-1.8.1.2-h14c3975_0.conda
2930
https://repo.anaconda.com/pkgs/main/linux-64/ncurses-6.1-he6710b0_1.conda
31+
https://repo.anaconda.com/pkgs/main/linux-64/nodejs-10.13.0-he6710b0_0.conda
3032
https://repo.anaconda.com/pkgs/main/linux-64/openssl-1.1.1d-h7b6447c_3.tar.bz2
3133
https://repo.anaconda.com/pkgs/main/linux-64/pcre-8.43-he6710b0_0.conda
3234
https://repo.anaconda.com/pkgs/main/linux-64/pixman-0.38.0-h7b6447c_0.conda
3335
https://repo.anaconda.com/pkgs/main/linux-64/tbb-2018.0.5-h6bb024c_0.conda
3436
https://repo.anaconda.com/pkgs/main/linux-64/xz-5.2.4-h14c3975_4.conda
35-
https://repo.continuum.io/pkgs/main/linux-64/yaml-0.1.7-had09818_2.tar.bz2
37+
https://repo.anaconda.com/pkgs/main/linux-64/yaml-0.1.7-had09818_2.conda
3638
https://repo.anaconda.com/pkgs/main/linux-64/zlib-1.2.11-h7b6447c_3.conda
3739
https://repo.anaconda.com/pkgs/main/linux-64/glib-2.63.1-h5a9c865_0.tar.bz2
3840
https://repo.anaconda.com/pkgs/main/linux-64/hdf4-4.2.13-h3ca952b_2.conda
@@ -62,8 +64,8 @@ https://repo.anaconda.com/pkgs/main/linux-64/libcurl-7.67.0-h20c2e04_0.tar.bz2
6264
https://repo.anaconda.com/pkgs/main/linux-64/libpq-11.2-h20c2e04_0.conda
6365
https://repo.anaconda.com/pkgs/main/linux-64/openjpeg-2.3.0-h05c96fa_1.conda
6466
https://repo.anaconda.com/pkgs/main/linux-64/proj-6.2.1-haa6030c_0.conda
65-
https://repo.anaconda.com/pkgs/main/linux-64/python-3.7.5-h0371630_0.conda
66-
https://repo.anaconda.com/pkgs/main/linux-64/asn1crypto-1.2.0-py37_0.tar.bz2
67+
https://repo.anaconda.com/pkgs/main/linux-64/python-3.7.6-h0371630_2.conda
68+
https://repo.anaconda.com/pkgs/main/linux-64/asn1crypto-1.3.0-py37_0.conda
6769
https://repo.anaconda.com/pkgs/main/noarch/attrs-19.3.0-py_0.tar.bz2
6870
https://repo.anaconda.com/pkgs/main/linux-64/backcall-0.1.0-py37_0.conda
6971
https://repo.anaconda.com/pkgs/main/linux-64/cairo-1.14.12-h8948797_3.conda
@@ -93,7 +95,7 @@ https://repo.anaconda.com/pkgs/main/linux-64/postgresql-11.2-h20c2e04_0.conda
9395
https://repo.anaconda.com/pkgs/main/noarch/prometheus_client-0.7.1-py_0.tar.bz2
9496
https://repo.anaconda.com/pkgs/main/linux-64/ptyprocess-0.6.0-py37_0.conda
9597
https://repo.anaconda.com/pkgs/main/linux-64/pycparser-2.19-py37_0.conda
96-
https://repo.anaconda.com/pkgs/main/noarch/pyparsing-2.4.5-py_0.tar.bz2
98+
https://repo.anaconda.com/pkgs/main/noarch/pyparsing-2.4.6-py_0.conda
9799
https://repo.anaconda.com/pkgs/main/linux-64/pyproj-2.4.1-py37h2ea87da_0.conda
98100
https://repo.anaconda.com/pkgs/main/linux-64/pysocks-1.7.1-py37_0.tar.bz2
99101
https://repo.anaconda.com/pkgs/main/noarch/pytz-2019.3-py_0.tar.bz2
@@ -105,31 +107,31 @@ https://repo.anaconda.com/pkgs/main/linux-64/send2trash-1.5.0-py37_0.conda
105107
https://repo.anaconda.com/pkgs/main/linux-64/sip-4.19.8-py37hf484d3e_0.conda
106108
https://repo.anaconda.com/pkgs/main/linux-64/six-1.13.0-py37_0.tar.bz2
107109
https://repo.anaconda.com/pkgs/main/linux-64/soupsieve-1.9.5-py37_0.tar.bz2
108-
https://repo.anaconda.com/pkgs/main/linux-64/sqlalchemy-1.3.11-py37h7b6447c_0.tar.bz2
110+
https://repo.anaconda.com/pkgs/main/linux-64/sqlalchemy-1.3.12-py37h7b6447c_0.conda
109111
https://repo.anaconda.com/pkgs/main/noarch/testpath-0.4.4-py_0.tar.bz2
110112
https://repo.anaconda.com/pkgs/main/noarch/toolz-0.10.0-py_0.tar.bz2
111113
https://repo.anaconda.com/pkgs/main/linux-64/tornado-6.0.3-py37h7b6447c_0.conda
112114
https://repo.anaconda.com/pkgs/main/linux-64/wcwidth-0.1.7-py37_0.conda
113115
https://repo.anaconda.com/pkgs/main/linux-64/webencodings-0.5.1-py37_1.conda
114116
https://repo.anaconda.com/pkgs/main/linux-64/xlrd-1.2.0-py37_0.conda
115-
https://repo.anaconda.com/pkgs/main/linux-64/beautifulsoup4-4.8.1-py37_0.tar.bz2
117+
https://repo.anaconda.com/pkgs/main/linux-64/beautifulsoup4-4.8.2-py37_0.conda
116118
https://repo.anaconda.com/pkgs/main/linux-64/cffi-1.13.2-py37h2e261b9_0.tar.bz2
117119
https://repo.anaconda.com/pkgs/main/noarch/click-plugins-1.1.1-py_0.tar.bz2
118120
https://repo.anaconda.com/pkgs/main/linux-64/cligj-0.5.0-py37_0.conda
119121
https://repo.anaconda.com/pkgs/main/linux-64/cycler-0.10.0-py37_0.conda
120-
https://repo.anaconda.com/pkgs/main/linux-64/jedi-0.15.1-py37_0.conda
122+
https://repo.anaconda.com/pkgs/main/linux-64/jedi-0.15.2-py37_0.conda
121123
https://repo.anaconda.com/pkgs/main/linux-64/libdap4-3.19.1-h6ec2957_0.conda
122124
https://repo.anaconda.com/pkgs/main/linux-64/libnetcdf-4.6.1-h11d0813_2.conda
123125
https://repo.anaconda.com/pkgs/main/linux-64/mkl-service-2.3.0-py37he904b0f_0.conda
124-
https://repo.anaconda.com/pkgs/main/noarch/packaging-19.2-py_0.tar.bz2
126+
https://repo.anaconda.com/pkgs/main/noarch/packaging-20.0-py_0.conda
125127
https://repo.anaconda.com/pkgs/main/linux-64/pexpect-4.7.0-py37_0.conda
126-
https://repo.anaconda.com/pkgs/main/linux-64/pillow-6.2.1-py37h34e0f95_0.tar.bz2
128+
https://repo.anaconda.com/pkgs/main/linux-64/pillow-7.0.0-py37hb39fc2d_0.conda
127129
https://repo.anaconda.com/pkgs/main/linux-64/poppler-0.65.0-h581218d_1.conda
128130
https://repo.anaconda.com/pkgs/main/linux-64/pyqt-5.9.2-py37h05f1152_2.conda
129131
https://repo.anaconda.com/pkgs/main/linux-64/pyrsistent-0.15.6-py37h7b6447c_0.tar.bz2
130132
https://repo.anaconda.com/pkgs/main/noarch/python-dateutil-2.8.1-py_0.tar.bz2
131133
https://repo.anaconda.com/pkgs/main/noarch/pyviz_comms-0.7.2-py_0.tar.bz2
132-
https://repo.anaconda.com/pkgs/main/linux-64/setuptools-42.0.2-py37_0.tar.bz2
134+
https://repo.anaconda.com/pkgs/main/linux-64/setuptools-44.0.0-py37_0.conda
133135
https://repo.anaconda.com/pkgs/main/linux-64/terminado-0.8.3-py37_0.tar.bz2
134136
https://repo.anaconda.com/pkgs/main/linux-64/tiledb-1.6.3-h1fb8f14_0.conda
135137
https://repo.anaconda.com/pkgs/main/linux-64/traitlets-4.3.3-py37_0.tar.bz2
@@ -142,7 +144,7 @@ https://repo.anaconda.com/pkgs/main/linux-64/jupyter_core-4.6.1-py37_0.tar.bz2
142144
https://repo.anaconda.com/pkgs/main/linux-64/libgdal-3.0.2-h27ab9cc_0.conda
143145
https://repo.anaconda.com/pkgs/main/noarch/munch-2.5.0-py_0.tar.bz2
144146
https://repo.anaconda.com/pkgs/main/noarch/networkx-2.4-py_0.tar.bz2
145-
https://repo.anaconda.com/pkgs/main/linux-64/numpy-base-1.17.4-py37hde5b4d6_0.conda
147+
https://repo.anaconda.com/pkgs/main/linux-64/numpy-base-1.18.1-py37hde5b4d6_0.conda
146148
https://repo.anaconda.com/pkgs/main/noarch/pygments-2.5.2-py_0.tar.bz2
147149
https://repo.anaconda.com/pkgs/main/linux-64/wheel-0.33.6-py37_0.tar.bz2
148150
https://conda.anaconda.org/conda-forge/noarch/branca-0.3.1-py_0.tar.bz2
@@ -151,34 +153,35 @@ https://repo.anaconda.com/pkgs/main/linux-64/jupyter_client-5.3.4-py37_0.tar.bz2
151153
https://repo.anaconda.com/pkgs/main/linux-64/pip-19.3.1-py37_0.tar.bz2
152154
https://repo.anaconda.com/pkgs/main/noarch/prompt_toolkit-2.0.10-py_0.tar.bz2
153155
https://repo.anaconda.com/pkgs/main/linux-64/pyopenssl-19.1.0-py37_0.tar.bz2
154-
https://repo.anaconda.com/pkgs/main/linux-64/ipython-7.10.2-py37h39e3cac_0.conda
156+
https://repo.anaconda.com/pkgs/main/linux-64/ipython-7.11.1-py37h39e3cac_0.conda
155157
https://repo.anaconda.com/pkgs/main/linux-64/nbformat-4.4.0-py37_0.conda
156158
https://repo.anaconda.com/pkgs/main/linux-64/urllib3-1.25.7-py37_0.tar.bz2
157-
https://repo.anaconda.com/pkgs/main/linux-64/ipykernel-5.1.3-py37h39e3cac_0.tar.bz2
159+
https://repo.anaconda.com/pkgs/main/linux-64/ipykernel-5.1.3-py37h39e3cac_1.conda
158160
https://repo.anaconda.com/pkgs/main/linux-64/nbconvert-5.6.1-py37_0.tar.bz2
159161
https://repo.anaconda.com/pkgs/main/linux-64/requests-2.22.0-py37_1.tar.bz2
160162
https://repo.anaconda.com/pkgs/main/linux-64/jupyter_console-6.0.0-py37_0.conda
161163
https://repo.anaconda.com/pkgs/main/linux-64/notebook-6.0.2-py37_0.tar.bz2
162-
https://repo.anaconda.com/pkgs/main/noarch/qtconsole-4.6.0-py_0.tar.bz2
164+
https://repo.anaconda.com/pkgs/main/noarch/qtconsole-4.6.0-py_1.conda
163165
https://repo.anaconda.com/pkgs/main/noarch/jupyterlab_server-1.0.6-py_0.tar.bz2
164166
https://repo.anaconda.com/pkgs/main/linux-64/widgetsnbextension-3.5.1-py37_0.conda
165167
https://repo.anaconda.com/pkgs/main/noarch/ipywidgets-7.5.1-py_0.tar.bz2
166-
https://repo.anaconda.com/pkgs/main/noarch/jupyterlab-1.2.4-pyhf63ae98_0.conda
168+
https://repo.anaconda.com/pkgs/main/noarch/jupyterlab-1.2.5-pyhf63ae98_0.conda
167169
https://repo.anaconda.com/pkgs/main/linux-64/jupyter-1.0.0-py37_7.conda
168170
https://conda.anaconda.org/conda-forge/noarch/vincent-0.4.4-py_1.tar.bz2
169171
https://repo.anaconda.com/pkgs/main/linux-64/bokeh-1.4.0-py37_0.tar.bz2
170172
https://repo.anaconda.com/pkgs/main/linux-64/gdal-3.0.2-py37hbb2a789_0.conda
171173
https://repo.anaconda.com/pkgs/main/linux-64/matplotlib-3.1.1-py37h5429711_0.conda
172-
https://repo.anaconda.com/pkgs/main/noarch/holoviews-1.12.7-py_0.tar.bz2
173174
https://repo.anaconda.com/pkgs/main/linux-64/mkl_fft-1.0.15-py37ha843d7b_0.tar.bz2
174175
https://repo.anaconda.com/pkgs/main/linux-64/mkl_random-1.1.0-py37hd6b4f25_0.conda
175-
https://repo.anaconda.com/pkgs/main/linux-64/numpy-1.17.4-py37hc1035e2_0.conda
176+
https://repo.anaconda.com/pkgs/main/linux-64/numpy-1.18.1-py37h4f9e942_0.conda
177+
https://repo.anaconda.com/pkgs/main/noarch/holoviews-1.12.7-py_0.tar.bz2
176178
https://repo.anaconda.com/pkgs/main/linux-64/pandas-0.25.3-py37he6710b0_0.tar.bz2
177179
https://repo.anaconda.com/pkgs/main/linux-64/scipy-1.3.2-py37h7c811a0_0.conda
178180
https://repo.anaconda.com/pkgs/main/linux-64/shapely-1.6.4-py37hc5e8c75_0.conda
179181
https://repo.anaconda.com/pkgs/main/linux-64/altair-3.2.0-py37_0.conda
180182
https://repo.anaconda.com/pkgs/main/linux-64/fiona-1.8.11-py37h41e4f33_0.conda
181183
https://repo.anaconda.com/pkgs/main/linux-64/patsy-0.5.1-py37_0.conda
184+
https://repo.anaconda.com/pkgs/main/noarch/xarray-0.14.1-py_1.conda
182185
https://conda.anaconda.org/conda-forge/noarch/folium-0.10.0-py_0.tar.bz2
183186
https://repo.anaconda.com/pkgs/main/noarch/geopandas-0.6.1-py_0.conda
184187
https://repo.anaconda.com/pkgs/main/linux-64/statsmodels-0.10.1-py37hdd07704_0.conda

source-code/README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,21 @@ to create it. There is some material not covered in the presentation as well.
2020
* networkx
2121
* jupyter
2222
* folium (with conda, use `-c conda-forge`)
23+
* xarray
2324

2425
## What is it?
2526
* [`db-access`](db-access): illustration of accessing SQLite databases and using
2627
SQLAlchemy, including object-relational mapping.
2728
* [`gis`](gis): illustrations of working with geospatial data, including geopandas.
2829
* [`holoviews`](holoviews): illustrations of using HoloViews for convenient
2930
visualizations.
31+
* [`networkx`](networkx): illustration of using the networkx library for graph
32+
representation and algorithms.
3033
* [`pandas`](pandas): illustrations of using pandas and seaborn.
3134
* [`regexes`](regexes): illustrations of using regular expressions for validation
3235
and information extraction from textual data.
33-
* [1seaborn`]:(seaborn): illustrations of using Seaborn to create plots.
36+
* [`seaborn`](seaborn): illustrations of using Seaborn to create plots.
3437
* [`web-scraping`](web-scraping): illustration of web scraping using beautiful soup
3538
and graph representation using networkx.
39+
* [`xarray`](xarray): illustrates the xarray library for pandas-like operations
40+
on multi-dimensional arrays.

source-code/networkx/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# NetworkX
2+
NetworkX is an excellent library that implements graph representations
3+
and algorithms. Note is is not part of Python's standard library.
4+
5+
## What is it?
6+
1. `generate_random_tree.py`: illustration of how to use the NetworkX
7+
DiGraph class to represent a tree, generates a random tree according
8+
to specifications
9+
1. `add_random_weights.py`: reads a GraphML representation of a tree, and
10+
addds random weights to the edges
11+
1. `compute_leaf_path_length.py`: compute the length of all paths from the
12+
tree's root to each of the leaves
13+
1. `par_compute_leaf_length.py`: compute the length of all paths
14+
from the tree's root to each of the leaves, uses `multiprocessing` for
15+
parallel processing
16+
1. `graph.xml`: example GraphML representation of a tree
17+
1. `graph.txt`: example edge list representation of a tree
18+
1. `weighted_tree.xml`: example GraphML representation of a weighted tree
19+
1. `max_flow.py`: illustration of the maximum flow algorithm on a very
20+
simple case of three parallel flows.
21+
1. `shortest_path.ipynb`: Jupyter notebook illustrating the shortest path
22+
algorithm.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python
2+
3+
from argparse import ArgumentParser
4+
import random
5+
import sys
6+
import networkx as nx
7+
8+
9+
def add_edge_weights(tree):
10+
_add_edge_weights(tree, '1')
11+
12+
13+
def _add_edge_weights(tree, node):
14+
for child in tree.neighbors_iter(node):
15+
tree[node][child]['weight'] = random.random()
16+
_add_edge_weights(tree, child)
17+
18+
19+
def main():
20+
arg_parser = ArgumentParser(description='add edge weights to tree')
21+
arg_parser.add_argument('--input', required=True,
22+
help='inpput file')
23+
arg_parser.add_argument('--output', required=True,
24+
help='outpput file')
25+
arg_parser.add_argument('--seed', type=int, default=None,
26+
help='seed for random number generator')
27+
arg_parser.add_argument('--delim', dest='delimiter', default=' ',
28+
help='delimiter for edge list')
29+
arg_parser.add_argument('--no-data', action='store_true',
30+
dest='no_data', help='show edge data')
31+
arg_parser.add_argument('--edge-list', action='store_true',
32+
help='generate edge list output')
33+
options = arg_parser.parse_args()
34+
random.seed(options.seed)
35+
tree = nx.read_graphml(options.input)
36+
add_edge_weights(tree)
37+
if options.edge_list:
38+
nx.write_edgelist(tree, options.output,
39+
delimiter=options.delimiter,
40+
data=not options.no_data)
41+
else:
42+
nx.write_graphml(tree, options.output)
43+
return 0
44+
45+
if __name__ == '__main__':
46+
status = main()
47+
sys.exit(status)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python
2+
3+
from argparse import ArgumentParser
4+
import sys
5+
import networkx as nx
6+
7+
8+
def is_leaf(tree, node):
9+
return len(tree.neighbors(node)) == 0
10+
11+
12+
def leaf_path_lengths(tree):
13+
path_lengths = nx.shortest_path_length(tree, '1', weight='weight')
14+
remove = []
15+
for node in path_lengths:
16+
if not is_leaf(tree, node):
17+
remove.append(node)
18+
for node in remove:
19+
del path_lengths[node]
20+
return path_lengths
21+
22+
23+
def main():
24+
arg_parser = ArgumentParser(description='compute leaf path lengths')
25+
arg_parser.add_argument('--input', required=True, help='input file')
26+
options = arg_parser.parse_args()
27+
tree = nx.read_graphml(options.input)
28+
path_lengths = leaf_path_lengths(tree)
29+
for leaf in path_lengths:
30+
print('{0}: {1:.4f}'.format(leaf, path_lengths[leaf]))
31+
return 0
32+
33+
if __name__ == '__main__':
34+
status = main()
35+
sys.exit(status)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env python
2+
3+
from argparse import ArgumentParser
4+
import random
5+
import sys
6+
import networkx as nx
7+
8+
9+
def random_tree(max_branch, max_height):
10+
G = nx.DiGraph()
11+
random_subtree(G, None, max_branch, max_height)
12+
return G
13+
14+
15+
def random_subtree(G, root, max_branch, max_height):
16+
if max_height:
17+
if root:
18+
nr_branches = random.randrange(0, max_branch + 1)
19+
for i in range(1, nr_branches + 1):
20+
node = root + '.' + str(i)
21+
G.add_edge(root, node)
22+
random_subtree(G, node, max_branch, max_height - 1)
23+
else:
24+
node = '1'
25+
random_subtree(G, node, max_branch, max_height - 1)
26+
27+
28+
def main():
29+
arg_parser = ArgumentParser(description='generate random tree')
30+
arg_parser.add_argument('--output', required=True,
31+
help='output file name')
32+
arg_parser.add_argument('--branching', dest='max_branch', type=int,
33+
default=3, help='maximum node branching')
34+
arg_parser.add_argument('--height', dest='max_height', type=int,
35+
default=4, help='maximum tree height')
36+
arg_parser.add_argument('--seed', type=int, default=None,
37+
help='seed for random number generator')
38+
arg_parser.add_argument('--delim', dest='delimiter', default=' ',
39+
help='delimiter for edge list')
40+
arg_parser.add_argument('--no-data', action='store_true',
41+
dest='no_data', help='show edge data')
42+
arg_parser.add_argument('--edge-list', action='store_true',
43+
dest='edge_list',
44+
help='generate edge list output')
45+
options = arg_parser.parse_args()
46+
random.seed(options.seed)
47+
tree = random_tree(options.max_branch, options.max_height)
48+
if options.edge_list:
49+
nx.write_edgelist(tree, options.output,
50+
delimiter=options.delimiter,
51+
data=not options.no_data)
52+
else:
53+
nx.write_graphml(tree, options.output)
54+
return 0
55+
56+
if __name__ == '__main__':
57+
status = main()
58+
sys.exit(status)

source-code/networkx/graph.txt

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
root child1 {'span': 1.3}
2+
child1 grandchild1 {'span': 0.4}
3+
root child2 {'span': 0.7}
4+
child2 grandchild2 {'span': 0.8}
5+
child2 grandchild3 {'span': 0.2}
6+
grandchild3 greatgrandchild1 {'span': 0.1}

source-code/networkx/graph.xml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?><graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
2+
<key attr.name="span" attr.type="double" for="edge" id="d0" />
3+
<graph edgedefault="directed">
4+
<node id="child1" />
5+
<node id="child2" />
6+
<node id="greatgrandchild1" />
7+
<node id="grandchild3" />
8+
<node id="grandchild2" />
9+
<node id="grandchild1" />
10+
<node id="root" />
11+
<edge source="root" target="child1">
12+
<data key="d0">1.3</data>
13+
</edge>
14+
<edge source="child1" target="grandchild1">
15+
<data key="d0">0.4</data>
16+
</edge>
17+
<edge source="child2" target="grandchild3">
18+
<data key="d0">0.2</data>
19+
</edge>
20+
<edge target="child2" source="root">
21+
<data key="d0">0.7</data>
22+
</edge>
23+
<edge source="child2" target="grandchild2">
24+
<data key="d0">0.8</data>
25+
</edge>
26+
<edge target="greatgrandchild1" source="grandchild3">
27+
<data key="d0">0.1</data>
28+
</edge>
29+
</graph>
30+
</graphml>

0 commit comments

Comments
 (0)