From 4681357e56701a124f58b00337a1c597bafda43f Mon Sep 17 00:00:00 2001 From: Daniel Brown <ddb@star.sr.bham.ac.uk> Date: Fri, 23 Jan 2015 17:50:18 +0000 Subject: [PATCH] changing ROMHOM output file --- pykat/optics/maps.py | 22 ++++++++++++---------- pykat/optics/romhom.py | 39 +++++++++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/pykat/optics/maps.py b/pykat/optics/maps.py index 64d0aef..8bdf6f9 100644 --- a/pykat/optics/maps.py +++ b/pykat/optics/maps.py @@ -143,28 +143,30 @@ class surfacemap(object): raise BasePyKatException("Map type needs handling") - def generateROMWeights(self, isModeMatched=True, verbose=False, interpolate=False, tolerance = 1e-12, sigma = 1, sort=False, greedyfile=None): + def generateROMWeights(self, isModeMatched=True, verbose=False, interpolate=False, interpolate_N=None, tolerance = 1e-12, sigma = 1, sort=False, greedyfile=None): if interpolate: from scipy.interpolate import interp2d import numpy as np D = interp2d(self.x, self.y, self.data, fill_value=0) - + if interpolate_N is None: + interpolate_N = (self.size[0], self.size[1]) + # only want even number of data points spread equally # about the axes - if self.size[0] % 2 == 0: - Nx = self.size[0] + if interpolate_N[0] % 2 == 0: + Nx = interpolate_N[0] else: - Nx = self.size[0]-1 + Nx = interpolate_N[0]-1 - if self.size[1] % 2 == 0: - Ny = self.size[1] + if interpolate_N[1] % 2 == 0: + Ny = interpolate_N[1] else: - Ny = self.size[1]-1 + Ny = interpolate_N[1]-1 - nx = np.linspace(min(self.x), max(self.x), Nx) - ny = np.linspace(min(self.y), max(self.y), Ny) + nx = np.linspace(min(self.x), max(self.x), interpolate_N[0]) + ny = np.linspace(min(self.y), max(self.y), interpolate_N[1]) data = D(nx-self.offset[0], ny-self.offset[0]) diff --git a/pykat/optics/romhom.py b/pykat/optics/romhom.py index 7119fb4..ac12c67 100644 --- a/pykat/optics/romhom.py +++ b/pykat/optics/romhom.py @@ -28,37 +28,48 @@ class ROMWeights: self.limits = limits def writeToFile(self, filename): - f = open(filename, 'w+') + """ + Writes this map's ROM weights to a file + that can be used with Finesse. The filename + is appended with '.rom' internally. + """ + f = open(filename + ".rom", 'w+') - f.write(repr(self.limits) + "\n") + f.write("zmin=%16.16e\n" % self.limits.zmin) + f.write("zmax=%16.16e\n" % self.limits.zmax) + f.write("w0min=%16.16e\n" % self.limits.w0min) + f.write("w0max=%16.16e\n" % self.limits.w0max) + f.write("maxorder=%i\n" % self.limits.max_order) + f.write("xnodes=%i\n" % len(self.EI["xm"].nodes)) + + for v in self.EI["xm"].nodes.flatten(): + f.write("%s\n" % repr(float(v))) + + f.write("ynodes=%i\n" % len(self.EI["ym"].nodes)) + + for v in self.EI["ym"].nodes.flatten(): + f.write("%s\n" % repr(float(v))) + f.write(repr(self.w_ij_Q1.shape) + "\n") for v in self.w_ij_Q1.flatten(): - f.write("%s " % repr(complex(v))[1:-1]) - - f.write("\n") + f.write("%s\n" % repr(complex(v))[1:-1]) f.write(repr(self.w_ij_Q2.shape) + "\n") for v in self.w_ij_Q2.flatten(): - f.write("%s " % repr(complex(v))[1:-1]) - - f.write("\n") + f.write("%s\n" % repr(complex(v))[1:-1]) f.write(repr(self.w_ij_Q3.shape) + "\n") for v in self.w_ij_Q3.flatten(): - f.write("%s " % repr(complex(v))[1:-1]) - - f.write("\n") + f.write("%s\n" % repr(complex(v))[1:-1]) f.write(repr(self.w_ij_Q4.shape) + "\n") for v in self.w_ij_Q4.flatten(): - f.write("%s " % repr(complex(v))[1:-1]) - - f.write("\n") + f.write("%s\n" % repr(complex(v))[1:-1]) f.close() -- GitLab