From f0b5c5f1587c5173c419113444913b049b31fc82 Mon Sep 17 00:00:00 2001
From: Daniel Brown <ddb@star.sr.bham.ac.uk>
Date: Thu, 24 Sep 2015 14:06:04 +0100
Subject: [PATCH] adding progress bar to parakat.getResults(), better parsig of
 funcs and changing default fsig name of xbeta/ybeta

---
 pykat/commands.py              |  6 +++++-
 pykat/components.py            |  4 ++--
 pykat/optics/gaussian_beams.py |  2 +-
 pykat/parallel.py              | 23 ++++++++++++++++++-----
 pykat/tools/redmine.py         |  2 +-
 5 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/pykat/commands.py b/pykat/commands.py
index 6b77824..ba6b085 100644
--- a/pykat/commands.py
+++ b/pykat/commands.py
@@ -101,13 +101,17 @@ class func(Command):
     @staticmethod
     def parseFinesseText(line, kat):
         v = line.split(None, 3)
+        v2 = line.split("=", 2)
         
         if "=" in v and len(v) == 4:
             v.remove("=")
+            return func(v[1], v[2]) 
+        if len(v2) == 2:
+            return func(v2[0].split()[1], v2[1]) 
         else:
             raise pkex.BasePyKatException("'{0}' not a valid Finesse func command".format(line))
         
-        return func(v[1], v[2]) 
+        
         
 
 
diff --git a/pykat/components.py b/pykat/components.py
index 613bb17..0bb6bbc 100644
--- a/pykat/components.py
+++ b/pykat/components.py
@@ -303,8 +303,8 @@ class AbstractMirrorComponent(Component):
         self.__phi = Param("phi", self, SIfloat(phi), canFsig=True, fsig_name="phase")
         self.__Rcx = AttrParam("Rcx", self, SIfloat(Rcx))
         self.__Rcy = AttrParam("Rcy", self, SIfloat(Rcy))
-        self.__xbeta = AttrParam("xbeta", self, SIfloat(xbeta), canFsig=True, fsig_name="x")
-        self.__ybeta = AttrParam("ybeta", self, SIfloat(ybeta), canFsig=True, fsig_name="y")
+        self.__xbeta = AttrParam("xbeta", self, SIfloat(xbeta), canFsig=True, fsig_name="xbeta")
+        self.__ybeta = AttrParam("ybeta", self, SIfloat(ybeta), canFsig=True, fsig_name="ybeta")
         self.__mass = AttrParam("mass", self, SIfloat(mass))
         self.__Ix = AttrParam("Ix", self, SIfloat(Ix))
         self.__Iy = AttrParam("Iy", self, SIfloat(Iy))
diff --git a/pykat/optics/gaussian_beams.py b/pykat/optics/gaussian_beams.py
index 19bd970..0ea9e31 100644
--- a/pykat/optics/gaussian_beams.py
+++ b/pykat/optics/gaussian_beams.py
@@ -53,7 +53,7 @@ class gauss_param(object):
             elif "z" in kwargs and "zr" in kwargs:
                 q = SIfloat(kwargs["z"]) + 1j * SIfloat(kwargs["zr"]) 
             elif "rc" in kwargs and "w" in kwargs:
-                one_q = 1 / SIfloat(kwargs["rc"]) - 1j * self.__lamda / (math.pi * self.__nr * SIfloat(kwargs["w"])**2)
+                one_q = 1 / SIfloat(kwargs["rc"]) - 1j * SIfloat(wavelength) / (math.pi * SIfloat(nr) * SIfloat(kwargs["w"])**2)
                 q = 1/one_q
             else:
                 raise pkex.BasePyKatException("Must specify: z and w0 or z and zr or rc and w or q, to define the beam parameter")
diff --git a/pykat/parallel.py b/pykat/parallel.py
index 1053718..997eb3f 100644
--- a/pykat/parallel.py
+++ b/pykat/parallel.py
@@ -24,12 +24,19 @@ Contact at ddb@star.sr.bham.ac.uk
 @author: Daniel Brown
 """
 
+import IPython
+
 # former syntax depreciated since ipython 4:
-#from IPython.parallel import Client
-from ipyparallel import Client
+if IPython.version_info[0] <= 3:
+    from IPython.parallel import Client
+else:
+    from ipyparallel import Client
+    
 import sys
 import os
 
+from pykat.external.progressbar import ProgressBar, ETA, Percentage, Bar
+
 def _run(commands, pwd, **kwargs):
     import os
     os.chdir(pwd)
@@ -46,8 +53,9 @@ class parakat(object):
     """
     Uses the ipython clustering for running kat objects in parallel.
     
-    To use this you must have installed ipyparallel, for example, with
-	pip install ipyparallel
+    To use this you must have installed ipyparallel, for example, with:
+	    
+        pip install ipyparallel
 
 	Then yoy must start an ipython cluster on your computer.
     From a new terminal use the command:
@@ -81,15 +89,20 @@ class parakat(object):
         self._lview = self._rc.load_balanced_view()
         self._lview.block = False
         self._results = []
+        self._run_count = 0
         
     def run(self, kat, **kwargs):
         self._results.append(self._lview.apply_async(_run, "".join(kat.generateKatScript()), os.getcwd(), **kwargs))
+        self._run_count += 1
         
     def getResults(self):
         out = []
         
-        self._lview.wait(self._results)
+        p = ProgressBar(maxval=self._run_count , widgets=["Parallel jobs: ", Percentage(), Bar()])
         
+        while not self._lview.wait(self._results, timeout=0.1):
+            p.update(self._run_count - self._lview.queue_status()['unassigned'])
+            
         for done in self._results:
             out.append(done.get())
             
diff --git a/pykat/tools/redmine.py b/pykat/tools/redmine.py
index 7ad3d43..e3c92e6 100644
--- a/pykat/tools/redmine.py
+++ b/pykat/tools/redmine.py
@@ -47,7 +47,7 @@ def processRedmineProductionLog(log, output):
                 if ext == "zip" or ext == "tar" or ext == "pdf":
                     ofile.write("%s %s %s\n" %(file, ip, date))
         
-                    print file, ip, date
+                    print(file, ip, date)
         
                 found = -1
                 
-- 
GitLab