From e6887387c84bcf2337a6dd7dbfd006fa22117a50 Mon Sep 17 00:00:00 2001
From: GUBAIDULIN <vadim.gubaidulin@synchrotron-soleil.fr>
Date: Mon, 17 Jun 2024 13:29:47 +0200
Subject: [PATCH] [Fix] Loading lattices with any periodicity

---
 mbtrack2/utilities/optics.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/mbtrack2/utilities/optics.py b/mbtrack2/utilities/optics.py
index 3c7ff92..79026f0 100644
--- a/mbtrack2/utilities/optics.py
+++ b/mbtrack2/utilities/optics.py
@@ -119,9 +119,10 @@ class Optics:
             self.periodicity = periodicity
 
         if self.periodicity > 1:
-            for i in range(self.periodicity - 1):
-                pos = np.append(twiss.s_pos,
-                                twiss.s_pos + twiss.s_pos[-1] * (i+1))
+            periods = np.arange(0, self.periodicity)
+            shift = periods*twiss.s_pos[-1]
+            shift = np.repeat(shift, len(twiss.s_pos))
+            pos = np.tile(twiss.s_pos.T, self.periodicity) + shift
         else:
             pos = twiss.s_pos
 
-- 
GitLab