From e52fa727bc93eae82fc39731a0934b72813a336c Mon Sep 17 00:00:00 2001
From: Lionel GUEZ <guez@lmd.ens.fr>
Date: Wed, 24 Jul 2024 17:32:28 +0200
Subject: [PATCH] Allow the independent creation of trajectory lists

The motivation is to be able to create the files `*traj*.json` for
only a component of the graph, so that `plot_traj.py` can plot the
trajectories in a single component, with different colors for
different trajectories.
---
 Trajectories/create_traj_lists.py | 33 ++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)
 mode change 100644 => 100755 Trajectories/create_traj_lists.py

diff --git a/Trajectories/create_traj_lists.py b/Trajectories/create_traj_lists.py
old mode 100644
new mode 100755
index c1e4bb75..c1cf3fcf
--- a/Trajectories/create_traj_lists.py
+++ b/Trajectories/create_traj_lists.py
@@ -28,9 +28,11 @@ def create_traj_list(
         else:
             traj_vert_ind[traj_prop[n]] = [n]
 
-    traj_vert_ind = [traj_vert_ind[t] for t in range(len(traj_vert_ind))]
-    # An element of traj_vert_ind is a trajectory, represented by a list
-    # of vertex indices.
+    traj_vert_ind = [traj_vert_ind[t] for t in sorted(traj_vert_ind)]
+    # sorted(traj_vert_ind) instead of range(len(traj_vert_ind))
+    # because create_traj_list can be called for a component of the
+    # graph. An element of traj_vert_ind is a trajectory, represented
+    # by a list of vertex indices.
 
     print("Number of trajectories: ", len(traj_vert_ind))
 
@@ -87,3 +89,28 @@ def create_traj_list(
         )
 
     print("Created expanded_traj.json.")
+
+
+if __name__ == "__main__":
+    import sys
+
+    import graph_tool
+    from graph_tool import topology
+
+    if len(sys.argv) != 2:
+        sys.exit("Required argument: input-graph")
+
+    g = graph_tool.load_graph(sys.argv[1])
+    print("Input graph:")
+    print("Number of vertices:", g.num_vertices())
+    print("Number of edges:", g.num_edges())
+    print("Internal properties:")
+    g.list_properties()
+    create_traj_list(
+        topology.topological_sort(g),
+        g.vp["traj"],
+        g.vp["name"],
+        g.vp["inst_eddies"],
+        g.gp["orientation"],
+        g.gp["e_overestim"],
+    )
-- 
GitLab