From f4a9990f5960601771d7bf3955a302655e62709e Mon Sep 17 00:00:00 2001 From: Alexis Gamelin <alexis.gamelin@synchrotron-soleil.fr> Date: Mon, 29 Jan 2024 13:32:13 +0100 Subject: [PATCH] [Fix] Bunch & WakePotential Update gitignore --- .gitignore | 1 + mbtrack2/tracking/particles.py | 18 ++++++++++-------- mbtrack2/tracking/wakepotential.py | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 2ec607f..1004a58 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.ipynb_checkpoints* test_*.py *.hdf5 +*.pyc diff --git a/mbtrack2/tracking/particles.py b/mbtrack2/tracking/particles.py index 04f26b8..f334be8 100644 --- a/mbtrack2/tracking/particles.py +++ b/mbtrack2/tracking/particles.py @@ -129,12 +129,12 @@ class Bunch: self._mp_number = int(mp_number) self.particles = { - "x": np.empty(self.mp_number, dtype=np.float64), - "xp": np.empty(self.mp_number, dtype=np.float64), - "y": np.empty(self.mp_number, dtype=np.float64), - "yp": np.empty(self.mp_number, dtype=np.float64), - "tau": np.empty(self.mp_number, dtype=np.float64), - "delta": np.empty(self.mp_number, dtype=np.float64), + "x": np.zeros(self.mp_number, dtype=np.float64), + "xp": np.zeros(self.mp_number, dtype=np.float64), + "y": np.zeros(self.mp_number, dtype=np.float64), + "yp": np.zeros(self.mp_number, dtype=np.float64), + "tau": np.zeros(self.mp_number, dtype=np.float64), + "delta": np.zeros(self.mp_number, dtype=np.float64), } self.track_alive = track_alive self.alive = np.ones((self.mp_number, ), dtype=bool) @@ -165,11 +165,13 @@ class Bunch: def __iter__(self): """Iterate over labels""" - return self.dtype.names.__iter__() + return self.particles.keys().__iter__() def __repr__(self): """Return representation of alive particles""" - return f'Bunch with macro-particles: \n {pd.DataFrame(self[:])!r}' + rep = pd.DataFrame(np.array([self[l] for l in self.__iter__()]).T, + columns=list(self.__iter__())) + return f'Bunch with macro-particles: \n {rep!r}' @property def mp_number(self): diff --git a/mbtrack2/tracking/wakepotential.py b/mbtrack2/tracking/wakepotential.py index eb6a105..d64865c 100644 --- a/mbtrack2/tracking/wakepotential.py +++ b/mbtrack2/tracking/wakepotential.py @@ -231,7 +231,7 @@ class WakePotential(Element): dtau0) W0 = np.insert(W0, 0, np.zeros(n)) n_to_add = len(tau0) - len(W0) - W0 = np.pad(W0, (n, n_to_add), + W0 = np.pad(W0, (0, n_to_add), mode="constant", constant_values=(0, 0)) -- GitLab