From 90e0e1a284e53dc2960e5f30f73c899c1c266079 Mon Sep 17 00:00:00 2001 From: Daniel Brown <ddb@star.sr.bham.ac.uk> Date: Wed, 18 Dec 2013 17:36:06 +0000 Subject: [PATCH] output now correctly returns detector values when using out['name']. If yaxis is used to specify multiple outputs values per detector the result of out[name] is a 2d array --- bin/test_plot.py | 6 ++++-- pykat/detectors.py | 13 ++++++++++++- pykat/finesse.py | 16 +++++++++------- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/bin/test_plot.py b/bin/test_plot.py index 0fc55de..bb18630 100644 --- a/bin/test_plot.py +++ b/bin/test_plot.py @@ -14,16 +14,17 @@ m m1 0.5 0.5 0 n2 n3 s s2 10 1 n3 n4 m m2 0.5 0.5 0 n4 n5 s s3 10 1 n5 n6 + +yaxis abs:deg """ -#kat = finesse.kat(katexe='/Users/adf/work/bin/kat') kat = finesse.kat() kat.parseCommands(code) kat.add(cavity('cav1', 'm1', 'n3', 'm2', 'n4')) -kat.add(photodiode('pd_cav','n4')) +kat.add(photodiode('pd_cav','n4',num_demods=1, demods=[1])) kat.add(photodiode('pd_ref','n2')) kat.add(photodiode('pd_trs','n5')) @@ -40,6 +41,7 @@ out = kat.run(printout=0,printerr=0) pl.figure() pl.plot(out.x, out["pd_cav"]) +pl.plot(out.x, out["pd_ref"]) pl.xlabel(out.xlabel) pl.ylabel("Intensity [W]") pl.legend(out.ylabels) diff --git a/pykat/detectors.py b/pykat/detectors.py index 67434f8..a24d4d9 100644 --- a/pykat/detectors.py +++ b/pykat/detectors.py @@ -21,6 +21,7 @@ class Detector(object) : self.tag = None self.__node = None self._params = [] + self._mask = {} if node.find('*'): self._alternate_beam = True @@ -59,8 +60,18 @@ class Detector(object) : def __str__(self): return self.name -class pd(Detector): + def mask(self, n, m, factor): + id = str(n)+"_"+str(m) + + # if the mask is 1 then remove this so it doesn't get + # printed as by default the value is 1.0 + if id in self._mask and factor == 1.0: + del self._mask[id] + + self._mask[id] = factor +class pd(Detector): + def __init__(self, name, num_demods, node_name, senstype=None, alternate_beam=False, **kwargs): Detector.__init__(self, name, node_name) diff --git a/pykat/finesse.py b/pykat/finesse.py index a3cf55b..e2c8f51 100644 --- a/pykat/finesse.py +++ b/pykat/finesse.py @@ -70,14 +70,16 @@ class katRun(object): def get(self, value): return self[value] def __getitem__(self, value): - if value in self.ylabels: - idx = self.ylabels.index(value) - if len(self.y.shape) == 1: - return self.y - else: - return self.y[:, idx] + idx = [i for i in range(len(self.ylabels)) if self.ylabels[i].split(" ")[0] == str(value)] + + if len(idx) == 1 and len(self.y.shape) == 1: + return self.y.squeeze() + elif len(idx) > 0: + return self.y[:,idx].squeeze() + elif len(idx) == 1: + return self.y[idx].squeeze() else: - raise pkex.BasePyKatException("No output by the name {0} found".format(value)) + raise pkex.BasePyKatException("No output by the name {0} found".format(str(value))) class katRun2D(object): def __init__(self): -- GitLab