Skip to content

Commit

Permalink
Merge pull request #6 from fneum/nodes
Browse files Browse the repository at this point in the history
G.node -> G.nodes
  • Loading branch information
coroa committed Nov 10, 2019
2 parents 405c428 + f223850 commit c8ed491
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
packages=find_packages(exclude=['doc', 'test']),
install_requires=['countrycode', 'fiona', 'matplotlib',
'memory_profiler',
'networkx>=1.10', 'numpy', 'pandas>=0.19.0',
'networkx>=2', 'numpy', 'pandas>=0.19.0',
'pyomo', 'scipy', 'pyproj', 'pyshp', 'rasterio>=1.0',
'shapely', 'six'],
classifiers=[
Expand Down
4 changes: 2 additions & 2 deletions vresutils/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ def nutsidofaplant(x):
try:
nregs = iso2_to_nuts[name_to_iso2[x['Country']]]
for n in nregs:
if G.node[n]['region'].contains(p):
if G.nodes[n]['region'].contains(p):
return n
else:
return min(nregs, key=lambda n: G.node[n]['region'].distance(p))
return min(nregs, key=lambda n: G.nodes[n]['region'].distance(p))
except KeyError:
return np.NaN

Expand Down
16 changes: 8 additions & 8 deletions vresutils/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def cell_subgraph(G, lat, lon, size, copy=True):

pos = np.array((lon, lat))
nodes = (n
for n, p in iteritems(G.node)
for n, p in iteritems(G.nodes)
if np.abs(p['pos'] - pos).max() <= size/2)
return giant_component(G.subgraph(nodes), copy=copy)

Expand All @@ -200,7 +200,7 @@ def polygon_subgraph(G, polygon, nneighbours=0, copy=True):
"""

nodes = set(n
for n, p in iteritems(G.node)
for n, p in iteritems(G.nodes)
if polygon.contains(Point(p['pos'])))

if nneighbours > 0:
Expand Down Expand Up @@ -250,7 +250,7 @@ def add_node(n):
if n in queue:
return queue[n]

attr_dict = G.node[n]
attr_dict = G.nodes[n]
pos = Point(attr_dict['pos'])
if polygon.contains(pos):
# in Polygon: keep it
Expand Down Expand Up @@ -353,7 +353,7 @@ def do_node(n):
if n in queue:
return queue[n]

pos = Point(G.node[n]['pos'])
pos = Point(G.nodes[n]['pos'])
# this two-step procedure checks the last successful shape
# first, as we are link-hopping through the graph
if do_node.shape.contains(pos):
Expand Down Expand Up @@ -452,7 +452,7 @@ def edge_attrs(H, n1, n2, d):
return a

for n in neigh_nodes:
pos = Point(G.node[n]['pos'])
pos = Point(G.nodes[n]['pos'])
for n2, reg in iteritems(regions):
if reg.contains(pos):
H.add_edges_from((n2, n3, edge_attrs(H, n2, n3, d))
Expand All @@ -462,7 +462,7 @@ def edge_attrs(H, n1, n2, d):
return H

def get_voronoi_regions(G, outline=None):
if 'region' not in next(itervalues(G.node)):
if 'region' not in next(itervalues(G.nodes)):
if callable(outline):
outline = outline()
assert outline is not None
Expand Down Expand Up @@ -559,7 +559,7 @@ def edge_to_shape(e):
if nm1 == nm2:
return nm1
else:
ls = LineString([G.node[n1]['pos'], G.node[n2]['pos']])
ls = LineString([G.nodes[n1]['pos'], G.nodes[n2]['pos']])
def length(nm):
return ls.intersection(shapes[nm]).length if nm is not None else 0
l1 = length(nm1)
Expand Down Expand Up @@ -799,7 +799,7 @@ def convert_node_labels_to_integers(G):
return relabel_nodes(G, dict(zip(G.nodes(), count())))

def get_node_attributes(G, attr):
return OrderedDict((n, d[attr]) for n, d in iteritems(G.node))
return OrderedDict((n, d[attr]) for n, d in iteritems(G.nodes))

def get_edge_attributes(G, attr):
return OrderedDict(((u, v), d[attr]) for u, v, d in iteritems(G.edges_iter(data=True)))
2 changes: 1 addition & 1 deletion vresutils/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def node_distance(G, n1, n2):
d : float
distance
"""
return 110. * np.sqrt(np.sum((G.node[n1]['pos'] - G.node[n2]['pos'])**2))
return 110. * np.sqrt(np.sum((G.nodes[n1]['pos'] - G.nodes[n2]['pos'])**2))

def heuristically_extend_edge_attributes(G, it=None):
if it is None:
Expand Down
2 changes: 1 addition & 1 deletion vresutils/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def save_graph_as_shapes(G, nodes_fn, links_fn):
extractor = itemgetter(*map(itemgetter(0), sf_links.fields))

for n1, n2, d in G.edges_iter(data=True):
sf_links.line(parts=[[list(G.node[n]['pos']) for n in (n1, n2)]])
sf_links.line(parts=[[list(G.nodes[n]['pos']) for n in (n1, n2)]])
sf_links.record(*extractor(d))

sf_links.save(links_fn)

0 comments on commit c8ed491

Please sign in to comment.