diff --git a/bin/test_fsig.py b/bin/test_fsig.py index 9fc47b5f150ed9a87fceb6a1300e213b1179e263..66ccfa125cefaf3ed7004667f05d3e8dbee7e192 100644 --- a/bin/test_fsig.py +++ b/bin/test_fsig.py @@ -28,7 +28,7 @@ put low_refl f $mx1 yaxis log re:im -fsig noise 9 +fsig noise m2 1 0 """ kat = finesse.kat(kat_code=code) diff --git a/pykat/components.py b/pykat/components.py index 37ff73bee7a835e2fe2b23ffaa552c888c7a9855..f6b5e83d6e80325fb8a6b7dbe2073fce55df90d0 100644 --- a/pykat/components.py +++ b/pykat/components.py @@ -76,6 +76,7 @@ class Component(object): self.tag = None self._params = [] self.__removed = False + self._default_fsig_param = None # store a unique ID for this component global next_component_id @@ -90,7 +91,21 @@ class Component(object): def _register_param(self, param): self._params.append(param) - + + def _default_fsig(self): + """ + Returns what Finesse internally determines as the default + fsig parameter. This is used mainly for parsing fsig command + lines where no target parameter is stated. + """ + if self._default_fsig_param != None: + if not self._default_fsig_param.canFsig: + raise pkex.BasePyKatException("Default fsig parameter %s is not possible to fsig" % (self.__default_fsig_param.name)) + else: + return self._default_fsig_param + else: + return None + def _on_kat_add(self, kat): """ Called when this component has been added to a kat object. @@ -226,6 +241,8 @@ class AbstractMirrorComponent(Component): self.__Frx = Param("Frx", self, 0, canFsig=True, isPutable=False, isPutter=False, isTunable=False, fsig_name="Frx") self.__Fry = Param("Fry", self, 0, canFsig=True, isPutable=False, isPutter=False, isTunable=False, fsig_name="Fry") + self._default_fsig_param = self.__phi + @property def z(self): return self.__z @property @@ -499,12 +516,14 @@ class space(Component): self._requested_node_names.append(node1) self._requested_node_names.append(node2) self._QItem = None - self.__L = Param("L", self, SIfloat(L)) + self.__L = Param("L", self, SIfloat(L), canFsig=True, fsig_name="phase") self.__n = Param("n", self, SIfloat(n)) self.__gx = AttrParam("gx", self, gx) self.__gy = AttrParam("gy", self, gy) + self._default_fsig_param = self.__L + @property def L(self): return self.__L @L.setter @@ -823,10 +842,11 @@ class modulator(Component): self._svgItem = None self.__f = Param("f", self, SIfloat(f)) self.__midx = Param("midx", self, SIfloat(midx)) - self.__phase = Param("phase", self, SIfloat(phase)) + self.__phase = Param("phase", self, SIfloat(phase), canFsig=True, fsig_name="phase") self.__order = order self.type = modulation_type + self._default_fsig_param = self.__phase @property def f(self): return self.__f @@ -906,6 +926,8 @@ class laser(Component): self.__noise = AttrParam("noise", self, None) self._svgItem = None + self._default_fsig_param = self.__f_offset + @property def P(self): return self.__power @P.setter diff --git a/pykat/finesse.py b/pykat/finesse.py index d793e7291dd3ed364a8ecde25524c7bc95fd1643..617515242f054ddc9a78c94089e9589653edc37a 100644 --- a/pykat/finesse.py +++ b/pykat/finesse.py @@ -248,7 +248,7 @@ class Signals(object): self.__signal = signal # unfortunatenly the target names for fsig are not the same as the - # various parameter names of the c omponents, e.g. mirror xbeta is x + # various parameter names of the components, e.g. mirror xbeta is x # for fsig. So we need to check here what type of component we are targetting # and then based on the parameter specfied get the name if not param.canFsig: @@ -347,8 +347,15 @@ class Signals(object): for t in self.targets: rtn.extend(t.getFinesseText()) - rtn.append("fsig {name} {comp} {target} {frequency} {phase} {amplitude}".format(name = t.name, comp=t.owner, target=t.target, frequency=str(self.f), phase=str(t.phase), amplitude=str(t.amplitude))) - + + rtn.append("fsig {name} {comp} {target} {frequency} {phase} {amplitude}" + .format(name = t.name, + comp=t.owner, + target=t.target, + frequency=str(self.f), + phase=str(t.phase), + amplitude=str(t.amplitude if t.amplitude != None else ""))) + for p in self._params: rtn.extend(p.getFinesseText()) @@ -703,8 +710,8 @@ class kat(object): elif(first == "gnuterm" or first == "pyterm"): if self.verbose: print "Ignoring Gnuplot/Python terminal command '{0}'".format(line) - #elif(first == "fsig"): - # after_process.append(line) + elif(first == "fsig"): + after_process.append(line) elif(first == "noplot"): obj = line self.__blocks[self.__currentTag].contents.append(line) @@ -797,13 +804,41 @@ class kat(object): v = line.split() - if v[2] in self.__components: - comp = self.__components[v[1]] - else: - raise pkex.BasePyKatException("Could not find the component '{0}' for attr command in line '{1}'".format(v[1], line)) + name = str(v[1]) + + if v[2] not in self.__components: + raise pkex.BasePyKatException("Could not find the component '{0}'. Line: '{1}'".format(v[2], line)) + comp = self.__components[v[2]] + + if comp._default_fsig() == None: + raise pkex.BasePyKatException("Component '{0}' cannot be fsig'd. Line: '{1}'".format(comp.name, line)) + + param = None + amp = None + + if len(v) == 5: + param == None + freq = float(v[3]) + phase = float(v[4]) + elif len(v) == 6: + if v[3].isdigit(): + freq = float(v[3]) + phase = float(v[4]) + amp = float(v[5]) + else: + param = v[3] + freq = float(v[4]) + phase = float(v[5]) + elif len(v) == 7: + param = v[3] + freq = float(v[4]) + phase = float(v[5]) + amp = float(v[6]) + else: + raise pkex.BasePyKatException("'{0}' isnot a valid fsig command".format(line)) - #kat.siganls.apply() + self.signals.apply(comp._default_fsig(), amp, phase, name) else: raise pkex.BasePyKatException("Haven't handled parsing of '{0}'".format(line))