Commit 49de1b71 authored by Daniel Brown's avatar Daniel Brown
Browse files

adding in block selector to loadkatfile and parsecommands, so that it only...

adding in block selector to loadkatfile and parsecommands, so that it only reads in certain blocks. Fixed factorial code in HG_beam
parent 2989e95b
...@@ -8,4 +8,6 @@ beam = HG_beam(gx,gy,0,0) ...@@ -8,4 +8,6 @@ beam = HG_beam(gx,gy,0,0)
beam.n = 5 beam.n = 5
beam.m = 6 beam.m = 6
beam.plot() beam.plot()
\ No newline at end of file
...@@ -20,7 +20,7 @@ class Command(object): ...@@ -20,7 +20,7 @@ class Command(object):
def __init__(self, name): def __init__(self, name):
self.tag = None self.tag = None
self.__removed = False self.__removed = False
self.__name = name self.__name = name.strip("*")
def getFinesseText(self): def getFinesseText(self):
""" Base class for individual finesse optical components """ """ Base class for individual finesse optical components """
......
...@@ -484,15 +484,15 @@ class kat(object): ...@@ -484,15 +484,15 @@ class kat(object):
( '::;;+;;: `-"' =" /,`"" `) / ( '::;;+;;: `-"' =" /,`"" `) /
L. \\`:::a:f c_/ n_' L. \\`:::a:f c_/ n_'
..`--...___`. . , ..`--...___`. . ,
`^-....____: +. {1}""".format(pykat.__version__, pykat_web) `^-....____: +. {1}\n""".format(pykat.__version__, pykat_web)
def loadKatFile(self, katfile): def loadKatFile(self, katfile, blocks=None):
commands=open(katfile).read() commands=open(katfile).read()
self.parseCommands(commands) self.parseCommands(commands, blocks=blocks)
def parseKatCode(self, code): def parseKatCode(self, code, blocks=None):
#commands = code.split("\n") #commands = code.split("\n")
self.parseCommands(code) self.parseCommands(code, blocks=blocks)
def processConstants(self, commands): def processConstants(self, commands):
""" """
...@@ -547,7 +547,7 @@ class kat(object): ...@@ -547,7 +547,7 @@ class kat(object):
return commands_new return commands_new
def parseCommands(self, commands): def parseCommands(self, commands, blocks=None):
blockComment = False blockComment = False
commands=self.remove_comments(commands) commands=self.remove_comments(commands)
...@@ -558,153 +558,163 @@ class kat(object): ...@@ -558,153 +558,163 @@ class kat(object):
# objects have been set and created # objects have been set and created
for line in commands: for line in commands:
#for line in commands: try:
if len(line.strip()) >= 2: if len(line.strip()) >= 2:
line = line.strip() line = line.strip()
# Looking for block start or end # Looking for block start or end
values = line.split() values = line.split()
if values[0] == "%%%":
if values[1] == "FTblock": if values[0] == "%%%":
newTag = values[2] if values[1] == "FTblock":
newTag = values[2]
if self.__currentTag != None and self.__currentTag != NO_BLOCK: if self.__currentTag != None and self.__currentTag != NO_BLOCK:
warnings.warn("found block {0} before block {1} ended".format(newTag, self.__currentTag)) warnings.warn("found block {0} before block {1} ended".format(newTag, self.__currentTag))
if newTag in self.__blocks: if newTag in self.__blocks:
raise pkex.BasePyKatException("Block `{0}` has already been read".format(newTag)) raise pkex.BasePyKatException("Block `{0}` has already been read".format(newTag))
self.__blocks[newTag] = Block(newTag) # create new list to store all references to components in block self.__blocks[newTag] = Block(newTag) # create new list to store all references to components in block
self.__currentTag = newTag self.__currentTag = newTag
if values[1] == "FTend": if values[1] == "FTend":
self.__currentTag = NO_BLOCK self.__currentTag = NO_BLOCK
continue continue
#warnings.warn("current tag {0}".format(self.__currentTag))
# don't read comment lines # only include listed blocks, if we have specfied them
if line[0] == "#" or line[0] == "%": if blocks != None and self.__currentTag not in blocks:
continue continue
# don't read comment lines
if line[0] == "#" or line[0] == "%":
continue
# check if block comment is being used # check if block comment is being used
if not blockComment and line[0:2] == "/*": if not blockComment and line[0:2] == "/*":
blockComment = True blockComment = True
continue continue
elif blockComment and line[0:2] == "*/": elif blockComment and line[0:2] == "*/":
blockComment = False blockComment = False
continue continue
first = line.split(" ",1)[0] first = line.split(" ",1)[0]
obj = None obj = None
if(first == "m" or first == "m1" or first == "m2"):
obj = pykat.components.mirror.parseFinesseText(line)
elif(first == "s"):
obj = pykat.components.space.parseFinesseText(line)
elif(first == "l"):
obj = pykat.components.laser.parseFinesseText(line)
elif(first == "sq"):
obj = pykat.components.squeezer.parseFinesseText(line)
elif(first[0:2] == "bs"):
obj = pykat.components.beamSplitter.parseFinesseText(line)
elif(first[0:2] == "gr"):
obj = pykat.components.grating.parseFinesseText(line)
elif(first[0:4] == "isol"):
obj = pykat.components.isolator.parseFinesseText(line)
elif(first[0:4] == "lens"):
obj = pykat.components.lens.parseFinesseText(line)
elif(first[0:3] == "mod"):
obj = pykat.components.modulator.parseFinesseText(line)
elif(first[0:2] == "ad"):
obj = pykat.detectors.ad.parseFinesseText(line)
elif(first[0:2] == "bp"):
obj = pykat.detectors.bp.parseFinesseText(line)
elif(first[0:4] == "gouy"):
obj = pykat.detectors.gouy.parseFinesseText(line)
elif(first[0:2] == "pd" and first != "pdtype"):
obj = pykat.detectors.pd.parseFinesseText(line)
elif(first == "qshot" or first == "qshotS" or first == "qshotN"):
obj = pykat.detectors.qshot.parseFinesseText(line)
elif(first == "qnoised" or first == "qnoisedS" or first == "qnoisedN"):
obj = pykat.detectors.qnoised.parseFinesseText(line)
elif(first == "xaxis" or first == "xaxis*"):
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**"):
after_process.append(line)
elif(first == "scale"):
after_process.append(line)
elif(first == "pdtype"):
after_process.append(line)
elif(first == "attr"):
after_process.append(line)
elif(first == "noxaxis"):
self.noxaxis = True
elif(first == "lambda"):
v = line.split()
self.lambda0 = SIfloat(v[-1])
elif(first == "yaxis"):
v = line.split()
self.yaxis = v[-1] if(first == "m" or first == "m1" or first == "m2"):
elif(first == "phase"): obj = pykat.components.mirror.parseFinesseText(line)
v = line.split() elif(first == "s"):
if len(v) != 2: obj = pykat.components.space.parseFinesseText(line)
raise pkex.BasePyKatException("phase command `{0}` is incorrect.".format(line)) elif(first == "l"):
else: obj = pykat.components.laser.parseFinesseText(line)
self.phase = int(v[1]) elif(first == "sq"):
elif(first == "maxtem"): obj = pykat.components.squeezer.parseFinesseText(line)
v = line.split() elif(first[0:2] == "bs"):
if len(v) != 2: obj = pykat.components.beamSplitter.parseFinesseText(line)
raise pkex.BasePyKatException("maxtem command `{0}` is incorrect.".format(line)) elif(first[0:2] == "gr"):
else: obj = pykat.components.grating.parseFinesseText(line)
if v[1] == "off": elif(first[0:4] == "isol"):
self.maxtem = -1 obj = pykat.components.isolator.parseFinesseText(line)
elif(first[0:4] == "lens"):
obj = pykat.components.lens.parseFinesseText(line)
elif(first[0:3] == "mod"):
obj = pykat.components.modulator.parseFinesseText(line)
elif(first[0:2] == "ad"):
obj = pykat.detectors.ad.parseFinesseText(line)
elif(first[0:2] == "bp"):
obj = pykat.detectors.bp.parseFinesseText(line)
elif(first[0:4] == "gouy"):
obj = pykat.detectors.gouy.parseFinesseText(line)
elif(first[0:2] == "pd" and first != "pdtype"):
obj = pykat.detectors.pd.parseFinesseText(line)
elif(first == "qshot" or first == "qshotS" or first == "qshotN"):
obj = pykat.detectors.qshot.parseFinesseText(line)
elif(first == "qnoised" or first == "qnoisedS" or first == "qnoisedN"):
obj = pykat.detectors.qnoised.parseFinesseText(line)
elif(first == "xaxis" or first == "xaxis*"):
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**"):
after_process.append(line)
elif(first == "scale"):
after_process.append(line)
elif(first == "pdtype"):
after_process.append(line)
elif(first == "attr"):
after_process.append(line)
elif(first == "noxaxis"):
self.noxaxis = True
elif(first == "lambda"):
v = line.split()
self.lambda0 = SIfloat(v[-1])
elif(first == "yaxis"):
v = line.split()
self.yaxis = v[-1]
elif(first == "phase"):
v = line.split()
if len(v) != 2:
raise pkex.BasePyKatException("phase command `{0}` is incorrect.".format(line))
else:
self.phase = int(v[1])
elif(first == "maxtem"):
v = line.split()
if len(v) != 2:
raise pkex.BasePyKatException("maxtem command `{0}` is incorrect.".format(line))
else:
if v[1] == "off":
self.maxtem = -1
else:
self.maxtem = int(v[1])
elif(first == "trace"):
v = line.split()
if len(v) > 2:
raise pkex.BasePyKatException("Trace command `{0}` is incorrect.".format(line))
elif len(v) == 2:
self.trace = v[1]
elif(first == "retrace"):
v = line.split()
if len(v) > 2:
raise pkex.BasePyKatException("Retrace command `{0}` is incorrect.".format(line))
elif len(v) == 2:
self.retrace = v[1]
elif(first == "deriv_h"):
v = line.split()
if len(v) != 2:
raise pkex.BasePyKatException("deriv_h command `{0}` is incorrect.".format(line))
else: else:
self.maxtem = int(v[1]) self.deriv_h = float(v[1])
elif(first == "trace"): elif(first == "gnuterm" or first == "pyterm"):
v = line.split() if self.verbose:
if len(v) > 2: print "Ignoring Gnuplot/Python terminal command '{0}'".format(line)
raise pkex.BasePyKatException("Trace command `{0}` is incorrect.".format(line)) #elif(first == "fsig"):
elif len(v) == 2: # after_process.append(line)
self.trace = v[1] elif(first == "noplot"):
elif(first == "retrace"): obj = line
v = line.split() self.__blocks[self.__currentTag].contents.append(line)
if len(v) > 2:
raise pkex.BasePyKatException("Retrace command `{0}` is incorrect.".format(line))
elif len(v) == 2:
self.retrace = v[1]
elif(first == "deriv_h"):
v = line.split()
if len(v) != 2:
raise pkex.BasePyKatException("deriv_h command `{0}` is incorrect.".format(line))
else: else:
self.deriv_h = float(v[1]) if self.verbose:
elif(first == "gnuterm" or first == "pyterm"): print "Parsing `{0}` into pykat object not implemented yet, added as extra line.".format(line)
if self.verbose:
print "Ignoring Gnuplot/Python terminal command '{0}'".format(line)
#elif(first == "fsig"):
# after_process.append(line)
elif(first == "noplot"):
obj = line
self.__blocks[self.__currentTag].contents.append(line)
else:
if self.verbose:
print "Parsing `{0}` into pykat object not implemented yet, added as extra line.".format(line)
obj = line obj = line
# manually add the line to the block contents # manually add the line to the block contents
self.__blocks[self.__currentTag].contents.append(line) self.__blocks[self.__currentTag].contents.append(line)
if obj != None and not isinstance(obj, str): if obj != None and not isinstance(obj, str):
if self.hasNamedObject(obj.name): if self.hasNamedObject(obj.name):
getattr(self, obj.name).remove() getattr(self, obj.name).remove()
print "Removed existing object '{0}' of type {1} to add line '{2}'".format(obj.name, obj.__class__, line) print "Removed existing object '{0}' of type {1} to add line '{2}'".format(obj.name, obj.__class__, line)
self.add(obj) self.add(obj)
except:
print "--------------------------------------------------------"
print "Error parsing line: " + line
print "--------------------------------------------------------"
raise
# now process all the varous gauss/attr etc. commands which require # now process all the varous gauss/attr etc. commands which require
# components to exist first before they can be processed # components to exist first before they can be processed
for line in after_process: for line in after_process:
...@@ -888,13 +898,13 @@ class kat(object): ...@@ -888,13 +898,13 @@ class kat(object):
# remove any ANSI commands # remove any ANSI commands
ansi = re.compile(r'\x1b[^m]*m') ansi = re.compile(r'\x1b[^m]*m')
line = ansi.sub('', line) line = ansi.sub('', line)
# warnings and errors start with an asterisk # warnings and errors start with an asterisk
# so if verbose show them # so if verbose show them
if line.lstrip().startswith('*'): if line.lstrip().startswith('*'):
if self.verbose: sys.stdout.write(line) if self.verbose: sys.stdout.write(line)
elif line.rstrip().endswith('s') and line.contains('%'): elif line.rstrip().endswith('s') and '%' in line:
vals = line.split("-") vals = line.split("-")
action = vals[0].strip() action = vals[0].strip()
prc = vals[1].strip()[:] prc = vals[1].strip()[:]
......
...@@ -43,6 +43,7 @@ def start(instance_path,port=5000, debug=True, ip="0.0.0.0", git_bin="/usr/bin/g ...@@ -43,6 +43,7 @@ def start(instance_path,port=5000, debug=True, ip="0.0.0.0", git_bin="/usr/bin/g
if not os.path.exists(os.path.join(app.instance_path,"finesse_test")): if not os.path.exists(os.path.join(app.instance_path,"finesse_test")):
print "finesse test folder didn't exist, cloning now..." print "finesse test folder didn't exist, cloning now..."
utils.git(["clone","git://gitmaster.atlas.aei.uni-hannover.de/finesse/test.git","finesse_test"]) utils.git(["clone","git://gitmaster.atlas.aei.uni-hannover.de/finesse/test.git","finesse_test"])
utils.git(["config","core.sharedRepository","true"], cwd="./finesse_test/")
# load up the actual interface code # load up the actual interface code
import pykat.testing.web.web_interface import pykat.testing.web.web_interface
......
...@@ -319,12 +319,12 @@ class HG_beam(object): ...@@ -319,12 +319,12 @@ class HG_beam(object):
def _calc_constants(self): def _calc_constants(self):
self.__xpre_const = math.pow(2.0/math.pi, 0.25) self.__xpre_const = math.pow(2.0/math.pi, 0.25)
self.__xpre_const *= np.sqrt(1.0/(self._qx.w0 * 2**(self._n) * np.factorial(self._n))) self.__xpre_const *= np.sqrt(1.0/(self._qx.w0 * 2**(self._n) * np.math.factorial(self._n)))
self.__xpre_const *= np.sqrt(1j*self._qx.imag / self._qx.q) self.__xpre_const *= np.sqrt(1j*self._qx.imag / self._qx.q)
self.__xpre_const *= ((1j*self._qx.imag * self._qx.q.conjugate())/(-1j*self._qx.imag * self._qx.q)) ** ( self._n/2.0) self.__xpre_const *= ((1j*self._qx.imag * self._qx.q.conjugate())/(-1j*self._qx.imag * self._qx.q)) ** ( self._n/2.0)
self.__ypre_const = math.pow(2.0/math.pi, 0.25) self.__ypre_const = math.pow(2.0/math.pi, 0.25)
self.__ypre_const *= np.sqrt(1.0/(self._qy.w0 * 2**(self._m) * np.factorial(self._m))) self.__ypre_const *= np.sqrt(1.0/(self._qy.w0 * 2**(self._m) * np.math.factorial(self._m)))
self.__ypre_const *= np.sqrt(1j*self._qy.imag / self._qy.q) self.__ypre_const *= np.sqrt(1j*self._qy.imag / self._qy.q)
self.__ypre_const *= ((1j*self._qy.imag * self._qy.q.conjugate())/(-1j*self._qy.imag * self._qy.q)) **(self._m/2.0) self.__ypre_const *= ((1j*self._qy.imag * self._qy.q.conjugate())/(-1j*self._qy.imag * self._qy.q)) **(self._m/2.0)
......
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