From 8e6ce4790f504252152a1fb82c72e56673329b7a Mon Sep 17 00:00:00 2001 From: Lionel GUEZ <guez@lmd.ens.fr> Date: Tue, 5 Jul 2022 16:15:54 +0200 Subject: [PATCH] Use `e_overestim.txt` Use `e_overestim.txt` instead of `node_id_param.json`. Since commit 43d2eff6, we wrote only `e_overestim` to the JSon file. Simpler to write the value alone in a text file. --- Convert_Matlab/overlap_v6.py | 4 +--- Inst_eddies/Analysis/eddy_dump.py | 6 +++--- Overlap/Tests/test_overlap.f90 | 5 ++--- Overlap/eddy_graph.f90 | 5 ++--- Overlap/eddy_graph.sh.in | 2 +- Overlap/report_graph.py | 5 ++--- Trajectories/cost_function.py | 7 ++----- Trajectories/tests.json | 4 ++-- 8 files changed, 15 insertions(+), 23 deletions(-) diff --git a/Convert_Matlab/overlap_v6.py b/Convert_Matlab/overlap_v6.py index 69c0961a..a5f82966 100755 --- a/Convert_Matlab/overlap_v6.py +++ b/Convert_Matlab/overlap_v6.py @@ -55,9 +55,7 @@ if __name__ == "__main__": e_overestim = id_child.shape[0] print("e_overestim =", e_overestim) d_init = to_days_1950(date_num[0]) - - with open("node_id_param.json", "w") as f: - json.dump({"e_overestim": e_overestim, "d_init": d_init}, f) + with open("e_overestim.txt", "w") as f: f.write(str(e_overestim) + "\n") with open("edgelist.csv", "w", newline = '') as edgelist: writer = csv.writer(edgelist, delimiter = ' ', lineterminator = "\n") diff --git a/Inst_eddies/Analysis/eddy_dump.py b/Inst_eddies/Analysis/eddy_dump.py index a9be69ed..3e32309f 100755 --- a/Inst_eddies/Analysis/eddy_dump.py +++ b/Inst_eddies/Analysis/eddy_dump.py @@ -27,9 +27,9 @@ if args.ishape: ishape = args.ishape else: if args.node: - with open("node_id_param.json") as f: node_id_param = json.load(f) - date, eddy_index = report_graph\ - .node_to_date_eddy(args.node, node_id_param["e_overestim"]) + with open("e_overestim.txt") as f: e_overestim = int(f.read()) + date, eddy_index = report_graph.node_to_date_eddy(args.node, + e_overestim) else: reply = input("date, eddy_index = ? ").split(",") date = int(reply[0]) diff --git a/Overlap/Tests/test_overlap.f90 b/Overlap/Tests/test_overlap.f90 index f5c8f8e4..c95e675b 100644 --- a/Overlap/Tests/test_overlap.f90 +++ b/Overlap/Tests/test_overlap.f90 @@ -70,9 +70,8 @@ program test_overlap < hshp%d0 + n_dates, "test_overlap k_test_1, k_test_2") e_overestim = maxval([hshp%ishape_last(hshp%d0) + 1, & ediff1d(hshp%ishape_last)]) - open(unit, file = "node_id_param.json", status = "replace", & - action = "write") - write(unit, fmt = *) '{"e_overestim": ', e_overestim, '}' + open(unit, file = "e_overestim.txt", status = "replace", action = "write") + write(unit, fmt = *) e_overestim close(unit) call read_snapshot(flow(1), [hshp], nlon, nlat, k_test_1, corner, step, copy) call read_snapshot(flow(max_delta + 1), [hshp], nlon, nlat, k_test_2, & diff --git a/Overlap/eddy_graph.f90 b/Overlap/eddy_graph.f90 index 35f6ba17..6b999e1f 100644 --- a/Overlap/eddy_graph.f90 +++ b/Overlap/eddy_graph.f90 @@ -112,9 +112,8 @@ program eddy_graph "eddy_graph: n_proc should be <= n_dates / (max_delta + 1)") e_overestim = maxval([(hshpc(i)%ishape_last(hshpc(i)%d0) + 1, & ediff1d(hshpc(i)%ishape_last), i = 1, n_shpc)]) - open(unit, file = "node_id_param.json", status = "replace", & - action = "write") - write(unit, fmt = *) '{"e_overestim": ', e_overestim, '}' + open(unit, file = "e_overestim.txt", status = "replace", action = "write") + write(unit, fmt = *) e_overestim close(unit) corner = corner_deg * deg_to_rad step = step_deg * deg_to_rad diff --git a/Overlap/eddy_graph.sh.in b/Overlap/eddy_graph.sh.in index e5c28f74..40c5bf63 100644 --- a/Overlap/eddy_graph.sh.in +++ b/Overlap/eddy_graph.sh.in @@ -34,4 +34,4 @@ sort --key=1,1 --key=2,2 --numeric-sort --output=edgelist.csv \ rm edgelist_unsorted.csv echo "Created files \"edgelist.csv\", \"isolated_nodes.txt\" and " \ - "\"node_id_param.json\"." + "\"e_overestim.txt\"." diff --git a/Overlap/report_graph.py b/Overlap/report_graph.py index 76b3504e..1990f49f 100755 --- a/Overlap/report_graph.py +++ b/Overlap/report_graph.py @@ -32,9 +32,8 @@ def read_eddy_graph(edgelist, shpc_dir = None): G = nx.read_edgelist(edgelist, create_using = nx.DiGraph, nodetype = int) dir_edgelist = path.dirname(edgelist) - node_id_param_file = path.join(dir_edgelist, "node_id_param.json") - with open(node_id_param_file) as f: node_id_param = json.load(f) - G.graph["e_overestim"] = node_id_param["e_overestim"] + e_overestim_file = path.join(dir_edgelist, "e_overestim.txt") + with open(e_overestim_file) as f: G.graph["e_overestim"] = int(f.read()) if shpc_dir is not None: # Read and set attributes of eddies: diff --git a/Trajectories/cost_function.py b/Trajectories/cost_function.py index 7dc58f11..83dc3fb5 100755 --- a/Trajectories/cost_function.py +++ b/Trajectories/cost_function.py @@ -5,7 +5,7 @@ computes the non-local cost functions applied to edges. Input: -- "node_id_param.json", expected to be in the current directory +- "e_overestim.txt", expected to be in the current directory - the graph of segments without cost functions, "segments.gt" or "segments.graphml", expected to be in the current directory @@ -95,10 +95,7 @@ parser.add_argument("SHPC_dir", nargs='+') parser.add_argument("--graphml", action = "store_true", help = "save to graphml format") args = parser.parse_args() - -# Grab e_overestim: -with open("node_id_param.json") as f: node_id_param = json.load(f) -e_overestim = node_id_param["e_overestim"] +with open("e_overestim.txt") as f: e_overestim = int(f.read()) # Set some values needed for the cost function: diff --git a/Trajectories/tests.json b/Trajectories/tests.json index 521960c3..ece315aa 100644 --- a/Trajectories/tests.json +++ b/Trajectories/tests.json @@ -17,7 +17,7 @@ "env": {"PYTHONPATH": "$src_dir/Overlap:$src_dir/Common"}, "symlink": [ - "$tests_old_dir/EGr2nd15md4/node_id_param.json", + "$tests_old_dir/EGr2nd15md4/e_overestim.txt", "$tests_old_dir/Segments/segments.graphml" ], "exclude_cmp": ["timings.txt"] @@ -44,7 +44,7 @@ "env": {"PYTHONPATH": "$src_dir/Overlap:$src_dir/Common"}, "symlink": [ - "$tests_old_dir/Greece_graph/node_id_param.json", + "$tests_old_dir/Greece_graph/e_overestim.txt", "$tests_old_dir/Greece_segments/segments.graphml" ] }, -- GitLab