diff --git a/bin/test_aperture.py b/bin/test_aperture.py index b88ce17bdd9d35831e803000711de8c391f4163a..c6bab5f08648b0048c9446d7530ab0ebce48e820 100644 --- a/bin/test_aperture.py +++ b/bin/test_aperture.py @@ -17,10 +17,10 @@ xaxis m1 r_ap lin 0.1e-3 2e-3 10 kat = finesse.kat(kat_code = code) -maxtem = np.arange(0, 1, 2) +maxtem = np.arange(0, 3, 2) for tem in maxtem: - print "Calculating maxtem ",tem,"..." + print "Calculating maxtem ", tem, "..." kat.maxtem = tem r = kat.run() pl.plot(r.x/1e-3, r.y, label="maxtem={0}".format(tem)) diff --git a/bin/test_plot.py b/bin/test_plot.py index bc6440cdd3a8268b0c24afd3f979b15bf76bd9b7..d42fba2c00daea99d091a2ab5db5af980251d93e 100644 --- a/bin/test_plot.py +++ b/bin/test_plot.py @@ -20,9 +20,9 @@ kat = finesse.kat(kat_code=code) kat.add(cavity('cav1','m1','n3','m2','n4')) -kat.add(photodiode('pd_cav','n4')) -kat.add(photodiode('pd_ref','n2')) -kat.add(photodiode('pd_trs','n5')) +kat.add(photodiode('pd_cav','n4',[])) +kat.add(photodiode('pd_ref','n2',[])) +kat.add(photodiode('pd_trs','n5',[])) kat.add(xaxis("lin", [0, 360], kat.m2, kat.m2.phi, 100)) diff --git a/bin/test_pykat_gui.py b/bin/test_pykat_gui.py index 3b39da58caad54f2f31129c9651e2c1ac2146bae..2a77fefee9a3de88c536ff4a94ecfe8b8f05a187 100644 --- a/bin/test_pykat_gui.py +++ b/bin/test_pykat_gui.py @@ -16,7 +16,6 @@ l l1 1 0 0 n1 kat = finesse.kat(kat_code = code) - kat.openGUI() diff --git a/bin/test_rad_pressure.py b/bin/test_rad_pressure.py new file mode 100644 index 0000000000000000000000000000000000000000..31e14772703cfc249927557bb72bc44ceaf6a46c --- /dev/null +++ b/bin/test_rad_pressure.py @@ -0,0 +1,51 @@ +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 diff --git a/pykat/detectors.py b/pykat/detectors.py index f28228b600ab93ed5850b3834b0a2f376738df1f..afdc83beaca2d878ff6c0ce250cb76729d2da979 100644 --- a/pykat/detectors.py +++ b/pykat/detectors.py @@ -8,7 +8,6 @@ import exceptions import pykat.gui.resources from pykat.utils import * - from pykat.gui.graphics import * from pykat.node_network import * @@ -40,8 +39,8 @@ class Detector(object) : def getQGraphicsItem(self): return None - def getNode(self): - return self.__node; + def getNodes(self): + return [self._node] def __getname(self): return self.__name @@ -49,6 +48,22 @@ class Detector(object) : name = property(__getname) 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 def parseFinesseText(text): raise NotImplementedError("This function is not implemented") @@ -71,7 +86,7 @@ class photodiode(Detector): def getQGraphicsItem(self): 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 \ No newline at end of file diff --git a/pykat/finesse.py b/pykat/finesse.py index 3124134cc49a657aa7715f9585c8a511207d837c..07478328e031f730875f1d453f58eaf72863f239 100644 --- a/pykat/finesse.py +++ b/pykat/finesse.py @@ -134,8 +134,23 @@ class kat(object): parseCommands(f.readlines()) def parseCommands(self, commands): + blockComment = False + 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] if(first == "m"): @@ -316,10 +331,18 @@ class kat(object): hdr = outfile.readline().replace('%','').replace('\n','').split(',') data = np.loadtxt(filename,comments='%') - rows,cols = data.shape + shape_len = len(data.shape) - x = data[:,0] - y = data[:,1:cols].squeeze() + if shape_len > 1: + 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] @@ -386,21 +409,32 @@ class kat(object): def hasComponent(self, name): return (name in self.__components) - 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' - ''' + def _newName(self, container, prefix): n = 1 name = "{0}{1}".format(prefix, n) - while name in self.__components: + while name in container: n += 1 name = "{0}{1}".format(prefix,n) 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): ''' Returns a list of names for N number of nodes which haven't already been added. diff --git a/pykat/gui/graphics.py b/pykat/gui/graphics.py index b5b1368e12d535ecc122aa8ae62f74ce8db2e963..66abe4ca3103e42073d09fd9f1e6c1bc2be674ef 100644 --- a/pykat/gui/graphics.py +++ b/pykat/gui/graphics.py @@ -10,7 +10,7 @@ from PyQt4.Qt import * import pykat.components import exceptions -nsize = 8 +nsize = 10 class NodeQGraphicItem(QGraphicsRectItem): diff --git a/pykat/gui/gui.py b/pykat/gui/gui.py index 6b82e3d35c0f7e1ccf7780937948a60af0c3171d..d59aba602b4ba8c45186a3a5d217c9b416004e8c 100644 --- a/pykat/gui/gui.py +++ b/pykat/gui/gui.py @@ -119,6 +119,14 @@ class pyKatGUI(QtGui.QMainWindow, qt_gui.Ui_MainWindow): 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) + l = pykat.detectors.photodiode(name, n[0], []) + + self.kat.add(l) + self.addComponentToScene(l,x,y) class pyKatGraphicsScene(QGraphicsScene): def drawBackground(self, painter, rect): @@ -159,7 +167,7 @@ class pyKatGraphicsView(QGraphicsView): def contextMenuEvent(self, ev): pt = self.mapToScene(ev.pos()) - + gui = self.parentWidget().parent() # get the main gui window menu = QMenu(self) @@ -174,8 +182,8 @@ class pyKatGraphicsView(QGraphicsView): action = addmenu.addAction("Laser") action.triggered.connect(functools.partial(gui.addLaser, pt.x(), pt.y())) - addmenu.addAction("Beamsplitter") - addmenu.addAction("Photodiode") + action = addmenu.addAction("Photodiode") + action.triggered.connect(functools.partial(gui.addPhotodiode, pt.x(), pt.y())) item = self.scene().itemAt(pt.x(),pt.y()) @@ -189,6 +197,7 @@ class pyKatGraphicsView(QGraphicsView): if isinstance(item,NodeQGraphicItem): menu.addSeparator() menu.addAction("Disconnect") + menu.popup(ev.globalPos()); @@ -248,7 +257,8 @@ class pyKatGraphicsView(QGraphicsView): # then refresh the graphical items qspace.refresh() qcomp.refresh() - + + self.setCursor(QCursor(Qt.ArrowCursor)) if self.__marked is not None: self.__marked.marked = False @@ -256,8 +266,7 @@ class pyKatGraphicsView(QGraphicsView): self.__marked = None self.__selected_item = None - self.setCursor(QCursor(Qt.ArrowCursor)) - + def mouseMoveEvent(self, ev): if self.__selected_item != None: