Commit e4b43993 authored by Daniel Brown's avatar Daniel Brown
Browse files

fixing scale commands

parent 86fbe41b
......@@ -12,12 +12,16 @@ fsig noise l1 amp 1 0 1
qhd qhd180 180 n2 n3
qhd qhd0 0 n2 n3
qhd qhd2 0 n2 n3
scale meter qhd180
scale meter qhd0
scale meter qhd2
scale 2 qhd0
xaxis l1 phase lin 0 360 360
""")
out = kat.run()
#out.plot()
out.plot()
print kat.qhd180
__version__ = "0.6.1"
__version__ = "0.6.2"
# This flag is used to switch on the gui features in pkat at import time
USE_GUI = False
......
......@@ -38,7 +38,7 @@ class BaseDetector(object) :
self.tag = None
self._params = []
self._mask = {}
self.__scale = None
self.__scale = []
self.__removed = False
self._alternate_beam = []
......@@ -110,7 +110,8 @@ class BaseDetector(object) :
def scale(self): return self.__scale
@scale.setter
def scale(self, value):
self.__scale = value
if value not in self.__scale:
self.__scale = value
@property
def name(self): return self.__name
......@@ -142,6 +143,16 @@ class BaseDetector(object) :
else:
raise pkex.BasePyKatException("There is no node called " + value + " in the kat object this detector is attached to.")
def _getScaleCmds(self, rtn):
if self.scale != None:
if isinstance(self.scale, str):
rtn.append("scale {1} {0}".format(self.name, self.scale))
elif isinstance(self.scale, (list, tuple)):
for s in self.scale:
rtn.append("scale {1} {0}".format(self.name, s))
else:
raise pkex.BasePyKatException("Scale command should either be a list of scales or a single string.")
class Detector1(BaseDetector):
"""
A detector that attaches to one node.
......@@ -524,9 +535,8 @@ class pd(Detector1):
rtn.append("pd{0}{1} {2}{3} {4}{5}".format(senstype, self.num_demods, self.name, fphi_str, self.node.name, alt_str))
if self.scale != None:
rtn.append("scale {1} {0}".format(self.name, self.scale))
self._getScaleCmds(rtn)
if self.pdtype != None:
rtn.append("pdtype {0} {1}".format(self.name, self.pdtype))
......@@ -631,8 +641,7 @@ class qnoised(pd):
rtn.append("qnoised{5} {0} {1} {2} {3}{4}".format(self.name, self.num_demods, fphi_str, self.node.name, alt_str, senstype))
if self.scale != None:
rtn.append("scale {1} {0}".format(self.name, self.scale))
self._getScaleCmds(rtn)
for p in self._params:
rtn.extend(p.getFinesseText())
......@@ -724,8 +733,7 @@ class qshot(pd):
rtn.append("qshot{5} {0} {1} {2} {3}{4}".format(self.name, self.num_demods, fphi_str, self.node.name, alt_str,senstype))
if self.scale != None:
rtn.append("scale {1} {0}".format(self.name, self.scale))
self._getScaleCmds(rtn)
for p in self._params:
rtn.extend(p.getFinesseText())
......@@ -761,8 +769,7 @@ def xd(Detector1):
if self.enabled:
rtn.append("xd {0} {1} {2}".format(self.name, self.component, self.motion))
if self.scale != None:
rtn.append("scale {1} {0}".format(self.name, self.scale))
self._getScaleCmds(rtn)
for p in self._params:
rtn.extend(p.getFinesseText())
......@@ -803,8 +810,7 @@ class hd(Detector2):
rtn.append("hd {0} {1} {2} {3}".format(self.name, self.phase, n1, n2))
if self.scale != None:
rtn.append("scale {1} {0}".format(self.name, self.scale))
self._getScaleCmds(rtn)
for p in self._params:
rtn.extend(p.getFinesseText())
......@@ -858,8 +864,7 @@ class qhd(Detector2):
rtn.append("qhd{4} {0} {1} {2} {3}".format(self.name, self.phase, n1, n2, self.sensitivity))
if self.scale != None:
rtn.append("scale {1} {0}".format(self.name, self.scale))
self._getScaleCmds(rtn)
for p in self._params:
rtn.extend(p.getFinesseText())
......
......@@ -729,10 +729,21 @@ class kat(object):
pykat.commands.gauss.parseFinesseText(line, self)
elif (first == "scale"):
v = line.split()
accepted = ["PSD","PSD_HF","ASD","ASD_HF","meter", "ampere", "degs"]
if len(v) == 3:
component_name = v[2]
if v[1] in accepted:
val = v[1]
else:
try:
val = SIfloat(v[1])
except ex as exception.ValueError:
raise pkex.BasePyKatException("Line `{0}`:\nAccepted scale values are decimal numbers or %s." % (line,str(accepted)))
if component_name in self.__detectors :
self.__detectors[component_name].scale = SIfloat(v[1])
self.__detectors[component_name].scale.append(val)
else:
raise pkex.BasePyKatException("scale command `{0}` refers to non-existing output".format(component_name))
elif len(v) == 2:
......
Supports Markdown
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