Commit bccb041c authored by Daniel Brown's avatar Daniel Brown
Browse files

adding in more gui fixes and another example

parent 64810bc8
...@@ -17,10 +17,10 @@ xaxis m1 r_ap lin 0.1e-3 2e-3 10 ...@@ -17,10 +17,10 @@ xaxis m1 r_ap lin 0.1e-3 2e-3 10
kat = finesse.kat(kat_code = code) kat = finesse.kat(kat_code = code)
maxtem = np.arange(0, 1, 2) maxtem = np.arange(0, 3, 2)
for tem in maxtem: for tem in maxtem:
print "Calculating maxtem ",tem,"..." print "Calculating maxtem ", tem, "..."
kat.maxtem = tem kat.maxtem = tem
r = kat.run() r = kat.run()
pl.plot(r.x/1e-3, r.y, label="maxtem={0}".format(tem)) pl.plot(r.x/1e-3, r.y, label="maxtem={0}".format(tem))
......
...@@ -20,9 +20,9 @@ kat = finesse.kat(kat_code=code) ...@@ -20,9 +20,9 @@ kat = finesse.kat(kat_code=code)
kat.add(cavity('cav1','m1','n3','m2','n4')) kat.add(cavity('cav1','m1','n3','m2','n4'))
kat.add(photodiode('pd_cav','n4')) kat.add(photodiode('pd_cav','n4',[]))
kat.add(photodiode('pd_ref','n2')) kat.add(photodiode('pd_ref','n2',[]))
kat.add(photodiode('pd_trs','n5')) kat.add(photodiode('pd_trs','n5',[]))
kat.add(xaxis("lin", [0, 360], kat.m2, kat.m2.phi, 100)) kat.add(xaxis("lin", [0, 360], kat.m2, kat.m2.phi, 100))
......
...@@ -16,7 +16,6 @@ l l1 1 0 0 n1 ...@@ -16,7 +16,6 @@ l l1 1 0 0 n1
kat = finesse.kat(kat_code = code) kat = finesse.kat(kat_code = code)
kat.openGUI() kat.openGUI()
from pykat import finesse
from pykat.detectors import *
from pykat.components import *
from pykat.commands import *
from pykat.structs import *
import numpy as np
import pylab as pl
code = """
l l1 1 0 n1
m m1 0.99 0.01 0 n1 n2
s cav1 1200 n2 n3
m m2 0.99 0.01 -0.1 n3 n4
#attr m1 m 1# mech sus1
attr m2 m 1# mech sus1
fsig sig l1 amp 1 0 4
#ad car_refl 0 n1
ad up_refl 0 n1
ad low_refl 0 n1
#qd refl_A 0 0 n1
#qd refl_Q 0 90 n1
#qd tran_A 0 0 n4
#qd tran_Q 0 90 n4
put up_refl f $x1
put low_refl f $mx1
xaxis sig f log 1 10000 1000
yaxis log re:im
"""
kat = finesse.kat(kat_code=code)
run = kat.run(printout=0,printerr=0)
# using real and imag part compute the complex value of the upper and lower sidebands
a_up = run.y[:,0] + run.y[:,1]*1j
a_lo = run.y[:,2] + run.y[:,3]*-1j
pl.figure()
pl.loglog(run.x, np.abs(a_up + a_lo), run.x, np.abs((a_up - a_lo) / (1j)))
pl.xlabel(run.xlabel)
pl.show()
pl.figure()
pl.loglog(run.x, np.abs(a_up), run.x, np.abs(a_lo))
pl.xlabel(run.xlabel)
pl.show()
\ No newline at end of file
...@@ -8,7 +8,6 @@ import exceptions ...@@ -8,7 +8,6 @@ import exceptions
import pykat.gui.resources import pykat.gui.resources
from pykat.utils import * from pykat.utils import *
from pykat.gui.graphics import * from pykat.gui.graphics import *
from pykat.node_network import * from pykat.node_network import *
...@@ -40,8 +39,8 @@ class Detector(object) : ...@@ -40,8 +39,8 @@ class Detector(object) :
def getQGraphicsItem(self): def getQGraphicsItem(self):
return None return None
def getNode(self): def getNodes(self):
return self.__node; return [self._node]
def __getname(self): def __getname(self):
return self.__name return self.__name
...@@ -49,6 +48,22 @@ class Detector(object) : ...@@ -49,6 +48,22 @@ class Detector(object) :
name = property(__getname) name = property(__getname)
class photodiode(Detector): class photodiode(Detector):
class demodulation:
def __init__(self, f, phase):
self.frequency = f
self.phase = phase
def __init__(self, name, node, demods):
Detector.__init__(self, name, node)
self._num_demods = len(demods)
for d in demods:
if not isinstance(d, photodiode.demodulation):
raise ValueError("demods array has something other than a demodulation in it")
self._demods.append(d)
@staticmethod @staticmethod
def parseFinesseText(text): def parseFinesseText(text):
raise NotImplementedError("This function is not implemented") raise NotImplementedError("This function is not implemented")
...@@ -71,7 +86,7 @@ class photodiode(Detector): ...@@ -71,7 +86,7 @@ class photodiode(Detector):
def getQGraphicsItem(self): def getQGraphicsItem(self):
if self._svgItem == None: if self._svgItem == None:
self._svgItem = ComponentQGraphicsItem(":/resources/photodiode_red.svg",self,[(-20,0,self.node)]) self._svgItem = ComponentQGraphicsItem(":/resources/photodiode_red.svg",self,[(-5,11,self._node)])
return self._svgItem return self._svgItem
\ No newline at end of file
...@@ -134,8 +134,23 @@ class kat(object): ...@@ -134,8 +134,23 @@ class kat(object):
parseCommands(f.readlines()) parseCommands(f.readlines())
def parseCommands(self, commands): def parseCommands(self, commands):
blockComment = False
for line in commands.split("\n"): for line in commands.split("\n"):
if len(line.strip()) > 0: if len(line.strip()) >= 2:
line = line.strip()
# don't read comment lines
if line[0] == "#" or line[0] == "%":
continue
# check if block comment is being used
if not blockComment and line[0:2] == "/*":
blockComment = True
continue
elif blockComment and line[0:2] == "*/":
blockComment = False
continue
first = line.split(" ",1)[0] first = line.split(" ",1)[0]
if(first == "m"): if(first == "m"):
...@@ -316,10 +331,18 @@ class kat(object): ...@@ -316,10 +331,18 @@ class kat(object):
hdr = outfile.readline().replace('%','').replace('\n','').split(',') hdr = outfile.readline().replace('%','').replace('\n','').split(',')
data = np.loadtxt(filename,comments='%') data = np.loadtxt(filename,comments='%')
rows,cols = data.shape shape_len = len(data.shape)
x = data[:,0] if shape_len > 1:
y = data[:,1:cols].squeeze() rows,cols = data.shape
x = data[:,0]
y = data[:,1:cols].squeeze()
else:
rows = 1
cols = data.shape[0]
x = data[0]
y = data[1:cols].squeeze()
return [x, y, hdr] return [x, y, hdr]
...@@ -386,21 +409,32 @@ class kat(object): ...@@ -386,21 +409,32 @@ class kat(object):
def hasComponent(self, name): def hasComponent(self, name):
return (name in self.__components) return (name in self.__components)
def getNewComponentName(self,prefix): def _newName(self, container, prefix):
'''
Returns a name for a component which hasn't already been added.
Returns [prefix] + number, where number is greater than 1. e.g.
if m1 exists getNewName('m') will return 'm2'
'''
n = 1 n = 1
name = "{0}{1}".format(prefix, n) name = "{0}{1}".format(prefix, n)
while name in self.__components: while name in container:
n += 1 n += 1
name = "{0}{1}".format(prefix,n) name = "{0}{1}".format(prefix,n)
return name return name
def getNewComponentName(self,prefix):
'''
Returns a name for a component which hasn't already been added.
Returns [prefix] + number, where number is greater than 1. e.g.
if m1 exists getNewName('m') will return 'm2'
'''
return self._newName(self.__components, prefix)
def getNewDetectorName(self,prefix):
'''
Returns a name for a component which hasn't already been added.
Returns [prefix] + number, where number is greater than 1. e.g.
if m1 exists getNewName('m') will return 'm2'
'''
return self._newName(self.__detectors, prefix)
def getNewNodeNames(self,prefix,N=1): def getNewNodeNames(self,prefix,N=1):
''' '''
Returns a list of names for N number of nodes which haven't already been added. Returns a list of names for N number of nodes which haven't already been added.
......
...@@ -10,7 +10,7 @@ from PyQt4.Qt import * ...@@ -10,7 +10,7 @@ from PyQt4.Qt import *
import pykat.components import pykat.components
import exceptions import exceptions
nsize = 8 nsize = 10
class NodeQGraphicItem(QGraphicsRectItem): class NodeQGraphicItem(QGraphicsRectItem):
......
...@@ -119,6 +119,14 @@ class pyKatGUI(QtGui.QMainWindow, qt_gui.Ui_MainWindow): ...@@ -119,6 +119,14 @@ class pyKatGUI(QtGui.QMainWindow, qt_gui.Ui_MainWindow):
self.kat.add(l) self.kat.add(l)
self.addComponentToScene(l,x,y) self.addComponentToScene(l,x,y)
def addPhotodiode(self, x, y):
name = self.kat.getNewDetectorName('pd')
n = self.kat.getNewNodeNames('n',1)
l = pykat.detectors.photodiode(name, n[0], [])
self.kat.add(l)
self.addComponentToScene(l,x,y)
class pyKatGraphicsScene(QGraphicsScene): class pyKatGraphicsScene(QGraphicsScene):
def drawBackground(self, painter, rect): def drawBackground(self, painter, rect):
...@@ -159,7 +167,7 @@ class pyKatGraphicsView(QGraphicsView): ...@@ -159,7 +167,7 @@ class pyKatGraphicsView(QGraphicsView):
def contextMenuEvent(self, ev): def contextMenuEvent(self, ev):
pt = self.mapToScene(ev.pos()) pt = self.mapToScene(ev.pos())
gui = self.parentWidget().parent() # get the main gui window gui = self.parentWidget().parent() # get the main gui window
menu = QMenu(self) menu = QMenu(self)
...@@ -174,8 +182,8 @@ class pyKatGraphicsView(QGraphicsView): ...@@ -174,8 +182,8 @@ class pyKatGraphicsView(QGraphicsView):
action = addmenu.addAction("Laser") action = addmenu.addAction("Laser")
action.triggered.connect(functools.partial(gui.addLaser, pt.x(), pt.y())) action.triggered.connect(functools.partial(gui.addLaser, pt.x(), pt.y()))
addmenu.addAction("Beamsplitter") action = addmenu.addAction("Photodiode")
addmenu.addAction("Photodiode") action.triggered.connect(functools.partial(gui.addPhotodiode, pt.x(), pt.y()))
item = self.scene().itemAt(pt.x(),pt.y()) item = self.scene().itemAt(pt.x(),pt.y())
...@@ -189,6 +197,7 @@ class pyKatGraphicsView(QGraphicsView): ...@@ -189,6 +197,7 @@ class pyKatGraphicsView(QGraphicsView):
if isinstance(item,NodeQGraphicItem): if isinstance(item,NodeQGraphicItem):
menu.addSeparator() menu.addSeparator()
menu.addAction("Disconnect") menu.addAction("Disconnect")
menu.popup(ev.globalPos()); menu.popup(ev.globalPos());
...@@ -248,7 +257,8 @@ class pyKatGraphicsView(QGraphicsView): ...@@ -248,7 +257,8 @@ class pyKatGraphicsView(QGraphicsView):
# then refresh the graphical items # then refresh the graphical items
qspace.refresh() qspace.refresh()
qcomp.refresh() qcomp.refresh()
self.setCursor(QCursor(Qt.ArrowCursor))
if self.__marked is not None: if self.__marked is not None:
self.__marked.marked = False self.__marked.marked = False
...@@ -256,8 +266,7 @@ class pyKatGraphicsView(QGraphicsView): ...@@ -256,8 +266,7 @@ class pyKatGraphicsView(QGraphicsView):
self.__marked = None self.__marked = None
self.__selected_item = None self.__selected_item = None
self.setCursor(QCursor(Qt.ArrowCursor))
def mouseMoveEvent(self, ev): def mouseMoveEvent(self, ev):
if self.__selected_item != None: if self.__selected_item != None:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment