This commit is contained in:
6
script/Correlation/Correlation.py
Executable file → Normal file
6
script/Correlation/Correlation.py
Executable file → Normal file
@@ -2,7 +2,7 @@ import math
|
||||
import sys, traceback
|
||||
from mathutils import fit_polynomial, PolynomialFunction
|
||||
from plotutils import plot_line, plot_function
|
||||
from ch.psi.pshell.swing.Shell import STDOUT_COLOR
|
||||
from ch.psi.pshell.swing.Shell import getColorStdout
|
||||
import org.apache.commons.math3.stat.correlation.PearsonsCorrelation as PearsonsCorrelation
|
||||
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
@@ -120,7 +120,7 @@ try:
|
||||
#Sample and plot data
|
||||
if bs == True:
|
||||
_stream.waitValueNot(_stream.take(), 10000)
|
||||
(x,y) = _stream.take().values
|
||||
(x,y) = _stream.take().values()
|
||||
else:
|
||||
x=dx.read()
|
||||
y=dy.read()
|
||||
@@ -142,7 +142,7 @@ try:
|
||||
if marker is not None:
|
||||
p.removeMarker(marker)
|
||||
marker = p.addMarker(x2+res, p.AxisId.X, s, p.getBackground())
|
||||
marker.setLabelPaint(STDOUT_COLOR)
|
||||
marker.setLabelPaint(getColorStdout())
|
||||
if linear_fit:
|
||||
#Calculate, print and plot linear fit
|
||||
pars_lin = (a0,a1) = fit_polynomial(ay, ax, 1)
|
||||
|
||||
4
script/Correlation/Correlation2.py
Executable file → Normal file
4
script/Correlation/Correlation2.py
Executable file → Normal file
@@ -2,7 +2,7 @@ import math
|
||||
import sys, traceback
|
||||
from mathutils import fit_polynomial, PolynomialFunction
|
||||
from plotutils import plot_line, plot_function
|
||||
from ch.psi.pshell.swing.Shell import STDOUT_COLOR
|
||||
from ch.psi.pshell.swing.Shell import getColorStdout
|
||||
import org.apache.commons.math3.stat.correlation.PearsonsCorrelation as PearsonsCorrelation
|
||||
import ch.psi.pshell.bs.PipelineServer as PipelineServer
|
||||
|
||||
@@ -186,7 +186,7 @@ try:
|
||||
if marker is not None:
|
||||
p.removeMarker(marker)
|
||||
marker = p.addMarker(x2+res, p.AxisId.X, s, p.getBackground())
|
||||
marker.setLabelPaint(STDOUT_COLOR)
|
||||
marker.setLabelPaint(getColorStdout())
|
||||
if linear_fit:
|
||||
#Calculate, print and plot linear fit
|
||||
pars_lin = (a0,a1) = fit_polynomial(ay, ax, 1)
|
||||
|
||||
30
script/Correlation/CorrelationStream.py
Executable file → Normal file
30
script/Correlation/CorrelationStream.py
Executable file → Normal file
@@ -14,7 +14,7 @@ class CorrelationStream():
|
||||
self.st=None
|
||||
self.running = False
|
||||
self.task=None
|
||||
|
||||
|
||||
|
||||
def get_channel_list(self):
|
||||
ch=[]
|
||||
@@ -41,7 +41,7 @@ class CorrelationStream():
|
||||
def start_stream(self, channel_list):
|
||||
try:
|
||||
self.st=None
|
||||
print "Starting stream"
|
||||
log("Starting stream: " + str(self.prefix))
|
||||
if len(channel_list)==0:
|
||||
raise Exception ("No channel defined")
|
||||
self. st = Stream("pulse_id", dispatcher)
|
||||
@@ -54,19 +54,20 @@ class CorrelationStream():
|
||||
if self.st.take() is None:
|
||||
raise Exception("Error initializing data stream")
|
||||
self.ack_channel_list(channel_list)
|
||||
print "Stream started"
|
||||
log("Stream started: " + str(self.prefix))
|
||||
except:
|
||||
self.stop_stream()
|
||||
self.st=None
|
||||
print sys.exc_info()[1]
|
||||
log(sys.exc_info()[1])
|
||||
|
||||
def stop_stream(self):
|
||||
log("Closing stream: " + str(self.prefix))
|
||||
try:
|
||||
if self.st:
|
||||
self.st.close()
|
||||
print "Stream closed"
|
||||
log("Stream closed: " + str(self.prefix))
|
||||
except:
|
||||
print sys.exc_info()[1]
|
||||
log(sys.exc_info()[1])
|
||||
finally:
|
||||
self.st=None
|
||||
self.ack_channel_list([])
|
||||
@@ -81,7 +82,7 @@ class CorrelationStream():
|
||||
buf[1] = num_channels
|
||||
buf[4] = self.empty_value
|
||||
#if (self.pid is not None) and ((self.pid+1) != msg.pulseId):
|
||||
# print "Missing pid: ", (self.pid+1)
|
||||
# msg("Missing pid: +str(self.pid+1))
|
||||
self.pid = msg.pulseId
|
||||
#Count
|
||||
if buf[2] < size_buffer:
|
||||
@@ -105,7 +106,7 @@ class CorrelationStream():
|
||||
|
||||
|
||||
def _run(self):
|
||||
print "Start running correlation stream " + str(self.prefix)
|
||||
log("Start running thread: " + str(self.prefix))
|
||||
channel_list = []
|
||||
|
||||
try:
|
||||
@@ -115,11 +116,10 @@ class CorrelationStream():
|
||||
while self.running:
|
||||
started = (start_channel.get()==1)
|
||||
if started and not self.st:
|
||||
print "Started"
|
||||
buf[2] = 0
|
||||
buf[3]= -1
|
||||
channel_list=self.get_channel_list()
|
||||
print "Channel list: ", channel_list
|
||||
log("Started " + str(self.prefix) + " - Channel list: " + str(channel_list) )
|
||||
self.start_stream(channel_list)
|
||||
if self.st is not None:
|
||||
class StreamListener (DeviceListener):
|
||||
@@ -132,14 +132,14 @@ class CorrelationStream():
|
||||
self.st.addListener(listener)
|
||||
|
||||
elif self.st and not started:
|
||||
print "Stopped"
|
||||
log("Stopped " + str(self.prefix))
|
||||
channel_list=[]
|
||||
self.stop_stream()
|
||||
time.sleep(0.1)
|
||||
except:
|
||||
print sys.exc_info()[1]
|
||||
log(sys.exc_info()[1])
|
||||
finally:
|
||||
print "Stop running correlation stream " + str(self.prefix)
|
||||
log("Stop running thread: " + str(self.prefix))
|
||||
self.stop_stream()
|
||||
if output_channel: output_channel.close()
|
||||
if start_channel: start_channel.close()
|
||||
@@ -155,9 +155,9 @@ class CorrelationStream():
|
||||
if self.running:
|
||||
self.running = False
|
||||
if (self.task is not None):
|
||||
print "Waiting correlation stream thread to stop..."
|
||||
log("Waiting correlation stream thread to stop..." + str(self.prefix))
|
||||
join([self.task,])
|
||||
print "Done"
|
||||
log("Done" + str(self.prefix))
|
||||
|
||||
def is_running(self):
|
||||
return (self.task is not None) and not (self.task.isDone())
|
||||
|
||||
10
script/Correlation/correlation_stream_mult.py
Executable file → Normal file
10
script/Correlation/correlation_stream_mult.py
Executable file → Normal file
@@ -1,9 +1,13 @@
|
||||
run("Correlation/CorrelationStream")
|
||||
|
||||
#PREFIX = "SLAAR"
|
||||
PREFIX = "SLG"
|
||||
|
||||
correlation_endstations=["SLAAR-LBSTREAM1","SLAAR-LBSTREAM2", "SLAAR-LBSTREAM3", "SLAAR-LBSTREAM4", "SLAAR-LBSTREAM5", "SLAAR-LBSTREAM6"]
|
||||
correlation_endstations=[PREFIX+"-LBSTREAM1",PREFIX+"-LBSTREAM2", PREFIX+"-LBSTREAM3", PREFIX+"-LBSTREAM4", PREFIX+"-LBSTREAM5", PREFIX+"-LBSTREAM6"]
|
||||
correlation_streams = []
|
||||
|
||||
log("Initializing...")
|
||||
|
||||
for es in correlation_endstations:
|
||||
correlation_streams.append(CorrelationStream(es))
|
||||
|
||||
@@ -14,5 +18,7 @@ try:
|
||||
cs.run()
|
||||
time.sleep(10.0)
|
||||
finally:
|
||||
log("Finalizing...")
|
||||
for cs in correlation_streams:
|
||||
cs.stop()
|
||||
cs.stop()
|
||||
log("Quit")
|
||||
Reference in New Issue
Block a user