diff --git a/examples/lkat_trace.py b/examples/lkat_trace.py index 2c7a88f5564c4323147cd694a2e515bb4a14b977..e29fa60e0c2fe88849fbafa479bfb57bc0062d0d 100644 --- a/examples/lkat_trace.py +++ b/examples/lkat_trace.py @@ -22,7 +22,7 @@ kat.parseCommands(cmd) info = kat.lkat_trace() -print "n1 qx =",info["n1"].qx +print "n1 qx =", info["n1"].qx print "Cavity info ", info["c1"] diff --git a/pykat/finesse.py b/pykat/finesse.py index 76603e08d25668cdc1015c34e2ffcc6a72b40cc7..9abd7aa3222628cbd8544a6387c69a324055c6a7 100644 --- a/pykat/finesse.py +++ b/pykat/finesse.py @@ -93,7 +93,7 @@ def f__lkat_process(callback, cmd, kwargs): lkat._pykat_finish(0) -def f__lkat_trace_callback(lkat, trace_info): +def f__lkat_trace_callback(lkat, trace_info, getCavities, getNodes, getSpaces): """ lkat callback for computing the beam traces through a setup. Returns a dictionary of nodes, spaces and cavities and the @@ -106,40 +106,43 @@ def f__lkat_trace_callback(lkat, trace_info): lkat._pykat_step() - for n in range(0, inter.num_nodes): - node = inter.node_list[n] - - node_info = node_trace( - qx = complex(node.qx.re, node.qx.im), - qy = complex(node.qy.re, node.qy.im) + if getNodes: + for n in range(0, inter.num_nodes): + node = inter.node_list[n] + + node_info = node_trace( + qx = complex(node.qx.re, node.qx.im), + qy = complex(node.qy.re, node.qy.im) + ) + + trace_info[node.name] = node_info + + if getCavities: + for c in range(0, inter.num_cavities): + cav = inter.cavity_list[c] + + cav_info = cav_trace( + isStable = (cav.stable == 1), + gx = cav.stability_x, + gy = cav.stability_y, + qx = complex(cav.qx.re, cav.qx.im), + qy = complex(cav.qy.re, cav.qy.im), + finesse = cav.finesse, + FSR = cav.FSR, + FWHM = cav.FWHM, + loss = cav.loss, + length = cav.length, + pole = cav.pole ) - trace_info[node.name] = node_info - - for c in range(0, inter.num_cavities): - cav = inter.cavity_list[c] - - cav_info = cav_trace( - isStable = (cav.stable == 1), - gx = cav.stability_x, - gy = cav.stability_y, - qx = complex(cav.qx.re, cav.qx.im), - qy = complex(cav.qy.re, cav.qy.im), - finesse = cav.finesse, - FSR = cav.FSR, - FWHM = cav.FWHM, - loss = cav.loss, - length = cav.length, - pole = cav.pole - ) - - trace_info[cav.name] = cav_info + trace_info[cav.name] = cav_info - for s in range(0, inter.num_spaces): - space = inter.space_list[s] + if getSpaces: + for s in range(0, inter.num_spaces): + space = inter.space_list[s] - trace_info[space.name] = space_trace(gouyx = space.gouy_x, - gouyy = space.gouy_y) + trace_info[space.name] = space_trace(gouyx = space.gouy_x, + gouyy = space.gouy_y) class katRun(object): @@ -1187,7 +1190,13 @@ class kat(object): return rtn - def lkat_trace(self): + def lkat_trace(self, getCavities=True, getNodes=True, getSpaces=True): + """ + Given the current state of the kat object a new FINESSE process is called and just + the beam tracing routine is run. The object that is returned contains all the information + from the beam tracing routine for each node and space components defined as well as cavity + commands. + """ if lkat_location == None: raise RuntimeError("Could not find shared library 'libkat', please install to a system location or copy to the same directory as this script") @@ -1197,15 +1206,15 @@ class kat(object): self.maxtem = 0 try: - p = self.getProcess(f__lkat_trace_callback, trace_info=trace_info) + p = self.getProcess(f__lkat_trace_callback, trace_info=trace_info, + getCavities=getCavities, getNodes=getNodes, getSpaces=getSpaces) p.start() p.join() - finally: + # return a local copy of the trace information dictionary + return dict(trace_info) + finally: self.maxtem = prev - - # return a local copy of the trace information dictionary - return dict(trace_info) def __add_detector(self, det):