From 0ca2da8cd6b7e436489776147a7bea574065cc36 Mon Sep 17 00:00:00 2001 From: Lionel GUEZ <guez@lmd.ens.fr> Date: Wed, 3 Feb 2021 22:36:26 +0100 Subject: [PATCH] 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. --- Analysis/report_graph.py | 43 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/Analysis/report_graph.py b/Analysis/report_graph.py index ce5b7a4c..cbbeae65 100755 --- a/Analysis/report_graph.py +++ b/Analysis/report_graph.py @@ -1,6 +1,7 @@ #!/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 -- GitLab