prepare for beamtime
This commit is contained in:
@@ -28,7 +28,8 @@ class HelicalScan:
|
||||
#fn='/home/zamofing_t/Documents/prj/SwissFEL/epics_ioc_modules/ESB_MX/python/data/'+time.strftime('%y-%m-%d-%H_%M_%S')
|
||||
#cfg = {"sequencer": ['gen_grid_points(w=5,h=5,pitch=100,rnd=0.4)', 'sort_points()','gen_prog(file="'+fn+'.prg",host="SAR-CPPM-EXPMX1",mode=1,pt2pt_time=10,cnt=1)', 'plot_gather("'+fn+'.npz")']}
|
||||
#cfg = {"sequencer": ['test_find_rot_ctr()']}
|
||||
cfg = {"sequencer": ['test_find_rot_ctr(n=5. ,per=1. ,phi=24.6 ,bias=2.31,ampl=4.12)']}
|
||||
#cfg = {"sequencer": ['test_find_rot_ctr(n=5. ,per=1.,bias=2.31,ampl=4.12,phi=24.6)']}
|
||||
cfg = {"sequencer": ['test_coord_trf()']}
|
||||
|
||||
self.cfg=dotdict(cfg)
|
||||
self.args=args
|
||||
@@ -51,7 +52,70 @@ class HelicalScan:
|
||||
if not dryrun:
|
||||
eval('self.' + cmd)
|
||||
|
||||
def meas_rot_ctr(self,y,per=1):
|
||||
def test_coord_trf(self):
|
||||
n = 3.; per = 1.; t = np.arange(n)
|
||||
p=((2.3,2.31,4.12,24.6),(6.2,2.74,32.1,3.28)) #(y, bias, ampl, phi)
|
||||
self.param=param=np.ndarray((len(p),5))
|
||||
z=4.5 # fix z position
|
||||
for i in range(2):
|
||||
(y, bias, ampl, phi) =p[i]
|
||||
x= ampl * np.cos(2 * np.pi * (per / n * t + phi / 360.)) + bias
|
||||
print('yMeas_%d='%i+str(y)+' xMeas_%d='%i+str(x))
|
||||
#param[i]=(z_i, y_i, x_i, r_i,phi_i)
|
||||
param[i][0] =z
|
||||
param[i][1] =y
|
||||
param[i][2:]=HelicalScan.meas_rot_ctr(x) #(bias,ampl,phase)
|
||||
pass
|
||||
print param
|
||||
#self.fwd_transform(param[0][1],0.,param[0][2],param[0][1])
|
||||
# y_0 ,120deg ,x_0 ,z_0)
|
||||
self.fwd_transform(param[0][1],2*np.pi/3.,param[0][2],param[0][0])
|
||||
#self.fwd_transform(param[1][1],0.,param[1][2],param[1][3])
|
||||
|
||||
|
||||
|
||||
def fwd_transform(self,y,w,cx,cz):
|
||||
#cx,cy: coarse stage
|
||||
#TODO: NOT WORKING AT ALL NOW...
|
||||
param=self.param
|
||||
# param[i]=(z_i, y_i, x_i, r_i,phi_i)
|
||||
p=np.ndarray((param.shape[0], 3))
|
||||
for i in range(2):
|
||||
#p[i][0]=param[i][2]+param[i][3]*np.cos(param[i][4]+w) # x= x_i+r_i*cos(phi_i*w)+cx
|
||||
p[i][0]=cx+param[i][3]*np.cos(param[i][4]+w) # x= x_i+r_i*cos(phi_i*w)+cx
|
||||
p[i][1]=param[i][1] # y= y_i
|
||||
#p[i][2]=param[i][2]+param[i][3]*np.sin(param[i][4]+w) # z= z_i+r_i*sin(phi_i*w)
|
||||
p[i][2] =cz + param[i][3] * np.sin(param[i][4] + w) # z= z_i+r_i*sin(phi_i*w)
|
||||
print p
|
||||
v=p[1]-p[0]
|
||||
v=v/np.sqrt(v.dot(v)) # v/|v|
|
||||
v=v*(y-param[0][1])/(param[1][1]-param[0][1]) # v(y)=v*(v-y_0)/(y_1-y_0)
|
||||
v=p[0]+v
|
||||
|
||||
#v=v/abs(v)
|
||||
print v
|
||||
|
||||
|
||||
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
|
||||
|
||||
#x,y,z
|
||||
#returns y,w,dx,dz
|
||||
pass
|
||||
|
||||
def inv_transform(y,phi,dx=0,dz=0):
|
||||
#dx,dy: deviation from cristal center line
|
||||
#ps= #x,y,z
|
||||
#returns y,phi,cx,cz
|
||||
pass
|
||||
|
||||
|
||||
@staticmethod
|
||||
def meas_rot_ctr(y,per=1):
|
||||
# find the amplitude bias and phase of an equidistant sampled sinus
|
||||
# it needs at least 3 measurements e.g. at 0,120 240 deg or 0 90 180 270 deg
|
||||
# per is the number of persiods, default is 1 period =360 deg
|
||||
@@ -61,9 +125,10 @@ class HelicalScan:
|
||||
bias=np.absolute(f[0]/n)
|
||||
phase=np.angle(f[idx])
|
||||
ampl=np.absolute(f[idx])*2/n
|
||||
return (bias,phase,ampl)
|
||||
return (bias,ampl,phase)
|
||||
|
||||
def test_find_rot_ctr(self,n=3. ,per=1. ,phi=37 ,bias=4.1,ampl=2.4):
|
||||
@staticmethod
|
||||
def test_find_rot_ctr(n=3.,per=1.,bias=4.1,ampl=2.4,phi=37):
|
||||
# find the rotation center, amplitude out of n (niminum 3) measurements
|
||||
# n number of equidistant measurements
|
||||
# per number of periods (full rotation of all measurements nut be a interger value for precise measurements)
|
||||
@@ -73,24 +138,18 @@ class HelicalScan:
|
||||
|
||||
t = np.arange(n)
|
||||
y=ampl*np.cos(2*np.pi*(per/n*t+phi/360.))+bias
|
||||
sp = np.fft.fft(y)
|
||||
freq = np.fft.fftfreq(t.shape[-1])
|
||||
plt.figure(1)
|
||||
plt.subplot(311)
|
||||
plt.plot(t,y,'b.-')
|
||||
plt.subplot(312)
|
||||
#plt.plot(t, sp.real,'b.-', t, sp.imag,'r.-')
|
||||
plt.step(t, sp.real,'b.-', t, sp.imag,'r.-', where='mid')
|
||||
#plt.stem(t, sp.real,'b-')
|
||||
#plt.plot(freq, sp.real,'b.-', freq, sp.imag,'r.-')
|
||||
|
||||
idx=int(per)
|
||||
bias=np.absolute(sp[0]/n)
|
||||
phase=np.angle(sp[idx])
|
||||
ampl=np.absolute(sp[idx]) * 2 / n
|
||||
plt.subplot(312)
|
||||
f = np.fft.fft(y)
|
||||
plt.step(t, f.real,'b.-', t, f.imag,'r.-', where='mid')
|
||||
|
||||
(bias,ampl,phase)=HelicalScan.meas_rot_ctr(y, per)
|
||||
print('bias: '+str(bias))
|
||||
print('phase: '+str(phase*360./2/np.pi))
|
||||
print('amplitude: '+str(ampl))
|
||||
print('phase: '+str(phase*360./2/np.pi))
|
||||
|
||||
plt.subplot(313)
|
||||
t2 = np.linspace(0,2*np.pi,64)
|
||||
|
||||
Reference in New Issue
Block a user