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

67 lines
1.6 KiB
Python
Executable File

#!/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()