Skip to content
Snippets Groups Projects
Commit 56ca8ea3 authored by Lionel GUEZ's avatar Lionel GUEZ
Browse files

Pass a handler to function `set_attribute`

Instead of a file name. Preparing for some more elaborate processing
in `set_attribute`.
parent e1921ec7
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,7 @@ from os import path
from networkx import nx_agraph
import os
import json
import util_eddies
def node_to_date_eddy(node_index, e_overestim, only_date = False):
"""Convert from node identification in graph to eddy identification in
......@@ -37,25 +38,24 @@ def read_eddy_graph(edgelist, shpc_dir = None):
if shpc_dir is not None:
# Read and set attributes of eddies:
extr_file = path.join(shpc_dir, "extremum")
set_attribute(G, extr_file)
handler = util_eddies.open_shpc(shpc_dir)
set_attribute(G, handler)
else:
print(edgelist, "not readable")
G = nx.DiGraph()
return G
def set_attribute(G, extr_file):
with shapefile.Reader(extr_file) as s_read:
for shape_rec in s_read:
n = date_eddy_to_node(shape_rec.record.date,
shape_rec.record.eddy_index,
G.graph["e_overestim"])
if shape_rec.record.valid == 1 and n in G:
G.add_node(n, coordinates = tuple(shape_rec.shape.points[0]),
speed = shape_rec.record.speed,
ssh = shape_rec.record.ssh)
def set_attribute(G, handler):
for shape_rec in handler["readers"]["extremum"]:
n = date_eddy_to_node(shape_rec.record.date,
shape_rec.record.eddy_index,
G.graph["e_overestim"])
if shape_rec.record.valid == 1 and n in G:
G.add_node(n, coordinates = tuple(shape_rec.shape.points[0]),
speed = shape_rec.record.speed,
ssh = shape_rec.record.ssh)
def to_eddy_agraph(G):
my_subgraphs = {}
......
../Common/util_eddies.py
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment