Skip to content
Snippets Groups Projects
Commit a7df0ed4 authored by Laurent Mercadier's avatar Laurent Mercadier
Browse files

Merge branch 'gpc_mnemonics' into 'master'

Added mnemonics for GPC motors, improved knife edge function

See merge request SCS/ToolBox!74
parents a4d8d960 77c198d1
No related branches found
No related tags found
1 merge request!74Added mnemonics for GPC motors, improved knife edge function
...@@ -237,6 +237,18 @@ mnemonics = { ...@@ -237,6 +237,18 @@ mnemonics = {
"GPC_EOS_DelayLine": {'source':'SCS_CDIDET_GRD/MOTOR/IMAGER', "GPC_EOS_DelayLine": {'source':'SCS_CDIDET_GRD/MOTOR/IMAGER',
'key':'actualPosition.value', 'key':'actualPosition.value',
'dim':None}, 'dim':None},
"GPC_X": {'source':'SCS_GPC_MOV/MOTOR/X',
'key':'actualPosition.value',
'dim':None},
"GPC_Y": {'source':'SCS_GPC_MOV/MOTOR/Y',
'key':'actualPosition.value',
'dim':None},
"GPC_THETA": {'source':'SCS_GPC_MOV/MOTOR/THETA',
'key':'actualPosition.value',
'dim':None},
"GPC_THETAMAG": {'source':'SCS_GPC_MOV/MOTOR/THETAMAG',
'key':'actualPosition.value',
'dim':None},
# FFT # FFT
"scannerX": {'source':'SCS_CDIFFT_SAM/LMOTOR/SCANNERX', "scannerX": {'source':'SCS_CDIFFT_SAM/LMOTOR/SCANNERX',
......
...@@ -63,11 +63,11 @@ def knife_edge(nrun, axisKey='scannerX', signalKey='FastADC4peaks', ...@@ -63,11 +63,11 @@ def knife_edge(nrun, axisKey='scannerX', signalKey='FastADC4peaks',
if axisRange[1] <= positions[0]: if axisRange[1] <= positions[0]:
raise ValueError('The maximum value of axisRange is too small') raise ValueError('The maximum value of axisRange is too small')
idxMax = bisect.bisect(positions, axisRange[1]) + 1 idxMax = bisect.bisect(positions, axisRange[1]) + 1
positions = positions[idxMin:idxMax] pos_sel = positions[idxMin:idxMax]
intensities = intensities[idxMin:idxMax] int_sel = intensities[idxMin:idxMax]
# estimate a linear slope fitting the data to determine which function to fit # estimate a linear slope fitting the data to determine which function to fit
slope = np.cov(positions, intensities)[0][1]/np.var(positions) slope = np.cov(pos_sel, int_sel)[0][1]/np.var(pos_sel)
if slope < 0: if slope < 0:
func = integPowerDown func = integPowerDown
funcStr = 'a*erfc(np.sqrt(2)*(x-x0)/w0) + b' funcStr = 'a*erfc(np.sqrt(2)*(x-x0)/w0) + b'
...@@ -75,8 +75,8 @@ def knife_edge(nrun, axisKey='scannerX', signalKey='FastADC4peaks', ...@@ -75,8 +75,8 @@ def knife_edge(nrun, axisKey='scannerX', signalKey='FastADC4peaks',
func = integPowerUp func = integPowerUp
funcStr = 'a*erfc(-np.sqrt(2)*(x-x0)/w0) + b' funcStr = 'a*erfc(-np.sqrt(2)*(x-x0)/w0) + b'
if p0 is None: if p0 is None:
p0 = [np.mean(positions), 0.1, np.max(intensities)/2, 0] p0 = [np.mean(pos_sel), 0.1, np.max(int_sel)/2, 0]
popt, pcov = curve_fit(func, positions, intensities, p0=p0) popt, pcov = curve_fit(func, pos_sel, int_sel, p0=p0)
print('fitting function:', funcStr) print('fitting function:', funcStr)
print('w0 = (%.1f +/- %.1f) um'%(popt[1]*1e3, pcov[1,1]**0.5*1e3)) print('w0 = (%.1f +/- %.1f) um'%(popt[1]*1e3, pcov[1,1]**0.5*1e3))
print('x0 = (%.3f +/- %.3f) mm'%(popt[0], pcov[0,0]**0.5)) print('x0 = (%.3f +/- %.3f) mm'%(popt[0], pcov[0,0]**0.5))
...@@ -87,7 +87,7 @@ def knife_edge(nrun, axisKey='scannerX', signalKey='FastADC4peaks', ...@@ -87,7 +87,7 @@ def knife_edge(nrun, axisKey='scannerX', signalKey='FastADC4peaks',
xfit = np.linspace(positions.min(), positions.max(), 1000) xfit = np.linspace(positions.min(), positions.max(), 1000)
yfit = func(xfit, *popt) yfit = func(xfit, *popt)
plt.figure(figsize=(7,4)) plt.figure(figsize=(7,4))
plt.scatter(positions, intensities, color='C1', label='exp', s=2, alpha=0.01) plt.scatter(positions, intensities, color='C1', label='exp', s=2, alpha=0.1)
plt.plot(xfit, yfit, color='C4', plt.plot(xfit, yfit, color='C4',
label=r'fit $\rightarrow$ $w_0=$(%.1f $\pm$ %.1f) $\mu$m'%(popt[1]*1e3, pcov[1,1]**0.5*1e3)) label=r'fit $\rightarrow$ $w_0=$(%.1f $\pm$ %.1f) $\mu$m'%(popt[1]*1e3, pcov[1,1]**0.5*1e3))
leg = plt.legend() leg = plt.legend()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment