This commit is contained in:
21
script/test/TestBsreadCamera.py
Normal file
21
script/test/TestBsreadCamera.py
Normal file
@@ -0,0 +1,21 @@
|
||||
CAMERA = "SARES20-CAMS142-M3"
|
||||
CAMERA = "SARFE10-PSSS059"
|
||||
CAMERA = "SATBD02-DSCR050"
|
||||
CAMERA = "SATES31-CAMS187-RIXS1"
|
||||
CAMERA = "SAROP21-PPRM138"
|
||||
CAMERA = "SARES20-CAMS142-C2"
|
||||
|
||||
CAMERA_URL = caget(CAMERA + ":BSREADCONFIG").replace("tcp://daq", "tcp://")
|
||||
#CAMERA_URL= "tcp://sf-sioc-cs-83:9020"
|
||||
#CAMERA_URL= "tcp://sf-sioc-cs-64:9000"
|
||||
|
||||
print CAMERA_URL
|
||||
st1 = Stream("st1", CAMERA_URL, SocketType.PULL)
|
||||
st1.initialize()
|
||||
st1.start()
|
||||
st1.waitCacheChange(3000)
|
||||
try:
|
||||
r=bscan (st1, records=5, timeout=10.0, save=False, enabled_plots=[st1,])
|
||||
v= st1.getValues()
|
||||
finally:
|
||||
st1.close()
|
||||
@@ -1,8 +1,29 @@
|
||||
from jeputils import *
|
||||
|
||||
"""
|
||||
import_py("CPython/linfit", "test")
|
||||
def test():
|
||||
return np.ones(5)
|
||||
print test()
|
||||
"""
|
||||
|
||||
|
||||
"""
|
||||
|
||||
def test2(name, x=None, y=None):
|
||||
print (name)
|
||||
return x+y
|
||||
import_py("CPython/linfit", "test2")
|
||||
print test2("x", to_array([0,1,2,3,4],'d'), to_array([5,1,2,3,4],'d'))
|
||||
|
||||
"""
|
||||
|
||||
data, dims = [1,2,3,4,5,6,7,8,9,0], [2,5]
|
||||
array = to_npa(data, dims,'d') #Auxiliary function to create numpy arrays from lists or java arrays.
|
||||
ret = call_jep("test/cpython", "calc", [array,])
|
||||
print ret.getDimensions(),ret.getData()
|
||||
|
||||
ret = call_jep("test/cpython", "test_pandas")
|
||||
ret = call_jep("test/cpython", "test_pandas")
|
||||
|
||||
|
||||
|
||||
|
||||
27
script/test/TestCameraScan.py
Normal file
27
script/test/TestCameraScan.py
Normal file
@@ -0,0 +1,27 @@
|
||||
dry_run = True
|
||||
use_screen_panel_stream = True
|
||||
camera_name = "simulation" if dry_run else "SINEG01-DSCR190"
|
||||
use_good_region=False
|
||||
number_images=5
|
||||
use_background=False
|
||||
source = "server"
|
||||
plot_image = False
|
||||
|
||||
setup_camera_scan()
|
||||
|
||||
|
||||
def after_sample(record, scan):
|
||||
x = record[0]
|
||||
y = record[1]
|
||||
stdev_x = record[2]
|
||||
stdev_y = record[3]
|
||||
x, y, stdev_x, stdev_y = x.mean, y.mean, x.stdev, y.stdev
|
||||
after_sample_camera_scan()
|
||||
|
||||
r = None
|
||||
|
||||
try:
|
||||
sensors = get_camera_scan_sensors()
|
||||
r = tscan(sensors, 10, 0.1, before_read = before_sample_camera_scan, after_read = after_sample)
|
||||
finally:
|
||||
end_camera_scan()
|
||||
45
script/test/TestChannelsModulo.py
Normal file
45
script/test/TestChannelsModulo.py
Normal file
@@ -0,0 +1,45 @@
|
||||
dispatcher.config.validationInconsistency = dispatcher.config.Inconsistency.keep_as_is
|
||||
#dispatcher.config.validationInconsistency = dispatcher.config.Inconsistency.adjust_global
|
||||
|
||||
import ch.psi.pshell.bs.StreamChannel as StreamChannel
|
||||
def bsget(channel, modulo=StreamChannel.DEFAULT_MODULO, offset=StreamChannel.DEFAULT_OFFSET, timeout = 5.0):
|
||||
"""Reads an values a bsread stream, using the default provider.
|
||||
|
||||
Args:
|
||||
channel(str or list of str): channel name(s)
|
||||
module(int, optional): stream modulo
|
||||
offset(int, optional): stream offset
|
||||
timeout(float, optional): stream timeout in secs
|
||||
Returns:
|
||||
BS value or list of values
|
||||
"""
|
||||
channels = to_list(channel)
|
||||
ret = Stream.readChannels(channels, modulo, offset, int(timeout * 1000))
|
||||
if is_string(channel):
|
||||
return ret[0]
|
||||
return ret
|
||||
|
||||
|
||||
run ("Tools/dispatcher")
|
||||
|
||||
channel = "SATMA02-RLLE-DSP:PHASE-VS"
|
||||
channel = "S10CB01-RLLE-DSP:PHASE-VS"
|
||||
print get_dispatcher_channel_modulo(channel)
|
||||
|
||||
|
||||
ch = get_dispatcher_channels("PHASE-VS")
|
||||
|
||||
for c in ch:
|
||||
print c["name"],c.get("modulo")
|
||||
|
||||
print bsget(channel)
|
||||
|
||||
|
||||
|
||||
st1 = Stream("st1", dispatcher)
|
||||
s1=st1.addScalar(channel,channel)
|
||||
st1.initialize()
|
||||
try:
|
||||
bscan (st1, 10, title="bscan")
|
||||
finally:
|
||||
st1.close()
|
||||
2
script/test/TestEpicsCmd.py
Normal file
2
script/test/TestEpicsCmd.py
Normal file
@@ -0,0 +1,2 @@
|
||||
#N_POINTS=3
|
||||
tscan(charge, N_POINTS, 1.0)
|
||||
22
script/test/TestJep.py
Normal file
22
script/test/TestJep.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from jeputils import import_py
|
||||
|
||||
import_py("CPython/linfit", "linfit")
|
||||
import_py("CPython/gfitoff", "gfitoff")
|
||||
|
||||
x=[0,1,2,3,4,5,6,7,8,9]
|
||||
y=[1,2,3,6,9,6,3,2,1,0]
|
||||
(p, x_fit, y_fit, R2) = linfit(x,y)
|
||||
#print "Fit: ", (p, x_fit, y_fit, R2)
|
||||
plot((y,y_fit), name=("data", "fit"),xdata=(x,x_fit))
|
||||
|
||||
time.sleep(1.0)
|
||||
|
||||
from mathutils import Gaussian
|
||||
x=to_array([-200.30429237268825, -200.2650700434188, -200.22115208318002, -199.9457671375377, -199.86345548879072, -199.85213073174933, -199.35687977133284, -199.13811861090275, -197.97304970346386, -197.2952215624348, -195.09076092936948, -192.92276048970703, -191.96871876227698, -189.49577852322938, -187.9652790409825, -183.63756456925222, -180.04899765472996, -178.43839623242422, -174.07311671294445, -172.0410133577918, -165.90824309893102, -160.99771795989466, -159.30176653939253, -154.27688897558514, -152.0854103810786, -145.75652847587313, -140.80843828908465, -139.23982133191495, -134.27073891256106, -132.12649284133064, -125.95947209775511, -121.00309550337462, -119.26736932643232, -114.2706655484383, -112.07393889578914, -105.72295990367157, -100.8088439880125, -99.2034906238494, -94.30042325164636, -92.15010048151461, -85.92203653534293, -81.03913275494665, -79.27412793784428, -74.33487658582118, -72.06274362408762, -65.76562628131825, -60.91255356825276, -59.20334389560392, -54.33286972659312, -52.19387171350535, -45.94978737932291, -41.03014719193582, -39.301602568238906, -34.35572209014114, -32.04464301272608, -25.8221033382824, -20.922074315528747, -19.21590299233186, -14.31090212502093, -12.217203140101386, -5.9283722049240435, -0.9863587170369246, 0.7408048387279834, 5.71126832601389, 7.972628957879352, 14.204559894256546, 19.11839959633025, 20.8218087836657, 25.678748486941828, 27.822718344586864, 34.062659474970715, 38.9745656819391, 40.77409719734158, 45.72080631619803, 47.974156754056835, 54.23453768983539, 59.12020360609568, 60.77306570712026, 65.70734521458867, 67.8344660434617, 74.03187028154134, 78.96532114824849, 80.76070945985495, 85.74802197591286, 87.9140889204674, 94.18082276873524, 99.25790470037091, 100.68454787413205, 105.7213026221542, 107.79483801526698, 113.99555681638138, 119.0707052529143, 120.72715813056156, 125.77551384921307, 127.91257836719551, 134.2011330887875, 139.23043006997628, 140.71673537840158, 145.76288138835983, 147.80216629676042, 154.06420451405637, 159.0846626604798, 160.76183155710717, 165.73699067536242, 167.9265357747636, 173.96705069576544, 178.2522282751915, 179.9042617354548, 183.54586165856657, 185.23269803071796, 189.41678143751972, 191.87149157986588, 192.8741468985015, 195.0241934550453, 195.966634211846, 197.9821647518146, 198.99006812859284, 199.33202054855676, 199.91897441965887, 200.11536227958896, 200.22280936469997, 200.25181179127208],'d')
|
||||
y=to_array([11.0, 6.0, 8.0, 5.0, 11.0, 7.0, 18.0, 11.0, 12.0, 10.0, 8.0, 6.0, 16.0, 4.0, 12.0, 9.0, 15.0, 14.0, 8.0, 20.0, 15.0, 8.0, 9.0, 11.0, 13.0, 12.0, 13.0, 15.0, 13.0, 20.0, 10.0, 7.0, 17.0, 11.0, 20.0, 13.0, 13.0, 23.0, 14.0, 10.0, 17.0, 15.0, 20.0, 16.0, 14.0, 13.0, 18.0, 22.0, 9.0, 20.0, 12.0, 14.0, 17.0, 19.0, 14.0, 14.0, 23.0, 19.0, 15.0, 20.0, 20.0, 21.0, 20.0, 23.0, 22.0, 15.0, 10.0, 17.0, 21.0, 15.0, 23.0, 23.0, 25.0, 18.0, 16.0, 21.0, 22.0, 16.0, 16.0, 14.0, 19.0, 20.0, 18.0, 20.0, 23.0, 13.0, 16.0, 20.0, 25.0, 15.0, 15.0, 17.0, 22.0, 26.0, 19.0, 30.0, 25.0, 17.0, 17.0, 23.0, 16.0, 27.0, 21.0, 21.0, 26.0, 27.0, 21.0, 17.0, 20.0, 20.0, 21.0, 19.0, 25.0, 19.0, 13.0, 23.0, 20.0, 20.0, 18.0, 20.0, 19.0, 25.0],'d')
|
||||
[off, amp, com, sigma] = gfitoff(x, y, off=None, amp=None, com=None, sigma=None)
|
||||
#print "Fit: ", [off, amp, com, sigma]
|
||||
g = Gaussian(amp, com, sigma)
|
||||
plot([y, [g.value(i)+off for i in x]], ["data", "fit"], xdata = x)
|
||||
|
||||
|
||||
6
script/test/TestMalojaPipelines.py
Normal file
6
script/test/TestMalojaPipelines.py
Normal file
@@ -0,0 +1,6 @@
|
||||
stream_url = cam_server.getStream("SATES21-CAMS154-GIGE3_proc") #It is fixed, it could be defined directly as: sf-daqsync-12.psi.ch:9051
|
||||
st1 = Stream("st1", stream_url, SocketType.PULL)
|
||||
add_device(st1, force = True)
|
||||
st1.start()
|
||||
st1.waitCacheChange(5000)
|
||||
show_panel(st1)
|
||||
258
script/test/TestMergeCorrelation.py
Normal file
258
script/test/TestMergeCorrelation.py
Normal file
@@ -0,0 +1,258 @@
|
||||
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 getColorStdout
|
||||
import org.apache.commons.math3.stat.correlation.PearsonsCorrelation as PearsonsCorrelation
|
||||
try:
|
||||
import ch.psi.pshell.bs.StreamMerger as StreamMerger
|
||||
except:
|
||||
merge_camera_stream = False
|
||||
|
||||
TYPE_CHANNEL = 0
|
||||
TYPE_STREAM = 1
|
||||
TYPE_CAMERA= 2
|
||||
|
||||
INVOKE_PLOT_UPDATES = True
|
||||
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
dx = "SINEG01-DICT215:B1_CHARGE"
|
||||
#dx=get_beam_ok_channel(1)
|
||||
#dx = "SLG-LCAM-C042 x_rms"
|
||||
#dxtype = TYPE_CHANNEL
|
||||
dxtype = TYPE_STREAM
|
||||
#dxtype = TYPE_CAMERA
|
||||
|
||||
#dy = "SINDI01-RLLE-STA:SLAVE1-DLTIMER"
|
||||
#dy = "SLG-LCAM-C042 y_rms"
|
||||
#dytype = TYPE_CHANNEL
|
||||
dy = "SATES31-CAMS187-RIXS1_sp1 intensity"
|
||||
dytype = TYPE_CAMERA
|
||||
#dy=get_beam_ok_channel(2)
|
||||
#dytype = TYPE_STREAM
|
||||
|
||||
interval = 0.01
|
||||
window = 40
|
||||
p = plot(None)[0]
|
||||
linear_fit = True
|
||||
quadratic_fit = True
|
||||
merge_camera_stream = True
|
||||
print dx, dxtype
|
||||
print dy, dytype
|
||||
|
||||
corr = None
|
||||
pars_lin = None
|
||||
pars_quad = None
|
||||
pos_peak = None
|
||||
neg_peak = None
|
||||
stop_exec = None
|
||||
|
||||
|
||||
bs = TYPE_STREAM in [dxtype, dytype]
|
||||
|
||||
for s in p.getAllSeries():
|
||||
p.removeSeries(s)
|
||||
|
||||
_stream = None
|
||||
_camname = None
|
||||
|
||||
instances = []
|
||||
|
||||
def _get_device(d, type):
|
||||
global _stream, _camname
|
||||
egu = None
|
||||
if isinstance(d, basestring):
|
||||
name = d.strip()
|
||||
d = None
|
||||
try:
|
||||
d = get_device(name)
|
||||
if d is None:
|
||||
d = eval(name)
|
||||
#print name
|
||||
if d is not None:
|
||||
if not isinstance(r, Device):
|
||||
d = None
|
||||
else:
|
||||
try:
|
||||
egu = d.unit
|
||||
except:
|
||||
pass
|
||||
except:
|
||||
pass
|
||||
if d is None:
|
||||
offset = 0
|
||||
if type==TYPE_STREAM:
|
||||
if " " in name:
|
||||
tokens = name.split(" ")
|
||||
name = tokens[0]
|
||||
offset = int(tokens[1])
|
||||
if _stream == None:
|
||||
_stream = Stream("corr_stream", dispatcher)
|
||||
instances.append(_stream)
|
||||
#d = _stream.addScalar(name, name, int(interval*100), offset)
|
||||
_stream.addScalar(name, name, int(interval*100), offset)
|
||||
d=name
|
||||
elif type==TYPE_CHANNEL:
|
||||
d = Channel(name)
|
||||
d.set_monitored(True)
|
||||
elif type==TYPE_CAMERA:
|
||||
tokens = name.split(" ")
|
||||
_camname = tokens[0]
|
||||
field = tokens[1]
|
||||
return field, ""
|
||||
else:
|
||||
raise Exception("Invalid type: " + str(type))
|
||||
if not isinstance(d, basestring):
|
||||
instances.append(d)
|
||||
try:
|
||||
if type==TYPE_CHANNEL:
|
||||
egu = caget(name+".EGU",'s')
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
egu = d.unit
|
||||
except:
|
||||
pass
|
||||
return d, egu
|
||||
|
||||
dx, egux = _get_device(dx, dxtype)
|
||||
dy, eguy = _get_device(dy, dytype)
|
||||
|
||||
p.getAxis(p.AxisId.X).setLabel(egux)
|
||||
p.getAxis(p.AxisId.Y).setLabel(eguy)
|
||||
|
||||
merge = False
|
||||
try:
|
||||
if _stream != None:
|
||||
_stream.initialize()
|
||||
_stream.start(True)
|
||||
if _camname != None:
|
||||
shared = _camname.endswith("_sp1")
|
||||
print "Camera: " , _camname, " shared: ", shared
|
||||
cam_server.start(_camname, shared )
|
||||
|
||||
cam_server.stream.waitCacheChange(10000);
|
||||
_camera_stream = cam_server.stream
|
||||
|
||||
if merge_camera_stream:
|
||||
merge = ((dxtype==TYPE_CAMERA) and (dytype == TYPE_STREAM)) or ((dxtype==TYPE_STREAM) and (dytype == TYPE_CAMERA))
|
||||
if merge:
|
||||
_merger = StreamMerger("stream", _stream, cam_server.stream)
|
||||
_merger.monitored=True
|
||||
_merger.start()
|
||||
_camera_stream.setBufferCapacity(500)
|
||||
_stream.setBufferCapacity(500)
|
||||
instances.append(_merger)
|
||||
_merger.waitCacheChange(5000)
|
||||
#print _merger.readables
|
||||
_camera_stream=_merger
|
||||
_stream = _merger
|
||||
|
||||
if dxtype==TYPE_CAMERA:
|
||||
dx=_camera_stream.getChild(dx)
|
||||
if dytype==TYPE_CAMERA:
|
||||
dy=_camera_stream.getChild(dy)
|
||||
|
||||
if dxtype==TYPE_STREAM:
|
||||
dx=_stream.getChild(dx)
|
||||
if dytype==TYPE_STREAM:
|
||||
dy=_stream.getChild(dy)
|
||||
|
||||
p.addSeries(LinePlotSeries("Data"))
|
||||
sd=p.getSeries(0)
|
||||
sd.setLinesVisible(False)
|
||||
sd.setPointSize(4)
|
||||
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
if globals().has_key("marker"):
|
||||
p.removeMarker(marker)
|
||||
if globals().has_key("peak_marker"):
|
||||
p.removeMarker(peak_marker)
|
||||
marker=None
|
||||
peak_marker=None
|
||||
|
||||
while(True):
|
||||
#Sample and plot data
|
||||
if bs == True:
|
||||
_stream.waitCacheChange(10000)
|
||||
#bsdata = list(_stream.take().values())
|
||||
x=dx.read()
|
||||
y=dy.read()
|
||||
|
||||
def update():
|
||||
global marker, peak_marker, corr, pars_lin, pars_quad, pos_peak, neg_peak, stop_exec
|
||||
sd.appendData(x, y)
|
||||
if len(sd.x) > window:
|
||||
#Remove First Element
|
||||
sd.token.remove(0)
|
||||
ax = sd.x
|
||||
ay = sd.y
|
||||
if len(ax)>2:
|
||||
x1, x2 = min(ax), max(ax)
|
||||
res = (x2-x1)/100
|
||||
if x1!=x2:
|
||||
#Display correlation
|
||||
corr= PearsonsCorrelation().correlation(to_array(ax,'d'), to_array(ay,'d'))
|
||||
s = "Correlation=" + str(round(corr,4))
|
||||
#print s
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
if marker is not None:
|
||||
p.removeMarker(marker)
|
||||
marker = p.addMarker(x2+res, p.AxisId.X, s, p.getBackground())
|
||||
marker.setLabelPaint(getColorStdout())
|
||||
if linear_fit:
|
||||
#Calculate, print and plot linear fit
|
||||
pars_lin = (a0,a1) = fit_polynomial(ay, ax, 1)
|
||||
#print "Fit lin a1:" , a1, " a0:",a0
|
||||
y1 = poly(x1, pars_lin)
|
||||
y2 = poly(x2, pars_lin)
|
||||
plot_line(p, x1, y1, x2, y2, width = 2, color = Color.BLUE, name = "Fit Linear")
|
||||
if quadratic_fit:
|
||||
#Calculate, print and plot quadratic fit
|
||||
pars_quad = (a0,a1,a2) = fit_polynomial(ay, ax, 2)
|
||||
#print "Fit quad a2:" , a2, "a1:" , a1, " a0:",a0
|
||||
fitted_quad_function = PolynomialFunction(pars_quad)
|
||||
ax = frange(x1, x2, res, True)
|
||||
plot_function(p, fitted_quad_function, "Fit Quadratic", ax, color=Color.GREEN)
|
||||
|
||||
peak = None
|
||||
peaks = calculate_peaks(fitted_quad_function, x1, x2, positive=True)
|
||||
if len(peaks)>0:
|
||||
peak = peaks[0]
|
||||
pos_peak = str(round(peak,4))
|
||||
peak_str = "Positive peak: " + pos_peak
|
||||
else:
|
||||
peaks = calculate_peaks(fitted_quad_function, x1, x2, positive=False)
|
||||
if len(peaks)>0:
|
||||
peak = peaks[0]
|
||||
neg_peak = str(round(peak,4))
|
||||
peak_str = "Negative peak: " + neg_peak
|
||||
else:
|
||||
pos_peak = neg_peak = None
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
if peak_marker is not None:
|
||||
p.removeMarker(peak_marker)
|
||||
if peak is not None:
|
||||
peak_marker = p.addMarker(peak, p.AxisId.X, peak_str, Color(0,128,0))
|
||||
if INVOKE_PLOT_UPDATES:
|
||||
invoke(update, False)
|
||||
else:
|
||||
update()
|
||||
|
||||
if stop_exec == True:
|
||||
stop_exec = False
|
||||
break
|
||||
if bs != True:
|
||||
time.sleep(interval)
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
finally:
|
||||
for dev in instances:
|
||||
try:
|
||||
dev.close()
|
||||
except:
|
||||
pass
|
||||
if _camname != None:
|
||||
cam_server.stop()
|
||||
|
||||
43
script/test/TestMergePipeline.py
Normal file
43
script/test/TestMergePipeline.py
Normal file
@@ -0,0 +1,43 @@
|
||||
SCAN_TIME = 60
|
||||
#dispatcher.config.mappingIncomplete=ch.psi.pshell.bs.DispatcherConfig.Incomplete.drop
|
||||
st1 = Stream("st1", "tcp://sf-daqsync-08.psi.ch:9001", SocketType.SUB)
|
||||
#st1 = Stream("st1", "tcp://sf-daqsync-02.psi.ch:31852", SocketType.PULL)
|
||||
|
||||
st2 = Stream("st1", dispatcher)
|
||||
st2.addScalar("B1","SIN-CVME-TIFGUN-EVR0:BUNCH-1-OK", 1, 0)
|
||||
st2.addScalar("B2","SIN-CVME-TIFGUN-EVR0:BUNCH-2-OK", 1, 0)
|
||||
|
||||
pids={}
|
||||
count={}
|
||||
|
||||
def after_read(record, scan):
|
||||
global pids, count
|
||||
lastpid=pids.get(scan)
|
||||
pid=record[0]
|
||||
if lastpid:
|
||||
if (lastpid+1)!=pid:
|
||||
print scan.tag, "received ", pid, " - waiting for ", (lastpid + 1)
|
||||
count[scan]=count[scan]+(pid - (lastpid+1))
|
||||
else:
|
||||
count[scan]=0
|
||||
pids[scan] = pid
|
||||
|
||||
def scan (st, name):
|
||||
st.initialize()
|
||||
st.start()
|
||||
st.waitCacheChange(3000)
|
||||
try:
|
||||
r=bscan (st, records=-1, timeout=SCAN_TIME, save=False, keep=False, #
|
||||
enabled_plots=[st1,], \
|
||||
#manual_range_y=[17449000000, 17551000000],
|
||||
title=name, tag=name, after_read=after_read)
|
||||
v= st.getValues()
|
||||
return r
|
||||
finally:
|
||||
st.close()
|
||||
|
||||
r1,r2 = parallelize( (scan,(st1, "Merge")) , \
|
||||
(scan, (st2, "Dispatcher")))
|
||||
|
||||
for sc in count.keys():
|
||||
print sc.tag, count[sc]
|
||||
39
script/test/TestMergeStreams.py
Normal file
39
script/test/TestMergeStreams.py
Normal file
@@ -0,0 +1,39 @@
|
||||
#run ("Devices/StreamMerger")
|
||||
from ch.psi.pshell.bs import StreamMerger as StreamMerger
|
||||
|
||||
set_exec_pars(save=False)
|
||||
|
||||
add_device (Stream("st1", cam_server.getStream("test_furka"), SocketType.SUB), True)
|
||||
add_device (Stream("st2", cam_server.getStream("simulation_sp1"), SocketType.SUB), True)
|
||||
add_device(Stream("st3", dispatcher), force = True)
|
||||
st3.addScalar(get_beam_ok_channel(1))
|
||||
st3.addScalar(get_beam_ok_channel(2))
|
||||
add_device(Stream("st4","tcp://sf-daqsync-18.psi.ch:9000", SocketType.PULL), True)
|
||||
|
||||
#st1.setBufferCapacity(1000)
|
||||
#st2.setBufferCapacity(1000)
|
||||
st3.setBufferCapacity(2000)
|
||||
st4.setBufferCapacity(2000)
|
||||
|
||||
#add_device(StreamMerger("merger",st1, st2), True)
|
||||
add_device(StreamMerger("merger",st3, st4), True)
|
||||
|
||||
#merger.setPolling(10)
|
||||
merger.monitored=True
|
||||
merger.start()
|
||||
merger.waitCacheChange(-1)
|
||||
|
||||
for i in range (5):
|
||||
merger.waitCacheChange(-1)
|
||||
#plot(merger.values, name=merger.keys) #"Devices/StreamMerger"
|
||||
plot(merger.take().values(), name=merger.take().keys()) #ch.psi.pshell.bs.StreamMerger
|
||||
|
||||
|
||||
|
||||
#bscan(merger, 2000)
|
||||
bscan(merger, -1, 3.0)
|
||||
|
||||
#r = mscan(merger, merger.getReadables(), 2, save=False)
|
||||
r = mscan(merger, merger.getReadables(), timeout=1)
|
||||
|
||||
|
||||
83
script/test/TestScanAverager.py
Normal file
83
script/test/TestScanAverager.py
Normal file
@@ -0,0 +1,83 @@
|
||||
import ch.psi.pshell.epics.Positioner as Positioner
|
||||
|
||||
USE_SCREEN_PANEL = False
|
||||
|
||||
start = 85.0
|
||||
stop = 90.0
|
||||
step = 0.5
|
||||
nb = 3
|
||||
lat = 0.1
|
||||
disp = -0.387
|
||||
p0 = 7.1
|
||||
plt = plot(None, title="Output")[0]
|
||||
thr = 500
|
||||
|
||||
A = p0 / disp / 1e6
|
||||
B = p0
|
||||
|
||||
#Plot setup
|
||||
plt.clear()
|
||||
plt.removeMarker(None)
|
||||
plt.setStyle(plt.Style.ErrorY)
|
||||
plt.addSeries(LinePlotErrorSeries("Momentum", Color.red))
|
||||
plt.addSeries(LinePlotErrorSeries("Momentum Spread", Color.yellow, 2))
|
||||
plt.getAxis(plt.AxisId.X).setLabel("Gun Beam Phase (deg)")
|
||||
plt.getAxis(plt.AxisId.Y).setLabel("Momentum (MeV/c)")
|
||||
plt.getAxis(plt.AxisId.Y2).setLabel("Momentum Spread (MeV/c)")
|
||||
plt.setLegendVisible(True)
|
||||
|
||||
|
||||
phase = DummyPositioner("Gun Phase")
|
||||
camera_name = "simulation"
|
||||
|
||||
phase.config.minValue = -90.0
|
||||
phase.config.maxValue = 360.0
|
||||
phase.config.precision = 4
|
||||
phase.config.resolution = 0.5
|
||||
phase.config.rotation = True
|
||||
phase.config.save()
|
||||
phase.initialize()
|
||||
phase0 = phase.read() % 360
|
||||
|
||||
#Camera setup
|
||||
if USE_SCREEN_PANEL:
|
||||
cam_server.start(camera_name+"_sp1", True) # shared pipeline
|
||||
else:
|
||||
cam_server.start(camera_name) # generic pipeline
|
||||
wait_cam_server_message()
|
||||
x = cam_server.stream.getChild("x_center_of_mass")
|
||||
dx = cam_server.stream.getChild("x_rms")
|
||||
cam_server.setThreshold(thr)
|
||||
cam_server.setBackgroundSubtraction(False)
|
||||
|
||||
#Creating averagers
|
||||
x_averager = create_averager(x, nb, -1) # -1 event based, waits for the next value
|
||||
dx_averager = create_averager(dx, nb, -1)
|
||||
dx_averager.monitored = True # not blocking, will return last nb values
|
||||
|
||||
#Record callback: uptate of output plot
|
||||
def after_sample(record, scan):
|
||||
global A, B, plt
|
||||
x_pos_mean, x_pos_stdev = record[0].mean, record[0].stdev
|
||||
x_width_mean, x_width_stdev = record[1].mean, record[1].stdev
|
||||
p_mean, p_stdev = A * x_pos_mean + B, abs(A) * x_pos_stdev
|
||||
dp_mean, dp_stdev = abs(A) * x_width_mean, abs(A) * x_width_stdev
|
||||
phase = ((record.positions[0] + 90) % 360) - 90 if start < 0 else record.positions[0]
|
||||
plt.getSeries(0).appendData(phase, p_mean, p_stdev)
|
||||
plt.getSeries(1).appendData(phase, dp_mean, dp_stdev)
|
||||
|
||||
#The scan loop
|
||||
try:
|
||||
phase.write(start)
|
||||
time.sleep(1.0)
|
||||
r = lscan(phase, [x_averager, dx_averager], start, stop, step , latency=lat, after_read = after_sample)
|
||||
finally:
|
||||
phase.write(phase0)
|
||||
phase.close()
|
||||
cam_server.stop() # stops cam_server but does not close it cam_server is a global object
|
||||
|
||||
ph = r.getPositions(0)
|
||||
if start < 0:
|
||||
ph = [((val + 90) % 360) -90 for val in ph ]
|
||||
p = [A * val.mean + B for val in r.getReadable(0)]
|
||||
dp = [abs(A) * val.mean for val in r.getReadable(1)]
|
||||
@@ -30,7 +30,7 @@ s1 = Stream("s1", dispatcher)
|
||||
s1.setIncomplete("fill_null")
|
||||
for c in channels:
|
||||
s1.addScalar(c,c, 1, 0)
|
||||
s1.addScalar("SAROP11-PBPS117:INTENSITY","SAROP11-PBPS117:INTENSITY", 10, 0)
|
||||
#s1.addScalar("SAROP11-PBPS117:INTENSITY","SAROP11-PBPS117:INTENSITY", 10, 0)
|
||||
|
||||
add_device(s1, True)
|
||||
|
||||
@@ -43,4 +43,4 @@ for i in range(20):
|
||||
s1.waitCacheChange(5000)
|
||||
|
||||
|
||||
#ret = bscan (s1, 20, None, save=False)
|
||||
ret = bscan (s1, 20, None, save=False)
|
||||
15
script/test/TestStreamChannelConfig.py
Normal file
15
script/test/TestStreamChannelConfig.py
Normal file
@@ -0,0 +1,15 @@
|
||||
st1 = Stream("st1", dispatcher)
|
||||
#st1.addScalar("X1", "SINEG01-DBPM340:X1", 10, 0)
|
||||
#st1.addScalar("Y1", "SINEG01-DBPM340:Y1", 10, 0)
|
||||
#st1.addScalar("Q1", "SINEG01-DBPM340:Q1", 10, 0)
|
||||
#w,h = caget("SLG-LCAM-C103:WIDTH", 'i'), caget("SLG-LCAM-C103:HEIGHT", 'i')
|
||||
#st1.addMatrix("VC", "SLG-LCAM-C103:FPICTURE", 10, 0, w,h)
|
||||
st1.addScalar("i", "SINBC02-DSRM310:intensity", 1, 0)
|
||||
st1.addWaveform("x", "SINBC02-DSRM310:x_profile", 1, 0,2048)
|
||||
st1.addWaveform("y", "SINBC02-DSRM310:y_profile", 1, 0,2048)
|
||||
st1.initialize()
|
||||
st1.start()
|
||||
st1.waitCacheChange(3000)
|
||||
for c in st1.getChildren():
|
||||
|
||||
print c, c.shape, c.getType(None)
|
||||
2
script/test/blm_gain_adjustment.py
Executable file → Normal file
2
script/test/blm_gain_adjustment.py
Executable file → Normal file
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
MIN_GAIN, MAX_GAIN = 0.5, 1.1
|
||||
DECREMENT_STEP = 0.02
|
||||
INCREMENT_FACTOR = 0.5
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
st1 = Stream("st1", dispatcher)
|
||||
st1.addScalar("X1", "SINEG01-DBPM340:X1", 10, 0)
|
||||
st1.addScalar("Y1", "SINEG01-DBPM340:Y1", 10, 0)
|
||||
st1.addScalar("Q1", "SINEG01-DBPM340:Q1", 10, 0)
|
||||
w,h = caget("SLG-LCAM-C103:WIDTH", 'i'), caget("SLG-LCAM-C103:HEIGHT", 'i')
|
||||
st1.addMatrix("VCC", "SLG-LCAM-C103:FPICTURE", 10, 0, w,h)
|
||||
#st1.addScalar("X1", "SINEG01-DBPM340:X1", 10, 0)
|
||||
#st1.addScalar("Y1", "SINEG01-DBPM340:Y1", 10, 0)
|
||||
#st1.addScalar("Q1", "SINEG01-DBPM340:Q1", 10, 0)
|
||||
#w,h = caget("SLG-LCAM-C103:WIDTH", 'i'), caget("SLG-LCAM-C103:HEIGHT", 'i')
|
||||
#st1.addMatrix("VC", "SLG-LCAM-C103:FPICTURE", 10, 0, w,h)
|
||||
st1.addScalar("i", "SINBC02-DSRM310:intensity", 1, 0)
|
||||
st1.addWaveform("x", "SINBC02-DSRM310:x_profile", 1, 0,2048)
|
||||
st1.addWaveform("y", "SINBC02-DSRM310:y_profile", 1, 0,2048)
|
||||
st1.initialize()
|
||||
|
||||
try:
|
||||
bscan (st1, 3)
|
||||
bscan (st1, 20)
|
||||
finally:
|
||||
st1.close()
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
st1 = Stream("st1", dispatcher)
|
||||
add_device(st1, force = True)
|
||||
st1.addScalar("mcpu", "SINDI01-RLLE-STA:MASTER-CPUTIMER", 10, 0)
|
||||
st1.addScalar("scpu", "SINDI01-RLLE-STA:SLAVE1-CPUTIMER", 10, 0)
|
||||
#st1.addWaveform("phase", "SINXB01-RWVG100-DCP10:FOR-PHASE", 10, 0, 2048)
|
||||
#st1.addWaveform("amplt", "SINXB01-RWVG100-DCP10:FOR-AMPLT", 10, 0, 2048)
|
||||
#st1.addScalar("mcpu", "SINDI01-RLLE-STA:MASTER-CPUTIMER", 10, 0)
|
||||
#st1.addScalar("scpu", "SINDI01-RLLE-STA:SLAVE1-CPUTIMER", 10, 0)
|
||||
st1.addWaveform("phase", "SINXB01-RWVG100-DCP10:FOR-PHASE", 10, 0, 2048)
|
||||
st1.addWaveform("amplt", "SINXB01-RWVG100-DCP10:FOR-AMPLT", 10, 0, 2048)
|
||||
st1.initialize()
|
||||
st1.start(True)
|
||||
try:
|
||||
|
||||
19
script/test/bs5.py
Normal file
19
script/test/bs5.py
Normal file
@@ -0,0 +1,19 @@
|
||||
st1 = Stream("st1", dispatcher)
|
||||
add_device(st1, force = True)
|
||||
ch1="SINEG01-DICT210:GUN_CHARGE"
|
||||
ch1="SATMA02-RLLE-DSP:PHASE-VS"
|
||||
wv1="SARES11-SPEC125-M1.roi_signal_x_profile"
|
||||
s1=st1.addScalar(ch1,ch1, 1, 0)
|
||||
#w1=st1.addWaveform(wv1,wv1, 1, 0)
|
||||
|
||||
#st1.addWaveform("phase", "SINXB01-RWVG100-DCP10:FOR-PHASE", 10, 0, 2048)
|
||||
#st1.addWaveform("amplt", "SINXB01-RWVG100-DCP10:FOR-AMPLT", 10, 0, 2048)
|
||||
st1.initialize()
|
||||
st1.start(True)
|
||||
print st1.waitCacheChange(5000)
|
||||
try:
|
||||
bscan (st1, 10, title="bscan")
|
||||
#tscan (st1.getReadables(), 10, 1, title="tscan")
|
||||
x = st1.take()
|
||||
finally:
|
||||
st1.close()
|
||||
11
script/test/bs6.py
Normal file
11
script/test/bs6.py
Normal file
@@ -0,0 +1,11 @@
|
||||
st1 = Stream("st1", dispatcher)
|
||||
add_device(st1, force = True)
|
||||
st1.addScalar("SLAAR21-LCAM-C561:intensity")
|
||||
st1.addScalar("SLAAR21-LCAM-C561:x_fit_mean")
|
||||
st1.addScalar("SLAAR21-LCAM-C561:y_fit_mean")
|
||||
st1.initialize()
|
||||
st1.start(True)
|
||||
try:
|
||||
bscan (st1, 10, save=False)
|
||||
finally:
|
||||
st1.close()
|
||||
9
script/test/import_utils.py
Normal file
9
script/test/import_utils.py
Normal file
@@ -0,0 +1,9 @@
|
||||
import data_utils
|
||||
import ijutils
|
||||
import jeputils
|
||||
import mathutils
|
||||
import plotutils
|
||||
import sessions
|
||||
import rsync
|
||||
import statsutils
|
||||
import diffutils
|
||||
8
script/test/test_merge_disp_sp.py
Normal file
8
script/test/test_merge_disp_sp.py
Normal file
@@ -0,0 +1,8 @@
|
||||
url = cam_server.getStream("test_merge_disp_sp")
|
||||
print url
|
||||
add_device (Stream("st", url, SocketType.SUB), True)
|
||||
st.start()
|
||||
|
||||
show_panel(st)
|
||||
|
||||
bscan(st, 5)
|
||||
43
script/test/test_pipeline_db_errors.py
Normal file
43
script/test/test_pipeline_db_errors.py
Normal file
@@ -0,0 +1,43 @@
|
||||
NUM_PIDS = 10000
|
||||
CHANNEL = "SARES11-SPEC125-M2.roi_signal_x_profile"
|
||||
KEEP=True
|
||||
#CHANNEL = "SARES11-SPEC125-M1.roi_signal_x_profile"
|
||||
|
||||
st = Stream("pulse_id", dispatcher)
|
||||
st.addWaveform(c, c, 1, 0)
|
||||
st.initialize()
|
||||
st.start()
|
||||
st.waitCacheChange(10000) #Wait stream be running before starting scan
|
||||
|
||||
if KEEP:
|
||||
try:
|
||||
r=bscan(st, NUM_PIDS, display=False, save=False)
|
||||
finally:
|
||||
st.close()
|
||||
|
||||
pids=r.getReadable(0)
|
||||
plot(pids)
|
||||
|
||||
error_count = 0
|
||||
cur = pids[0]
|
||||
for i in range(len(pids)-1):
|
||||
if pids[i+1] != cur+1:
|
||||
print ("Error in " + str(i))
|
||||
error_count = error_count+1
|
||||
cur = pids[i+1]
|
||||
pid_range = (pids[-1]-pids[0]+1)
|
||||
else:
|
||||
first = None
|
||||
last = None
|
||||
def after_read(record, scan):
|
||||
global first, last
|
||||
last=record[0]
|
||||
if first is None: first = last
|
||||
try:
|
||||
r=bscan(st, NUM_PIDS, display=False, save=False, keep=False, after_read=after_read)
|
||||
finally:
|
||||
st.close()
|
||||
pid_range = (last-first+1)
|
||||
|
||||
missing = pid_range-NUM_PIDS
|
||||
print "TOTAL MISSING: ", missing, "/", pid_range, " RATE: ", (100.0*missing/pid_range), "%"
|
||||
Reference in New Issue
Block a user