added lots of .py

This commit is contained in:
gac-alvra
2023-10-23 18:49:28 +02:00
parent 56327ce073
commit fa2caeff3e
24 changed files with 1771 additions and 0 deletions

134
camerata/main.py Executable file
View File

@ -0,0 +1,134 @@
#!/usr/bin/env python
from time import sleep
from collections import deque
import numpy as np
import scipy.signal
from zoetrope import aniplot as plt
from bstrd import BS, bsstream
plt.blit = False
# config
cam_name = "SARES11-XMI125-C4P1"
xmin = 0
xmax = 400
ymin = 400
ymax = 700
proj_axis = 0
um_per_px = 2.28
buffer_length = 100
def get_data(cam):
img = 0
for i in range(1):
img += cam.get()
next(bsstream)
cropped = img[xmin:xmax, ymin:ymax]
projx = cropped.mean(axis=proj_axis)
projy = cropped.mean(axis=int(not proj_axis))
return cropped, projx, projy
def find_spacing(py, extend=5):
py -= py.mean()
if extend > 1:
py = np.concatenate((py, np.zeros(len(py) * extend)))
spectrum = np.abs(np.fft.fft(py))
freq = np.fft.fftfreq(len(spectrum))
which = (freq > 0.005)
spectrum = spectrum[which]
freq = freq[which]
index_peaks = scipy.signal.find_peaks(spectrum)[0]
peaks_pos = freq[index_peaks]
peak_height = spectrum[index_peaks]
cut_freq = peaks_pos[np.argmax(peak_height)]
return freq, spectrum, cut_freq
def make_xs(arr):
return np.arange(len(arr))
# create channel
cam = BS(cam_name + ".roi_signal_x_profile", modulo=5)
cropped, width, proj = get_data(cam)
pixel_proj = make_xs(proj)
pixel_width = make_xs(width)
plt.fig.set_figheight(12)
plt.fig.set_figwidth(9)
plt.suptitle(cam_name)
plt.subplot(321)
plt.title(f"cropped image\n[{xmin}:{xmax}, {ymin}:{ymax}]")
pimg = plt.imshow(cropped, origin="lower")
plt.subplot(322)
plt.title("projection")
pln_proj = plt.plot(proj, pixel_proj)
plt.subplot(323)
plt.title("projection")
pln_width = plt.plot([0])
plt.subplot(324)
plt.title("FFT")
plt.xlabel("frequency in 1/pixel")
pln_fft_spec = plt.plot([0])
plt.xlim(0,0.2)
pln_fft_cut = plt.plot([0])
plt.subplot(313)
plt.title(f"spacing assuming {um_per_px} μm per pixel")
pln_spac = plt.plot([0], 'o')
plt.ylim(0,250)
plt.tight_layout()
spacings = deque(maxlen=buffer_length)
for counter in plt.show():
print(counter)
next(bsstream)
cropped, width, proj = get_data(cam)
pimg.set(cropped)
pln_proj.set(proj, pixel_proj)
pln_width.set(pixel_width, width)
freq, spectrum, cut_freq = find_spacing(proj, extend=10)
spac = um_per_px / cut_freq
spacings.append(spac)
pln_spac.set(make_xs(spacings), spacings)
pln_fft_spec.set(freq, spectrum)
pln_fft_cut.set([cut_freq]*2, [spectrum.min(), spectrum.max()])
pln_fft_spec.ax.set_title(f"FFT\ncurrent spacing: {spac:.1f} μm")
# this, I need to move into the library
ps = [pln_proj, pln_width, pln_spac, pln_fft_spec]
for p in ps:
p.ax.relim()
p.ax.autoscale_view()
bsstream.close()

132
camerata/main_less_simple.py Executable file
View File

@ -0,0 +1,132 @@
#!/usr/bin/env python
from time import sleep
from collections import deque
import numpy as np
from scipy import signal
from zoetrope import aniplot as plt
from bstrd import BS, bsstream
plt.blit = False
# config
#cam_name = "SARES11-XMI125-C4P1.jet_projection"
cam_name = "SARES11-SPEC125-M2.jet_projection"
#xmin = 0
#xmax = 400
#ymin = 400
#ymax = 700
#proj_axis = 0
#um_per_px = 2.28
um_per_px = 3.33
buffer_length = 1000
shots = 10
def get_data(cam):
jet = np.empty((shots, 550))
for i in range(shots):
jet[i] = cam.get()
next(bsstream)
proj = jet.max(axis=0)
return proj
#def get_data(cam):
# jet = np.empty(550)
# jet = cam.get()
# next(bsstream)
# proj = jet
# return proj
def find_spacing(py, extend=5):
py -= py.mean()
#tukey_filter = np.concatenate((signal.tukey(120)[0:30],np.ones(291),signal.tukey(120)[-30:-1]))
#tukey_filter = signal.gaussian(350, 100)
#py *= tukey_filter
#py = signal.savgol_filter(py, 39, polyorder=2)
if extend > 1:
py = np.concatenate((py, np.zeros(len(py) * extend)))
spectrum = np.abs(np.fft.fft(py))**2
freq = np.fft.fftfreq(len(spectrum))
which = (freq > 0.005)
spectrum = spectrum[which]
freq = freq[which]
index_peaks = signal.find_peaks(spectrum)[0]
peaks_pos = freq[index_peaks]
peak_height = spectrum[index_peaks]
cut_freq = peaks_pos[np.argmax(peak_height)]
return freq, spectrum, cut_freq
def make_xs(arr):
return np.arange(len(arr))
# create channel
cam = BS(cam_name)
proj = get_data(cam)
pixel_proj = make_xs(proj)
plt.fig.set_figheight(9)
plt.fig.set_figwidth(9)
plt.suptitle(cam_name)
plt.subplot(221)
plt.title("projection")
pln_proj = plt.plot(proj, pixel_proj)
plt.xlim(-45,45)
plt.grid()
plt.subplot(222)
plt.title("FFT")
plt.xlabel("frequency in 1/pixel")
pln_fft_spec = plt.plot([0])
plt.xlim(0,0.25)
plt.grid()
#plt.ylim(0,500000)
pln_fft_cut = plt.plot([0])
plt.subplot(212)
plt.title(f"spacing assuming {um_per_px} μm per pixel")
pln_spac = plt.plot([0], 'o')
pln_spac.ax.axhline(y=120, color='r') # 120um spacing set for Neutze cytco
plt.xlabel('1000 (*10) most recent images')
plt.ylabel('ladder spacing in $\mu$m')
plt.ylim(0,250)
plt.xlim(0,buffer_length)
plt.grid()
plt.tight_layout()
spacings = deque(maxlen=buffer_length)
for counter in plt.show():
print(counter)
next(bsstream)
proj = get_data(cam)
pln_proj.set(proj, pixel_proj)
freq, spectrum, cut_freq = find_spacing(proj, extend=10)
spac = um_per_px / cut_freq
spacings.append(spac)
pln_spac.set(make_xs(spacings), spacings)
pln_fft_spec.set(freq, spectrum)
pln_fft_cut.set([cut_freq]*2, [spectrum.min(), spectrum.max()])
pln_fft_spec.ax.set_title(f"FFT\ncurrent spacing: {spac:.1f} μm")
# this, I need to move into the library
ps = [pln_proj, pln_spac, pln_fft_spec]
for p in ps:
p.ax.relim()
p.ax.autoscale_view()
bsstream.close()

116
camerata/main_simple.py Executable file
View File

@ -0,0 +1,116 @@
#!/usr/bin/env python
from time import sleep
from collections import deque
import numpy as np
import scipy.signal
from zoetrope import aniplot as plt
from bstrd import BS, bsstream
plt.blit = False
# config
cam_name = "SARES11-XMI125-C4P1.jet_projection"
#xmin = 0
#xmax = 400
#ymin = 400
#ymax = 700
#proj_axis = 0
um_per_px = 2.28
buffer_length = 1000
def get_data(cam):
jet = 0
for i in range(1):
jet += cam.get()
next(bsstream)
proj = jet
return proj
def find_spacing(py, extend=5):
py -= py.mean()
if extend > 1:
py = np.concatenate((py, np.zeros(len(py) * extend)))
spectrum = np.abs(np.fft.fft(py))
freq = np.fft.fftfreq(len(spectrum))
which = (freq > 0.005)
spectrum = spectrum[which]
freq = freq[which]
index_peaks = scipy.signal.find_peaks(spectrum)[0]
peaks_pos = freq[index_peaks]
peak_height = spectrum[index_peaks]
cut_freq = peaks_pos[np.argmax(peak_height)]
return freq, spectrum, cut_freq
def make_xs(arr):
return np.arange(len(arr))
# create channel
cam = BS(cam_name)
proj = get_data(cam)
pixel_proj = make_xs(proj)
plt.fig.set_figheight(12)
plt.fig.set_figwidth(9)
plt.suptitle(cam_name)
plt.subplot(311)
plt.title("projection")
pln_proj = plt.plot(proj, pixel_proj)
plt.grid()
plt.subplot(312)
plt.title("FFT")
plt.xlabel("frequency in 1/pixel")
pln_fft_spec = plt.plot([0])
plt.xlim(0,0.2)
plt.grid()
pln_fft_cut = plt.plot([0])
plt.subplot(313)
plt.title(f"spacing assuming {um_per_px} μm per pixel")
pln_spac = plt.plot([0], 'o')
pln_spac.ax.axhline(y=80, color='r')
plt.ylim(0,250)
plt.grid()
plt.tight_layout()
spacings = deque(maxlen=buffer_length)
for counter in plt.show():
print(counter)
next(bsstream)
proj = get_data(cam)
pln_proj.set(proj, pixel_proj)
freq, spectrum, cut_freq = find_spacing(proj, extend=10)
spac = um_per_px / cut_freq
spacings.append(spac)
pln_spac.set(make_xs(spacings), spacings)
pln_fft_spec.set(freq, spectrum)
pln_fft_cut.set([cut_freq]*2, [spectrum.min(), spectrum.max()])
pln_fft_spec.ax.set_title(f"FFT\ncurrent spacing: {spac:.1f} μm")
# this, I need to move into the library
ps = [pln_proj, pln_spac, pln_fft_spec]
for p in ps:
p.ax.relim()
p.ax.autoscale_view()
bsstream.close()

90
dioderata/arrival_times.py Executable file
View File

@ -0,0 +1,90 @@
#!/usr/bin/env python
from time import sleep
from collections import deque
import numpy as np
import scipy.signal
import epics
from epics import caput
from zoetrope import aniplot as plt
from bstrd import BS, bsstream
plt.blit = False
plt.style.use('ggplot')
def goodshots(events, *arrays):
fel = events[:, 13]
laser = events[:, 18]
darkShot = events[:, 21]
pumped_shots = np.logical_and.reduce((fel, laser, np.logical_not(darkShot)))
return [a[pumped_shots] for a in arrays]
# config
STAGEpv = epics.PV('SLAAR11-LMOT-M452:MOTOR_1.VAL') # global globi
chname_amplitude = "SARES11-SPEC125-M1.edge_amplitude"
chname_jitter = "SARES11-SPEC125-M1.edge_position"
chname_events = "SAR-CVME-TIFALL4:EvtSet"
chname_iZero = "SAROP11-PBPS110:INTENSITY"
length = 500
mm2fs = 6671.2 # lightspeed and delay stages
# create channel
ch_amp = BS(chname_amplitude)
ch_jitter = BS(chname_jitter)
ch_events = BS(chname_events)
ch_iZero = BS(chname_iZero)
n = 100
amp = np.empty(n)
jitter = np.empty(n)
iZero = np.empty(n)
evts = np.empty((n, 256))
# create a buffer for the plotting
jitter_vals = deque(maxlen=length)
jitter_stds = deque(maxlen=length)
amplitude_vals = deque(maxlen=length)
iZero_vals = deque(maxlen=length)
# create the empty plot
pd = plt.plot([0])
# some plot settings
plt.suptitle("arrival time, fs")
plt.fig.set_figheight(5)
plt.fig.set_figwidth(15)
plt.tight_layout()
for counter, data in zip(plt.show(), bsstream):
print(counter)
for i in range(n):
evts[i] = ch_events.get()
jitter[i] = ch_jitter.get()
amp[i] = ch_amp.get()
iZero[i] = ch_iZero.get()
next(bsstream) # this gets the next set of data
edge_amp, edge_pos, i_zero = goodshots(evts, amp, jitter, iZero)
jitter_avg = np.mean(edge_pos[edge_amp > 10])
jitter_std = np.std(edge_pos[edge_amp > 10])
jitter_vals.append(jitter_avg)
jitter_stds.append(jitter_std)
edge_amp_avg = np.mean(edge_amp)
amplitude_vals.append(edge_amp_avg)
xs = np.arange(len(jitter_vals))
pd.set(xs, amplitude_vals)
# this, I need to move into the library
pd.ax.relim()
pd.ax.autoscale_view()
# if (np.abs(jitter_avg) > 100) & (np.abs(jitter_avg) < 500):
# moveTo = STAGEpv.get()*mm2fs - jitter_avg
# STAGEpv.put(moveTo/mm2fs)
# print('Stage moved.')
bsstream.close()

View File

@ -0,0 +1,72 @@
#!/usr/bin/env python
from time import sleep
from collections import deque
import numpy as np
import scipy.signal
import epics
from epics import caput
from zoetrope import aniplot as plt
from bstrd import BS, bsstream
from datetime import datetime
def goodshots(events, *arrays):
fel = events[:, 13]
laser = events[:, 18]
darkShot = events[:, 21]
pumped_shots = np.logical_and.reduce((fel, laser, np.logical_not(darkShot)))
return [a[pumped_shots] for a in arrays]
# config
STAGEpv = epics.PV('SLAAR11-LMOT-M452:MOTOR_1.VAL') # global globi
chname_amplitude = "SARES11-SPEC125-M1.edge_amplitude"
chname_jitter = "SARES11-SPEC125-M1.edge_position"
chname_events = "SAR-CVME-TIFALL4:EvtSet"
chname_iZero = "SAROP11-PBPS110:INTENSITY"
length = 500
mm2fs = 6671.2 # lightspeed and delay stages
threshold = 7
# create channel
ch_amp = BS(chname_amplitude)
ch_jitter = BS(chname_jitter)
ch_events = BS(chname_events)
ch_iZero = BS(chname_iZero)
n = 500
amp = np.empty(n)
jitter = np.empty(n)
iZero = np.empty(n)
evts = np.empty((n, 256))
while True:
# print(counter)
timeofdata = datetime.now()
for i in range(n):
evts[i] = ch_events.get()
jitter[i] = ch_jitter.get()
amp[i] = ch_amp.get()
iZero[i] = ch_iZero.get()
next(bsstream) # this gets the next set of data
edge_amp, edge_pos, i_zero = goodshots(evts, amp, jitter, iZero)
jitter_avg = np.mean(edge_pos[edge_amp > threshold])
jitter_std = np.std(edge_pos[edge_amp > threshold])
if len(edge_pos[edge_amp > threshold] > 125):
print("{} statistics on {} shots: offset of {} fs, jitter of {} fs rms".format(timeofdata.strftime('%Y-%m-%d-%H:%M:%S'), len(edge_pos[edge_amp > threshold]), round(jitter_avg, 2), round(jitter_std, 2)))
if (np.abs(jitter_avg) > 100) & (np.abs(jitter_avg) < 500):
moveTo = STAGEpv.get()*mm2fs - jitter_avg
STAGEpv.put(moveTo/mm2fs)
print('Stage moved.')
else:
print ("{} Where are my X-rays?!".format(timeofdata.strftime('%Y-%m-%d-%H:%M:%S')))
bsstream.close()

64
dioderata/correlate.py Executable file
View File

@ -0,0 +1,64 @@
#!/usr/bin/env python
from time import sleep
from collections import deque
import numpy as np
from zoetrope import aniplot as plt
from scipy.stats.stats import pearsonr
from bstrd import BS, bsstream
plt.blit = False
plt.style.use('ggplot')
def pumpedshots(events, *arrays):
laser = events[:, 18]
darkShot = events[:, 21]
pumped_shots = np.logical_and.reduce((laser, np.logical_not(darkShot)))
return [a[pumped_shots] for a in arrays]
#chname_diode = "SLAAR11-LSCP1-FNS:CH0:VAL_GET"
#chname_diode1 = "SARES11-GES1:CH1_VAL_GET"
chname_diode1 = "SARES12-GES1:PR1_CH2_VAL_GET"
chname_i0 = "SAROP11-PBPS110:INTENSITY"
chname_events = "SAR-CVME-TIFALL4:EvtSet"
length = 500
# create channel
ch_diode1 = BS(chname_diode1)
ch_i0 = BS(chname_i0)
ch_events = BS(chname_events)
n = 200
sigs1 = np.empty(n)
i0s = np.empty(n)
evts = np.empty((n, 256))
# create the empty plot
pd = plt.plot([0])
# some plot settings
plt.fig.set_figheight(6)
plt.fig.set_figwidth(7)
for counter, data in zip(plt.show(), bsstream):
print(counter)
for i in range(n):
sigs1[i] = ch_diode1.get()
i0s[i] = ch_i0.get()
evts[i] = ch_events.get()
next(bsstream) # this gets the next set of data
pearscoeff1, _ = pearsonr(i0s, sigs1)
pumpi0s, pumpsigs = pumpedshots(evts, i0s, sigs1)
#xs = np.arange(len(pp_sigs))
plt.tight_layout()
plt.clf()
plt.scatter(i0s, sigs1)
plt.scatter(pumpi0s, pumpsigs)
plt.title("{}".format(round(pearscoeff1, 4)))
plt.xlabel('sarop11-pbps110:intensity')
plt.ylabel('tfy, sares11-ges1:ch1_val_get')
plt.show()
bsstream.close()

66
dioderata/correlate_2diodes.py Executable file
View File

@ -0,0 +1,66 @@
#!/usr/bin/env python
from time import sleep
from collections import deque
import numpy as np
import scipy.signal
from zoetrope import aniplot as plt
from scipy.stats.stats import pearsonr
from bstrd import BS, bsstream
plt.blit = False
plt.style.use('ggplot')
#chname_diode = "SLAAR11-LSCP1-FNS:CH0:VAL_GET"
chname_diode1 = "SARES12-GES1:PR1_CH1_VAL_GET"
chname_diode2 = "SARES12-GES1:PR1_CH2_VAL_GET"
chname_i0 = "SAROP11-PBPS110:INTENSITY"
length = 500
# create channel
ch_diode1 = BS(chname_diode1)
ch_diode2 = BS(chname_diode2)
ch_i0 = BS(chname_i0)
n = 200
sigs1 = np.empty(n)
sigs2 = np.empty(n)
i0s = np.empty(n)
# create a buffer for the plotting
pp_sigs = deque(maxlen=length)
# create the empty plot
pd = plt.plot([0])
# some plot settings
plt.suptitle("{}, {}".format(chname_diode1, chname_diode2))
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):
sigs1[i] = ch_diode1.get()
sigs2[i] = ch_diode2.get()
i0s[i] = ch_i0.get()
next(bsstream) # this gets the next set of data
pearscoeff1, _ = pearsonr(i0s, sigs1)
pearscoeff2, _ = pearsonr(i0s, sigs2)
#xs = np.arange(len(pp_sigs))
plt.clf()
plt.scatter(i0s, sigs1, label=chname_diode1)
plt.scatter(i0s, sigs2, label=chname_diode2)
plt.title("{}, ch1:{}, ch2:{}".format(chname_i0.split(':')[0].split('-')[-1], round(pearscoeff1, 4), round(pearscoeff2, 4)))
plt.legend(loc='best')
plt.show()
# this, I need to move into the library
# pd.ax.relim()
# pd.ax.autoscale_view()
bsstream.close()

72
dioderata/correlate_2tt.py Executable file
View File

@ -0,0 +1,72 @@
#!/usr/bin/env python
from time import sleep
from collections import deque
import numpy as np
import scipy.signal
from zoetrope import aniplot as plt
from scipy.stats.stats import pearsonr
from bstrd import BS, bsstream
plt.blit = False
plt.style.use('ggplot')
def pumpedshots(events, *arrays):
laser = events[:, 18]
darkShot = events[:, 21]
pumped_shots = np.logical_and.reduce((laser, np.logical_not(darkShot)))
return [a[pumped_shots] for a in arrays]
chname_tt1 = "SARES11-SPEC125-M1.edge_position"
chname_tt2 = "SARES11-SPEC125-M1.edge_position2"
chname_i0 = "SAROP11-PBPS110:INTENSITY"
chname_events = "SAR-CVME-TIFALL4:EvtSet"
length = 500
# create channel
ch_tt1 = BS(chname_tt1)
ch_tt2 = BS(chname_tt2)
ch_i0 = BS(chname_i0)
ch_events = BS(chname_events)
n = 200
tt1 = np.empty(n)
tt2 = np.empty(n)
i0s = np.empty(n)
evts = np.empty((n, 256))
# create a buffer for the plotting
pp_sigs = deque(maxlen=length)
# create the empty plot
pd = plt.plot([0])
# some plot settings
plt.suptitle("{}, {}".format(chname_tt1, chname_tt2))
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):
tt1[i] = ch_tt1.get()
tt2[i] = ch_tt2.get()
i0s[i] = ch_i0.get()
evts[i] = ch_events.get()
next(bsstream) # this gets the next set of data
pumptt1, pumptt2 = pumpedshots(evts, tt1, tt2)
pearscoeff1, _ = pearsonr(pumptt1, pumptt2)
#xs = np.arange(len(pp_sigs))
plt.clf()
plt.scatter(pumptt1, pumptt2)
plt.title("{}".format(round(pearscoeff1, 4)))
plt.show()
bsstream.close()

72
dioderata/correlate_2tt_amp.py Executable file
View File

@ -0,0 +1,72 @@
#!/usr/bin/env python
from time import sleep
from collections import deque
import numpy as np
import scipy.signal
from zoetrope import aniplot as plt
from scipy.stats.stats import pearsonr
from bstrd import BS, bsstream
plt.blit = False
plt.style.use('ggplot')
def pumpedshots(events, *arrays):
laser = events[:, 18]
darkShot = events[:, 21]
pumped_shots = np.logical_and.reduce((laser, np.logical_not(darkShot)))
return [a[pumped_shots] for a in arrays]
chname_tt1 = "SARES11-SPEC125-M1.edge_amplitude"
chname_tt2 = "SARES11-SPEC125-M1.edge_amplitude2"
chname_i0 = "SAROP11-PBPS110:INTENSITY"
chname_events = "SAR-CVME-TIFALL4:EvtSet"
length = 500
# create channel
ch_tt1 = BS(chname_tt1)
ch_tt2 = BS(chname_tt2)
ch_i0 = BS(chname_i0)
ch_events = BS(chname_events)
n = 200
tt1 = np.empty(n)
tt2 = np.empty(n)
i0s = np.empty(n)
evts = np.empty((n, 256))
# create a buffer for the plotting
pp_sigs = deque(maxlen=length)
# create the empty plot
pd = plt.plot([0])
# some plot settings
plt.suptitle("{}, {}".format(chname_tt1, chname_tt2))
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):
tt1[i] = ch_tt1.get()
tt2[i] = ch_tt2.get()
i0s[i] = ch_i0.get()
evts[i] = ch_events.get()
next(bsstream) # this gets the next set of data
pumptt1, pumptt2 = pumpedshots(evts, tt1, tt2)
pearscoeff1, _ = pearsonr(pumptt1, pumptt2)
#xs = np.arange(len(pp_sigs))
plt.clf()
plt.scatter(pumptt1, pumptt2)
plt.title("{}".format(round(pearscoeff1, 4)))
plt.show()
bsstream.close()

59
dioderata/correlate_2wieser.py Executable file
View File

@ -0,0 +1,59 @@
#!/usr/bin/env python
from time import sleep
from collections import deque
import numpy as np
import scipy.signal
from zoetrope import aniplot as plt
from scipy.stats.stats import pearsonr
from bstrd import BS, bsstream
plt.blit = False
plt.style.use('ggplot')
chname_x1 = "SLAAR-LADC-WL001:ADCX_VAL"
chname_x2 = "SLAAR-LADC-WL002:ADCX_VAL"
chname_i0 = "SLAAR-LADC-WL003:ADCI_VAL"
# create channel
ch_x1 = BS(chname_x1)
ch_x2 = BS(chname_x2)
#ch_i0 = BS(chname_i0)
n = 100
sigs1 = np.empty(n)
sigs2 = np.empty(n)
#i0s = np.empty(n)
# create the empty plot
pd = plt.plot([0])
# some plot settings
#plt.suptitle("{}, {}".format(chname_diode1, chname_diode2))
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):
sigs1[i] = ch_x1.get()
sigs2[i] = ch_x2.get()
#i0s[i] = ch_i0.get()
next(bsstream) # this gets the next set of data
#xs = np.arange(len(pp_sigs))
plt.clf()
#plt.plot(sigs1)
plt.scatter(sigs1, sigs2)
#plt.title("{}, ch1:{}, ch2:{}".format(chname_i0.split(':')[0].split('-')[-1], round(pearscoeff1, 4), round(pearscoeff2, 4)))
#plt.legend(loc='best')
plt.show()
# this, I need to move into the library
pd.ax.relim()
pd.ax.autoscale_view()
bsstream.close()

16
dioderata/dark_light.py Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env python
import epics
import time
# config
darkPV = epics.PV('SLAAR03-LTIM-PDLY:DARKSHOT.PROC')
normalPV = epics.PV('SLAAR03-LTIM-PDLY:NORMAL.PROC')
while True:
time.sleep(20)
darkPV.put(1)
print('dark')
time.sleep(20)
normalPV.put(1)
print('light')

72
dioderata/fft.py Executable file
View File

@ -0,0 +1,72 @@
#!/usr/bin/env python
from time import sleep
from collections import deque
import numpy as np
import scipy.signal
import epics
from zoetrope import aniplot as plt
from scipy.stats.stats import pearsonr
from bstrd import BS, bsstream
def goodshots(events, *arrays):
#fel = events[:, 13]
laser = events[:, 18]
darkShot = events[:, 21]
pumped_shots = np.logical_and.reduce((laser, np.logical_not(darkShot)))
return [a[pumped_shots] for a in arrays]
plt.blit = False
plt.style.use('ggplot')
chname_diode = "SARES12-LSCP11-FNS:CH4:VAL_GET"
#chname_diode = "SLAAR-LSCP1-FNS:CH4:VAL_GET"
chname_events = "SAR-CVME-TIFALL4:EvtSet"
chname_laserRate = "SIN-TIMAST-TMA:Evt-23-Freq-SP"
# create channel
ch_diode = BS(chname_diode)
ch_events = BS(chname_events)
ch_laserRate = epics.PV(chname_laserRate)
n = 1000
sigs = np.empty(n)
evts = np.empty((n, 256))
# create the empty plot
pd = plt.plot([0])
plt.suptitle("{}".format(chname_diode))
plt.fig.set_figheight(4)
plt.fig.set_figwidth(8)
plt.tight_layout()
for counter, data in zip(plt.show(), bsstream):
print(counter)
for i in range(n):
sigs[i] = ch_diode.get()
evts[i] = ch_events.get()
next(bsstream) # this gets the next set of data
laserRate = ch_laserRate.get()
if not(laserRate):
laserRate = 100
goodsigs, _ = goodshots(evts, sigs, sigs)
x=np.arange(0,np.ceil(laserRate),np.ceil(laserRate)/len(goodsigs))
vals = np.hstack((goodsigs-np.mean(goodsigs), np.zeros_like(goodsigs)))
power = np.abs(np.fft.fft(vals))**2
print(x[0])
print(len(x))
print(x[-1])
print(len(power))
plt.clf()
plt.plot(x[0:200]/2, power[0:200])
plt.show()
bsstream.close()

24
dioderata/infinite_jest.py Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env python
import epics
from epics import caput
import numpy as np
# config
#STAGEpv = epics.PV('SLAAR11-LMOT-M452:MOTOR_1.VAL') # global globi
stagePV = epics.PV('SLAAR11-LMOT-M424:MOT.VAL')
c = 299792458
def mm2fs(d):
# d in mm, output in fs
return np.around(2*d*10**(-3)/c*10**15, decimals=5)
def fs2mm(t):
# t in fs, output in mm
return np.around(c*t/2*10**(-12), decimals=5)
t0 = 168.760
while True:
stagePV.put(t0 - fs2mm(200))
stagePV.put(t0 + fs2mm(500))

88
dioderata/knife_edge.py Executable file
View File

@ -0,0 +1,88 @@
#!/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()

80
dioderata/lost_pids.py Executable file
View File

@ -0,0 +1,80 @@
#!/photonics/home/gac-alvra/.conda/envs/adaq/bin/python
from collections import defaultdict
import numpy as np
from bstrd import BS, bsstream
#from zoetrope import aniplot as plt
#plt.blit = False
chname = "SARES11-SPEC125-M1.edge_amplitude"
ch = BS(chname)
pids = BS("pid")
nblock = 100
def analyse(data):
data = np.array(data)
delta = np.diff(data)
x, y = discrete_histogram(delta)
return x, y
def discrete_histogram(data):
left_of_first_bin = data.min() - 1/2
right_of_last_bin = data.max() + 1/2
bins = np.arange(left_of_first_bin, right_of_last_bin+1)
hist, edges = np.histogram(data, bins=bins)
edges += 1/2
edges = edges.astype(int)
return edges, hist
#xs = [1]
#ys = [0]
#pd = plt.step([1], [0])
i = 0
seen = []
accum = defaultdict(int)
#for counter, _ in zip(plt.show(), bsstream):
# print(counter)
for _ in bsstream:
curr = pids.get()
seen.append(curr)
if len(seen) == nblock:
res = analyse(seen)
for x, y in zip(*res):
accum[x] += y
xs, ys = zip(*accum.items())
print(xs)
print(ys)
print()
xs = np.array(xs)
ys = np.array(ys)
one = (xs == 1)
other = (xs != 1)
one = ys[one].sum()
other = ( (xs[other] - 1) * ys[other] ).sum()
print(round(other / one * 100, 1), one, other)
# pd.set(xs, ys)
# i += 1
# if i == 3:
# break
last = seen[-1]
seen = [last] # use the last entry of the previous round as new first entry
bsstream.stop()

53
dioderata/lost_pids1.py Executable file
View File

@ -0,0 +1,53 @@
#!/photonics/home/gac-alvra/.conda/envs/adaq/bin/python
#from time import sleep
#from collections import deque
#import numpy as np
#import scipy.signal
from bstrd import BS, bsstream
#from zoetrope import aniplot as plt
#plt.blit = False
chname = "SARES11-SPEC125-M1.edge_amplitude"
ch = BS(chname)
pids = BS("pid")
seen = set()
#last = None
missing_prev = set()
#missing_next = set()
for _ in bsstream:
p_curr = pids.get()
p_prev = p_curr - 1
p_next = p_curr + 1
seen.add(p_curr)
if p_prev not in seen:
missing_prev.add(p_curr)
# miss_prev.remove(prev)
last_few = sorted(seen)[-23:]
if missing_prev:
print("missing prev:", missing_prev)
print("last few: ", last_few)
print(p_curr)
to_be_removed = set()
for p in missing_prev:
if p-1 in seen:
print("late:", p)
print("max:", max(seen), "-- min:", min(seen))
to_be_removed.add(p)
raise SystemExit
missing_prev -= to_be_removed

13
dioderata/mod_mod.py Executable file
View File

@ -0,0 +1,13 @@
#!/usr/bin/env python
import epics
import time
# config
modPV = epics.PV('SIN-TIMAST-TMA:Evt-23-Off-SP')
while True:
time.sleep(5)
modPV.put(0)
time.sleep(5)
modPV.put(1)

80
dioderata/online_abs.py Executable file
View File

@ -0,0 +1,80 @@
#!/usr/bin/env python
from time import sleep
from collections import deque
import numpy as np
import scipy.signal
from zoetrope import aniplot as plt
from bstrd import BS, bsstream
plt.blit = False
plt.style.use('ggplot')
def unpumpedXrays(events, *arrays):
laser = events[:, 18]
darkShot = events[:, 21]
background_shots = np.logical_and.reduce((laser, darkShot))
return [a[background_shots] for a in arrays]
def pumpedXrays(events, *arrays):
fel = events[:, 13]
laser = events[:, 18]
darkShot = events[:, 21]
pumped_shots = np.logical_and.reduce((laser, np.logical_not(darkShot)))
return [a[pumped_shots] for a in arrays]
# config
#chname_diode = "SLAAR11-LSCP1-FNS:CH0:VAL_GET"
chname_diode = "SARES11-SPEC125-M1.edge_amplitude"
#chname_diode = "SARES11-GES1:CH2_VAL_GET"
chname_events = "SAR-CVME-TIFALL4:EvtSet"
length = 500
# create channel
ch_diode = BS(chname_diode)
ch_events = BS(chname_events)
n = 10
sigs = np.empty(n)
evts = np.empty((n, 256))
# create a buffer for the plotting
pp_sigs = deque(maxlen=length)
# create the empty plot
pd = plt.plot([0])
# some plot settings
plt.suptitle(chname_diode)
plt.fig.set_figheight(5)
plt.fig.set_figwidth(15)
plt.tight_layout()
for counter, data in zip(plt.show(), bsstream):
print(counter)
for i in range(n):
evts[i] = ch_events.get()
sigs[i] = ch_diode.get()
next(bsstream) # this gets the next set of data
# sigs_p = pumpedXrays(evts, sigs)
# sigs_u = unpumpedXrays(evts, sigs)
sig = np.mean(sigs)
# sig_p = np.mean(sigs_p)
# sig_u = np.mean(sigs_u)
# sig = -np.log10(sig_p/sig_u)
pp_sigs.append(sig)
xs = np.arange(len(pp_sigs))
pd.set(xs, pp_sigs)
# this, I need to move into the library
pd.ax.relim()
pd.ax.autoscale_view()
bsstream.close()

83
dioderata/prime_pp.py Executable file
View File

@ -0,0 +1,83 @@
#!/usr/bin/env python
from time import sleep
from collections import deque
import numpy as np
import scipy.signal
from zoetrope import aniplot as plt
from bstrd import BS, bsstream
plt.blit = False
plt.style.use('ggplot')
def unpumped(events, *arrays):
laser = events[:, 18]
darkShot = events[:, 21]
background_shots = np.logical_and.reduce((laser, darkShot))
return [a[background_shots] for a in arrays]
def pumped(events, *arrays):
fel = events[:, 13]
laser = events[:, 18]
darkShot = events[:, 21]
pumped_shots = np.logical_and.reduce((laser, np.logical_not(darkShot)))
return [a[pumped_shots] for a in arrays]
# config
chname_diode = "SLAAR11-LSCP1-FNS:CH0:VAL_GET"
#chname_diode = "SARES11-GES1:CH1_VAL_GET"
chname_events = "SAR-CVME-TIFALL4:EvtSet"
chname_i0 = "SAROP11-PBPS110:INTENSITY"
length = 100
# create channel
ch_diode = BS(chname_diode)
ch_events = BS(chname_events)
ch_i0 = BS(chname_i0)
n = 50
sigs = np.empty(n)
evts = np.empty((n, 256))
i0s = np.empty(n)
# create a buffer for the plotting
pp_sigs = deque(maxlen=length)
# create the empty plot
pd = plt.plot([0])
# some plot settings
plt.suptitle(chname_diode)
plt.fig.set_figheight(5)
plt.fig.set_figwidth(15)
plt.tight_layout()
for counter, data in zip(plt.show(), bsstream):
print(counter)
for i in range(n):
evts[i] = ch_events.get()
sigs[i] = ch_diode.get()
i0s[i] = ch_i0.get()
next(bsstream) # this gets the next set of data
sigs_p = pumped(evts, sigs)
sigs_u = unpumped(evts, sigs)
i0s_p = pumped(evts, i0s)
i0s_u = unpumped(evts, i0s)
sig_p = np.mean(np.asarray(sigs_p))#/np.asarray(i0s_p))
sig_u = np.mean(np.asarray(sigs_u))#/np.asarray(i0s_u))
sig = -np.log10(sig_p/sig_u)
pp_sigs.append(sig)
xs = np.arange(len(pp_sigs))
pd.set(xs, pp_sigs)
# this, I need to move into the library
pd.ax.relim()
pd.ax.autoscale_view()
bsstream.close()

81
dioderata/prime_pp2.py Executable file
View File

@ -0,0 +1,81 @@
#!/usr/bin/env python
from time import sleep
from collections import deque
import numpy as np
import scipy.signal
from zoetrope import aniplot as plt
from bstrd import BS, bsstream
plt.blit = False
plt.style.use('ggplot')
def unpumpedXrays(events, *arrays):
laser = events[:, 18]
darkShot = events[:, 21]
background_shots = np.logical_and.reduce((laser, darkShot))
return [a[background_shots] for a in arrays]
def pumpedXrays(events, *arrays):
fel = events[:, 13]
laser = events[:, 18]
darkShot = events[:, 21]
pumped_shots = np.logical_and.reduce((laser, np.logical_not(darkShot)))
return [a[pumped_shots] for a in arrays]
# config
#chname_diode = "SLAAR11-LSCP1-FNS:CH0:VAL_GET"
#chname_diode = "SARES11-SPEC125-M1.edge_position"
#chname_diode = "SARES11-GES1:CH2_VAL_GET"
chname_diode = "SARES11-SPEC125-M1.edge_amplitude"
chname_events = "SAR-CVME-TIFALL4:EvtSet"
length = 500
# create channel
ch_diode = BS(chname_diode)
ch_events = BS(chname_events)
n = 10
sigs = np.empty(n)
evts = np.empty((n, 256))
# create a buffer for the plotting
pp_sigs = deque(maxlen=length)
# create the empty plot
pd = plt.plot([0])
# some plot settings
plt.suptitle(chname_diode)
plt.fig.set_figheight(5)
plt.fig.set_figwidth(15)
plt.tight_layout()
for counter, data in zip(plt.show(), bsstream):
print(counter)
for i in range(n):
evts[i] = ch_events.get()
sigs[i] = ch_diode.get()
next(bsstream) # this gets the next set of data
# sigs_p = pumpedXrays(evts, sigs)
# sigs_u = unpumpedXrays(evts, sigs)
sig = np.mean(sigs)
# sig_p = np.mean(sigs_p)
# sig_u = np.mean(sigs_u)
# sig = -np.log10(sig_p/sig_u)
pp_sigs.append(sig)
xs = np.arange(len(pp_sigs))
pd.set(xs, pp_sigs)
# this, I need to move into the library
pd.ax.relim()
pd.ax.autoscale_view()
bsstream.close()

88
dioderata/prime_pp_sigma.py Executable file
View File

@ -0,0 +1,88 @@
#!/usr/bin/env python
from time import sleep
from collections import deque
import numpy as np
import scipy.signal
from zoetrope import aniplot as plt
from bstrd import BS, bsstream
plt.blit = False
plt.style.use('ggplot')
def unpumped(events, *arrays):
laser = events[:, 18]
darkShot = events[:, 21]
background_shots = np.logical_and.reduce((laser, darkShot))
return [a[background_shots] for a in arrays]
def pumped(events, *arrays):
fel = events[:, 13]
laser = events[:, 18]
darkShot = events[:, 21]
pumped_shots = np.logical_and.reduce((laser, np.logical_not(darkShot)))
return [a[pumped_shots] for a in arrays]
# config
chname_diode = "SLAAR11-LSCP1-FNS:CH0:VAL_GET"
#chname_diode = "SARES11-GES1:CH1_VAL_GET"
chname_events = "SAR-CVME-TIFALL4:EvtSet"
chname_i0 = "SAROP11-PBPS110:INTENSITY"
length = 100
# create channel
ch_diode = BS(chname_diode)
ch_events = BS(chname_events)
ch_i0 = BS(chname_i0)
n = 50
sigs = np.empty(n)
evts = np.empty((n, 256))
i0s = np.empty(n)
# create a buffer for the plotting
u_std = deque(maxlen=length)
p_std = deque(maxlen=length)
# create the empty plot
pd = plt.plot([0])
# some plot settings
plt.suptitle('std of {}'.format(chname_diode))
plt.fig.set_figheight(5)
plt.fig.set_figwidth(15)
plt.tight_layout()
plt.legend(loc='best')
for counter, data in zip(plt.show(), bsstream):
print(counter)
for i in range(n):
evts[i] = ch_events.get()
sigs[i] = ch_diode.get()
i0s[i] = ch_i0.get()
next(bsstream) # this gets the next set of data
sigs_p = pumped(evts, sigs)
sigs_u = unpumped(evts, sigs)
i0s_p = pumped(evts, i0s)
i0s_u = unpumped(evts, i0s)
# sig = np.mean(sigs)
std_p = np.nanstd(np.asarray(sigs_p))#/np.asarray(i0s_p))
std_u = np.nanstd(np.asarray(sigs_u))#/np.asarray(i0s_u))
#sig = -np.log10(sig_p/sig_u)
u_std.append(std_u)
p_std.append(std_p)
xs = np.arange(len(p_std))
pd.set(xs, p_std)
# this, I need to move into the library
pd.ax.relim()
pd.ax.autoscale_view()
bsstream.close()

85
dioderata/spec_pp.py Executable file
View File

@ -0,0 +1,85 @@
#!/usr/bin/env python
from time import sleep
from collections import deque
import numpy as np
import scipy.signal
from zoetrope import aniplot as plt
from bstrd import BS, bsstream
plt.blit = False
plt.style.use('ggplot')
def unpumped(events, *arrays):
laser = events[:, 18]
darkShot = events[:, 21]
background_shots = np.logical_and.reduce((laser, darkShot))
return [a[background_shots] for a in arrays]
def pumped(events, *arrays):
fel = events[:, 13]
laser = events[:, 18]
darkShot = events[:, 21]
pumped_shots = np.logical_and.reduce((laser, np.logical_not(darkShot)))
return [a[pumped_shots] for a in arrays]
# config
chname_diode = "SLAAR11-LSCP1-FNS:CH0:VAL_GET"
#chname_diode = "SARES11-GES1:CH1_VAL_GET"
chname_events = "SAR-CVME-TIFALL4:EvtSet"
chname_i0 = "SAROP11-PBPS110:INTENSITY"
length = 100
# create channel
ch_diode = BS(chname_diode)
ch_events = BS(chname_events)
ch_i0 = BS(chname_i0)
n = 50
sigs = np.empty(n)
evts = np.empty((n, 256))
i0s = np.empty(n)
# create a buffer for the plotting
pp_sigs = deque(maxlen=length)
# create the empty plot
pd = plt.plot([0])
# some plot settings
plt.suptitle(chname_diode)
plt.fig.set_figheight(5)
plt.fig.set_figwidth(15)
plt.tight_layout()
for counter, data in zip(plt.show(), bsstream):
print(counter)
for i in range(n):
evts[i] = ch_events.get()
sigs[i] = ch_diode.get()
i0s[i] = ch_i0.get()
next(bsstream) # this gets the next set of data
sigs_p = pumped(evts, sigs)
sigs_u = unpumped(evts, sigs)
i0s_p = pumped(evts, i0s)
i0s_u = unpumped(evts, i0s)
# sig = np.mean(sigs)
sig_p = np.mean(np.asarray(sigs_p))#/np.asarray(i0s_p))
sig_u = np.mean(np.asarray(sigs_u))#/np.asarray(i0s_u))
sig = -np.log10(sig_p/sig_u)
pp_sigs.append(sig)
xs = np.arange(len(pp_sigs))
pd.set(xs, pp_sigs)
# this, I need to move into the library
pd.ax.relim()
pd.ax.autoscale_view()
bsstream.close()

70
dioderata/spectrum_ta.py Executable file
View File

@ -0,0 +1,70 @@
#!/usr/bin/env python
from time import sleep
from collections import deque
import numpy as np
from zoetrope import aniplot as plt
from scipy.stats.stats import pearsonr
from bstrd import BS, bsstream
plt.blit = False
plt.style.use('ggplot')
wav = np.linspace(409.914, 672.792, num=2048)
def unpumpedshots(pulseids, *arrays):
unpumped_shots = (pulseids%2 == 0)
return [a[unpumped_shots] for a in arrays]
def pumpedshots(pulseids, *arrays):
pumped_shots = (pulseids%2 == 1)
return [a[pumped_shots] for a in arrays]
chname_specsig = "SARES11-SPEC125-M2.projection_signal"
chname_specback = "SARES11-SPEC125-M2.projection_background"
chname_i0 = "SLAAR11-LSCP1-FNS:CH5:VAL_GET"
#chname_events = "SAR-CVME-TIFALL4:EvtSet"
chname_pids = "SATCB01-RLLE-STA:MASTER-EVRPULSEID"
# create channel
ch_spec1 = BS(chname_specsig)
ch_back1 = BS(chname_specback)
ch_i0 = BS(chname_i0)
ch_pids = BS(chname_pids)
n = 200
sigs1 = np.empty((n, 2048))
backs1 = np.empty((n, 2048))
i0s = np.empty(n)
pids = np.empty(n)
# create the empty plot
pd = plt.plot([0])
# some plot settings
plt.fig.set_figheight(6)
plt.fig.set_figwidth(7)
for counter, data in zip(plt.show(), bsstream):
print(counter)
for i in range(n):
sigs1[i] = ch_spec1.get()
backs1[i] = ch_back1.get()
i0s[i] = ch_i0.get()
pids[i] = int(ch_pids.get())
next(bsstream) # this gets the next set of data
pumpi0s, pumpsigs, pumpbacks = pumpedshots(pids, i0s, sigs1, backs1)
unpumpi0s, unpumpsigs, unpumpbacks = unpumpedshots(pids, i0s, sigs1, backs1)
diffa = np.mean((pumpsigs - pumpbacks), axis=0) / np.mean((unpumpsigs - unpumpbacks), axis=0)
plt.tight_layout()
plt.clf()
plt.xlim(450, 650)
plt.ylim(-0.05, 0.05)
plt.plot(wav, -np.log10(diffa))
plt.show()
bsstream.close()

61
dioderata/tt_vs_stage.py Executable file
View File

@ -0,0 +1,61 @@
#!/usr/bin/env python
from time import sleep
from collections import deque
import numpy as np
from zoetrope import aniplot as plt
from scipy.stats.stats import pearsonr
from bstrd import BS, bsstream
plt.blit = False
plt.style.use('ggplot')
def pumpedshots(events, *arrays):
laser = events[:, 18]
darkShot = events[:, 21]
pumped_shots = np.logical_and.reduce((laser, np.logical_not(darkShot)))
return [a[pumped_shots] for a in arrays]
chname_tt = "SARES11-SPEC125-M1.edge_position"
chname_stage = "SLAAR11-LMOT-M452:ENC_1_BS"
chname_events = "SAR-CVME-TIFALL4:EvtSet"
length = 500
# create channel
ch_tt = BS(chname_tt)
ch_stage = BS(chname_stage)
ch_events = BS(chname_events)
n = 200
tt = np.empty(n)
stage = np.empty(n)
evts = np.empty((n, 256))
# create the empty plot
pd = plt.plot([0])
# some plot settings
plt.fig.set_figheight(6)
plt.fig.set_figwidth(7)
for counter, data in zip(plt.show(), bsstream):
print(counter)
for i in range(n):
tt[i] = ch_tt.get()
stage[i] = ch_stage.get()
evts[i] = ch_events.get()
next(bsstream) # this gets the next set of data
pumpstage, pumptt = pumpedshots(evts, stage, tt)
pearscoeff1, _ = pearsonr(stage, tt)
#xs = np.arange(len(pp_sigs))
plt.tight_layout()
plt.clf()
plt.scatter(pumpstage, pumptt)
plt.title("{}".format(round(pearscoeff1, 4)))
plt.xlabel('m452')
plt.ylabel('arrival time')
plt.show()
bsstream.close()