Commit 489129df authored by Daniel Brown's avatar Daniel Brown
Browse files

fixing fsig parsing of 'fsig signal frequency'. Adding code to allow surface motions.

parent 449bf621
...@@ -321,6 +321,11 @@ class AbstractMirrorComponent(Component): ...@@ -321,6 +321,11 @@ class AbstractMirrorComponent(Component):
self.__Frx = Param("Frx", self, None, canFsig=True, isPutable=False, isPutter=False, isTunable=False, fsig_name="Frx") self.__Frx = Param("Frx", self, None, canFsig=True, isPutable=False, isPutter=False, isTunable=False, fsig_name="Frx")
self.__Fry = Param("Fry", self, None, canFsig=True, isPutable=False, isPutter=False, isTunable=False, fsig_name="Fry") self.__Fry = Param("Fry", self, None, canFsig=True, isPutable=False, isPutter=False, isTunable=False, fsig_name="Fry")
self.__Fs0 = Param("Fs0", self, None, canFsig=True, isPutable=False, isPutter=False, isTunable=False, fsig_name="Fs0")
self.__Fs1 = Param("Fs1", self, None, canFsig=True, isPutable=False, isPutter=False, isTunable=False, fsig_name="Fs1")
self.__Fs0 = Param("s0", self, None, canFsig=True, isPutable=False, isPutter=False, isTunable=False, fsig_name="s0")
self.__Fs1 = Param("s1", self, None, canFsig=True, isPutable=False, isPutter=False, isTunable=False, fsig_name="s1")
self._default_fsig_param = self.__phi self._default_fsig_param = self.__phi
@property @property
......
...@@ -382,6 +382,7 @@ class Signals(object): ...@@ -382,6 +382,7 @@ class Signals(object):
return rtn return rtn
@property @property
def name(self): def name(self):
# if we don't have any signals yet then use a dummy name # if we don't have any signals yet then use a dummy name
...@@ -389,7 +390,7 @@ class Signals(object): ...@@ -389,7 +390,7 @@ class Signals(object):
# so need to get the name of at least one of them # so need to get the name of at least one of them
# as if you tune one you tune them all # as if you tune one you tune them all
if len(self.targets) == 0: if len(self.targets) == 0:
return "fsignal" return self._default_name
else: else:
return self.targets[0].name return self.targets[0].name
...@@ -408,6 +409,7 @@ class Signals(object): ...@@ -408,6 +409,7 @@ class Signals(object):
def f(self,value): self.__f.value = SIfloat(value) def f(self,value): self.__f.value = SIfloat(value)
def __init__(self, kat): def __init__(self, kat):
self._default_name = "fsignal"
self.targets = [] self.targets = []
self._params = [] self._params = []
self.__f = Param("f", self, 1) self.__f = Param("f", self, 1)
...@@ -429,16 +431,21 @@ class Signals(object): ...@@ -429,16 +431,21 @@ class Signals(object):
def getFinesseText(self): def getFinesseText(self):
rtn = [] rtn = []
for t in self.targets: if len(self.targets) == 0 and self.f != 0:
rtn.extend(t.getFinesseText()) rtn.append("fsig {name} {frequency}"
.format(name = self.name,
frequency=str(self.f)))
else:
for t in self.targets:
rtn.extend(t.getFinesseText())
rtn.append("fsig {name} {comp} {target} {frequency} {phase} {amplitude}" rtn.append("fsig {name} {comp} {target} {frequency} {phase} {amplitude}"
.format(name = t.name, .format(name = t.name,
comp=t.owner, comp=t.owner,
target=t.target, target=t.target,
frequency=str(self.f), frequency=str(self.f),
phase=str(t.phase), phase=str(t.phase),
amplitude=str(t.amplitude if t.amplitude != None else ""))) amplitude=str(t.amplitude if t.amplitude != None else "")))
for p in self._params: for p in self._params:
rtn.extend(p.getFinesseText()) rtn.extend(p.getFinesseText())
...@@ -1003,61 +1010,69 @@ class kat(object): ...@@ -1003,61 +1010,69 @@ class kat(object):
name = str(v[1]) name = str(v[1])
if v[2] not in self.__components: if len(v) == 3:
raise pkex.BasePyKatException("Could not find the component '{0}'. Line: '{1}'".format(v[2], line)) self.signals._default_name = name
self.signals.f = SIfloat(v[2])
else:
if v[2] not in self.__components:
raise pkex.BasePyKatException("Could not find the component '{0}'. Line: '{1}'".format(v[2], line))
comp = self.__components[v[2]] comp = self.__components[v[2]]
if comp._default_fsig() is None: if comp._default_fsig() is None:
raise pkex.BasePyKatException("Component '{0}' cannot be fsig'd. Line: '{1}'".format(comp.name, line)) raise pkex.BasePyKatException("Component '{0}' cannot be fsig'd. Line: '{1}'".format(comp.name, line))
param_name = None param_name = None
amp = None amp = None
if len(v) == 5: if len(v) == 3:
#param is None self.signals._default_name = name
freq = SIfloat(v[3]) freq = SIfloat(v[3])
phase = SIfloat(v[4]) elif len(v) == 5:
elif len(v) == 6: #param is None
try:
SIfloat(v[3])
isFloat = True
except:
isFloat = False
if isFloat:
freq = SIfloat(v[3]) freq = SIfloat(v[3])
phase = SIfloat(v[4]) phase = SIfloat(v[4])
amp = SIfloat(v[5]) elif len(v) == 6:
else:
try:
SIfloat(v[3])
isFloat = True
except:
isFloat = False
if isFloat:
freq = SIfloat(v[3])
phase = SIfloat(v[4])
amp = SIfloat(v[5])
else:
param_name = v[3]
freq = SIfloat(v[4])
phase = SIfloat(v[5])
elif len(v) == 7:
param_name = v[3] param_name = v[3]
freq = SIfloat(v[4]) freq = SIfloat(v[4])
phase = SIfloat(v[5]) phase = SIfloat(v[5])
amp = SIfloat(v[6])
elif len(v) == 7: else:
param_name = v[3] raise pkex.BasePyKatException("'{0}' isnot a valid fsig command".format(line))
freq = SIfloat(v[4])
phase = SIfloat(v[5])
amp = SIfloat(v[6])
else:
raise pkex.BasePyKatException("'{0}' isnot a valid fsig command".format(line))
self.signals.f = freq self.signals.f = freq
param = None
if param_name is None: param = None
param = comp._default_fsig()
else: if param_name is None:
for p in comp._params: param = comp._default_fsig()
if p.canFsig and p.fsigName == param_name: else:
param = p for p in comp._params:
break if p.canFsig and p.fsigName == param_name:
param = p
break
if param is None:
raise pkex.BasePyKatException("Line: '{0}': {1} is not a valid fsig target for {2}".format(line, param_name, comp.name))
if param is None: self.signals.apply(param, amp, phase, name)
raise pkex.BasePyKatException("Line: '{0}': {1} is not a valid fsig target for {2}".format(line, param_name, comp.name))
self.signals.apply(param, amp, phase, name)
else: else:
raise pkex.BasePyKatException("Haven't handled parsing of '{0}'".format(line)) raise pkex.BasePyKatException("Haven't handled parsing of '{0}'".format(line))
......
...@@ -16,6 +16,7 @@ from __future__ import print_function ...@@ -16,6 +16,7 @@ from __future__ import print_function
from pykat.optics.romhom import makeWeightsNew from pykat.optics.romhom import makeWeightsNew
from scipy.interpolate import interp2d, interp1d from scipy.interpolate import interp2d, interp1d
from pykat.maths.zernike import * from pykat.maths.zernike import *
from pykat.exceptions import BasePyKatException
import numpy as np import numpy as np
import math import math
...@@ -108,11 +109,11 @@ class surfacemap(object): ...@@ -108,11 +109,11 @@ class surfacemap(object):
@property @property
def x(self): def x(self):
return self.step_size[0] * (np.array(range(1, self.data.shape[0]+1)) - self.center[0]) return self.step_size[0] * (np.array(range(0, self.data.shape[0])) - self.center[0])
@property @property
def y(self): def y(self):
return self.step_size[1] * (np.array(range(1, self.data.shape[1]+1))- self.center[1]) return self.step_size[1] * (np.array(range(0, self.data.shape[1]))- self.center[1])
@property @property
def size(self): def size(self):
...@@ -120,7 +121,7 @@ class surfacemap(object): ...@@ -120,7 +121,7 @@ class surfacemap(object):
@property @property
def offset(self): def offset(self):
return np.array(self.step_size)*(np.array(self.center) - 1/2. - np.array(self.size)/2.0) return np.array(self.step_size)*(np.array(self.center) - (np.array(self.size)-1)/2.0)
@property @property
def ROMWeights(self): def ROMWeights(self):
...@@ -176,6 +177,11 @@ class surfacemap(object): ...@@ -176,6 +177,11 @@ class surfacemap(object):
return np.sqrt(1.0 - data) return np.sqrt(1.0 - data)
else: else:
return np.sqrt(1.0 - data[:, ::-1]) return np.sqrt(1.0 - data[:, ::-1])
elif "surface_motion" in self.type:
if direction == "reflection_front":
return data
else:
return data[:, ::-1]
else: else:
raise BasePyKatException("Map type needs handling") raise BasePyKatException("Map type needs handling")
...@@ -193,6 +199,9 @@ class surfacemap(object): ...@@ -193,6 +199,9 @@ class surfacemap(object):
return np.sqrt(1.0 - data) return np.sqrt(1.0 - data)
else: else:
return np.sqrt(1.0 - data[:, ::-1]) return np.sqrt(1.0 - data[:, ::-1])
elif "surface_motion" in self.type:
return np.ones(data.shape)
else: else:
raise BasePyKatException("Map type needs handling") raise BasePyKatException("Map type needs handling")
...@@ -274,10 +283,10 @@ class surfacemap(object): ...@@ -274,10 +283,10 @@ class surfacemap(object):
D = interp2d(self.x, self.y, self.data, **kwargs) D = interp2d(self.x, self.y, self.data, **kwargs)
data = D(nx-self.offset[0], ny-self.offset[0]) data = D(nx-self.offset[0], ny-self.offset[1])
Dx = interp1d(nx, np.arange(1,len(nx)+1)) Dx = interp1d(nx, np.arange(0,len(nx)))
Dy = interp1d(ny, np.arange(1,len(ny)+1)) Dy = interp1d(ny, np.arange(0,len(ny)))
self.center = (Dx(0), Dy(0)) self.center = (Dx(0), Dy(0))
self.step_size = (nx[1]-nx[0], ny[1]-ny[0]) self.step_size = (nx[1]-nx[0], ny[1]-ny[0])
...@@ -313,7 +322,7 @@ class surfacemap(object): ...@@ -313,7 +322,7 @@ class surfacemap(object):
yrange = 100*self.y yrange = 100*self.y
fig = pylab.figure() fig = pylab.figure()
axes = pylab.pcolormesh(xrange, yrange, self.data, vmin=zmin, vmax=zmax) axes = pylab.pcolormesh(xrange, yrange, self.data*self.scaling, vmin=zmin, vmax=zmax)
pylab.xlabel('x [cm]') pylab.xlabel('x [cm]')
pylab.ylabel('y [cm]') pylab.ylabel('y [cm]')
...@@ -406,11 +415,11 @@ class mergedmap: ...@@ -406,11 +415,11 @@ class mergedmap:
@property @property
def x(self): def x(self):
return self.step_size[0] * (np.array(range(1, self.size[0]+1)) - self.center[0]) return self.step_size[0] * (np.array(range(0, self.size[0])) - self.center[0])
@property @property
def y(self): def y(self):
return self.step_size[1] * (np.array(range(1, self.size[1]+1))- self.center[1]) return self.step_size[1] * (np.array(range(0, self.size[1])) - self.center[1])
@property @property
def size(self): def size(self):
...@@ -418,7 +427,7 @@ class mergedmap: ...@@ -418,7 +427,7 @@ class mergedmap:
@property @property
def offset(self): def offset(self):
return np.array(self.step_size)*(np.array(self.center) - 1/2. - np.array(self.size)/2.0) return np.array(self.step_size)*(np.array(self.center) - (np.array(self.size)-1)/2.0)
@property @property
def ROMWeights(self): def ROMWeights(self):
......
...@@ -481,6 +481,7 @@ def MakeROMFromHDF5(hdf5Filename, greedyFilename=None, EIFilename=None, tol=1e-1 ...@@ -481,6 +481,7 @@ def MakeROMFromHDF5(hdf5Filename, greedyFilename=None, EIFilename=None, tol=1e-1
V[m][l] = RB_matrix[l][EI_indices[m]] # Part of (5) of Algorithm 2: making V_{ij} V[m][l] = RB_matrix[l][EI_indices[m]] # Part of (5) of Algorithm 2: making V_{ij}
invV = inv(V[0:len(EI_indices), 0:len(EI_indices)]) invV = inv(V[0:len(EI_indices), 0:len(EI_indices)])
B = B_matrix(invV, np.array(RB_matrix)) B = B_matrix(invV, np.array(RB_matrix))
_TS = TS[str(next_RB_index)] _TS = TS[str(next_RB_index)]
...@@ -546,7 +547,7 @@ def makeWeightsNew(smap, EIxFilename, EIyFilename=None, verbose=True, newtonCote ...@@ -546,7 +547,7 @@ def makeWeightsNew(smap, EIxFilename, EIyFilename=None, verbose=True, newtonCote
A_xy_Q2 = A_xy[Q2xy] A_xy_Q2 = A_xy[Q2xy]
A_xy_Q3 = A_xy[Q3xy] A_xy_Q3 = A_xy[Q3xy]
A_xy_Q4 = A_xy[Q4xy] A_xy_Q4 = A_xy[Q4xy]
full_x = smap.x full_x = smap.x
full_y = smap.y full_y = smap.y
......
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