Commit ed7f6c2a authored by Daniel Brown's avatar Daniel Brown
Browse files

fixing output from kat binary so correctly displays the percentage done. Added in x2axis

parent 1487f402
...@@ -39,7 +39,7 @@ kat.maxtem = 0 ...@@ -39,7 +39,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.y) pl.plot(out.x, out["pd_cav"])
pl.xlabel(out.xlabel) pl.xlabel(out.xlabel)
pl.ylabel("Intensity [W]") pl.ylabel("Intensity [W]")
pl.legend(out.ylabels) pl.legend(out.ylabels)
......
...@@ -77,7 +77,8 @@ class attr(): ...@@ -77,7 +77,8 @@ class attr():
class xaxis(Command): class xaxis(Command):
def __init__(self, scale, limits, comp, param, steps): def __init__(self, scale, limits, comp, param, steps, axis_type="xaxis"):
self._axis_type = axis_type
if scale == "lin": if scale == "lin":
scale = Scale.linear scale = Scale.linear
...@@ -121,23 +122,43 @@ class xaxis(Command): ...@@ -121,23 +122,43 @@ class xaxis(Command):
def parseFinesseText(text): def parseFinesseText(text):
values = text.split(" ") values = text.split(" ")
if values[0] != "xaxis" and values[0] != "xaxis*" and values[0] != "x2axis" and values[0] != "x2axis*": if values[0] != "xaxis" and values[0] != "xaxis*":
raise exceptions.RuntimeError("'{0}' not a valid Finesse xaxis command".format(text)) raise exceptions.RuntimeError("'{0}' not a valid Finesse xaxis command".format(text))
axis_type = values[0]
values.pop(0) # remove initial value values.pop(0) # remove initial value
if len(values) != 6: if len(values) != 6:
raise exceptions.RuntimeError("xaxis Finesse code format incorrect '{0}'".format(text)) raise exceptions.RuntimeError("xaxis Finesse code format incorrect '{0}'".format(text))
return xaxis(values[2], [values[3], values[4]], values[0], values[1], values[5]) return xaxis(values[2], [values[3], values[4]], values[0], values[1], values[5], axis_type=axis_type)
def getFinesseText(self): def getFinesseText(self):
# store either the component name of the string provided # store either the component name of the string provided
comp_name = self.__comp.name if isinstance(self.__comp, Component) else self.__comp comp_name = self.__comp.name if isinstance(self.__comp, Component) else self.__comp
param_name = self.__param.name if isinstance(self.__param, Param) else self.__param param_name = self.__param.name if isinstance(self.__param, Param) else self.__param
return 'xaxis {0} {1} {2} {3} {4} {5}'.format( return '{axis_type} {0} {1} {2} {3} {4} {5}'.format(
comp_name, param_name, self.scale, comp_name, param_name, self.scale,
min(self.limits), max(self.limits), self.steps); min(self.limits), max(self.limits), self.steps, axis_type=self._axis_type);
class x2axis(xaxis):
def __init__(self, scale, limits, comp, param, steps):
xaxis.__init__(self, scale, limits, comp, param, steps, axis_type="x2axis")
@staticmethod
def parseFinesseText(text):
values = text.split(" ")
if values[0] != "x2axis" and values[0] != "x2axis*":
raise exceptions.RuntimeError("'{0}' not a valid Finesse xaxis command".format(text))
axis_type = values[0]
values.pop(0) # remove initial value
if len(values) != 6:
raise exceptions.RuntimeError("xaxis Finesse code format incorrect '{0}'".format(text))
return x2axis(values[2], [values[3], values[4]], values[0], values[1], values[5])
\ No newline at end of file
...@@ -345,7 +345,7 @@ class space(Component): ...@@ -345,7 +345,7 @@ class space(Component):
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._QItem = None
self.__L = SIfloat(L) self.__L = SIfloat(L)
self.__n = SIfloat(n) self.__n = SIfloat(n)
......
...@@ -67,6 +67,17 @@ class katRun(object): ...@@ -67,6 +67,17 @@ class katRun(object):
with open(filename,'r') as infile: with open(filename,'r') as infile:
return pickle.load(infile) return pickle.load(infile)
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]
else:
raise pkex.BasePyKatExeception("No output by the name {0} found", value)
class Block: class Block:
def __init__(self, name): def __init__(self, name):
...@@ -213,8 +224,10 @@ class kat(object): ...@@ -213,8 +224,10 @@ class kat(object):
obj = pykat.components.lens.parseFinesseText(line) obj = pykat.components.lens.parseFinesseText(line)
elif(first[0:2] == "pd"): elif(first[0:2] == "pd"):
obj = pykat.detectors.photodiode.parseFinesseText(line) obj = pykat.detectors.photodiode.parseFinesseText(line)
elif(first == "xaxis" or first == "x2axis" or first == "xaxis*" or first == "x2axis*"): elif(first == "xaxis" or first == "xaxis*"):
obj = pykat.commands.xaxis.parseFinesseText(line) obj = pykat.commands.xaxis.parseFinesseText(line)
elif(first == "x2axis" or first == "x2axis*"):
obj = pykat.commands.x2axis.parseFinesseText(line)
elif(first == "gauss" or first == "gauss*" or first == "gauss**"): elif(first == "gauss" or first == "gauss*" or first == "gauss**"):
after_process.append(line) after_process.append(line)
else: else:
...@@ -251,13 +264,17 @@ class kat(object): ...@@ -251,13 +264,17 @@ class kat(object):
except BasePyKatException as ex: except BasePyKatException as ex:
print ex print ex
def run(self, printout=1, printerr=1, save_output=False, save_kat=False,kat_name=None) : def run(self, printout=0, printerr=0, save_output=False, save_kat=False,kat_name=None) :
""" """
Runs the current simulation setup that has been built thus far. Runs the current simulation setup that has been built thus far.
It returns a katRun object which is populated with the various It returns a katRun object which is populated with the various
data from the simulation run. data from the simulation run.
""" """
try: try:
print "--------------------------------------------------------------"
start = datetime.datetime.now()
print "Running kat - Started at " + str(start)
r = katRun() r = katRun()
r.katScript = "".join(self.generateKatScript()) r.katScript = "".join(self.generateKatScript())
...@@ -295,27 +312,36 @@ class kat(object): ...@@ -295,27 +312,36 @@ class kat(object):
katfile.flush() katfile.flush()
cmd=[kat_exec, '--perl1'] cmd=[kat_exec, '--perl1']
if self.__time_code: if self.__time_code:
cmd.append('--perf-timing') cmd.append('--perf-timing')
cmd.append('--no-backspace') cmd.append('--no-backspace')
# set default format so that less repeated numbers are printed to the
# output file, should speed up running and parsing of output files
cmd.append('-format=%.15g')
cmd.append(katfile.name) cmd.append(katfile.name)
if self.verbose:
print cmd #if self.verbose:
#print cmd
p=subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p=subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
err = "" err = ""
print "Finesse binary output:"
for line in iter(p.stderr.readline, ""): for line in iter(p.stderr.readline, ""):
err += line #err += line
vals = line.split("-")
if len(vals) == 2: if len(line) > 0:
if line.rstrip().endswith('%'):
vals = line.split("-")
action = vals[0].strip() action = vals[0].strip()
prc = vals[1].strip()[:-1] prc = vals[1].strip()[:-1]
#sys.stdout.write("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b")
sys.stdout.write("\r{0} {1}%".format(action, prc)) sys.stdout.write("\r{0} {1}%".format(action, prc))
sys.stdout.flush() elif line[0] == '*':
sys.stdout.write(line)
[out,errpipe] = p.communicate() [out,errpipe] = p.communicate()
...@@ -339,7 +365,7 @@ class kat(object): ...@@ -339,7 +365,7 @@ class kat(object):
[r.x,r.y,hdr] = self.readOutFile(outfile) [r.x,r.y,hdr] = self.readOutFile(outfile)
r.xlabel = hdr[0] r.xlabel = hdr[0]
r.ylabels = hdr[1:] r.ylabels = map(str.strip, hdr[1:])
if save_output: if save_output:
newoutfile = "{0}.out".format(base) newoutfile = "{0}.out".format(base)
...@@ -385,6 +411,9 @@ class kat(object): ...@@ -385,6 +411,9 @@ class kat(object):
except FinesseRunError as fe: except FinesseRunError as fe:
print fe print fe
finally:
print ""
print "Finished in " + str(datetime.datetime.now()-start)
def add(self, obj): def add(self, obj):
......
import pykat.exceptions as pkex import pykat.exceptions as pkex
import numpy import numpy
import math import math
import copy
class gauss_param(object): class gauss_param(object):
""" """
...@@ -142,3 +143,48 @@ class gauss_param(object): ...@@ -142,3 +143,48 @@ class gauss_param(object):
def imag(self): return self.__q.imag def imag(self): return self.__q.imag
@imag.setter @imag.setter
def imag(self, value): self.__q.imag = SIfloat(value) def imag(self, value): self.__q.imag = SIfloat(value)
class HG_gauss_beam(object):
def __init__(self, qx, qy=None, n=0, m=0):
self._qx = copy.deepcopy(qx)
self._2pi_qrt = math.pow(2.0/math.pi, 0.25)
if qy == None:
self._q0 = copy.deepcopy(qx)
else:
self._q0 = copy.deepcopy(qy)
self.n = n
self.m = m
self._calc_constants()
@property
def n(self): return self._n
@n.setter
def n(self,value):
self._n = float(value)
self._calc_constants()
@property
def m(self): return self._m
@m.setter
def m(self,value):
self._m = float(value)
self._calc_constants()
def _calc_constants(self):
self.__xpre_const = math.pow(2.0/math.pi, 0.25)
self.__xpre_const *= math.sqrt(1/(2**self._n * math.factorial(self._n)))
self.__xpre_const *= math.sqrt(1j*self._qx.imag / self._qx)
self.__xpre_const *= math.pow((1j*self._qx.imag * self._qx.conjugate)/(-1j*self._qx.imag * self._qx), self._n/2.0)
self.__ypre_const = math.pow(2.0/math.pi, 0.25)
self.__ypre_const *= math.sqrt(1/(2**self._m * math.factorial(self._m)))
self.__ypre_const *= math.sqrt(1j*self._qy.imag / self._qy)
self.__ypre_const *= math.pow((1j*self._qy.imag * self._qy.conjugate)/(-1j*self._qy.imag * self._qy), self._m/2.0)
def Unm(self, n, m, x, y):
return self.__xpre_const * special
\ No newline at end of file
Markdown is supported
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