diff --git a/pykat/commands.py b/pykat/commands.py index 9f85839f517a58ce9db9d4ed437242b756903932..e90e507a8a3b22a20d68c87c0856e4288aa0cf10 100644 --- a/pykat/commands.py +++ b/pykat/commands.py @@ -46,8 +46,8 @@ class gauss(object): values = text.split(" ") 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): def __init__(self, scale, limits, comp, param, steps, axis_type="xaxis"): @@ -57,7 +57,7 @@ class xaxis(Command): self.mx = putter("mx1") if scale == "lin": - scale = Scale.linear + scale = cale.linear elif scale == "log": scale = Scale.logarithmic elif isinstance(scale, str): @@ -139,4 +139,4 @@ class x2axis(xaxis): 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 + return x2axis(values[2], [values[3], values[4]], values[0], values[1], values[5]) diff --git a/pykat/detectors.py b/pykat/detectors.py index 149b7a39494cc43e0ac0034eedc0b2b120d5110c..1e0fae04875ae68948d231ea48b1a6a77e4a6b6f 100644 --- a/pykat/detectors.py +++ b/pykat/detectors.py @@ -10,7 +10,7 @@ import pykat.gui.resources from pykat.utils import * from pykat.gui.graphics import * from pykat.node_network import * -from pykat.param import Param, ScaleParam +from pykat.param import Param class Detector(object) : @@ -24,7 +24,7 @@ class Detector(object) : self.__node = None self._params = [] self._mask = {} - self.__scale = ScaleParam("scale", self, SIfloat(1.0)) + self.__scale = "" if node.find('*'): self._alternate_beam = True @@ -48,13 +48,12 @@ class Detector(object) : def getQGraphicsItem(self): return None - @property def scale(self): return self.__scale @scale.setter - def sclae(self, value): - self.__scale = SIfloat(value) + def scale(self, value): + self.__scale = value @property def node(self): return self.__node @@ -302,7 +301,10 @@ class photodiode(Detector): rtn.append("pd{0}{1} {2} {3} {4}".format(self.senstype, self.num_demods, self.name, __f_phi_str, self.node.name)) else: rtn.append("pd{0}{1} {2} {3} {4}*".format(self.senstype, self.num_demods, self.name, __f_phi_str, self.node.name)) - + + if self.scale !=1.0 and self.scale != None: + rtn.append("scale {0} {1}".format(self.name, self.scale)) + if self.noplot: rtn.append("noplot {0}".format(self.name)) diff --git a/pykat/finesse.py b/pykat/finesse.py index f709805afa07ab1054e3a00d96f93a54ccb60050..cb839f163d80f20f87bb33e9246d85e57e421da9 100644 --- a/pykat/finesse.py +++ b/pykat/finesse.py @@ -39,6 +39,7 @@ from pykat.detectors import Detector from pykat.components import Component from pykat.commands import Command, xaxis from pykat.gui.gui import pyKatGUI +from pykat.SIfloat import * import pykat.exceptions as pkex @@ -145,6 +146,7 @@ class kat(object): # and have no name attached to them. self.retrace = None self.deriv_h = None + self.scale = None self.__phase = None self.__maxtem = None self.__noxaxis = None @@ -171,7 +173,7 @@ class kat(object): def phase(self): return self.__phase @phase.setter def phase(self,value): self.__phase = int(value) - + @property def getPerformanceData(self): return self.__time_code @getPerformanceData.setter @@ -279,6 +281,8 @@ class kat(object): obj = pykat.commands.x2axis.parseFinesseText(line) elif(first == "gauss" or first == "gauss*" or first == "gauss**"): after_process.append(line) + elif(first == "scale"): + after_process.append(line) elif(first == "noxaxis"): self.noxaxis = True elif(first == "phase"): @@ -313,11 +317,24 @@ class kat(object): # now process all the varous gauss/attr etc. commands which require # components to exist first before they can be processed for line in after_process: - first = line.split(" ",1)[0] - + first = line.split(" ",1)[0] if first == "gauss" or first == "gauss*" or first == "gauss**": pykat.commands.gauss.parseFinesseText(line) - + elif (first == "scale"): + v = line.split(" ") + if len(v) == 3: + component_name = v[2] + if component_name in self.__detectors : + self.__detectors[component_name].scale = SIfloat(v[1]) + else: + raise pkex.BasePyKatException("scale command `{0}` refers to non-existing output".format(text)) + elif len(values) == 2: + self.scale = SIfloat(v[1]) + else: + raise pkex.BasePyKatException("scale command `{0}` is incorrect.".format(text)) + + + self.__currentTag = NO_BLOCK def saveScript(self, filename=None): @@ -536,7 +553,7 @@ class kat(object): self.__commands[obj.__class__.__name__] = obj self.__add_command(obj) - else : + else: raise pkex.BasePyKatException("Object {0} could not be added".format(obj)) obj._on_kat_add(self) @@ -623,6 +640,8 @@ class kat(object): else: out.append(txt + "\n") + + if self.scale != None and self.scale !=1.0: out.append("scale {0}\n".format(self.scale)) if self.phase != None: out.append("phase {0}\n".format(self.phase)) if self.maxtem != None: out.append("maxtem {0}\n".format(self.maxtem)) diff --git a/pykat/node_network.py b/pykat/node_network.py index 8d5be82a2761e7dff4f8b81b9d6acbc3f4e8c00e..8928cf8a86c0fe3bede503e706ac4a8cd8767ba0 100644 --- a/pykat/node_network.py +++ b/pykat/node_network.py @@ -264,7 +264,7 @@ class Node(object): return [] rtn = [] - + if self.__q_x == self.__q_y: rtn.append("gauss* g_{node} {comp} {node} {z} {zr}".format(node=self.name, comp=self.__q_comp.name, z=self.__q_x.real, zr=self.__q_x.imag)) else: @@ -329,4 +329,4 @@ class DumpNode(Node): def __init__(self): Node.__init__(self, 'dump', None, -1) - \ No newline at end of file + diff --git a/pykat/param.py b/pykat/param.py index f535d88f60a2392daffd50267c20176360350107..e47d378b248c218aef32e905d24df4f17a838ae7 100644 --- a/pykat/param.py +++ b/pykat/param.py @@ -1,4 +1,3 @@ -from pykat.SIfloat import SIfloat import abc import pykat.exceptions as pkex @@ -166,23 +165,4 @@ class AttrParam(Param): return rtn -class ScaleParam(Param): - """ - The scale parameter of a detector is set using the Finesse `scale` command. - - This inherits directly from a Param object so can be set whether this attribute - is putable or a putter. - - If the value pf the parameter is not 1.0 the scale command will be printed. - """ - def getFinesseText(self): - rtn = [] - - if self.value != 1.0: - rtn.append("scale {0} {1}".format(self._owner.name, self.value)) - - rtn.extend(super(ScaleParam, self).getFinesseText()) - - return rtn -