From 056dd5ed421d35a319f2e0a84c0a9451ff7b9a5c Mon Sep 17 00:00:00 2001
From: Daniel Brown <ddb@star.sr.bham.ac.uk>
Date: Sat, 14 Dec 2013 02:48:14 +0000
Subject: [PATCH] adding string conversion for detectors and components to
 return its name, you can then get outputs like out[kat.pd1] or out['pd1']

---
 bin/test_2d_plot.py |  4 ++--
 pykat/components.py |  2 ++
 pykat/detectors.py  | 10 +++++-----
 pykat/finesse.py    |  6 +++---
 4 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/bin/test_2d_plot.py b/bin/test_2d_plot.py
index b178319..82d95e7 100644
--- a/bin/test_2d_plot.py
+++ b/bin/test_2d_plot.py
@@ -33,14 +33,14 @@ out = kat.run(printout=0,printerr=0)
 fig = pl.figure()
 ax = fig.add_subplot(1, 1, 1, projection='3d')
 x, y = np.meshgrid(out.x, out.y)
-p = ax.plot_wireframe(x, y, out.z[1])   
+p = ax.plot_wireframe(x, y, out["b1"])   
 pl.xlabel(out.xlabel)
 pl.ylabel(out.ylabel)
 pl.show()
 
 pl.figure()
 extent = [np.min(out.x),np.max(out.x),np.min(out.y),np.max(out.y)]
-imgplot = pl.imshow(out.z[1], extent=extent)
+imgplot = pl.imshow(out["b1"], extent=extent)
 #imgplot.set_interpolation('bicubic')
 imgplot.set_interpolation('nearest')
 pl.colorbar()
diff --git a/pykat/components.py b/pykat/components.py
index 87df724..25ab313 100644
--- a/pykat/components.py
+++ b/pykat/components.py
@@ -143,6 +143,8 @@ class Component(object):
     @property
     def id(self): return self.__id
     
+    def __str__(self): return self.name
+    
 class Param(float):
     def __new__(self,name,value):
         return float.__new__(self,SIfloat(value))
diff --git a/pykat/detectors.py b/pykat/detectors.py
index f66dc95..1f0384c 100644
--- a/pykat/detectors.py
+++ b/pykat/detectors.py
@@ -43,12 +43,12 @@ class Detector(object) :
     
     @property 
     def node(self): return self.__node
-        
-    def __getname(self):
-        return self.__name        
-        
-    name = property(__getname)
+    
+    @property
+    def name(self): return self.__name        
 
+    def __str__(self): return self.name
+    
 class photodiode(Detector):
 
     class __F(list):
diff --git a/pykat/finesse.py b/pykat/finesse.py
index 6e5b336..1a2d53d 100644
--- a/pykat/finesse.py
+++ b/pykat/finesse.py
@@ -103,12 +103,12 @@ class katRun2D(object):
     def get(self, value): return self[value]
     
     def __getitem__(self, value):
-        idx = [i for i in range(len(self.zlabels)) if self.zlabels[i].split(" ")[0] == value]
+        idx = [i for i in range(len(self.zlabels)) if self.zlabels[i].split(" ")[0] == str(value)]
         
         if len(idx) > 0:
-            return self.z[:, idx].squeeze()
+            return self.z[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 Block:
     def __init__(self, name):
-- 
GitLab