From d95e461962382da6e2563ed34cca3e504f396870 Mon Sep 17 00:00:00 2001 From: Lionel GUEZ <guez@lmd.ens.fr> Date: Wed, 21 Feb 2024 19:06:34 +0100 Subject: [PATCH] Add new scripts --- Trajectories/search_segment.py | 21 +++++++++++++++++++++ Trajectories/search_traj.py | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100755 Trajectories/search_segment.py create mode 100755 Trajectories/search_traj.py diff --git a/Trajectories/search_segment.py b/Trajectories/search_segment.py new file mode 100755 index 00000000..ab81355c --- /dev/null +++ b/Trajectories/search_segment.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +"""This script reads a graph of segments (with or without cost values) +and searches the segment containing a given instantaneous eddy. + +""" + +import sys +import json + +import graph_tool + +g = graph_tool.load_graph(sys.argv[1]) +node = int(sys.argv[2]) + +for v in g.vertices(): + if node in g.vp.inst_eddies[v]: + print("segment =", g.vp.inst_eddies[v]) + break +else: + sys.exit("Node not found") diff --git a/Trajectories/search_traj.py b/Trajectories/search_traj.py new file mode 100755 index 00000000..d24e0d55 --- /dev/null +++ b/Trajectories/search_traj.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +"""This script reads a Json file containing trajectories as lists of +segments, and searches the trajectory which contains a given segment. + +""" + +import sys +import json + +with open(sys.argv[1]) as f_obj: + traj_segm = json.load(f_obj) + +segment = int(sys.argv[2]) + +for traj in traj_segm: + if segment in traj: + print(f"{traj=}") + break +else: + sys.exit("Trajectory not found") -- GitLab