Commit 94f811e6 authored by Daniel Brown's avatar Daniel Brown
Browse files

EOL changes

parent 6b2e8649
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
m m2 0.5 0.5 0 n4 dump
pd PD1 n2
xaxis m1 phi lin 0 360 1000
from pykat import finesse from pykat import finesse
from pykat.detectors import * from pykat.detectors import *
from pykat.components import * from pykat.components import *
from pykat.commands import * from pykat.commands import *
from pykat.structs import * from pykat.structs import *
import numpy as np import numpy as np
import pylab as pl import pylab as pl
code = """ code = """
l l1 1 0 0 n1 l l1 1 0 0 n1
s s1 10 1 n1 n2 s s1 10 1 n1 n2
m m1 0.5 0.5 0 n2 n3 m m1 0.5 0.5 0 n2 n3
s s2 10 1 n3 n4 s s2 10 1 n3 n4
m m2 0.5 0.5 0 n4 n5 m m2 0.5 0.5 0 n4 n5
s s3 10 1 n5 n6 s s3 10 1 n5 n6
""" """
#kat = finesse.kat(katexe='/Users/adf/work/bin/kat') #kat = finesse.kat(katexe='/Users/adf/work/bin/kat')
kat = finesse.kat() kat = finesse.kat()
kat.parseCommands(code) kat.parseCommands(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))
kat.m1.Rcx = -1000.0 kat.m1.Rcx = -1000.0
kat.m1.Rcy = -1000.0 kat.m1.Rcy = -1000.0
kat.m2.Rcx = 1000.0 kat.m2.Rcx = 1000.0
kat.m2.Rcy = 1000.0 kat.m2.Rcy = 1000.0
kat.maxtem = 0 kat.maxtem = 0
out = kat.run(printout=0,printerr=0) out = kat.run(printout=0,printerr=0)
pl.figure() pl.figure()
pl.plot(out.x, out["pd_cav"]) pl.plot(out.x, out["pd_cav"])
pl.xlabel(out.xlabel) pl.xlabel(out.xlabel)
pl.ylabel("Intensity [W]") pl.ylabel("Intensity [W]")
pl.legend(out.ylabels) pl.legend(out.ylabels)
pl.show() pl.show()
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
Created on Mon Jan 28 10:43:18 2013 Created on Mon Jan 28 10:43:18 2013
@author: Daniel @author: Daniel
""" """
class colours: class colours:
HEADER = '\033[95m' HEADER = '\033[95m'
OKBLUE = '\033[94m' OKBLUE = '\033[94m'
OKGREEN = '\033[92m' OKGREEN = '\033[92m'
WARNING = '\033[93m' WARNING = '\033[93m'
FAIL = '\033[91m' FAIL = '\033[91m'
ENDC = '\033[0m' ENDC = '\033[0m'
def disable(self): def disable(self):
self.HEADER = '' self.HEADER = ''
self.OKBLUE = '' self.OKBLUE = ''
self.OKGREEN = '' self.OKGREEN = ''
self.WARNING = '' self.WARNING = ''
self.FAIL = '' self.FAIL = ''
self.ENDC = '' self.ENDC = ''
\ No newline at end of file
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
Created on Mon Jan 28 11:58:09 2013 Created on Mon Jan 28 11:58:09 2013
@author: Daniel @author: Daniel
""" """
import numpy import numpy
from numpy import min,max from numpy import min,max
import exceptions import exceptions
from components import * from components import *
from structs import * from structs import *
from pykat.param import Param, putter from pykat.param import Param, putter
class Command(object): class Command(object):
def __init__(self): def __init__(self):
self.tag = None self.tag = None
def getFinesseText(self): def getFinesseText(self):
""" Base class for individual finesse optical components """ """ Base class for individual finesse optical components """
raise NotImplementedError("This function is not implemented") raise NotImplementedError("This function is not implemented")
@staticmethod @staticmethod
def parseFinesseText(text): def parseFinesseText(text):
raise NotImplementedError("This function is not implemented") raise NotImplementedError("This function is not implemented")
def _on_kat_add(self, kat): def _on_kat_add(self, kat):
""" """
Called when this component has been added to a kat object Called when this component has been added to a kat object
""" """
self._kat = kat self._kat = kat
class cavity(Command): class cavity(Command):
def __init__(self, name, c1, n1, c2, n2): def __init__(self, name, c1, n1, c2, n2):
self.__name = name self.__name = name
self.__c1 = c1 self.__c1 = c1
self.__c2 = c2 self.__c2 = c2
self.__n1 = n1 self.__n1 = n1
self.__n2 = n2 self.__n2 = n2
def getFinesseText(self): def getFinesseText(self):
return 'cav {0} {1} {2} {3} {4}'.format(self.__name, self.__c1, self.__n1, self.__c2, self.__n2); return 'cav {0} {1} {2} {3} {4}'.format(self.__name, self.__c1, self.__n1, self.__c2, self.__n2);
class gauss(object): class gauss(object):
@staticmethod @staticmethod
def parseFinesseText(text, kat): def parseFinesseText(text, kat):
values = text.split(" ") values = text.split(" ")
if not values[0].startswith("gauss"): if not values[0].startswith("gauss"):
raise exceptions.RuntimeError("'{0}' not a valid Finesse gauss command".format(text)) raise exceptions.RuntimeError("'{0}' not a valid Finesse gauss command".format(text))
class xaxis(Command): class xaxis(Command):
def __init__(self, scale, limits, comp, param, steps, axis_type="xaxis"): def __init__(self, scale, limits, comp, param, steps, axis_type="xaxis"):
self._axis_type = axis_type self._axis_type = axis_type
self.x = putter("x1") self.x = putter("x1")
self.mx = putter("mx1") self.mx = putter("mx1")
if scale == "lin": if scale == "lin":
scale = Scale.linear scale = Scale.linear
elif scale == "log": elif scale == "log":
scale = Scale.logarithmic scale = Scale.logarithmic
elif isinstance(scale, str): elif isinstance(scale, str):
# else we have a string but not a recognisable one # else we have a string but not a recognisable one
raise exceptions.ValueError("scale argument '{0}' is not valid, must be 'lin' or 'log'".format(scale)) raise exceptions.ValueError("scale argument '{0}' is not valid, must be 'lin' or 'log'".format(scale))
if scale != Scale.linear and scale != Scale.logarithmic: if scale != Scale.linear and scale != Scale.logarithmic:
raise exceptions.ValueError("scale is not Scale.linear or Scale.logarithmic") raise exceptions.ValueError("scale is not Scale.linear or Scale.logarithmic")
self.scale = scale self.scale = scale
if numpy.size(limits) != 2 : if numpy.size(limits) != 2 :
raise exceptions.ValueError("limits input should be a 2x1 vector of limits for the xaxis") raise exceptions.ValueError("limits input should be a 2x1 vector of limits for the xaxis")
self.limits = numpy.array(SIfloat(limits)).astype(float) self.limits = numpy.array(SIfloat(limits)).astype(float)
if steps <= 0 : if steps <= 0 :
raise exceptions.ValueError("steps value should be > 0") raise exceptions.ValueError("steps value should be > 0")
self.steps = int(steps) self.steps = int(steps)
# if entered component is a string then just store and use that # if entered component is a string then just store and use that
if isinstance(comp, str): if isinstance(comp, str):
self.__comp = comp self.__comp = comp
elif not isinstance(comp, Component): elif not isinstance(comp, Component):
raise exceptions.ValueError("{0} has not been added".format(comp)) raise exceptions.ValueError("{0} has not been added".format(comp))
else: else:
self.__comp = comp self.__comp = comp
if isinstance(param, str): if isinstance(param, str):
self.__param = param self.__param = param
elif not isinstance(param, Param) : elif not isinstance(param, Param) :
raise exceptions.ValueError("param argument is not of type Param") raise exceptions.ValueError("param argument is not of type Param")
else: else:
self.__param = param self.__param = param
@staticmethod @staticmethod
def parseFinesseText(text): def parseFinesseText(text):
values = text.split(" ") values = text.split(" ")
if values[0] != "xaxis" and values[0] != "xaxis*": if values[0] != "xaxis" and values[0] != "xaxis*":
raise exceptions.RuntimeError("'{0}' not a valid Finesse xaxis command".format(text)) raise exceptions.RuntimeError("'{0}' not a valid Finesse xaxis command".format(text))
axis_type = values[0] axis_type = values[0]
values.pop(0) # remove initial value values.pop(0) # remove initial value
if len(values) != 6: if len(values) != 6:
raise exceptions.RuntimeError("xaxis Finesse code format incorrect '{0}'".format(text)) raise exceptions.RuntimeError("xaxis Finesse code format incorrect '{0}'".format(text))
return xaxis(values[2], [values[3], values[4]], values[0], values[1], values[5], axis_type=axis_type) return xaxis(values[2], [values[3], values[4]], values[0], values[1], values[5], axis_type=axis_type)
def getFinesseText(self): def getFinesseText(self):
# store either the component name of the string provided # store either the component name of the string provided
comp_name = self.__comp.name if isinstance(self.__comp, Component) else self.__comp comp_name = self.__comp.name if isinstance(self.__comp, Component) else self.__comp
param_name = self.__param.name if isinstance(self.__param, Param) else self.__param param_name = self.__param.name if isinstance(self.__param, Param) else self.__param
return '{axis_type} {0} {1} {2} {3} {4} {5}'.format( return '{axis_type} {0} {1} {2} {3} {4} {5}'.format(
comp_name, param_name, self.scale, comp_name, param_name, self.scale,
min(self.limits), max(self.limits), self.steps, axis_type=self._axis_type); min(self.limits), max(self.limits), self.steps, axis_type=self._axis_type);
class x2axis(xaxis): class x2axis(xaxis):
def __init__(self, scale, limits, comp, param, steps): def __init__(self, scale, limits, comp, param, steps):
xaxis.__init__(self, scale, limits, comp, param, steps, axis_type="x2axis") xaxis.__init__(self, scale, limits, comp, param, steps, axis_type="x2axis")
self.x = putter("x2") self.x = putter("x2")
self.mx = putter("mx2") self.mx = putter("mx2")
@staticmethod @staticmethod
def parseFinesseText(text): def parseFinesseText(text):
values = text.split(" ") values = text.split(" ")
if values[0] != "x2axis" and values[0] != "x2axis*": if values[0] != "x2axis" and values[0] != "x2axis*":
raise exceptions.RuntimeError("'{0}' not a valid Finesse xaxis command".format(text)) raise exceptions.RuntimeError("'{0}' not a valid Finesse xaxis command".format(text))
axis_type = values[0] axis_type = values[0]
values.pop(0) # remove initial value values.pop(0) # remove initial value
if len(values) != 6: if len(values) != 6:
raise exceptions.RuntimeError("xaxis Finesse code format incorrect '{0}'".format(text)) raise exceptions.RuntimeError("xaxis Finesse code format incorrect '{0}'".format(text))
return x2axis(values[2], [values[3], values[4]], values[0], values[1], values[5]) return x2axis(values[2], [values[3], values[4]], values[0], values[1], values[5])
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
import exceptions import exceptions
class BasePyKatException(Exception): class BasePyKatException(Exception):
def __init__(self, msg): def __init__(self, msg):
self.__msg = msg self.__msg = msg
def __str__(self): def __str__(self):
return self.__msg return self.__msg
class FinesseParse(BasePyKatException) : class FinesseParse(BasePyKatException) :
def __init__(self, msg): def __init__(self, msg):
BasePyKatException.__init__(self, "Error parsing Finesse input\n{0}".format(msg)) BasePyKatException.__init__(self, "Error parsing Finesse input\n{0}".format(msg))
class MissingFinesseEnvVar(BasePyKatException) : class MissingFinesseEnvVar(BasePyKatException) :
def __init__(self): def __init__(self):
BasePyKatException.__init__(self, "The environment variable FINESSE_DIR was not defined") BasePyKatException.__init__(self, "The environment variable FINESSE_DIR was not defined")
class MissingFinesse(BasePyKatException) : class MissingFinesse(BasePyKatException) :
def __init__(self): def __init__(self):
BasePyKatException.__init__(self, "Could not find the finesse executable 'kat' in '{0}'," \ BasePyKatException.__init__(self, "Could not find the finesse executable 'kat' in '{0}'," \
"or you do not have the permissions to run it." \ "or you do not have the permissions to run it." \
.format(os.environ.get('FINESSE_DIR'))) .format(os.environ.get('FINESSE_DIR')))
class FinesseRunError(BasePyKatException) : class FinesseRunError(BasePyKatException) :
def __init__(self, err, kat): def __init__(self, err, kat):
self.__err = err self.__err = err
self.__kat = kat self.__kat = kat
BasePyKatException.__init__(self, "Finesse returned an error running {1}: {0}".format(self.__err, self.__kat)) BasePyKatException.__init__(self, "Finesse returned an error running {1}: {0}".format(self.__err, self.__kat))
This diff is collapsed.
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
Created on Fri Feb 01 09:13:03 2013 Created on Fri Feb 01 09:13:03 2013
@author: Daniel @author: Daniel
""" """
from PyQt4.QtGui import * from PyQt4.QtGui import *
from PyQt4.Qt import * from PyQt4.Qt import *
from PyQt4 import QtSvg from PyQt4 import QtSvg
from PyQt4.QtSvg import QGraphicsSvgItem from PyQt4.QtSvg import QGraphicsSvgItem
import pykat.components import pykat.components
import exceptions import exceptions
nsize = 10 nsize = 10
class NodeQGraphicItem(QGraphicsRectItem): class NodeQGraphicItem(QGraphicsRectItem):
def __init__(self, node, x,y, *args, **kwargs): def __init__(self, node, x,y, *args, **kwargs):
QGraphicsRectItem.__init__(self, *args, **kwargs) QGraphicsRectItem.__init__(self, *args, **kwargs)
self.__node = node self.__node = node
self.setPos(x,y) self.setPos(x,y)
item = QGraphicsTextItem(node.name, self) item = QGraphicsTextItem(node.name, self)
rect = item.boundingRect() rect = item.boundingRect()
item.setPos(-0.5*rect.width(), 0) item.setPos(-0.5*rect.width(), 0)
self.setAcceptHoverEvents(True) self.setAcceptHoverEvents(True)
self.marked = False self.marked = False
@property @property
def node(self): return self.__node def node(self): return self.__node
def refresh(self): def refresh(self):
if not self.marked: if not self.marked:
if self.__node.isConnected(): if self.__node.isConnected():
self.setBrush(QBrush(Qt.red)) self.setBrush(QBrush(Qt.red))
else: else:
self.setBrush(QBrush(Qt.green)) self.setBrush(QBrush(Qt.green))
else: else:
self.setBrush(QBrush(Qt.yellow)) self.setBrush(QBrush(Qt.yellow))
class SpaceQGraphicsItem(QGraphicsLineItem): class SpaceQGraphicsItem(QGraphicsLineItem):
def __init__(self, spaceComponent): def __init__(self, spaceComponent):
QGraphicsLineItem.__init__(self) QGraphicsLineItem.__init__(self)
self.__n1 = None self.__n1 = None
self.__n2 = None self.__n2 = None
self.__space = spaceComponent self.__space = spaceComponent
item = QGraphicsTextItem(self.__space.name, self) item = QGraphicsTextItem(self.__space.name, self)
rect = item.boundingRect() rect = item.boundingRect()
item.setPos(-0.5*rect.width(),0*rect.height()) item.setPos(-0.5*rect.width(),0*rect.height())
self.refresh() self.refresh()
@property @property
def space(self): return self.__space def space(self): return self.__space
def refresh(self): def refresh(self):
nodes = self.__space.nodes nodes = self.__space.nodes
conn = nodes[0].amIConnected(self.__space) conn = nodes[0].amIConnected(self.__space)
x1 = 0 x1 = 0
y1 = 0 y1 = 0
x2 = 0 x2 = 0
y2 = 0 y2 = 0
if conn[0]: if conn[0]:
if conn[1] != None: if conn[1] != None:
if self.__n1 is not None: if self.__n1 is not None:
# i.e. we have a node graphic item but now it is connected to something # i.e. we have a node graphic item but now it is connected to something
self.__n1.scene().removeItem(self.__n1) self.__n1.scene().removeItem(self.__n1)
self.__n1 = None self.__n1 = None
# now check if a connected component was returned too # now check if a connected component was returned too
if conn[1] != None: if conn[1] != None:
# so this node should be attached to something # so this node should be attached to something
# in this case we get the position of their node # in this case we get the position of their node
# and draw the the line from their # and draw the the line from their