Commit f9929e7c authored by Andreas Freise's avatar Andreas Freise
Browse files

adding handling of scale command.

parent 350c61ce
......@@ -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])
......@@ -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))
......
......@@ -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))
......
......@@ -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
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
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