From 7d134302415ddc1a7b17ff8b1984a042eaf21389 Mon Sep 17 00:00:00 2001
From: Yngve Inntjore Levinsen <Yngve.Levinsen@esss.se>
Date: Fri, 22 Jul 2016 17:17:58 +0200
Subject: [PATCH] added option to add and remove particles from the dst object

---
 ess/TraceWin.py | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/ess/TraceWin.py b/ess/TraceWin.py
index 4a62fdf..9e14096 100644
--- a/ess/TraceWin.py
+++ b/ess/TraceWin.py
@@ -12,7 +12,7 @@ class dst:
       - y [m]
       - yp [rad]
       - phi [rad]
-      - E [MeV]
+      - E [MeV] (kinetic energy)
     '''
     def __init__(self, filename):
         # easy storage..
@@ -22,6 +22,34 @@ class dst:
         # read in the file..
         self._readBinaryFile()
 
+    def append(self,x=0.0,xp=0.0,y=0.0,yp=0.0,E=0.0,phi=0.0):
+        '''
+        Append one particle to the distribution
+
+        - Kinetic Energy in MeV
+        - x,y in m
+        - xp,yp in rad
+        - phi in rad
+        '''
+        import numpy
+
+        self._data=numpy.append(self._data, [[x,xp,y,yp,phi,E]], 0)
+        self.Np+=1
+
+
+    def remove(self, i=None):
+        '''
+        Removes all particles from the distribution, or the line specified by i
+        '''
+        import numpy
+
+        if i==None:
+            self._data=numpy.delete(self._data,numpy.s_[:],0)
+            self.Np=0
+        else:
+            self._data=numpy.delete(self._data,i,0)
+            self.Np-=1
+
     def _readBinaryFile(self):
         # Thanks Emma!
 
-- 
GitLab