Commit 4350b768 authored by Daniel Brown's avatar Daniel Brown
Browse files

Adding in map reading/writing class and updates to various gui components,...

Adding in map reading/writing class and updates to various gui components, trying to get rotation working but failing so far
parent fcdb904f
......@@ -11,20 +11,23 @@ s s1 10 1 n1 n2
m m1 1 0 0 n2 n3
pd refl n2
gauss g1 m1 n2 1e-3 0
xaxis m1 r_ap lin 0.1e-3 2e-3 10
"""
kat = finesse.kat()
kat.parseCommands(code)
maxtem = np.linspace(0, 1, 2)
maxtem = np.arange(0, 4)
kat.m1.n2.q = gauss_param(w0=1e-3, z=0)
#kat.m1.n2.q = gauss_param(w0=1e-3, z=0)
kat.verbose = False
for tem in maxtem:
print "Calculating maxtem ", tem, "..."
kat.maxtem = tem
r = kat.run()
pl.plot(r.x/1e-3, r.y, label="maxtem={0}".format(tem))
......
......@@ -8,7 +8,7 @@ import numpy as np
import pylab as pl
code = """
l l1 1 0 0 n1 ### test
l l1 1 0 0 n1
s s1 10 1 n1 n2
m m1 0.5 0.5 0 n2 n3
s s2 10 1 n3 n4
......@@ -25,7 +25,6 @@ attr m1 Rc 1
"""
kat = finesse.kat()
kat.parseCommands(code)
kat.add(xaxis("lin", [0, 360], kat.m2.phi, 100))
......@@ -37,11 +36,6 @@ kat.m2.Rcy = 1000.0
kat.maxtem = 0
out = kat.run(printout=0,printerr=0)
out = kat.run()
out.plot()
pl.figure()
pl.plot(out.x, out.y)
pl.xlabel(out.xlabel)
pl.ylabel("Intensity [W]")
pl.legend(out.ylabels)
pl.show()
......@@ -466,7 +466,7 @@ class beamSplitter(AbstractMirrorComponent):
def getQGraphicsItem(self):
if self._svgItem == None:
# FIXME: make proper SVG component for beam splitter
self._svgItem = pykat.gui.graphics.ComponentQGraphicsItem(":/resources/mirror_flat.svg", self ,[(-4,15,self.nodes[0]), (14,15,self.nodes[1])])
self._svgItem = pykat.gui.graphics.ComponentQGraphicsItem(":/resources/mirror_flat.svg", self ,[(-4,24,self.nodes[0]), (-4,6,self.nodes[1]), (14,6,self.nodes[2]), (14,24,self.nodes[3])])
return self._svgItem
......@@ -592,7 +592,8 @@ class grating(Component):
self.__eta_3 = AttrParam("eta_3", self, SIfloat(eta_3))
self.__rho_0 = AttrParam("rho_0", self, SIfloat(rho_0))
self.__alpha = AttrParam("alpha", self, SIfloat(alpha))
self._svgItem = None
@property
def n(self): return Param('n', self.__n)
@n.setter
......@@ -686,10 +687,10 @@ class grating(Component):
return rtn
def getQGraphicsItem(self):
if self._QItem == None:
self._QItem = pykat.gui.graphics.SpaceQGraphicsItem(self) # TODO: make SVG graphic for grating
if self._svgItem == None:
self._svgItem = pykat.gui.graphics.SpaceQGraphicsItem(self) # TODO: make SVG graphic for grating
return self._QItem
return self._svgItem
class isolator(Component):
def __init__(self, name, node1, node2, S = 0, node3="dump"):
......@@ -698,6 +699,7 @@ class isolator(Component):
self._requested_node_names.append(node1)
self._requested_node_names.append(node2)
self._requested_node_names.append(node3)
self._svgItem = None
self.__S = Param("S",self,SIfloat(S))
......@@ -731,18 +733,18 @@ class isolator(Component):
return rtn
def getQGraphicsItem(self):
if self._QItem == None:
self._QItem = pykat.gui.graphics.SpaceQGraphicsItem(self) # TODO: make isolator graphic
if self._svgItem == None:
self._svgItem = pykat.gui.graphics.ComponentQGraphicsItem(":/resources/isolator.svg", self ,[(-4,15,self.nodes[0]), (14,15,self.nodes[1]), (14,24,self.nodes[2])])
return self._QItem
return self._svgItem
class lens(Component):
def __init__(self, name, node1, node2, f):
def __init__(self, name, node1, node2, f=1):
Component.__init__(self, name)
self._requested_node_names.append(node1)
self._requested_node_names.append(node2)
self._svgItem = None
self.__f = Param("f", self, SIfloat(f))
@property
......@@ -773,18 +775,18 @@ class lens(Component):
return rtn
def getQGraphicsItem(self):
if self._QItem == None:
self._QItem = pykat.gui.graphics.SpaceQGraphicsItem(self) # TODO: make lens graphic
if self._svgItem == None:
self._svgItem = pykat.gui.graphics.ComponentQGraphicsItem(":/resources/lens.svg", self ,[(-4,15,self.nodes[0]), (14,15,self.nodes[1])])
return self._QItem
return self._svgItem
class modulator(Component):
def __init__(self, name, f, midx, order, modulation_type, node1, node2, phase=0):
def __init__(self, name, node1, node2, f, midx, order, modulation_type='pm', phase=0):
Component.__init__(self, name)
self._requested_node_names.append(node1)
self._requested_node_names.append(node2)
self._svgItem = None
self.__f = Param("f", self, SIfloat(f))
self.__midx = Param("midx", self, SIfloat(midx))
self.__phase = Param("phase", self, SIfloat(phase))
......@@ -835,9 +837,9 @@ class modulator(Component):
v.pop(0) # remove initial value
if len(v) == 7:
return modulator(v[0], v[1], v[2], v[3], v[4], v[5], v[6])
return modulator(v[0], v[5], v[6], v[1], v[2], v[3], v[4])
if len(v) == 8:
return modulator(v[0], v[1], v[2], v[3], v[4], v[6], v[7], phase=v[5])
return modulator(v[0], v[6], v[7], v[1], v[2], v[3], v[4], phase=v[5])
else:
raise pkex.BasePyKatException("Modulator Finesse code format incorrect '{0}'".format(text))
......@@ -850,10 +852,10 @@ class modulator(Component):
return rtn
def getQGraphicsItem(self):
if self._QItem == None:
self._QItem = pykat.gui.graphics.SpaceQGraphicsItem(self) # TODO: make lens graphic
if self._svgItem == None:
self._svgItem = pykat.gui.graphics.ComponentQGraphicsItem(":/resources/modulator.svg", self ,[(-4,15,self.nodes[0]), (14,15,self.nodes[1])])
return self._QItem
return self._svgItem
class laser(Component):
def __init__(self,name,node,P=1,f_offset=0,phase=0):
......@@ -865,6 +867,7 @@ class laser(Component):
self.__f_offset = Param("f", self, SIfloat(f_offset), canFsig=True, fsig_name="f")
self.__phase = Param("phase", self, SIfloat(phase), canFsig=True, fsig_name="phase")
self.__noise = AttrParam("noise", self, None)
self._svgItem = None
@property
def P(self): return self.__power
......
......@@ -156,6 +156,14 @@ class katRun(object):
self.katScript = None
self.katVersion = None
self.yaxis = None
def plot(self):
import pylab
pylab.plot(self.x, self.y)
pylab.legend(self.ylabels,0)
pylab.xlabel(self.xlabel)
pylab.show()
def savekatRun(self, filename):
with open(filename,'w') as outfile:
......@@ -865,6 +873,7 @@ class kat(object):
[out,errpipe] = p.communicate()
if printout == 1:
print out
else:
......@@ -905,12 +914,13 @@ class kat(object):
r.xlabel = hdr[0]
r.ylabel = hdr[1]
r.zlabels = map(str.strip, hdr[2:])
else:
[r.x,r.y,hdr] = self.readOutFile(outfile)
r.xlabel = hdr[0]
r.ylabels = map(str.strip, hdr[1:])
if save_kat:
if kat_name == None:
kat_name = "pykat_output"
......@@ -1169,17 +1179,14 @@ class kat(object):
if self.noxaxis == True:
out.append("noxaxis\n")
<<<<<<< HEAD
if self.yaxis != None:
out.append("yaxis {0}\n".format(self.yaxis))
# ensure we don't do any plotting. That should be handled
# by user themselves
out.append("gnuterm no\n")
out.append("pyterm no\n")
=======
>>>>>>> a76f88c16370e3db396376d1b684d24aa7f00c89
#out.append("gnuterm no\n")
#out.append("pyterm no\n")
return out
......
......@@ -52,7 +52,6 @@ class SpaceQGraphicsItem(QGraphicsLineItem):
item = QGraphicsTextItem(self.__space.name, self)
rect = item.boundingRect()
item.setPos(-0.5*rect.width(),0*rect.height())
self.refresh()
@property
......@@ -142,13 +141,20 @@ class SpaceQGraphicsItem(QGraphicsLineItem):
self.setPen(QPen(Qt.red, 3))
class ComponentQGraphicsItem(QtSvg.QGraphicsSvgItem):
class ComponentQGraphicsItem(QGraphicsObject): #(QtSvg.QGraphicsSvgItem):
def __init__(self, svgfile, component, nodes):
QGraphicsSvgItem.__init__(self,svgfile)
#QGraphicsSvgItem.__init__(self,svgfile)
QGraphicsObject.__init__(self)
self.__svggraphic = QGraphicsSvgItem(svgfile)
rect = self.__svggraphic.boundingRect()
self.__nodeGraphics = []
self.__component = weakref.ref(component)
# self.setRotation(432.34234)
# this signals the itemChange() method when this item is moved
# used for refreshing the spaces between components
self.setFlags(QGraphicsItem.ItemSendsGeometryChanges)
......@@ -170,7 +176,15 @@ class ComponentQGraphicsItem(QtSvg.QGraphicsSvgItem):
self.refresh()
self.installEventFilter(self)
self.setHandlesChildEvents(True)
def boundingRect(self):
return self.__svggraphic.boundingRect()
def paint(self, arg1, arg2, arg3):
self.__svggraphic.rotate(45)
self.__svggraphic.paint( arg1, arg2, arg3)
@property
def component(self): return self.__component()
......
......@@ -121,6 +121,14 @@ class pyKatGUI(QtGui.QMainWindow, qt_gui.Ui_MainWindow):
self.kat.add(m)
self.addComponentToScene(m,x,y)
def addBeamsplitter(self, x, y):
name = self.kat.getNewComponentName('bs')
n = self.kat.getNewNodeNames('n', 4)
m = pykat.components.beamSplitter(name,n[0],n[1],n[2],n[3],R=0.5,T=0.5)
self.kat.add(m)
self.addComponentToScene(m,x,y)
def addSpace(self, x,y):
name = self.kat.getNewComponentName('s')
n = self.kat.getNewNodeNames('n',2)
......@@ -137,6 +145,30 @@ class pyKatGUI(QtGui.QMainWindow, qt_gui.Ui_MainWindow):
self.kat.add(l)
self.addComponentToScene(l,x,y)
def addModulator(self, x,y):
name = self.kat.getNewComponentName('mod')
n = self.kat.getNewNodeNames('n',2)
l = pykat.components.modulator(name, n[0], n[1], 1e6, 0.1, 1)
self.kat.add(l)
self.addComponentToScene(l,x,y)
def addLens(self, x,y):
name = self.kat.getNewComponentName('lens')
n = self.kat.getNewNodeNames('n',2)
l = pykat.components.lens(name, n[0], n[1])
self.kat.add(l)
self.addComponentToScene(l,x,y)
def addIsolator(self, x,y):
name = self.kat.getNewComponentName('isol')
n = self.kat.getNewNodeNames('n',3)
l = pykat.components.isolator(name, n[0], n[1], node3=n[2])
self.kat.add(l)
self.addComponentToScene(l,x,y)
def addPhotodiode(self, x, y):
name = self.kat.getNewDetectorName('pd')
n = self.kat.getNewNodeNames('n',1)
......@@ -219,9 +251,21 @@ class pyKatGraphicsView(QGraphicsView):
action = addmenu.addAction("Mirror")
action.triggered.connect(functools.partial(gui.addMirror, pt.x(), pt.y()))
action = addmenu.addAction("Beamsplitter")
action.triggered.connect(functools.partial(gui.addBeamsplitter, pt.x(), pt.y()))
action = addmenu.addAction("Laser")
action.triggered.connect(functools.partial(gui.addLaser, pt.x(), pt.y()))
action = addmenu.addAction("Lens")
action.triggered.connect(functools.partial(gui.addLens, pt.x(), pt.y()))
action = addmenu.addAction("Isolator")
action.triggered.connect(functools.partial(gui.addIsolator, pt.x(), pt.y()))
action = addmenu.addAction("Modulator")
action.triggered.connect(functools.partial(gui.addModulator, pt.x(), pt.y()))
action = addmenu.addAction("Photodiode")
action.triggered.connect(functools.partial(gui.addPhotodiode, pt.x(), pt.y()))
......@@ -372,7 +416,7 @@ class pyKatGraphicsView(QGraphicsView):
else:
self.__itemHover = None
if self.__itemHover is not None:
if self.__itemHover is not None:
self.setCursor(QCursor(Qt.OpenHandCursor))
else:
self.setCursor(QCursor(Qt.ArrowCursor))
......
This diff is collapsed.
......@@ -4,6 +4,9 @@
<file>resources/laser.svg</file>
<file>resources/mirror_flat.svg</file>
<file>resources/mirror_curve.svg</file>
<file>resources/modulator.svg</file>
<file>resources/lens.svg</file>
<file>resources/isolator.svg</file>
<file>resources/photodiode_green.svg</file>
<file>resources/photodiode_red.svg</file>
</qresource>
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:i="http://ns.adobe.com/AdobeIllustrator/10.0/"
xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="51.78125"
height="23.4375"
id="svg18505"
version="1.1"
inkscape:version="0.48.2 r9819"
sodipodi:docname="modulator.svg">
<defs
id="defs18507">
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4599"
id="linearGradient8910"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.8,0,0,0.8,-34.8284,-61.1108)"
x1="43.5355"
y1="107.446"
x2="43.5355"
y2="85.247253" />
<linearGradient
gradientTransform="matrix(0.8,0,0,0.8,-35.0284,-61.5817)"
y2="86.302696"
x2="63.7393"
y1="107.5635"
x1="63.7393"
gradientUnits="userSpaceOnUse"
id="linearGradient4599">
<stop
id="stop4569"
style="stop-color:#FFFFFF"
offset="0" />
<stop
id="stop4571"
style="stop-color:#FFFF99"
offset="0.2501" />
<stop
id="stop4573"
style="stop-color:#FFFF58"
offset="0.428" />
<stop
id="stop4575"
style="stop-color:#FFFF3E"
offset="0.5112" />
<stop
id="stop4577"
style="stop-color:#FFFF53"
offset="0.581" />
<stop
id="stop4579"
style="stop-color:#FFFF89"
offset="0.7253" />
<stop
id="stop4581"
style="stop-color:#FFFFE0"
offset="0.9301" />
<stop
id="stop4583"
style="stop-color:#FFFFFF"
offset="1" />
<a:midPointStop
style="stop-color:#FFFFFF"
offset="0" />
<a:midPointStop
style="stop-color:#FFFFFF"
offset="0.4636" />
<a:midPointStop
style="stop-color:#FFFF3E"
offset="0.5112" />
<a:midPointStop
style="stop-color:#FFFF3E"
offset="0.5441" />
<a:midPointStop
style="stop-color:#FFFFFF"
offset="1" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient5654"
id="linearGradient5672"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(-0.8,0,0,-0.8,-254.9407,-236.2836)"
x1="-364.73962"
y1="-319.32449"
x2="-383.39462"
y2="-300.66949" />
<linearGradient
gradientTransform="matrix(0.8,0,0,0.8,-33.0283,-62.3896)"
y2="83.771004"
x2="59.4697"
y1="101.4873"
x1="41.753399"
gradientUnits="userSpaceOnUse"
id="linearGradient5654">
<stop
id="stop5609"
style="stop-color:#FFFFFF"
offset="0" />
<stop
id="stop5611"
style="stop-color:#89A4B6"
offset="1" />
<a:midPointStop
style="stop-color:#FFFFFF"
offset="0" />
<a:midPointStop
style="stop-color:#FFFFFF"
offset="0.5" />
<a:midPointStop
style="stop-color:#89A4B6"
offset="1" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient5647"
id="linearGradient5674"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(-0.8,0,0,-0.8,-254.9407,-236.2836)"
x1="-318.67587"
y1="-319.32449"
x2="-337.32837"
y2="-300.66949" />
<linearGradient
gradientTransform="matrix(0.8,0,0,0.8,-33.0283,-62.3896)"
y2="83.769798"
x2="105.5344"
y1="101.4873"
x1="87.816902"
gradientUnits="userSpaceOnUse"
id="linearGradient5647">
<stop
id="stop5598"
style="stop-color:#FFFFFF"
offset="0" />
<stop
id="stop5600"
style="stop-color:#89A4B6"
offset="1" />
<a:midPointStop
style="stop-color:#FFFFFF"
offset="0" />
<a:midPointStop
style="stop-color:#FFFFFF"
offset="0.5" />
<a:midPointStop
style="stop-color:#89A4B6"
offset="1" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient5660"
id="linearGradient5676"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(-0.8,0,0,-0.8,-254.9407,-236.2836)"
x1="-365.67712"
y1="-324.6395"
x2="-365.67712"
y2="-295.35449" />
<linearGradient
gradientTransform="matrix(0.8,0,0,0.8,-33.0283,-62.3896)"
y2="78.454102"
x2="73.643097"
y1="106.8008"
x1="73.643097"
gradientUnits="userSpaceOnUse"
id="linearGradient5660">
<stop
id="stop5618"
style="stop-color:#FFFFFF"
offset="0" />
<stop
id="stop5620"
style="stop-color:#C4C4C4"
offset="0.1314" />
<stop
id="stop5622"
style="stop-color:#5C5C5C"
offset="0.3752" />
<stop
id="stop5624"
style="stop-color:#1A1A1A"
offset="0.5444" />
<stop
id="stop5626"
style="stop-color:#000000"
offset="0.6236" />
<stop
id="stop5628"
style="stop-color:#151515"
offset="0.6657" />
<stop
id="stop5630"
style="stop-color:#4C4C4C"
offset="0.7529" />
<stop
id="stop5632"
style="stop-color:#A2A2A2"
offset="0.8765" />
<stop
id="stop5634"
style="stop-color:#FFFFFF"
offset="1" />
<a:midPointStop
style="stop-color:#FFFFFF"
offset="0" />
<a:midPointStop
style="stop-color:#FFFFFF"
offset="0.4636" />
<a:midPointStop
style="stop-color:#000000"
offset="0.6236" />
<a:midPointStop
style="stop-color:#000000"
offset="0.5441" />
<a:midPointStop
style="stop-color:#FFFFFF"
offset="1" />
</linearGradient>
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"