diff --git a/pykat/SIfloat.py b/pykat/SIfloat.py index 4276cc42ad16bd5a33b5e4f607398d38485ac098..23e863f1cf33edae1703b8f959a45c5191e7229b 100644 --- a/pykat/SIfloat.py +++ b/pykat/SIfloat.py @@ -3,6 +3,8 @@ import re #staticmethod def SIfloat(value): + if value==None: + return value if type(value)==list: return [convertToFloat(s) for s in value] else: diff --git a/pykat/commands.py b/pykat/commands.py index 6022f7dd0c1d527dfb8152b15e07dd245efe2bfb..d01b42bf6ae3141015406bb5b7bbe03db3f13119 100644 --- a/pykat/commands.py +++ b/pykat/commands.py @@ -128,6 +128,16 @@ class xaxis(Command): self.__param = param self.__comp = param._owner.name + @property + def param(self): return self.__param + @param.setter + def param(self, value): + if not isinstance(value, Param): + raise pkex.BasePyKatException("param argument is not of type Param") + else: + self.__param = value + self.__comp = value._owner.name + @staticmethod def parseFinesseText(text): values = text.split() diff --git a/pykat/components.py b/pykat/components.py index 6d4f64be470a3a2dbe8fa5b099e50d22f0e2738b..5ae2630aae9d3ecc7dceaf3e68f9a8f911926bf1 100644 --- a/pykat/components.py +++ b/pykat/components.py @@ -155,9 +155,9 @@ class Component(object): class AbstractMirrorComponent(Component): __metaclass__ = abc.ABCMeta - def __init__(self, name, R=None, T=None, L=None, phi=0, Rcx=0, Rcy=0, xbeta=0, ybeta=0, mass=0, r_ap=0): + def __init__(self, name, R=None, T=None, L=None, phi=0, Rcx=None, Rcy=None, xbeta=None, ybeta=None, mass=None, r_ap=None): super(AbstractMirrorComponent, self).__init__(name) - + if (L != None and R != None and T != None) and SIfloat(R)+SIfloat(T)+SIfloat(L) != 1: raise pkex.BasePyKatException('L+R+T must equal 1 if all are specified') elif (R != None and L is None and T != None): @@ -166,7 +166,7 @@ class AbstractMirrorComponent(Component): R = 1 - (SIfloat(L)+SIfloat(T)) elif (R != None and L != None and T is None): T = 1 - (SIfloat(L)+SIfloat(R)) - else: + elif (L is None and R is None and T is None): raise pkex.BasePyKatException('Must specify at least two of L, R or T') self.__R = Param("R", self, SIfloat(R)) @@ -184,7 +184,7 @@ class AbstractMirrorComponent(Component): @property def L(self): return self.__L @L.setter - def L(self,value): self.__L.value = SIfloat(value) + def L(self,value): self.__L.value = SIfloat(value) @property def r_ap(self): return self.__r_ap @@ -244,7 +244,7 @@ class AbstractMirrorComponent(Component): self.Rcy.value = SIfloat(value) class mirror(AbstractMirrorComponent): - def __init__(self,name,node1,node2,R=None,T=None,L=None,phi=0,Rcx=0,Rcy=0,xbeta=0,ybeta=0,mass=0, r_ap=0): + def __init__(self,name,node1,node2,R=None,T=None,L=None,phi=0,Rcx=None,Rcy=None,xbeta=None,ybeta=None,mass=None, r_ap=None): super(mirror, self).__init__(name, R, T, L, phi, Rcx, Rcy, xbeta, ybeta, mass, r_ap) self._requested_node_names.append(node1) @@ -293,8 +293,8 @@ class mirror(AbstractMirrorComponent): return self._svgItem class beamSplitter(AbstractMirrorComponent): - def __init__(self, name, node1, node2, node3, node4, R = 0, T = 0, phi = 0, alpha = 0, Rcx = 0, Rcy = 0, xbeta = 0, ybeta = 0, mass = 0, r_ap = 0): - super(beamSplitter, self).__init__(name, R, T, phi, Rcx, Rcy, xbeta, ybeta, mass, r_ap) + def __init__(self, name, node1, node2, node3, node4, R = None, T = None, L=None, phi = 0, alpha = 0, Rcx = None, Rcy = None, xbeta = None, ybeta = None, mass = None, r_ap = None): + super(beamSplitter, self).__init__(name, R, T, L, phi, Rcx, Rcy, xbeta, ybeta, mass, r_ap) self._requested_node_names.append(node1) self._requested_node_names.append(node2) @@ -341,8 +341,8 @@ class beamSplitter(AbstractMirrorComponent): rtn = [] rtn.append('bs {0} {1} {2} {3} {4} {5} {6} {7} {8}'.format( - self.name, self.R.value, self.T.value, self.phi.value, - self.alpha.value, self.nodes[0].name, + self.name, self.R.value, self.T.value, self.alpha.value, + self.phi.value, self.nodes[0].name, self.nodes[1].name, self.nodes[2].name, self.nodes[3].name)) @@ -359,7 +359,7 @@ class beamSplitter(AbstractMirrorComponent): return self._svgItem class space(Component): - def __init__(self, name, node1, node2, L=0, n=1): + def __init__(self, name, node1, node2, L = 0, n = 1, g = None, gx = None, gy = None): Component.__init__(self, name) self._requested_node_names.append(node1) @@ -367,6 +367,10 @@ class space(Component): self._QItem = None self.__L = Param("L", self, SIfloat(L)) self.__n = Param("n", self, SIfloat(n)) + + self.__g = AttrParam("g", self, g) + self.__gx = AttrParam("gx", self, gx) + self.__gy = AttrParam("gy", self, gy) @property def L(self): return self.__L @@ -376,6 +380,21 @@ class space(Component): def n(self): return self.__n @n.setter def n(self,value): self.__n.value = SIfloat(value) + + @property + def g(self): return self.__g + @g.setter + def g(self,value): self.__g.value = SIfloat(value) + + @property + def gx(self): return self.__gx + @gx.setter + def gx(self,value): self.__gx.value = SIfloat(value) + + @property + def gy(self): return self.__gy + @gy.setter + def gy(self,value): self.__gy.value = SIfloat(value) @staticmethod def parseFinesseText(text): @@ -413,7 +432,7 @@ class space(Component): return self._QItem class grating(Component): - def __init__(self, name, node1, node2, node3 = None, node4 = None, n = 2, d = 0, eta_0 = 0, eta_1 = 0, eta_2 = 0, eta_3 = 0, rho_0 = 0, alpha = 0): # TODO: implement Rcx, Rcy and Rc + def __init__(self, name, node1, node2, node3 = None, node4 = None, n = 2, d = 0, eta_0 = None, eta_1 = None, eta_2 = None, eta_3 = None, rho_0 = None, alpha = None): # TODO: implement Rcx, Rcy and Rc Component.__init__(self, name) self._requested_node_names.append(node1) @@ -711,12 +730,12 @@ class laser(Component): self.__power = Param("P", self, SIfloat(P), canFsig=True, fsig_name="amp") self.__f_offset = Param("f", self, SIfloat(f_offset), canFsig=True, fsig_name="f") self.__phase = Param("phase", self, SIfloat(phase), canFsig=True, fsig_name="phase") - self.__noise = AttrParam("noise", self, 0) + self.__noise = AttrParam("noise", self, None) @property - def power(self): return self.__power - @power.setter - def power(self,value): self.__power.value = float(value) + def P(self): return self.__power + @P.setter + def P(self,value): self.__power.value = float(value) @property def f(self): return self.__f_offset diff --git a/pykat/detectors.py b/pykat/detectors.py index 5356f551b70977d012c04e02f9001db58b6f9a7e..907f239d73968ceb047373b346b83296895f9ea5 100644 --- a/pykat/detectors.py +++ b/pykat/detectors.py @@ -272,18 +272,18 @@ class pd(Detector): elif len(values[0]) == 3: demods = int(values[0][2]) elif len(values[0]) != 2: - raise pkex.BasePyKatException("Photodiode code format incorrect '{0}'".format(text)) + raise pkex.BasePyKatException("Photodiode code format incorrect '{0}' (1)".format(text)) if len(values) <= 3 and demods > 0: - raise pkex.BasePyKatException("Photodiode code format incorrect '{0}'".format(text)) + raise pkex.BasePyKatException("Photodiode code format incorrect '{0}' (2)".format(text)) elif len(values) > 3 and demods == 0: - raise pkex.BasePyKatException("Photodiode code format incorrect '{0}'".format(text)) + raise pkex.BasePyKatException("Photodiode code format incorrect '{0}' (3)".format(text)) num_f_phs = len(values) - 3 expected_f_phs = demods * 2 - if num_f_phs != expected_f_phs and num_f_phs-1 != expected_f_phs: - raise pkex.BasePyKatException("Photodiode code format incorrect '{0}'".format(text)) + if not (num_f_phs == expected_f_phs or num_f_phs == expected_f_phs-1): + raise pkex.BasePyKatException("Photodiode code format incorrect '{0}' (4)".format(text)) f = values[2:len(values)-1:2] phs = values[3:len(values)-1:2] diff --git a/pykat/param.py b/pykat/param.py index 52a5fc88554f8ce86990f5d672a8ec652fd65c09..798535afd103226921d0cd5eec9e19f3663e8b7d 100644 --- a/pykat/param.py +++ b/pykat/param.py @@ -173,7 +173,7 @@ class AttrParam(Param): def getFinesseText(self): rtn = [] - if self.value != 0: + if self.value != None: rtn.append("attr {0} {1} {2}".format(self._owner.name, self.name, self.value)) rtn.extend(super(AttrParam, self).getFinesseText())