Commit 8e51b3ba authored by Daniel Brown's avatar Daniel Brown
Browse files

adding in qnoised detector and qshot, adding 3 port isolator

parent 79d24154
...@@ -16,19 +16,16 @@ m m2 0.5 0.5 0 n4 n5 ...@@ -16,19 +16,16 @@ m m2 0.5 0.5 0 n4 n5
s s3 10 1 n5 n6 s s3 10 1 n5 n6
yaxis abs:deg yaxis abs:deg
pd pd_cav n3
cav c1 m1 n3 m2 n4
""" """
kat = finesse.kat() kat = finesse.kat()
kat.parseCommands(code) kat.parseCommands(code)
kat.add(cavity('cav1', 'm1', 'n3', 'm2', 'n4'))
kat.add(photodiode('pd_ref','n2'))
kat.add(photodiode('pd_trs','n5'))
kat.add(photodiode('pd_cav','n4', num_demods=1, demods=[1]))
kat.add(xaxis("lin", [0, 360], kat.m2.phi, 100)) kat.add(xaxis("lin", [0, 360], kat.m2.phi, 100))
kat.m1.Rcx = -1000.0 kat.m1.Rcx = -1000.0
...@@ -41,7 +38,7 @@ kat.maxtem = 0 ...@@ -41,7 +38,7 @@ kat.maxtem = 0
out = kat.run(printout=0,printerr=0) out = kat.run(printout=0,printerr=0)
pl.figure() pl.figure()
pl.plot(out.x, out["pd_cav"]) pl.plot(out.x, out.y)
pl.xlabel(out.xlabel) pl.xlabel(out.xlabel)
pl.ylabel("Intensity [W]") pl.ylabel("Intensity [W]")
pl.legend(out.ylabels) pl.legend(out.ylabels)
......
...@@ -558,11 +558,12 @@ class grating(Component): ...@@ -558,11 +558,12 @@ class grating(Component):
return self._QItem return self._QItem
class isolator(Component): class isolator(Component):
def __init__(self, name, node1, node2, S = 0): def __init__(self, name, node1, node2, node3="dump", S = 0):
Component.__init__(self, name) Component.__init__(self, name)
self._requested_node_names.append(node1) self._requested_node_names.append(node1)
self._requested_node_names.append(node2) self._requested_node_names.append(node2)
self._requested_node_names.append(node3)
self.__S = Param("S",self,SIfloat(S)) self.__S = Param("S",self,SIfloat(S))
...@@ -582,11 +583,13 @@ class isolator(Component): ...@@ -582,11 +583,13 @@ class isolator(Component):
if len(values) == 4: if len(values) == 4:
return isolator(values[0], values[2], values[3], values[1]) return isolator(values[0], values[2], values[3], values[1])
elif len(values) == 5:
return isolator(values[0], values[2], values[3], values[4], values[1])
else: else:
raise pkex.BasePyKatException("Isolator Finesse code format incorrect '{0}'".format(text)) raise pkex.BasePyKatException("Isolator Finesse code format incorrect '{0}'".format(text))
def getFinesseText(self): def getFinesseText(self):
rtn = ['isol {0} {1} {2} {3}'.format(self.name, self.S.value, self.nodes[0].name, self.nodes[1].name)] rtn = ['isol {0} {1} {2} {3} {4}'.format(self.name, self.S.value, self.nodes[0].name, self.nodes[1].name, self.nodes[2].name)]
for p in self._params: for p in self._params:
rtn.extend(p.getFinesseText()) rtn.extend(p.getFinesseText())
......
...@@ -28,6 +28,7 @@ class Detector(object) : ...@@ -28,6 +28,7 @@ class Detector(object) :
self._mask = {} self._mask = {}
self.__scale = None self.__scale = None
if node != None:
if node[-1]=='*': if node[-1]=='*':
self._alternate_beam = True self._alternate_beam = True
node=node[:-1] node=node[:-1]
...@@ -38,6 +39,7 @@ class Detector(object) : ...@@ -38,6 +39,7 @@ class Detector(object) :
self._params.append(param) self._params.append(param)
def _on_kat_add(self, kat): def _on_kat_add(self, kat):
if self.__requested_node != None:
self.__node = kat.nodes.createNode(self.__requested_node) self.__node = kat.nodes.createNode(self.__requested_node)
@staticmethod @staticmethod
...@@ -335,130 +337,130 @@ class pd(Detector): ...@@ -335,130 +337,130 @@ class pd(Detector):
return rtn return rtn
class photodiode(Detector): def qnoised(pd):
class __F(list): def __init__(self, name, num_demods, node_name, alternate_beam=False, pdtype=None, **kwargs):
def __init__(self, values=None): pd.__init__(self, name, num_demods, node_name, alternate_beam=False, **kwargs)
if values==None:
values = []
list.__init__(self,[SIfloat(value) for value in values])
class __Phi(list): self.__homangle = AttrParam("homangle", self, None)
def __convertValue(self, value):
if value=="max":
return value
else:
return SIfloat(value)
def __init__(self, values=None):
if values==None:
values = []
list.__init__(self,[self.__convertValue(value) for value in values])
def __getitem__(self, key): # probably not needed
if list.__getitem__(self,key)=="max":
return list.__getitem__(self,key)
else:
return float(list.__getitem__(self,key))
@property @property
def f(self): return self.__f def homangle(self): return self.__homangle
@homangle.setter
def homangle(self, value): self.__homangle.value = value
@property @pd.pdtype.setter
def phi(self): return self.__phi def pdtype(self, value): raise pkex.BasePyKatException("Setting pdtype is not possible with qnoised detectors")
@property @pd.senstype.setter
def pdtype(self): return self.__pdtype def senstype(self,value): raise pkex.BasePyKatException("qnoised detector has no sensitvity type")
@pdtype.setter
def pdtype(self, value): self.__pdtype = value
def __init__(self, name, node, senstype="", num_demods=0, demods=[], pdtype=None):
Detector.__init__(self, name, node)
if num_demods>2: @staticmethod
raise NotImplementedError("pd with more than two demodulations not implemented yet") def parseFinesseText(text):
values = text.split()
self.num_demods = num_demods if len(values) <= 3:
self.senstype = senstype raise pkex.BasePyKatException("Photodiode code format incorrect '{0}' (2)".format(text))
self.__pdtype = pdtype
demods = values[2]
# every second element into f (starting at 1) if len(values) <= 4 and demods > 0:
self.__f = self.__F(demods[::2]) raise pkex.BasePyKatException("Photodiode code format incorrect '{0}' (2)".format(text))
elif len(values) > 4 and demods == 0:
raise pkex.BasePyKatException("Photodiode code format incorrect '{0}' (3)".format(text))
# Every second element into phi (starting at 2) num_f_phs = len(values) - 4
self.__phi = self.__Phi(demods[1::2]) expected_f_phs = demods * 2
@staticmethod if not (num_f_phs == expected_f_phs or num_f_phs == expected_f_phs-1):
def parseFinesseText(text): raise pkex.BasePyKatException("Photodiode code format incorrect '{0}' (4)".format(text))
values = text.split()
if values[0][0:2] != "pd": f = values[3:len(values)-1:2]
raise exceptions.FinesseParse("'{0}' not a valid photodiode command".format(text)) phs = values[4:len(values)-1:2]
if len(values[0])==2:
__num_demods=0
__senstype=""
elif len(values[0])==3 or len(values[0])==4:
if values[0][2]=="S":
__senstype="S"
elif values[0][2]=="N":
__senstype="N"
else:
try:
__num_demods=int(values[0][2])
__senstype=""
except ValueError:
raise exceptions.FinesseParse("'{0}' not a valid photodiode command".format(text))
if len(values[0])==4:
try:
__num_demods=int(values[0][3])
except ValueError:
raise exceptions.FinesseParse("'{0}' not a valid photodiode command".format(text))
else:
raise exceptions.FinesseParse("'{0}' not a valid photodiode command".format(text))
if __num_demods<0 or __num_demods>5: dict = {}
raise exceptions.FinesseParse("'{0}' number of demodulations must be >0 and <5".format(text))
values.pop(0) # remove initial value for i in range(len(f)):
dict['f{0}'.format(i+1)] = f[i]
for i in range(len(phs)):
dict['phi{0}'.format(i+1)] = phs[i]
if len(values) == 2 * __num_demods + 1 or len(values) == 2 * __num_demods + 2: node = values[-1]
return photodiode(values[0], values[-1], __senstype, __num_demods, values[1:len(values)-1]) alt_beam = node[-1] == '*'
else:
raise exceptions.FinesseParse("Photodiode code format incorrect '{0}'".format(text)) if alt_beam:
node = node[0:-1]
#return photodiode("name", "node", demods) return qnoised(values[1], demods, node, alternate_beam=alt_beam, **dict)
#raise NotImplementedError("This function is not implemented")
def getFinesseText(self) : def getFinesseText(self) :
if self.enabled:
rtn = [] rtn = []
__f_phi=range(len(self.f)+len(self.phi))
__f_phi[::2]=self.f
__f_phi[1::2]=self.phi
__f_phi_str = " ".join(map(str, __f_phi))
if self._alternate_beam: if self.enabled:
rtn.append("pd{0}{1} {2} {3} {4}".format(self.senstype, self.num_demods, self.name, __f_phi_str, self.node.name)) alt_str = ""
else: fphi_str = ""
rtn.append("pd{0}{1} {2} {3} {4}*".format(self.senstype, self.num_demods, self.name, __f_phi_str, self.node.name))
if self.scale != None and self.scale !='': if self.alternate_beam:
rtn.append("scale {1} {0}".format(self.name, self.scale)) alt_str = "*"
if self.pdtype != None and self.pdtype != '': for n in range(1, 1+self.num_demods):
rtn.append("pdtype {0} {1}".format(self.name, self.pdtype)) fphi_str += " " + str(self.__getattribute__("f"+str(n)))
phi_val = self.__getattribute__("phi"+str(n))
if phi_val != None:
fphi_str += " " + str(phi_val)
if self.noplot: senstype = self.senstype
rtn.append("noplot {0}".format(self.name))
if senstype == None:
senstype = ""
rtn.append("qnoised {0} {1} {2} {3}{4}".format(self.name, self.num_demods, fphi_str, self.node.name, alt_str))
if self.scale != None:
rtn.append("scale {1} {0}".format(self.name, self.scale))
for p in self._params:
rtn.extend(p.getFinesseText())
return rtn return rtn
else:
return None
def getQGraphicsItem(self): def xd(Detector):
if self._svgItem == None:
self._svgItem = ComponentQGraphicsItem(":/resources/photodiode_red.svg",self,[(-5,11,self.node)]) def __init__(self, name, node_name, component, motion):
Detector.__init__(name, None)
self.__motion = motion
self.__component = component
@property
def motion(self): return self.__motion
@property
def component(self): return self.__component
@staticmethod
def parseFinesseText(text):
values = text.split()
if len(values) != 4:
raise pkex.BasePyKatException("Motion detector command format incorrect '{0}' (2)".format(text))
return xd(values[1], values[2], values[3])
def getFinesseText(self) :
rtn = []
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))
for p in self._params:
rtn.extend(p.getFinesseText())
return rtn
return self._svgItem
\ No newline at end of file
...@@ -33,6 +33,7 @@ import pickle ...@@ -33,6 +33,7 @@ import pickle
import pykat import pykat
import warnings import warnings
import re import re
import collections
from collections import namedtuple from collections import namedtuple
...@@ -53,7 +54,6 @@ NO_GUI = False ...@@ -53,7 +54,6 @@ NO_GUI = False
NO_BLOCK = "NO_BLOCK" NO_BLOCK = "NO_BLOCK"
pykat_web = "www.gwoptics.org/pykat" pykat_web = "www.gwoptics.org/pykat"
class katRun(object): class katRun(object):
def __init__(self): def __init__(self):
self.runDateTime = datetime.datetime.now() self.runDateTime = datetime.datetime.now()
...@@ -258,6 +258,7 @@ class kat(object): ...@@ -258,6 +258,7 @@ class kat(object):
self.pykatgui = None self.pykatgui = None
self.__signals = Signals() self.__signals = Signals()
self.constants = {} self.constants = {}
self.vacuum = []
# initialise default block # initialise default block
self.__currentTag= NO_BLOCK self.__currentTag= NO_BLOCK
...@@ -857,6 +858,25 @@ class kat(object): ...@@ -857,6 +858,25 @@ class kat(object):
out.append(txt + "\n") out.append(txt + "\n")
if self.vacuum != None:
if isinstance(self.vacuum, collections.Container):
objs = []
if len(self.vacuum) > 0:
for a in self.vacuum:
if hasattr(a, 'name'):
objs.append(a.name)
else:
objs.append(str(a))
out.append("vacuum {0}\n".format(" ".join(objs)))
elif isinstance(self.vacuum, str):
out.append("vacuum {0}\n".format(self.vacuum))
else:
pkex.BasePyKatException("Couldn't understand vacuum input list")
if self.scale != None and self.scale !='': out.append("scale {0}\n".format(self.scale)) if self.scale != None and self.scale !='': out.append("scale {0}\n".format(self.scale))
if self.phase != None: out.append("phase {0}\n".format(self.phase)) if self.phase != None: out.append("phase {0}\n".format(self.phase))
if self.maxtem != None: if self.maxtem != None:
......
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