Commit 241e44c0 authored by Daniel Toyra's avatar Daniel Toyra
Browse files

Merge branch 'master' of gitlab.aei.uni-hannover.de:finesse/pykat

parents 98549ca8 31995ed8
Pipeline #1549 passed with stage
in 29 seconds
......@@ -3,7 +3,7 @@ from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
__version__ = "1.0.6"
__version__ = "1.0.8"
# This flag is used to switch on the gui features in pkat at import time
USE_GUI = False
......
......@@ -1003,35 +1003,58 @@ class isolator(Component):
return self._svgItem
class lens(Component):
def __init__(self, name, node1, node2, f=1):
def __init__(self, name, node1, node2, f=1, p=None):
Component.__init__(self, name)
if not ((f is None) ^ (p is None)):
raise pkex.BasePyKatException("Specify either a focal length or power, not both.")
self._requested_node_names.append(node1)
self._requested_node_names.append(node2)
self._svgItem = None
self.__f = Param("f", self, SIfloat(f))
self.__p = Param("p", self, SIfloat(p))
@property
def f(self): return self.__f
@f.setter
def f(self, value): self.__f.value = SIfloat(value)
def f(self, value):
self.__f.value = SIfloat(value)
self.__p.value = None
@property
def p(self): return self.__p
@p.setter
def p(self, value):
self.__p.value = SIfloat(value)
self.__f.value = None
@staticmethod
def parseFinesseText(text):
values = text.split()
if values[0] != "lens":
if not values[0].startswith("lens"):
raise pkex.BasePyKatException("'{0}' not a valid Finesse lens command".format(text))
alt = values[0].endswith("*")
values.pop(0) # remove initial value
if len(values) == 4:
return lens(values[0], values[2], values[3], values[1])
if not alt:
return lens(values[0], values[2], values[3], f=values[1], p=None)
else:
return lens(values[0], values[2], values[3], f=None, p=values[1])
else:
raise pkex.BasePyKatException("Lens Finesse code format incorrect '{0}'".format(text))
def getFinesseText(self):
rtn = ['lens {0} {1} {2} {3}'.format(self.name, self.f.value, self.nodes[0].name, self.nodes[1].name)]
if self.__p.value is None:
rtn = ['lens {0} {1} {2} {3}'.format(self.name, self.f.value, self.nodes[0].name, self.nodes[1].name)]
else:
rtn = ['lens* {0} {1} {2} {3}'.format(self.name, self.p.value, self.nodes[0].name, self.nodes[1].name)]
for p in self._params:
rtn.extend(p.getFinesseText())
......
......@@ -642,13 +642,19 @@ class Signals(object):
@property
def f(self): return self.__f
@f.setter
def f(self,value): self.__f.value = SIfloat(value)
def f(self,value):
v = SIfloat(value)
if v <= 0:
raise pkex.BasePyKatException("Signal frequency must be greater than 0.")
self.__f.value = SIfloat(value)
def __init__(self, kat):
self._default_name = "fsignal"
self.targets = []
self._params = []
self.__f = Param("f", self, 0)
self.__f = Param("f", self, None)
self._kat = kat
def _register_param(self, param):
......@@ -667,21 +673,22 @@ class Signals(object):
def getFinesseText(self):
rtn = []
if len(self.targets) == 0 and (self.f != 0 and self.f is not None):
rtn.append("fsig {name} {frequency}"
.format(name = self.name,
frequency=str(self.f)))
else:
for t in self.targets:
rtn.extend(t.getFinesseText())
rtn.append("fsig {name} {comp} {target} {frequency} {phase} {amplitude}"
.format(name = t.name,
comp=t.owner,
target=t.target,
frequency=str(self.f),
phase=str(t.phase),
amplitude=str(t.amplitude if t.amplitude != None else "")))
if self.f.value is not None and self.f is not None:
if len(self.targets) == 0:
rtn.append("fsig {name} {frequency}"
.format(name = self.name,
frequency=str(self.f.value)))
else:
for t in self.targets:
rtn.extend(t.getFinesseText())
rtn.append("fsig {name} {comp} {target} {frequency} {phase} {amplitude}"
.format(name = t.name,
comp=t.owner,
target=t.target,
frequency=str(self.f.value),
phase=str(t.phase),
amplitude=str(t.amplitude if t.amplitude != None else "")))
for p in self._params:
rtn.extend(p.getFinesseText())
......
Markdown is supported
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