Commit 4a93bd25 authored by Daniel Toyra's avatar Daniel Toyra
Browse files

Fixed issue with the noplot command. Now it works for detectors and functions...

Fixed issue with the noplot command. Now it works for detectors and functions when using the pykat plotting method.
parent ab4ea4e4
...@@ -97,7 +97,14 @@ class func(Command): ...@@ -97,7 +97,14 @@ class func(Command):
self.noplot = False self.noplot = False
def getFinesseText(self): def getFinesseText(self):
return "func {name} = {value}".format(name=self.name, value=str(self.value)) rtn = []
if self.noplot:
rtn.append("noplot " + self.name)
rtn.append("func {name} = {value}".format(name=self.name, value=str(self.value)))
return rtn
@staticmethod @staticmethod
def parseFinesseText(line, kat): def parseFinesseText(line, kat):
......
...@@ -134,7 +134,12 @@ class BaseDetector(object) : ...@@ -134,7 +134,12 @@ class BaseDetector(object) :
def getFinesseText(self): def getFinesseText(self):
""" Base class for individual finesse optical components """ """ Base class for individual finesse optical components """
raise NotImplementedError("This function is not implemented") #raise NotImplementedError("This function is not implemented")
if self.noplot:
return ["noplot " + self.name]
else:
return []
def getQGraphicsItem(self): def getQGraphicsItem(self):
if not USE_GUI: if not USE_GUI:
...@@ -258,7 +263,7 @@ class beam(Detector1): ...@@ -258,7 +263,7 @@ class beam(Detector1):
raise pkex.BasePyKatException('Beam detector code "{0}" is not a valid FINESSE command'.format(text)) raise pkex.BasePyKatException('Beam detector code "{0}" is not a valid FINESSE command'.format(text))
def getFinesseText(self) : def getFinesseText(self) :
rtn = [] rtn = BaseDetector.getFinesseText(self)
if self.alternate_beam: if self.alternate_beam:
alt = '*' alt = '*'
...@@ -269,7 +274,7 @@ class beam(Detector1): ...@@ -269,7 +274,7 @@ class beam(Detector1):
rtn.append("beam {name} {node}{alt}".format(name=self.name, node=self.node.name, alt=alt)) rtn.append("beam {name} {node}{alt}".format(name=self.name, node=self.node.name, alt=alt))
else: else:
rtn.append("beam {name} {f} {node}{alt}".format(name=self.name, f=str(self.f.value), node=self.node.name, alt=alt)) rtn.append("beam {name} {f} {node}{alt}".format(name=self.name, f=str(self.f.value), node=self.node.name, alt=alt))
for p in self._params: for p in self._params:
rtn.extend(p.getFinesseText()) rtn.extend(p.getFinesseText())
...@@ -321,7 +326,7 @@ class cp(Detector0): ...@@ -321,7 +326,7 @@ class cp(Detector0):
raise pkex.BasePyKatException('Cavity parameter detector code "{0}" is not a valid FINESSE command'.format(text)) raise pkex.BasePyKatException('Cavity parameter detector code "{0}" is not a valid FINESSE command'.format(text))
def getFinesseText(self) : def getFinesseText(self) :
rtn = [] rtn = BaseDetector.getFinesseText(self)
rtn.append("cp {name} {cavity} {direction} {parameter}".format(name=self.name, rtn.append("cp {name} {cavity} {direction} {parameter}".format(name=self.name,
cavity=str(self.cavity), cavity=str(self.cavity),
...@@ -348,7 +353,7 @@ class xd(Detector0): ...@@ -348,7 +353,7 @@ class xd(Detector0):
raise pkex.BasePyKatException('Motion detector code "{0}" is not a valid FINESSE command'.format(text)) raise pkex.BasePyKatException('Motion detector code "{0}" is not a valid FINESSE command'.format(text))
def getFinesseText(self) : def getFinesseText(self) :
rtn = [] rtn = BaseDetector.getFinesseText(self)
rtn.append("xd {name} {component} {motion}".format(name=self.name, rtn.append("xd {name} {component} {motion}".format(name=self.name,
component=self.component, component=self.component,
...@@ -394,7 +399,7 @@ class ad(Detector1): ...@@ -394,7 +399,7 @@ class ad(Detector1):
raise pkex.BasePyKatException('Amplitude detector code "{0}" is not a valid FINESSE command'.format(text)) raise pkex.BasePyKatException('Amplitude detector code "{0}" is not a valid FINESSE command'.format(text))
def getFinesseText(self) : def getFinesseText(self) :
rtn = [] rtn = BaseDetector.getFinesseText(self)
if self.alternate_beam: if self.alternate_beam:
alt = '*' alt = '*'
...@@ -448,7 +453,7 @@ class gouy(Detector1): ...@@ -448,7 +453,7 @@ class gouy(Detector1):
raise pkex.BasePyKatException('Gouy detector code "{0}" is not a valid FINESSE command'.format(text)) raise pkex.BasePyKatException('Gouy detector code "{0}" is not a valid FINESSE command'.format(text))
def getFinesseText(self) : def getFinesseText(self) :
rtn = [] rtn = BaseDetector.getFinesseText(self)
rtn.append("gouy {name} {dir} {spaces}".format(name=self.name, dir=str(self.direction), spaces=" ".join(self.spaces))) rtn.append("gouy {name} {dir} {spaces}".format(name=self.name, dir=str(self.direction), spaces=" ".join(self.spaces)))
...@@ -500,7 +505,7 @@ class bp(Detector1): ...@@ -500,7 +505,7 @@ class bp(Detector1):
raise pkex.BasePyKatException('Gouy detector code "{0}" is not a valid FINESSE command'.format(text)) raise pkex.BasePyKatException('Gouy detector code "{0}" is not a valid FINESSE command'.format(text))
def getFinesseText(self) : def getFinesseText(self) :
rtn = [] rtn = BaseDetector.getFinesseText(self)
if self.alternate_beam: if self.alternate_beam:
alt = "*" alt = "*"
...@@ -721,7 +726,7 @@ class pd(Detector1): ...@@ -721,7 +726,7 @@ class pd(Detector1):
def getFinesseText(self) : def getFinesseText(self) :
rtn = [] rtn = BaseDetector.getFinesseText(self)
if self.enabled: if self.enabled:
alt_str = "" alt_str = ""
...@@ -833,7 +838,7 @@ class qnoised(pd): ...@@ -833,7 +838,7 @@ class qnoised(pd):
return qnoised(values[1], demods, node, senstype=sens, alternate_beam=alt_beam, **dict) return qnoised(values[1], demods, node, senstype=sens, alternate_beam=alt_beam, **dict)
def getFinesseText(self) : def getFinesseText(self) :
rtn = [] rtn = BaseDetector.getFinesseText(self)
if self.enabled: if self.enabled:
alt_str = "" alt_str = ""
...@@ -931,7 +936,7 @@ class qshot(pd): ...@@ -931,7 +936,7 @@ class qshot(pd):
return qshot(values[1], demods, node, senstype=sens, alternate_beam=alt_beam, **dict) return qshot(values[1], demods, node, senstype=sens, alternate_beam=alt_beam, **dict)
def getFinesseText(self) : def getFinesseText(self) :
rtn = [] rtn = BaseDetector.getFinesseText(self)
if self.enabled: if self.enabled:
alt_str = "" alt_str = ""
...@@ -993,7 +998,7 @@ class hd(Detector2): ...@@ -993,7 +998,7 @@ class hd(Detector2):
return hd(values[1], float(values[2]), str(values[3]), str(values[4])) return hd(values[1], float(values[2]), str(values[3]), str(values[4]))
def getFinesseText(self): def getFinesseText(self):
rtn = [] rtn = BaseDetector.getFinesseText(self)
if self.enabled: if self.enabled:
n1 = self.node1.name n1 = self.node1.name
...@@ -1052,7 +1057,7 @@ class qhd(Detector2): ...@@ -1052,7 +1057,7 @@ class qhd(Detector2):
return qhd(values[1], float(values[2]), str(values[3]), str(values[4]), sensitivity = sens) return qhd(values[1], float(values[2]), str(values[3]), str(values[4]), sensitivity = sens)
def getFinesseText(self): def getFinesseText(self):
rtn = [] rtn = BaseDetector.getFinesseText(self)
if self.enabled: if self.enabled:
n1 = self.node1.name n1 = self.node1.name
......
...@@ -375,6 +375,7 @@ class katRun(object): ...@@ -375,6 +375,7 @@ class katRun(object):
for det in detectors: for det in detectors:
if not hasattr(kat, det) or (hasattr(kat, det) and not getattr(kat, det).noplot): if not hasattr(kat, det) or (hasattr(kat, det) and not getattr(kat, det).noplot):
if dual_plot: if dual_plot:
ax = pyplot.subplot(2,1,1) ax = pyplot.subplot(2,1,1)
...@@ -1146,7 +1147,13 @@ class kat(object): ...@@ -1146,7 +1147,13 @@ class kat(object):
self.add(obj, block=self.__currentTag) self.add(obj, block=self.__currentTag)
# Before processing the rest, all "noplot" commands are moved to the
# end of the list to make sure they are after all "func" commands.
for k in range(len(after_process)-1,-1,-1):
if after_process[k][0].split(" ", 1)[0] == "noplot":
after_process.append(after_process.pop(k))
# now process all the varous gauss/attr etc. commands which require # now process all the varous gauss/attr etc. commands which require
# components to exist first before they can be processed # components to exist first before they can be processed
for item in after_process: for item in after_process:
...@@ -1168,6 +1175,7 @@ class kat(object): ...@@ -1168,6 +1175,7 @@ class kat(object):
elif (first == "variable"): elif (first == "variable"):
self.add(pykat.commands.variable.parseFinesseText(line, self), block=block) self.add(pykat.commands.variable.parseFinesseText(line, self), block=block)
elif (first == "noplot"): elif (first == "noplot"):
if not hasattr(self, rest): if not hasattr(self, rest):
raise pkex.BasePyKatException("noplot command `{0}` refers to non-existing detector".format(line)) raise pkex.BasePyKatException("noplot command `{0}` refers to non-existing detector".format(line))
...@@ -1964,6 +1972,7 @@ class kat(object): ...@@ -1964,6 +1972,7 @@ class kat(object):
writeBlock() writeBlock()
out.append("%%% FTend " + key + "\n") out.append("%%% FTend " + key + "\n")
# write the NO_BLOCK blocks # write the NO_BLOCK blocks
for key in self.__blocks: for key in self.__blocks:
objs = self.__blocks[key].contents objs = self.__blocks[key].contents
...@@ -2039,7 +2048,7 @@ class kat(object): ...@@ -2039,7 +2048,7 @@ class kat(object):
if self.lambda0 != 1064e-9: if self.lambda0 != 1064e-9:
out.append("lambda {0}\n".format(self.lambda0)) out.append("lambda {0}\n".format(self.lambda0))
# ensure we don't do any plotting. That should be handled # ensure we don't do any plotting. That should be handled
# by user themselves # by user themselves
#out.append("gnuterm no\n") #out.append("gnuterm no\n")
......
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