Skip to content
Snippets Groups Projects
Commit b20e1b58 authored by Daniel Brown's avatar Daniel Brown
Browse files

fixing gauss param naming

parent bc77f025
No related branches found
No related tags found
No related merge requests found
......@@ -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])
......
......@@ -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):
......
......@@ -434,12 +434,26 @@ class Node(object):
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
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment