Files
ALF/dioderata/knife_edge.py
2023-10-23 19:03:37 +02:00

89 lines
2.3 KiB
Python
Executable File

#!/usr/bin/env python
from time import sleep
from collections import deque
import numpy as np
import scipy.signal
from scipy.special import erf
from scipy.optimize import curve_fit
from zoetrope import aniplot as plt
from bstrd import BS, bsstream
plt.blit = False
plt.style.use('ggplot')
# config
#chname_diode = "SLAAR11-LSCP1-FNS:CH0:VAL_GET"
chname_diode = "SARES11-GES1:CH1_VAL_GET"
chname_i0 = "SAROP11-PBPS110:INTENSITY"
chname_xhuber = "SARES11-XSAM125:ENC_X1_BS"
chname_yhuber = "SARES11-XSAM125:ENC_Y1_BS"
chname_events = "SAR-CVME-TIFALL4:EvtSet"
length = 5000
# create channel
ch_diode = BS(chname_diode)
ch_i0 = BS(chname_i0)
ch_xhuber = BS(chname_xhuber)
ch_yhuber = BS(chname_yhuber)
ch_evts = BS(chname_events)
n = 100
sigs = np.empty(n)
i0s = np.empty(n)
x_pos = np.empty(n)
y_pos = np.empty(n)
evts = np.empty((n, 256))
# create a buffer for the plotting
#ke_sigs = deque(maxlen=length)
#x_poses = deque(maxlen=length)
#y_poses = deque(maxlen=length)
ke_sigs = []
x_poses = []
y_poses = []
i_zeroes = []
# fit stuff for knife edge scans
def errfunc_fwhm(x, x0, amplitude, width, offset):
return offset + amplitude*erf((x0-x)*2*np.sqrt(np.log(2))/(np.abs(width))) #d is fwhm
# create the empty plot
pd = plt.plot([0])
# some plot settings
plt.suptitle(chname_diode)
plt.fig.set_figheight(5)
plt.fig.set_figwidth(5)
plt.tight_layout()
for counter, data in zip(plt.show(), bsstream):
print(counter)
for i in range(n):
# sigs[i] = ch_diode.get()
# i0s[i] = ch_i0.get()
# x_pos[i] = ch_xhuber.get()
# y_pos[i] = ch_yhuber.get()
ke_sigs.append(ch_diode.get())
x_poses.append(ch_xhuber.get())
y_poses.append(ch_yhuber.get())
i_zeroes.append(ch_i0.get())
next(bsstream) # this gets the next set of data
# sig_norm = sigs#/np.asarray(i0s)
# ke_sigs.append(sig_norm)
pd.set(x_poses, np.asarray(ke_sigs)/(i_zeroes))
# popt, pcov = curve_fit(errfunc_fwhm, np.asarray(x_poses), np.asarray(ke_sigs)/(i_zeroes), p0=[np.mean(x_poses), (np.max(ke_sigs)-np.min(ke_sigs)), 10, 0])
# pd.set(x_poses, errfunc_fwhm(x_poses, *popt))
print(np.shape(x_poses))
# this, I need to move into the library
pd.ax.relim()
pd.ax.autoscale_view()
# pd.ax.suptitle("{}, {}".format(popt[0], popt[2]))
bsstream.close()