From 9687f9fd52d2ce8e0f94243e1e543aa78a667e35 Mon Sep 17 00:00:00 2001
From: Yngve Inntjore Levinsen <Yngve.Levinsen@esss.se>
Date: Thu, 26 Jan 2017 10:39:59 +0100
Subject: [PATCH] Making plt-> dst conversion a bit clearer new function
 plt.get_dst returns a dst object function plt.save_dst forces you to provide
 a file name (and use get_dst)

---
 ess/TraceWin.py | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/ess/TraceWin.py b/ess/TraceWin.py
index 150e5e4..5cfefe9 100644
--- a/ess/TraceWin.py
+++ b/ess/TraceWin.py
@@ -499,8 +499,10 @@ class plt:
         self.twiss_alpha = [[-self.sigma[j][i][i+1]/self.twiss_eps[j,i/2] for i in (0,2,4)] for j in range(len(self.Nelp))]
         self.twiss_alpha = numpy.array(self.twiss_alpha)
 
-
-    def save_dst(self, index,filename=''):
+    def get_dst(self, index):
+        '''
+        Returns the dst corresponding to the given index
+        '''
         import numpy
    
         dset=self[index]
@@ -516,8 +518,16 @@ class plt:
                            dset['yp'],
                            dset['phi'],
                            dset['E']]).transpose()
-        if filename:
-            _dst.save(filename)
+        return _dst
+
+    def save_dst(self, index,filename):
+        '''
+        Saves the dst at the specified index to file
+
+        Returns the same dst object.
+        '''
+        _dst=get_dst(index)
+        _dst.save(filename)
         return _dst
 
 
-- 
GitLab