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.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 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 n5
s s3 10 1 n5 n6
"""
#kat = finesse.kat(katexe='/Users/adf/work/bin/kat')
kat = finesse.kat()
kat.parseCommands(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(xaxis("lin", [0, 360], kat.m2, kat.m2.phi, 100))
kat.m1.Rcx = -1000.0
kat.m1.Rcy = -1000.0
kat.m2.Rcx = 1000.0
kat.m2.Rcy = 1000.0
kat.maxtem = 0
out = kat.run(printout=0,printerr=0)
pl.figure()
pl.plot(out.x, out["pd_cav"])
pl.xlabel(out.xlabel)
pl.ylabel("Intensity [W]")
pl.legend(out.ylabels)
pl.show()
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 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 n5
s s3 10 1 n5 n6
"""
#kat = finesse.kat(katexe='/Users/adf/work/bin/kat')
kat = finesse.kat()
kat.parseCommands(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(xaxis("lin", [0, 360], kat.m2, kat.m2.phi, 100))
kat.m1.Rcx = -1000.0
kat.m1.Rcy = -1000.0
kat.m2.Rcx = 1000.0
kat.m2.Rcy = 1000.0
kat.maxtem = 0
out = kat.run(printout=0,printerr=0)
pl.figure()
pl.plot(out.x, out["pd_cav"])
pl.xlabel(out.xlabel)
pl.ylabel("Intensity [W]")
pl.legend(out.ylabels)
pl.show()
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 28 10:43:18 2013
@author: Daniel
"""
class colours:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
def disable(self):
self.HEADER = ''
self.OKBLUE = ''
self.OKGREEN = ''
self.WARNING = ''
self.FAIL = ''
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 28 10:43:18 2013
@author: Daniel
"""
class colours:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
def disable(self):
self.HEADER = ''
self.OKBLUE = ''
self.OKGREEN = ''
self.WARNING = ''
self.FAIL = ''
self.ENDC = ''
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 28 11:58:09 2013
@author: Daniel
"""
import numpy
from numpy import min,max
import exceptions
from components import *
from structs import *
from pykat.param import Param, putter
class Command(object):
def __init__(self):
self.tag = None
def getFinesseText(self):
""" Base class for individual finesse optical components """
raise NotImplementedError("This function is not implemented")
@staticmethod
def parseFinesseText(text):
raise NotImplementedError("This function is not implemented")
def _on_kat_add(self, kat):
"""
Called when this component has been added to a kat object
"""
self._kat = kat
class cavity(Command):
def __init__(self, name, c1, n1, c2, n2):
self.__name = name
self.__c1 = c1
self.__c2 = c2
self.__n1 = n1
self.__n2 = n2
def getFinesseText(self):
return 'cav {0} {1} {2} {3} {4}'.format(self.__name, self.__c1, self.__n1, self.__c2, self.__n2);
class gauss(object):
@staticmethod
def parseFinesseText(text, kat):
values = text.split(" ")
if not values[0].startswith("gauss"):
raise exceptions.RuntimeError("'{0}' not a valid Finesse gauss command".format(text))
class xaxis(Command):
def __init__(self, scale, limits, comp, param, steps, axis_type="xaxis"):
self._axis_type = axis_type
self.x = putter("x1")
self.mx = putter("mx1")
if scale == "lin":
scale = Scale.linear
elif scale == "log":
scale = Scale.logarithmic
elif isinstance(scale, str):
# 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))
if scale != Scale.linear and scale != Scale.logarithmic:
raise exceptions.ValueError("scale is not Scale.linear or Scale.logarithmic")
self.scale = scale
if numpy.size(limits) != 2 :
raise exceptions.ValueError("limits input should be a 2x1 vector of limits for the xaxis")
self.limits = numpy.array(SIfloat(limits)).astype(float)
if steps <= 0 :
raise exceptions.ValueError("steps value should be > 0")
self.steps = int(steps)
# if entered component is a string then just store and use that
if isinstance(comp, str):
self.__comp = comp
elif not isinstance(comp, Component):
raise exceptions.ValueError("{0} has not been added".format(comp))
else:
self.__comp = comp
if isinstance(param, str):
self.__param = param
elif not isinstance(param, Param) :
raise exceptions.ValueError("param argument is not of type Param")
else:
self.__param = param
@staticmethod
def parseFinesseText(text):
values = text.split(" ")
if values[0] != "xaxis" and values[0] != "xaxis*":
raise exceptions.RuntimeError("'{0}' not a valid Finesse xaxis command".format(text))
axis_type = values[0]
values.pop(0) # remove initial value
if len(values) != 6:
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)
def getFinesseText(self):
# store either the component name of the string provided
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
return '{axis_type} {0} {1} {2} {3} {4} {5}'.format(
comp_name, param_name, self.scale,
min(self.limits), max(self.limits), self.steps, axis_type=self._axis_type);
class x2axis(xaxis):
def __init__(self, scale, limits, comp, param, steps):
xaxis.__init__(self, scale, limits, comp, param, steps, axis_type="x2axis")
self.x = putter("x2")
self.mx = putter("mx2")
@staticmethod
def parseFinesseText(text):
values = text.split(" ")
if values[0] != "x2axis" and values[0] != "x2axis*":
raise exceptions.RuntimeError("'{0}' not a valid Finesse xaxis command".format(text))
axis_type = values[0]
values.pop(0) # remove initial value
if len(values) != 6:
raise exceptions.RuntimeError("xaxis Finesse code format incorrect '{0}'".format(text))
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 28 11:58:09 2013
@author: Daniel
"""
import numpy
from numpy import min,max
import exceptions
from components import *
from structs import *
from pykat.param import Param, putter
class Command(object):
def __init__(self):
self.tag = None
def getFinesseText(self):
""" Base class for individual finesse optical components """
raise NotImplementedError("This function is not implemented")
@staticmethod
def parseFinesseText(text):
raise NotImplementedError("This function is not implemented")
def _on_kat_add(self, kat):
"""
Called when this component has been added to a kat object
"""
self._kat = kat
class cavity(Command):
def __init__(self, name, c1, n1, c2, n2):
self.__name = name
self.__c1 = c1
self.__c2 = c2
self.__n1 = n1
self.__n2 = n2
def getFinesseText(self):
return 'cav {0} {1} {2} {3} {4}'.format(self.__name, self.__c1, self.__n1, self.__c2, self.__n2);
class gauss(object):
@staticmethod
def parseFinesseText(text, kat):
values = text.split(" ")
if not values[0].startswith("gauss"):
raise exceptions.RuntimeError("'{0}' not a valid Finesse gauss command".format(text))
class xaxis(Command):
def __init__(self, scale, limits, comp, param, steps, axis_type="xaxis"):
self._axis_type = axis_type
self.x = putter("x1")
self.mx = putter("mx1")
if scale == "lin":
scale = Scale.linear
elif scale == "log":
scale = Scale.logarithmic
elif isinstance(scale, str):
# 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))
if scale != Scale.linear and scale != Scale.logarithmic:
raise exceptions.ValueError("scale is not Scale.linear or Scale.logarithmic")
self.scale = scale
if numpy.size(limits) != 2 :
raise exceptions.ValueError("limits input should be a 2x1 vector of limits for the xaxis")
self.limits = numpy.array(SIfloat(limits)).astype(float)
if steps <= 0 :
raise exceptions.ValueError("steps value should be > 0")
self.steps = int(steps)
# if entered component is a string then just store and use that
if isinstance(comp, str):
self.__comp = comp
elif not isinstance(comp, Component):
raise exceptions.ValueError("{0} has not been added".format(comp))
else:
self.__comp = comp
if isinstance(param, str):
self.__param = param
elif not isinstance(param, Param) :
raise exceptions.ValueError("param argument is not of type Param")
else:
self.__param = param
@staticmethod
def parseFinesseText(text):
values = text.split(" ")
if values[0] != "xaxis" and values[0] != "xaxis*":
raise exceptions.RuntimeError("'{0}' not a valid Finesse xaxis command".format(text))
axis_type = values[0]
values.pop(0) # remove initial value
if len(values) != 6:
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)
def getFinesseText(self):
# store either the component name of the string provided
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
return '{axis_type} {0} {1} {2} {3} {4} {5}'.format(
comp_name, param_name, self.scale,
min(self.limits), max(self.limits), self.steps, axis_type=self._axis_type);
class x2axis(xaxis):
def __init__(self, scale, limits, comp, param, steps):
xaxis.__init__(self, scale, limits, comp, param, steps, axis_type="x2axis")
self.x = putter("x2")
self.mx = putter("mx2")
@staticmethod
def parseFinesseText(text):
values = text.split(" ")
if values[0] != "x2axis" and values[0] != "x2axis*":
raise exceptions.RuntimeError("'{0}' not a valid Finesse xaxis command".format(text))
axis_type = values[0]
values.pop(0) # remove initial value
if len(values) != 6:
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])
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 28 11:10:01 2013
@author: Daniel
"""
import exceptions
import pykat.exceptions as pkex
import pykat
from pykat.node_network import *
from pykat.exceptions import *
import abc
import pykat.gui.resources
import pykat.gui.graphics
from pykat.gui.graphics import *
from pykat.SIfloat import *
from pykat.param import Param, AttrParam
next_component_id = 1
class NodeGaussSetter(object):
def __init__(self, component, node):
self.__comp = component
self.__node = node
@property
def node(self):
return self.__node
@property
def q(self):
return self.__node.qx
@q.setter
def q(self, value):
self.__node.setGauss(self.__comp, complex(value))
@property
def qx(self):
return self.__node.qx
@qx.setter
def qx(self, value):
self.__node.setGauss(self.__comp, complex(value))
@property
def qy(self):
return self.__node.qy
@qy.setter
def qy(self, value):
self.__node.setGauss(self.__comp, self.qx, complex(value))
class Component(object):
__metaclass__ = abc.ABCMeta
def __init__(self, name):
self.__name = name
self._svgItem = None
self._requested_node_names = []
self._kat = None
self.tag = None
self._params = []
# store a unique ID for this component
global next_component_id
self.__id = next_component_id
next_component_id += 1
# This creates an instance specific class for the component
# this enables us to add properties to instances rather than
# all classes
cls = type(self)
self.__class__ = type(cls.__name__, (cls,), {})
def _register_param(self, param):
self._params.append(param)
def _on_kat_add(self, kat):
"""
Called when this component has been added to a kat object.
kat is the finesse.kat object which it now belongs to and
node_array is an array specific to this object which contains
references to the nodes that are attached to it.
"""
if self._kat != None:
raise pkex.BasePyKatException("Component has already been added to a finesse.kat object")
self._kat = kat
kat.nodes.registerComponentNodes(self, self._requested_node_names, self.__on_node_change)
def __on_node_change(self):
# need to update the node gauss parameter setter members
self.__update_node_setters()
def __update_node_setters(self):
# check if any node setters have already been added. If so we
# need to remove them. This function should get called if the nodes
# are updated, either by some function call or the GUI
key_rm = [k for k in self.__dict__ if k.startswith("__nodesetter_", 0, 13)]
# now we have a list of which to remove
for key in key_rm:
ns = self.__dict__[key]
delattr(self, '__nodesetter_' + ns.node.name)
delattr(self.__class__, ns.node.name)
for node in self.nodes:
if type(node) != pykat.node_network.DumpNode:
ns = NodeGaussSetter(self, node)
self.__add_node_setter(ns)
def __add_node_setter(self, ns):
if not isinstance(ns, NodeGaussSetter):
raise exceptions.ValueError("Argument is not of type NodeGaussSetter")
name = ns.node.name
fget = lambda self: self.__get_node_setter(name)
setattr(self.__class__, name, property(fget))
setattr(self, '__nodesetter_' + name, ns)
def __get_node_setter(self, name):
return getattr(self, '__nodesetter_' + name)
@staticmethod
@abc.abstractmethod
def parseFinesseText(text):
"""Parses Finesse syntax"""
raise NotImplementedError("This function is not implemented")
@abc.abstractmethod
def getFinesseText(self):
""" Base class for individual Finesse optical components """
raise NotImplementedError("This function is not implemented")
@abc.abstractmethod
def getQGraphicsItem(self):
return None
@property
def nodes(self): return self._kat.nodes.getComponentNodes(self)
@property
def name(self): return self.__name
@property
def id(self): return self.__id
def __str__(self): return self.name
class AbstractMirrorComponent(Component):
__metaclass__ = abc.ABCMeta
def __init__(self, name, R=0, T=0, phi=0, Rcx=0, Rcy=0, xbeta=0, ybeta=0, mass=0, r_ap=0):
super(AbstractMirrorComponent, self).__init__(name)
self.__R = Param("R", self, SIfloat(R))
self.__T = Param("T", self, SIfloat(T))
self.__phi = Param("phi", self, SIfloat(phi))
self.__Rcx = AttrParam("Rcx", self, SIfloat(Rcx))
self.__Rcy = AttrParam("Rcy", self, SIfloat(Rcy))
self.__xbeta = AttrParam("xbeta", self, SIfloat(xbeta))
self.__ybeta = AttrParam("ybeta", self, SIfloat(ybeta))
self.__mass = AttrParam("mass", self, SIfloat(mass))
self.__r_ap = AttrParam("r_ap", self, SIfloat(r_ap))
@property