diff --git a/pykat/commands.py b/pykat/commands.py index 2d8953ccedf6887d666e68225689ea9e984deb51..877f640a461ee5b99e6775732c88a26dba2c7357 100644 --- a/pykat/commands.py +++ b/pykat/commands.py @@ -61,7 +61,6 @@ class cavity(Command): class gauss(object): @staticmethod def parseFinesseText(text, kat): - print "parsing gauss", kat.lambda0 values = text.split() if not values[0].startswith("gauss") or (len(values) != 6 and len(values) != 8): @@ -71,6 +70,21 @@ class gauss(object): component = values[2] node = values[3] + # setting the name of the gauss parameter is slightly convoluted + # as we don't explicitly store gauss paramters as an object, they + # are simply just complex numbers stored at each node. To fix this + # the name is stored in the NodeGaussSetter object for each component + + if component in kat.components: + c = kat.components[component] + if hasattr(c, node): + ns = getattr(c, node) + ns.name = name + else: + raise pkex.BasePyKatException("Component '{0}' is not attached to node {1}".format(component, node)) + else: + raise pkex.BasePyKatException("Component '{0}' was not found".format(component)) + if not values[0].endswith("*"): if len(values) == 6: gp = beam_param(kat.lambda0, w0=values[-2], z=values[-1]) diff --git a/pykat/components.py b/pykat/components.py index 9c5205e92942c97047977e3897d112c2e30f48fb..67b22331b01579792b24b5c9ec6485efea96d97e 100644 --- a/pykat/components.py +++ b/pykat/components.py @@ -25,6 +25,15 @@ class NodeGaussSetter(object): def __init__(self, component, node): self.__comp = weakref.ref(component) self.__node = weakref.ref(node) + self.__name = None + + @property + def name(self): + return self.__name + + @name.setter + def name(self, value): + self.__name = str(value) @property def node(self): diff --git a/pykat/node_network.py b/pykat/node_network.py index e91d32ce9bb8d7c48a29a7a220c2795269c7a198..fa9f282c0f99f0cf4b641aeaa8f6260084fb5663 100644 --- a/pykat/node_network.py +++ b/pykat/node_network.py @@ -433,13 +433,27 @@ class Node(object): return [] rtn = [] - + + # to get the name of the gauss parameter is a bit convoluted... + # firstly the name is set in the NodeGaussSetter object which is + # connected to each component, so this has to be retrieved and + # then applied. + if hasattr(self.__q_comp, self.name): + ns = getattr(self.__q_comp, self.name) + + # if no name is present give it a default one + if ns.name != None: + name = ns.name + else: + name = "g_%s" % self.name + else: + raise pkex.BasePyKatException("Node {0} is not connected to {1}".format(self.name, self.__q_comp.name)) + + if self.__q_x == self.__q_y: - rtn.append("gauss g_{node} {comp} {node} {w0:.15g} {z:.15g}".format(node=self.name, comp=self.__q_comp.name, w0=self.__q_x.w0, z=self.__q_x.z)) - #rtn.append("gauss* g_{node} {comp} {node} {z} {zr}".format(node=self.name, comp=self.__q_comp.name, z=self.__q_x.real, zr=self.__q_x.imag)) + rtn.append("gauss {name} {comp} {node} {w0:.15g} {z:.15g}".format(name=name, node=self.name, comp=self.__q_comp.name, w0=self.__q_x.w0, z=self.__q_x.z)) else: - rtn.append("gauss g_{node} {comp} {node} {w0x:.15g} {zx:.15g} {w0y:.15g} {zy:.15g}".format(node=self.name, comp=self.__q_comp.name, w0x=self.__q_x.w0, zx=self.__q_x.z, w0y=self.__q_y.w0, zy=self.__q_y.z)) - #rtn.append("gauss* g_{node} {comp} {node} {zx} {zrx} {zy} {zry}".format(node=self.name, comp=self.__q_comp.name, zx=self.__q_x.real, zrx=self.__q_x.imag, zy=self.__q_y.real, zry=self.__q_y.imag)) + rtn.append("gauss {name} {comp} {node} {w0x:.15g} {zx:.15g} {w0y:.15g} {zy:.15g}".format(name=name, node=self.name, comp=self.__q_comp.name, w0x=self.__q_x.w0, zx=self.__q_x.z, w0y=self.__q_y.w0, zy=self.__q_y.z)) return rtn diff --git a/pykat/utilities/maps.py b/pykat/utilities/maps.py index 5e10b7bcd329dbe8afed8cd0e1693d00d5d1786d..02bd5128006f3ba31e2bf7020138564b8428c9a1 100644 --- a/pykat/utilities/maps.py +++ b/pykat/utilities/maps.py @@ -29,12 +29,20 @@ class surfacemap: mapfile.write("%.15g " % self.data[i,j]) mapfile.write("\n") + @property + def x(self): + return self.step_size[0] * (numpy.array(range(0, self.data.shape[0]))- self.center[0]) + + @property + def y(self): + return self.step_size[1] * (numpy.array(range(0, self.data.shape[1]))- self.center[1]) + def plot(self, show=True, clabel=None): import pylab - xrange = 100*self.step_size[0] * (numpy.array(range(0, self.data.shape[0]))- self.center[0]) - yrange = 100*self.step_size[1] * (numpy.array(range(0, self.data.shape[1]))- self.center[1]) + xrange = 100*self.x + yrange = 100*self.y fig = pylab.figure() axes = pylab.imshow(self.data, extent=[min(xrange),max(xrange),min(yrange),max(yrange)]) @@ -66,7 +74,7 @@ def read_map(filename): - data = numpy.loadtxt(filename, dtype=numpy.float64, skiprows=9,ndmin=2) + data = numpy.loadtxt(filename, dtype=numpy.float64,ndmin=2,comments='%') return surfacemap(name,maptype,size,center,step,scaling,data)