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

Process either anticyclones or cyclones

The choice is made with a command line argument. We need this fix
following the evolution of program `eddy_graph`. We now have to check
that the interpolated eddies are in the chosen graph so it makes sense
to create function `set_attribute`. Note that we no longer create the
attribute cyclone of nodes.
parent a0517593
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
"""edgelist.csv must be in the current directory."""
"""edgelist_anti.csv or edgelist_cyclo.csv must be in the current
directory."""
import networkx as nx
import csv
......@@ -34,33 +35,28 @@ def read_eddy_graph(edgelist, shp_tr_dir = None, read_interp = True):
# Assuming that the directory containing the interpolated
# eddies is in the same location as edgelist:
extremum = path.join(path.dirname(edgelist), "SHP_triplet", "extremum")
with shapefile.Reader(extremum) as s_read:
for shape_rec in s_read:
n = (shape_rec.record.date_index, shape_rec.record.eddy_index)
G.add_node(n, coordinates = tuple(shape_rec.shape.points[0]),
cyclone = shape_rec.record.cyclone == 1,
interpolat = True, speed = shape_rec.record.speed,
ssh = shape_rec.record.ssh)
set_attribute(G, extremum)
if shp_tr_dir is not None:
# Read and set attributes of Visible eddies:
extremum = path.join(shp_tr_dir, "extremum")
with shapefile.Reader(extremum) as s_read:
for shape_rec in s_read:
n = (shape_rec.record.date_index, shape_rec.record.eddy_index)
if shape_rec.record.valid == 1 and n in G:
G.add_node(n,
coordinates = tuple(shape_rec.shape.points[0]),
cyclone = shape_rec.record.cyclone == 1,
interpolat = shape_rec.record.interpolat == 1,
speed = shape_rec.record.speed,
ssh = shape_rec.record.ssh)
set_attribute(G, extremum)
return G
def set_attribute(G, extremum):
with shapefile.Reader(extremum) as s_read:
for shape_rec in s_read:
n = (shape_rec.record.date_index, shape_rec.record.eddy_index)
if (shape_rec.record.valid == 1
or shape_rec.record.interpolat == 1) and n in G:
G.add_node(n,
coordinates = tuple(shape_rec.shape.points[0]),
interpolat = shape_rec.record.interpolat == 1,
speed = shape_rec.record.speed,
ssh = shape_rec.record.ssh)
def to_eddy_agraph(G):
my_subgraphs = {}
......@@ -116,9 +112,12 @@ if __name__ == "__main__":
action = "store_true")
parser.add_argument("--interp", help = "Read interpolated eddies",
action = "store_true")
parser.add_argument("orientation", help ="Choose a graph",
choices = ["anti", "cyclo"])
args = parser.parse_args()
G = read_eddy_graph("edgelist.csv", read_interp = args.interp)
G = read_eddy_graph(f"edgelist_{args.orientation}.csv",
read_interp = args.interp)
if args.node is None:
H = G
......
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