From 2fecc0f6bba652b90f5267a4e5da65e22935da45 Mon Sep 17 00:00:00 2001
From: Daniel Brown <ddb@star.sr.bham.ac.uk>
Date: Mon, 9 Dec 2013 00:26:41 +0000
Subject: [PATCH] can now do kat.m1.n1.q = 1+100j and it converts it correctly
 into a gaussian beam parameter object

---
 pykat/components.py                      | 6 +++---
 pykat/node_network.py                    | 9 +++++----
 pykat/utilities/optics/gaussian_beams.py | 8 ++++++++
 3 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/pykat/components.py b/pykat/components.py
index f4ed356..2b3b9b6 100644
--- a/pykat/components.py
+++ b/pykat/components.py
@@ -32,21 +32,21 @@ class NodeGaussSetter(object):
         
     @q.setter
     def q(self, value):
-        self.__node.setGauss(self.__comp, value)
+        self.__node.setGauss(self.__comp, complex(value))
         
     @property
     def qx(self):
         return self.__node.qx
     @qx.setter
     def qx(self, value):
-        self.__node.setGauss(self.__comp, value)
+        self.__node.setGauss(self.__comp, complex(value))
     
     @property
     def qy(self):
         return self.__node.qy
     @qy.setter
     def qy(self, value):
-        self.__node.setGauss(self.__comp, self.qx, value)
+        self.__node.setGauss(self.__comp, self.qx, complex(value))
         
 class Component(object) :
     def __init__(self, name):
diff --git a/pykat/node_network.py b/pykat/node_network.py
index 0e915d7..8c6a50a 100644
--- a/pykat/node_network.py
+++ b/pykat/node_network.py
@@ -9,6 +9,7 @@ import pykat.gui.graphics
 import pykat.exceptions as pkex
 from pykat.components import Component
 from pykat.detectors import Detector
+from pykat.utilities.optics.gaussian_beams import gauss_param
 
 class NodeNetwork(object):
     def __init__(self, kat):
@@ -241,11 +242,11 @@ class Node(object):
         self.__q_comp = component
         
         if len(args) == 1:
-            self.__q_x = args[0]
-            self.__q_y = args[0]
+            self.__q_x = gauss_param(q=args[0])
+            self.__q_y = gauss_param(q=args[0])
         elif len(args) == 2:
-            self.__q_x = args[0]
-            self.__q_y = args[1]
+            self.__q_x = gauss_param(q=args[0])
+            self.__q_y = gauss_param(q=args[1])
         else:
             raise pkex.BasePyKatException("Must specify either 1 Gaussian beam parameter or 2 for astigmatic beams")
         
diff --git a/pykat/utilities/optics/gaussian_beams.py b/pykat/utilities/optics/gaussian_beams.py
index 568dbd5..f5efa4c 100644
--- a/pykat/utilities/optics/gaussian_beams.py
+++ b/pykat/utilities/optics/gaussian_beams.py
@@ -14,6 +14,7 @@ class gauss_param(object):
         q = gauss_param(w0=w0, z=z)
         q = gauss_param(z=z, zr=zr)
         q = gauss_param(wz=wz, rc=rc)
+        q = gauss_param(q=a) # where a is a complex number
         
         or change default wavelength and refractive index with:
         
@@ -27,6 +28,13 @@ class gauss_param(object):
         
         if len(args) == 1:
             self.__q = args[0]
+        
+        elif len(kwargs) == 1:
+            if "q" in kwargs:
+                self.__q = complex(kwargs["q"])        
+            else:
+                raise pkex.BasePyKatException("Must specify: z and w0 or z and zr or rc and wz, to define the beam parameter")
+                
         elif len(kwargs) == 2:        
             
             if "w0" in kwargs and "z" in kwargs:
-- 
GitLab