This commit is contained in:
47
script/test/Averaging.py
Executable file
47
script/test/Averaging.py
Executable file
@@ -0,0 +1,47 @@
|
||||
###################################################################################################
|
||||
# Scan averaging sensor value, storing all values, mean and variance
|
||||
###################################################################################################
|
||||
|
||||
|
||||
class AnalogInput(ReadonlyRegisterBase):
|
||||
def doRead(self):
|
||||
time.sleep(0.001)
|
||||
self.val = to_array(self.calc(), 'd')
|
||||
return self.val
|
||||
|
||||
class SinusoidSample(AnalogInput):
|
||||
def calc(self):
|
||||
self.x = self.x + 0.1 if hasattr(self, 'x') else 0.0
|
||||
noise = (random.random() - 0.5) / 10.0
|
||||
return math.sin(self.x) + noise
|
||||
|
||||
class SinusoidTime(AnalogInput):
|
||||
def calc(self):
|
||||
noise = (random.random() - 0.5) / 10.0
|
||||
return math.sin(time.time()) + noise
|
||||
|
||||
class Const(AnalogInput):
|
||||
def calc(self):
|
||||
return 5.0
|
||||
|
||||
|
||||
add_device(SinusoidSample("ai1"), True)
|
||||
add_device(SinusoidTime("ai2"), True)
|
||||
add_device(Const("ai3"), True)
|
||||
|
||||
av1 = create_averager(ai3, 5, -0.1)
|
||||
av2 = create_averager(ai2, 5, 0)
|
||||
|
||||
#ai1.setPolling(10)
|
||||
#ai2.setPolling(10)
|
||||
ai3.setPolling(10)
|
||||
|
||||
|
||||
#av1.setMonitored(True)
|
||||
#av2.setMonitored(True)
|
||||
|
||||
sleep(0.5) #Give some time for the averager to fill its buffer, before first use
|
||||
#res= lscan(out, (ai1, av1, av1.samples, ai2, av2, av2.samples), 0, 40, 20, 0.1)
|
||||
res= lscan(out, ( av1, av1.samples, av2, av2.samples), 0, 40, 20, 0.1)
|
||||
|
||||
|
||||
67
script/test/CreateDevice.py
Normal file
67
script/test/CreateDevice.py
Normal file
@@ -0,0 +1,67 @@
|
||||
devices = create_device(["bs://Int32Waveform?waveform=true&samples=5&interval=-1&op=sum&integrate=true", ])
|
||||
try:
|
||||
mscan([], devices , 5, -1) #ar is ony updated on read
|
||||
#tscan( devices , 5, 0.1)
|
||||
finally:
|
||||
devices[0].source.parent.close()
|
||||
|
||||
|
||||
|
||||
|
||||
devices = create_device(["dev://arr","ca://TESTIOC:TESTWF2:MyWF", ]) #TODO: Why does not work?
|
||||
try:
|
||||
#mscan([], devices , 5, -1) #ar is ony updated on read
|
||||
tscan( devices , 5, 0.1)
|
||||
finally:
|
||||
devices[1].close()
|
||||
|
||||
|
||||
devices = create_device(["bs://PID", "bs://Int32Scalar", "bs://Int16Scalar", "dev://arr?op=sum"])
|
||||
try:
|
||||
mscan([], devices , 5, 5.0)
|
||||
finally:
|
||||
devices[0].parent.close()
|
||||
|
||||
|
||||
|
||||
|
||||
devices = create_device(["bs://Int32Scalar"])
|
||||
|
||||
try:
|
||||
mscan([], devices , 5, 5.0)
|
||||
finally:
|
||||
devices[0].parent.close()
|
||||
|
||||
|
||||
|
||||
device = create_device("bs://Int32Scalar?samples=3&interval=-1")
|
||||
|
||||
try:
|
||||
mscan([], device , 5, 5.0)
|
||||
finally:
|
||||
#device is averager, parent s scalar, parent.parent is stream
|
||||
device.parent.parent.close()
|
||||
|
||||
|
||||
|
||||
s = Stream("stream", dispatcher)
|
||||
devices = create_device(["bs://Int32Scalar", "bs://Int16Scalar"],s)
|
||||
|
||||
try:
|
||||
s.initialize()
|
||||
s.start()
|
||||
s.waitCacheChange(10000)
|
||||
mscan([], devices , 5, 5.0)
|
||||
finally:
|
||||
s.close()
|
||||
|
||||
|
||||
device = create_device('ca://TESTIOC:TESTSINUS:SinCalc?monitored=true')
|
||||
|
||||
mscan([], [device], 5, 5.0)
|
||||
|
||||
|
||||
|
||||
devices = create_device(['ca://TESTIOC:TESTSINUS:SinCalc?monitored=true', 'ca://TESTIOC:TESTCALCOUT:Output?monitored=true'])
|
||||
|
||||
mscan([], devices, 5, 5.0)
|
||||
21
script/test/DataLink.py
Normal file
21
script/test/DataLink.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import random
|
||||
|
||||
positioner = DummyPositioner("positioner")
|
||||
|
||||
class Sensor(Readable):
|
||||
def __init__(self):
|
||||
self.index = -1
|
||||
def read(self):
|
||||
#time.sleep(0.001)
|
||||
self.index +=1
|
||||
return self.index
|
||||
#noise = (random.random() - 0.5) / 10.0
|
||||
#return math.sin(time.time()) + noise
|
||||
sensor = Sensor()
|
||||
|
||||
|
||||
ret = lscan(positioner, sensor, scan_start, scan_stop, scan_steps, 0.01)
|
||||
av = mean(ret.getReadable(0))
|
||||
set_exec_pars(open=False)
|
||||
print ret.path
|
||||
set_return([av, ret.path + sensor.name])
|
||||
51
script/test/ExampleContinuousMultipass.py
Normal file
51
script/test/ExampleContinuousMultipass.py
Normal file
@@ -0,0 +1,51 @@
|
||||
|
||||
THETA_RANGE = (0.0, 5.0)
|
||||
THETA_STEP = 1.0
|
||||
PHI_RANGE = (-160.0, +160.0)
|
||||
PHI_STEP = 40.0
|
||||
|
||||
LATENCY = 0.0
|
||||
ZIGZAG = True
|
||||
ENDSCAN = False
|
||||
MOTORS = (motor)
|
||||
SENSORS = (sin, arr, out, inp, motor.readback)
|
||||
|
||||
|
||||
set_preference(Preference.PLOT_TYPES, {'Scienta spectrum':1})
|
||||
|
||||
# time per scienta acquisition in second
|
||||
scienta_time = 0.1
|
||||
print "scienta_time: ", scienta_time
|
||||
|
||||
|
||||
|
||||
# time for one theta scan in seconds
|
||||
THETA_NSTEPS = int((THETA_RANGE[1] - THETA_RANGE[0]) / THETA_STEP) + 1
|
||||
theta_time = scienta_time * THETA_NSTEPS
|
||||
print "theta_time: ", theta_time
|
||||
|
||||
PHI_NSTEPS = int((PHI_RANGE[1] - PHI_RANGE[0]) / PHI_STEP) + 1
|
||||
phi_positions = [PHI_RANGE[0] + PHI_STEP * i for i in range(PHI_NSTEPS)]
|
||||
print "phi_positions: ", phi_positions
|
||||
|
||||
def before_pass(pass_num, scan):
|
||||
print "Initializing pass ", pass_num
|
||||
phi = phi_positions[pass_num]
|
||||
inp.write(phi)
|
||||
print "phi = ", phi
|
||||
|
||||
#phi = phi_positions[record.index/THETA_NSTEPS]
|
||||
#ManipulatorPhi.write(phi)
|
||||
#print "phi = ", phi
|
||||
#ManipulatorPhi.waitValueInRange(phi, 1.0, 100)
|
||||
|
||||
try:
|
||||
|
||||
try:
|
||||
cscan(MOTORS, SENSORS, THETA_RANGE[0], THETA_RANGE[1], THETA_NSTEPS - 1, time=theta_time, passes = len(phi_positions), zigzag = ZIGZAG, before_pass=before_pass)
|
||||
except Exception:
|
||||
print sys.exc_info()[1]
|
||||
|
||||
finally:
|
||||
if ENDSCAN:
|
||||
after_scan()
|
||||
22
script/test/TEST12.xml
Executable file
22
script/test/TEST12.xml
Executable file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<configuration xmlns="http://www.psi.ch/~ebner/models/scan/1.0" numberOfExecution="1" failOnSensorError="true">
|
||||
<data format="txt" fileName="test"/>
|
||||
<scan>
|
||||
<dimension zigzag="false" dataGroup="false">
|
||||
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinearPositioner" name="TESTIOC:TESTCALCOUT:Input" settlingTime="0.1" type="Integer" id="ScanX">
|
||||
<start>6.0</start>
|
||||
<end>6.15</end>
|
||||
<stepSize>0.002</stepSize>
|
||||
</positioner>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ArrayDetector" arraySize="10" name="TESTIOC:TESTWF2:MyWF" id="Array"/>
|
||||
</dimension>
|
||||
<dimension>
|
||||
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinearPositioner" name="TESTIOC:TESTCALCOUT:Output" settlingTime="0.1" id="ScanY">
|
||||
<start>14.2</start>
|
||||
<end>14.02</end>
|
||||
<stepSize>0.002</stepSize>
|
||||
</positioner>
|
||||
</dimension>
|
||||
</scan>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="MatrixPlot" x="ScanX" y="ScanY" z="Array"/>
|
||||
</configuration>
|
||||
127
script/test/TestAlignmentScan.py
Executable file
127
script/test/TestAlignmentScan.py
Executable file
@@ -0,0 +1,127 @@
|
||||
# Tool to align the solenoid on the gun.
|
||||
# S. Bettoni, A. Gobbo, D. Voulot
|
||||
# 06/06/2016
|
||||
#Code ok with the GUI
|
||||
|
||||
# Procedure:
|
||||
# switch off all the magnets between the gun solenoid and the screen or BPM used for the measurement
|
||||
# change the current of the gun soleoid
|
||||
# look at the centroid position (BPM or screen) downstream of the gun.
|
||||
|
||||
import datetime
|
||||
|
||||
mode = "camtool" # "camtool", "bpm" or "direct"
|
||||
camera_name = "simulation"
|
||||
#camera_name = "SLG-LCAM-C041"
|
||||
use_good_region=False
|
||||
|
||||
if True: #get_exec_pars().source == CommandSource.ui:
|
||||
I1 = 95.0
|
||||
I2 = 100.0
|
||||
dI = 1.0
|
||||
settling_time = 0.1
|
||||
plot_image = False
|
||||
number_images = 3
|
||||
use_background = False
|
||||
multiple_background = True
|
||||
number_backgrounds = 3
|
||||
do_elog = False
|
||||
centroid_excursion_plot = True
|
||||
else:
|
||||
centroid_excursion_plot = False
|
||||
|
||||
#check_camtool()
|
||||
|
||||
#laser_was_on = is_laser_on()
|
||||
positioner = DummyPositioner("positioner")
|
||||
|
||||
original_gun_solenoid = positioner.read()
|
||||
|
||||
|
||||
multiple_background = multiple_background and use_background
|
||||
print "Parameters: ", I1, I2, dI, settling_time, plot_image, number_images, use_background, multiple_background, number_backgrounds
|
||||
|
||||
plot_name = datetime.datetime.fromtimestamp(time.time()).strftime('%H%M%S')
|
||||
|
||||
if mode == "camtool":
|
||||
if use_background:
|
||||
#laser_off()
|
||||
if not multiple_background:
|
||||
camtool.stop()
|
||||
camtool.grabBackground(camera_name, number_backgrounds)
|
||||
#camtool.stop()
|
||||
#camtool.startPipeline(camera_name, 0, use_background, None, 0.0, None)
|
||||
#camtool.startReceiver();
|
||||
camtool.start(camera_name, 0, use_background, None, 0.0, None)
|
||||
if camtool.value is not None: print "Started " , camtool.value.getTimestamp()
|
||||
wait_camtool_message()
|
||||
print "OK"
|
||||
else:
|
||||
if mode == "bpm":
|
||||
add_device(BpmStats("image_stats", camera_name), True)
|
||||
else:
|
||||
add_device(ImageStats(PsiCamera("image_stats", camera_name)), True)
|
||||
multiple_background = False
|
||||
use_background = False
|
||||
image_stats.setNumberOfImages(max(number_images,1))
|
||||
|
||||
#switch_off_magnets()
|
||||
|
||||
# add here gun phase setting see wiki page
|
||||
def before_sample():
|
||||
if mode == "camtool":
|
||||
if multiple_background:
|
||||
camtool.stop()
|
||||
camtool.grabBackground(camera_name, number_backgrounds)
|
||||
camtool.start(camera_name, 0, use_background, None, 0.0, None)
|
||||
#laser_on()
|
||||
wait_camtool_message(number_images) #Wait filing the averager cache
|
||||
else:
|
||||
image_stats.update()
|
||||
|
||||
def after_sample():
|
||||
if multiple_background:
|
||||
#laser_off()
|
||||
pass
|
||||
|
||||
r = None
|
||||
#if not multiple_background:
|
||||
# laser_on()
|
||||
|
||||
try:
|
||||
if mode == "camtool":
|
||||
print "Getting sensors"
|
||||
sensors = get_camtool_stats(number_images, good_region=use_good_region)
|
||||
print "Sensors ok"
|
||||
if plot_image:
|
||||
sensors.append(camtool.getDataMatrix())
|
||||
else:
|
||||
sensors = [image_stats.com_x_mean, image_stats.com_y_mean, image_stats.com_x_stdev, image_stats.com_y_stdev]
|
||||
r = lscan(positioner, sensors , I1, I2, dI, settling_time, before_read = before_sample, after_read = after_sample)
|
||||
finally:
|
||||
if mode == "camtool": camtool.stop()
|
||||
#pass
|
||||
|
||||
positioner.write(original_gun_solenoid)
|
||||
#if laser_was_on:
|
||||
# laser_on()
|
||||
#else:
|
||||
# laser_off()
|
||||
|
||||
|
||||
# take the result of the scan and generate convex hull plot
|
||||
if centroid_excursion_plot:
|
||||
(hx,hy)=add_convex_hull_plot ("Centroid excursion", r.getReadable(0),r.getReadable(1), plot_name)
|
||||
else:
|
||||
(hx,hy)= convex_hull(x=r.getReadable(0), y=r.getReadable(1))
|
||||
hx.append(hx[0]); hy.append(hy[0])
|
||||
|
||||
# save the entry in the logbook
|
||||
gsa_log_msg = "Data file: " + get_exec_pars().path
|
||||
gsa_log_msg = gsa_log_msg + "\nImages: " + str(number_images)
|
||||
gsa_log_msg = gsa_log_msg + "\nBackground: enabled=" + str(use_background) + " multiple=" + str(multiple_background) + " number=" + str(number_backgrounds)
|
||||
gsa_log_msg = gsa_log_msg + "\n\n" + r.print()
|
||||
if do_elog:
|
||||
elog("Gun solenoid current scan", gsa_log_msg , get_plot_snapshots())
|
||||
|
||||
set_return([r, hx, hy])
|
||||
9
script/test/TestAveragePlot.py
Executable file
9
script/test/TestAveragePlot.py
Executable file
@@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
#av1 = create_averager(sin, 5, -1)
|
||||
|
||||
r= lscan(out, av1 , 0, 40, 10, 0.01)
|
||||
plot(r.getReadable(0), title = "Data" )
|
||||
to_array(r.getReadable(0),'d')
|
||||
|
||||
|
||||
37
script/test/TestBsMonitorScan.py
Executable file
37
script/test/TestBsMonitorScan.py
Executable file
@@ -0,0 +1,37 @@
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
st1 = Stream("st1", dispatcher)
|
||||
|
||||
#Adding channels to that stream
|
||||
s1=st1.addScalar("Int8Scalar", "Int8Scalar", 1, 0)
|
||||
#s2=st1.addScalar("Float64Scalar", "Float64Scalar", 1, 0)
|
||||
#w1=st1.addWaveform("Int32Waveform", "Int32Waveform", 1, 0)
|
||||
#mt1=st1.addMatrix("Int16Waveform", "Int16Waveform", 10, 0, 64, 32)
|
||||
st1.initialize()
|
||||
st1.start()
|
||||
|
||||
|
||||
|
||||
def after(rec, scan):
|
||||
path = get_exec_pars().group+"/TimeIOC"
|
||||
pathpc = get_exec_pars().group+"/TimePC"
|
||||
if rec.index==0:
|
||||
create_dataset(path, 's')
|
||||
create_dataset(pathpc, 's')
|
||||
nanos = st1.timestampNanos
|
||||
dt = datetime.fromtimestamp(nanos/1e9)
|
||||
time_str = str(dt).ljust(26,'0') + str(int(nanos % 1000)).zfill(3)
|
||||
append_dataset(path, time_str , type = 's')
|
||||
|
||||
append_dataset(pathpc, str(datetime.fromtimestamp(time.time())) , type = 's')
|
||||
|
||||
#bscan (st1, 10) #Sampling 10 elements
|
||||
|
||||
#tscan (st1.getReadables(), 10 , 0.2)
|
||||
|
||||
|
||||
|
||||
mscan (st1, st1.getReadables(), -1, 3.0, after_read = after)
|
||||
|
||||
st1.close()
|
||||
3
script/test/TestBsread2.py
Executable file
3
script/test/TestBsread2.py
Executable file
@@ -0,0 +1,3 @@
|
||||
while(True):
|
||||
print bsget(["Int32Scalar", "Int8Scalar"])
|
||||
time.sleep(0.01)
|
||||
41
script/test/TestConsinuousMscan.py
Normal file
41
script/test/TestConsinuousMscan.py
Normal file
@@ -0,0 +1,41 @@
|
||||
SCAN_RANGE = [0.0, 1.0]
|
||||
SCAN_TIME = 10.0
|
||||
|
||||
STREAM_SCALARS = ['Int8Scalar', 'Float64Scalar']
|
||||
STREAM_WAVEFORMS = ['Int32Waveform']
|
||||
EPICS_CHANELS = ['TESTIOC:TESTCALCOUT:Output']
|
||||
|
||||
|
||||
stream = Stream("PID", dispatcher)
|
||||
|
||||
modulo, offset = 10,0
|
||||
for name in STREAM_SCALARS:
|
||||
stream.addScalar(name, name, modulo, offset )
|
||||
plot_types = {}
|
||||
for name in STREAM_WAVEFORMS:
|
||||
stream.addWaveform(name, name, modulo, offset )
|
||||
plot_types[name]=1
|
||||
|
||||
|
||||
stream.initialize()
|
||||
stream.start()
|
||||
|
||||
velocity = abs(float(SCAN_RANGE[1]-SCAN_RANGE[0])) / SCAN_TIME
|
||||
motor.setSpeed(motor.defaultSpeed)
|
||||
motor.move(float(SCAN_RANGE[0]))
|
||||
motor.setSpeed(float(velocity) )
|
||||
|
||||
channels = []
|
||||
for name in EPICS_CHANELS:
|
||||
channel = Channel(name, 'd')
|
||||
channel.monitored= True
|
||||
channels.append(channel)
|
||||
|
||||
|
||||
stream.waitCacheChange(10000)
|
||||
motor.moveAsync(float(SCAN_RANGE[1]))
|
||||
try:
|
||||
mscan(stream, stream.getReadables() + channels, -1, SCAN_TIME, plot_types=plot_types)
|
||||
finally:
|
||||
stream.close()
|
||||
motor.setSpeed(motor.defaultSpeed)
|
||||
127
script/test/TestFitProfile.py
Executable file
127
script/test/TestFitProfile.py
Executable file
@@ -0,0 +1,127 @@
|
||||
###################################################################################################
|
||||
# Least square optimization problem to fit a gaussian with offset
|
||||
###################################################################################################
|
||||
|
||||
from mathutils import *
|
||||
from plotutils import *
|
||||
|
||||
run("CPython/GaussFit_wrapper")
|
||||
###################################################################################################
|
||||
#Fitting the gaussian function with offset f(x) = a + b * exp(-(pow((x - c), 2) / (2 * pow(d, 2))))
|
||||
###################################################################################################
|
||||
|
||||
camtool.start("Simulation")
|
||||
|
||||
time.sleep(2.0)
|
||||
xdata =camtool.getValue("x_axis")
|
||||
ydata = camtool.getValue("x_profile")
|
||||
|
||||
|
||||
p = plot(ydata, "Data" , xdata)[0]
|
||||
p.setLegendVisible(True)
|
||||
|
||||
def fit_gaussian_offset(y, x, start_point = None, weights = None):
|
||||
"""Fits data into a gaussian with offset.
|
||||
f(x) = a + b * exp(-(pow((x - c), 2) / (2 * pow(d, 2))))
|
||||
|
||||
Args:
|
||||
x(float array or list): observed points x
|
||||
y(float array or list): observed points y
|
||||
start_point(optional tuple of float): initial parameters (normalization, mean, sigma)
|
||||
weights(optional float array or list): weight for each observed point
|
||||
Returns:
|
||||
Tuples of gaussian parameters: (offset, normalization, mean, sigma)
|
||||
"""
|
||||
|
||||
# For normalised gauss curve sigma=1/(amp*sqrt(2*pi))
|
||||
if start_point is None:
|
||||
off = min(y) # good enough starting point for offset
|
||||
com = x[y.index(max(y))]
|
||||
amp = max(y) - off
|
||||
sigma = trapz([v-off for v in y], x) / (amp*math.sqrt(2*math.pi))
|
||||
start_point = [off, amp, com , sigma]
|
||||
|
||||
class Model(MultivariateJacobianFunction):
|
||||
def value(self, variables):
|
||||
value = ArrayRealVector(len(x))
|
||||
jacobian = Array2DRowRealMatrix(len(x), 4)
|
||||
for i in range(len(x)):
|
||||
(a,b,c,d) = (variables.getEntry(0), variables.getEntry(1), variables.getEntry(2), variables.getEntry(3))
|
||||
v = math.exp(-(math.pow((x[i] - c), 2) / (2 * math.pow(d, 2))))
|
||||
model = a + b * v
|
||||
value.setEntry(i, model)
|
||||
jacobian.setEntry(i, 0, 1) # derivative with respect to p0 = a
|
||||
jacobian.setEntry(i, 1, v) # derivative with respect to p1 = b
|
||||
v2 = b*v*((x[i] - c)/math.pow(d, 2))
|
||||
jacobian.setEntry(i, 2, v2) # derivative with respect to p2 = c
|
||||
jacobian.setEntry(i, 3, v2*(x[i] - c)/d ) # derivative with respect to p3 = d
|
||||
return Pair(value, jacobian)
|
||||
|
||||
model = Model()
|
||||
target = [v for v in y] #the target is to have all points at the positios
|
||||
(parameters, residuals, rms, evals, iters) = optimize_least_squares(model, target, start_point, weights)
|
||||
return parameters
|
||||
|
||||
|
||||
|
||||
start = time.time()
|
||||
(off, amp, com, sigma) = fit_gaussian_offset(ydata, xdata, None, None)
|
||||
f = Gaussian(amp, com, sigma)
|
||||
gauss = [f.value(i)+off for i in xdata]
|
||||
s = LinePlotSeries("Fit with offset")
|
||||
p.addSeries(s)
|
||||
s.setData(to_array(xdata,'d'), to_array(gauss,'d'))
|
||||
error=0
|
||||
for i in range(len(ydata)) : error += abs(ydata[i]-gauss[i])
|
||||
print "\nFit with offset:\off: ", off , " amp: ", amp, " com: ", com, " sigma: ", sigma, " error: ", error
|
||||
print "Time: ",(time.time()-start)
|
||||
|
||||
start = time.time()
|
||||
(amp, com, sigma) = fit_gaussian(ydata, xdata, None, None)
|
||||
f = Gaussian(amp, com, sigma)
|
||||
gauss = [f.value(i) for i in xdata]
|
||||
s = LinePlotSeries("Normal Fit")
|
||||
p.addSeries(s)
|
||||
s.setData(to_array(xdata,'d'), to_array(gauss,'d'))
|
||||
error=0
|
||||
for i in range(len(ydata)) : error += abs(ydata[i]-gauss[i])
|
||||
print "\nNormal fit:\amp: ", amp, " com: ", com, sigma, " error: ", error, " time: ", (time.time()-start)
|
||||
|
||||
start = time.time()
|
||||
[off, amp, com, sigma] = gfitoff(xdata, ydata, off=None, amp=None, com=None, sigma=None)
|
||||
from mathutils import Gaussian
|
||||
g = Gaussian(amp, com, sigma)
|
||||
gauss = [g.value(i)+off for i in xdata]
|
||||
s = LinePlotSeries("CPython Fit")
|
||||
p.addSeries(s)
|
||||
s.setData(to_array(xdata,'d'), to_array(gauss,'d'))
|
||||
error=0
|
||||
for i in range(len(ydata)) : error += abs(ydata[i]-gauss[i])
|
||||
print "\nCPython Fit:\n", off , " amp: ", amp, " com: ", com, " sigma: ", sigma, error, " time: ", (time.time()-start)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
off = min(ydata) # good enough starting point for offset
|
||||
com = xdata[ydata.index(max(ydata))]
|
||||
amp = max(ydata) - off
|
||||
sigma = trapz([v-off for v in ydata], xdata) / (amp*math.sqrt(2*math.pi))
|
||||
g = Gaussian(amp, com, sigma)
|
||||
gauss = [g.value(i)+off for i in xdata]
|
||||
s = LinePlotSeries("Start Point")
|
||||
p.addSeries(s)
|
||||
s.setData(to_array(xdata,'d'), to_array(gauss,'d'))
|
||||
error=0
|
||||
for i in range(len(ydata)) : error += abs(ydata[i]-gauss[i])
|
||||
print "\nStartPoint:\n", off , " amp: ", amp, " com: ", com, " sigma: ", sigma, error, " time: ", (time.time()-start)
|
||||
|
||||
|
||||
fit_point_list = create_fit_point_list(ydata, xdata, None)
|
||||
(amp, com, sigma) = GaussianCurveFitter.ParameterGuesser(fit_point_list).guess().tolist()
|
||||
gauss = [g.value(i)+off for i in xdata]
|
||||
s = LinePlotSeries("Default SP")
|
||||
p.addSeries(s)
|
||||
s.setData(to_array(xdata,'d'), to_array(gauss,'d'))
|
||||
error=0
|
||||
for i in range(len(ydata)) : error += abs(ydata[i]-gauss[i])
|
||||
15
script/test/TestMonitorCallbackBug.py
Normal file
15
script/test/TestMonitorCallbackBug.py
Normal file
@@ -0,0 +1,15 @@
|
||||
class Listener (DeviceListener):
|
||||
def onValueChanged(self, device, value, former):
|
||||
sin.removeListener(self)
|
||||
print "--"
|
||||
try:
|
||||
print out.read()
|
||||
print "Ok"
|
||||
except:
|
||||
print sys.exc_info()[1]
|
||||
|
||||
out.setTrustedMonitor(False)
|
||||
sin.addListener(Listener())
|
||||
|
||||
|
||||
c = create_channel("TESTIOC:TESTCALCOUT:Input")
|
||||
2
script/test/TestMscan.py
Normal file
2
script/test/TestMscan.py
Normal file
@@ -0,0 +1,2 @@
|
||||
#mscan([], [create_averager('bs://Int32Scalar', 3, -1.0, None, True)], points=10, timeout=-1, name='stream')
|
||||
mscan([], ['bs://Int32Scalar?samples=-3&interval=-1'], points=10, timeout=-1, name='stream')
|
||||
33
script/test/TestMultiCycles.py
Executable file
33
script/test/TestMultiCycles.py
Executable file
@@ -0,0 +1,33 @@
|
||||
scan_complete=False
|
||||
scan_result = None
|
||||
|
||||
def check_end_scan(record, scan):
|
||||
global scan_complete, scan_result
|
||||
if record.index>=50:
|
||||
print "Data aquisition completed"
|
||||
scan.abort()
|
||||
scan_complete=True
|
||||
record.cancel()
|
||||
scan_result = scan.result
|
||||
elif (record.index>0) and (record.index % 10 == 0):
|
||||
get_context().dataManager.splitScanData(scan)
|
||||
|
||||
|
||||
xxx=None
|
||||
def do_scan():
|
||||
global scan_complete, scan_result
|
||||
scan_complete=False
|
||||
try:
|
||||
mscan (sin, [sin,arr], -1, -1, after_read = check_end_scan, range="auto")
|
||||
except:
|
||||
if not scan_complete:
|
||||
raise
|
||||
return scan_result
|
||||
|
||||
|
||||
set_exec_pars(group="x_{count}", reset=True);
|
||||
r1 =do_scan()
|
||||
|
||||
#set_exec_pars(group="y_{count}", reset=True)
|
||||
#r2 = do_scan()
|
||||
|
||||
23
script/test/TestNested2.py
Normal file
23
script/test/TestNested2.py
Normal file
@@ -0,0 +1,23 @@
|
||||
index=0
|
||||
|
||||
set_exec_pars(tag="scan {count} {count}%02d {index}%04d")
|
||||
def calc():
|
||||
global index
|
||||
index += 1
|
||||
ret= tscan(sin, 10, 0.1)
|
||||
#ret= tscan(sin, 10, 0.1)
|
||||
v = max(ret.getReadable(0))
|
||||
return float(v)
|
||||
|
||||
|
||||
class PseudoDev(Readable):
|
||||
def read(self):
|
||||
return calc()
|
||||
|
||||
d= PseudoDev()
|
||||
|
||||
|
||||
ret= lscan(inp, (d), 0, 40, 5, 0.2)
|
||||
#ret= lscan(inp, (d), 0, 40, 5, 0.2)
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
plot([1,2,3,4,5,4,3,2,1], "test")
|
||||
attachments = get_plot_snapshots()
|
||||
print attachments
|
||||
start = 0
|
||||
end = 10.0
|
||||
steps = 10
|
||||
|
||||
|
||||
r = lscan (out, sin, start, end, steps, 0.2)
|
||||
|
||||
4
script/test/TestPlot2.py
Normal file
4
script/test/TestPlot2.py
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
plot([1,2,3,4,5,4,3,2,1])
|
||||
|
||||
set_return (get_plot_snapshots())
|
||||
@@ -1,7 +1,39 @@
|
||||
|
||||
prosilica.writeParameter("FrameStartTriggerMode","Freerun")
|
||||
prosilica.writeParameter("PixelFormat","Bayer8" )
|
||||
prosilica.writeParameter("GainValue",0)
|
||||
prosilica.writeParameter("ExposureValue",15000)
|
||||
prosilica.writeParameter("FrameRate",5.000)
|
||||
|
||||
|
||||
while (True):
|
||||
prosilica.stop()
|
||||
time.sleep(0.1)
|
||||
prosilica.start()
|
||||
time.sleep(0.5)
|
||||
|
||||
|
||||
print prosilica.readParameter("AcquisitionMode")
|
||||
print prosilica.readParameter("AcquisitionFrameCount")
|
||||
print prosilica.readParameter("FrameRate")
|
||||
|
||||
|
||||
print prosilica.readParameterRange("AcquisitionMode")
|
||||
print prosilica.readParameterRange("AcquisitionFrameCount")
|
||||
print prosilica.readParameterRange("FrameRate")
|
||||
|
||||
|
||||
print prosilica.writeParameter("AcquisitionMode", "SingleFrame")
|
||||
print prosilica.writeParameter("AcquisitionFrameCount", 2)
|
||||
print prosilica.writeParameter("FrameRate", 6.0)
|
||||
|
||||
|
||||
print prosilica.readParameter("AcquisitionMode")
|
||||
print prosilica.readParameter("AcquisitionFrameCount")
|
||||
print prosilica.readParameter("FrameRate")
|
||||
|
||||
|
||||
|
||||
print prosilica.writeParameter("AcquisitionMode", "Continuous")
|
||||
print prosilica.writeParameter("AcquisitionFrameCount", 1)
|
||||
print prosilica.writeParameter("FrameRate", 5.0)
|
||||
|
||||
|
||||
print prosilica.readParameter("AcquisitionMode")
|
||||
print prosilica.readParameter("AcquisitionFrameCount")
|
||||
print prosilica.readParameter("FrameRate")
|
||||
|
||||
8
script/test/TestPseudo.py
Executable file
8
script/test/TestPseudo.py
Executable file
@@ -0,0 +1,8 @@
|
||||
class PseudoDevice(ReadonlyRegisterBase):
|
||||
def doRead(self):
|
||||
return sin.take()/take.read()
|
||||
|
||||
pd = PseudoDevice()
|
||||
pd.triggers = [sin, out]
|
||||
pd.initialize()
|
||||
add_device(pd, True)
|
||||
39
script/test/TestRecordNull.py
Executable file
39
script/test/TestRecordNull.py
Executable file
@@ -0,0 +1,39 @@
|
||||
index = 0
|
||||
class AnalogInput(ReadonlyRegisterBase):
|
||||
def doRead(self):
|
||||
global index
|
||||
index = index+1
|
||||
if index<5:
|
||||
return None
|
||||
return sin.read()
|
||||
|
||||
class Waveform(ReadonlyRegisterBase, ReadonlyRegisterArray):
|
||||
def doRead(self):
|
||||
global index
|
||||
index = index+1
|
||||
if index<5:
|
||||
return None
|
||||
return arr.read()
|
||||
|
||||
def getSize(self):
|
||||
return arr.size
|
||||
|
||||
class Image(ReadonlyRegisterBase, ReadonlyRegisterMatrix):
|
||||
def doRead(self):
|
||||
global index
|
||||
index = index+1
|
||||
if index<5:
|
||||
return None
|
||||
return matrix.read()
|
||||
|
||||
def getWidth(self):
|
||||
return matrix.width
|
||||
|
||||
def getHeight(self):
|
||||
return matrix.height
|
||||
|
||||
add_device(AnalogInput("tst"), True)
|
||||
add_device(Waveform("tst2"), True)
|
||||
add_device(Image("tst3"), True)
|
||||
|
||||
tscan(tst3, 10, 0.1)
|
||||
@@ -1,5 +1,4 @@
|
||||
print args
|
||||
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
msg = None
|
||||
start = 0
|
||||
|
||||
13
script/test/TestScanControlledVar.py
Executable file
13
script/test/TestScanControlledVar.py
Executable file
@@ -0,0 +1,13 @@
|
||||
import ch.psi.pshell.epics.ControlledVariable as ControlledVariable
|
||||
|
||||
phase = ControlledVariable("Phase", "TESTIOC:TESTCALCOUT:Input", "TESTIOC:TESTSINUS:SinCalc")
|
||||
phase.config.minValue = 0
|
||||
phase.config.maxValue = 1000
|
||||
phase.config.resolution = 1
|
||||
phase.initialize()
|
||||
|
||||
try:
|
||||
r = lscan(phase, sin, 0, 100, 10, latency=0.5)
|
||||
finally:
|
||||
phase.close()
|
||||
#st.close()
|
||||
44
script/test/TestTypeTimestampe.py
Normal file
44
script/test/TestTypeTimestampe.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
|
||||
c = ChannelDouble("c","TESTIOC:TESTCALCOUT:Input", -1, False)
|
||||
c.initialize()
|
||||
c.write(1)
|
||||
c = ChannelDouble("c","TESTIOC:TESTCALCOUT:Input", -1, True)
|
||||
c.initialize()
|
||||
c.write(2)
|
||||
|
||||
|
||||
|
||||
import ch.psi.pshell.epics.ChannelByte as ChannelByte
|
||||
c = ChannelByte("c","TESTIOC:TESTCALCOUT:Input", False)
|
||||
c.initialize()
|
||||
c.write(3.0)
|
||||
c = ChannelByte("c","TESTIOC:TESTCALCOUT:Input", True)
|
||||
c.initialize()
|
||||
c.write(4.0)
|
||||
|
||||
|
||||
import ch.psi.pshell.epics.ChannelInteger as ChannelInteger
|
||||
c = ChannelInteger("c","TESTIOC:TESTCALCOUT:Input", False)
|
||||
c.initialize()
|
||||
c.write(5.0)
|
||||
c = ChannelInteger("c","TESTIOC:TESTCALCOUT:Input", True)
|
||||
c.initialize()
|
||||
c.write(6.0)
|
||||
|
||||
|
||||
import ch.psi.pshell.epics.ChannelShort as ChannelShort
|
||||
c = ChannelShort("c","TESTIOC:TESTCALCOUT:Input", False)
|
||||
c.initialize()
|
||||
c.write(7.0)
|
||||
c = ChannelShort("c","TESTIOC:TESTCALCOUT:Input", True)
|
||||
c.initialize()
|
||||
c.write(8.0)
|
||||
|
||||
|
||||
import ch.psi.pshell.epics.ChannelDouble as ChannelFloat
|
||||
c = ChannelFloat("c","TESTIOC:TESTCALCOUT:Input", -1, False)
|
||||
c.initialize()
|
||||
c.write(9)
|
||||
c = ChannelFloat("c","TESTIOC:TESTCALCOUT:Input", -1, True)
|
||||
c.initialize()
|
||||
c.write(10)
|
||||
7
script/test/TestWaitChange.py
Executable file
7
script/test/TestWaitChange.py
Executable file
@@ -0,0 +1,7 @@
|
||||
start = time.time()
|
||||
for i in range(20):
|
||||
#sin.waitTimestampChange(0)
|
||||
sin.waitValueChange(0)
|
||||
print sin.take()
|
||||
|
||||
print "TIME: " , time.time() - start
|
||||
29
script/test/TestWireScan.py
Normal file
29
script/test/TestWireScan.py
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
p = "2018_03/20180312/20180312_231754_WireScan.h5|/x_000"
|
||||
p = "2018_03/20180312/20180312_233008_WireScan.h5|/x_000"
|
||||
p = "2018_03/20180312/20180312_234230_WireScan.h5|/x_000"
|
||||
|
||||
def gd(i):
|
||||
global p
|
||||
return load_data(p+str(i)+"/blm1")
|
||||
|
||||
def gt(i):
|
||||
global p
|
||||
return load_data(p+str(i)+"/Time")
|
||||
def gp(i):
|
||||
global p
|
||||
return load_data(p+str(i)+"/w_pos")
|
||||
|
||||
plot([gd(1), gd(2), gd(3), gd(4), gd(5), gd(6)], ["1", "2", "3", "4", "5", "6"], xdata = [gp(1), gp(2), gp(3), gp(4), gp(5), gp(6)])
|
||||
|
||||
x,y = to_array(gd(1),'d'), to_array(gp(1),'d')
|
||||
print call_jep(MODULE, "profile_rms_stats", [to_npa(x), to_npa(y), 0, 3.5])
|
||||
|
||||
run("Diagnostics/sig_process_wrapper")
|
||||
[rms_com, rms_sigma] = profile_rms_stats(x,y,noise_std=0, n_sigma=3.5)
|
||||
print [rms_com, rms_sigma]
|
||||
for i in [1,2,3,4,5,6]:
|
||||
print profile_rms_stats(gd(i), gp(i),noise_std=0, n_sigma=3.5)
|
||||
|
||||
|
||||
|
||||
269
script/test/WireScanMock.py
Normal file
269
script/test/WireScanMock.py
Normal file
@@ -0,0 +1,269 @@
|
||||
import traceback
|
||||
|
||||
is_panel = get_exec_pars().source != CommandSource.ui #Must be checked before callin "run"
|
||||
|
||||
#set_exec_pars(provider="txt")
|
||||
|
||||
BPM_SENSORS = [("x","X1"), ("y","Y1"), ("q","Q1")] #(logic name sufix, channel sufix)
|
||||
|
||||
#Paramter parsing
|
||||
prefix = args[0] if is_panel else "S30CB09-DWSC440" #"SINDI01-DWSC090"
|
||||
scan_type = args[1] if is_panel else "X1"
|
||||
scan_range = args[2] if is_panel else [-200, 200, -200, 200]
|
||||
cycles = args[3] if is_panel else 3
|
||||
velocity = args[4] if is_panel else 200
|
||||
bpms = args[5] if is_panel else ["BPM1", "BPM2"]
|
||||
blms = args[6] if is_panel else ["BLM1", "BLM2"]
|
||||
bkgrd = args[7] if is_panel else 10
|
||||
plt = args[8] if is_panel else plot(None, title = "Wire Scan")[0]
|
||||
save_raw = args[9] if is_panel else False
|
||||
do_elog = False if (plt is None) else (True if is_panel else False)
|
||||
print "WireScan parameters: ", prefix, scan_type, scan_range, cycles, velocity, bpms, blms, bkgrd
|
||||
|
||||
print "---"
|
||||
print get_exec_pars().source
|
||||
print is_panel
|
||||
print plt
|
||||
|
||||
#Plot setup
|
||||
if plt is not None:
|
||||
plt.clear()
|
||||
plt.removeMarker(None)
|
||||
plt.getAxis(plt.AxisId.X).setLabel("Position");
|
||||
plt.getAxis(plt.AxisId.Y).setLabel("");
|
||||
plt.getAxis(plt.AxisId.Y2).setLabel("");
|
||||
plt.setLegendVisible(True);
|
||||
snapshots = []
|
||||
|
||||
#Creating WireScanner object
|
||||
print "Creating scanner..."
|
||||
scanner = DummyPositioner("scanner")
|
||||
|
||||
|
||||
class Sensor(ReadonlyRegisterBase):
|
||||
def __init__(self, name):
|
||||
ReadonlyRegisterBase.__init__(self, name)
|
||||
self.index = -1
|
||||
self.initialize()
|
||||
|
||||
def doRead(self):
|
||||
self.index +=1
|
||||
return float(self.index)
|
||||
|
||||
|
||||
#Lis of stream channels
|
||||
channels = [Sensor("m_pos"),
|
||||
Sensor("cur_cycle"),
|
||||
Sensor("scanning")]
|
||||
for i in range (len(blms)):
|
||||
channels.append (Sensor("blm" + str(i+1)))
|
||||
if plt is not None:
|
||||
series = LinePlotSeries(blms[i], None, min(i+1, 2))
|
||||
plt.addSeries(series)
|
||||
series.setLinesVisible(False)
|
||||
series.setPointSize(2)
|
||||
if save_raw:
|
||||
channels.append (Sensor("blm" + str(i+1) + "_raw"))
|
||||
for i in range (len(bpms)):
|
||||
for sensor in BPM_SENSORS:
|
||||
channels.append (Sensor("bpm" + str(i+1) + "_" + sensor[0]))
|
||||
|
||||
#Metadata
|
||||
print "1"
|
||||
set_attribute("/", "Wire Scanner", prefix)
|
||||
set_attribute("/", "Scan Type", scan_type)
|
||||
set_attribute("/", "Range", scan_range)
|
||||
set_attribute("/", "Cycles", cycles)
|
||||
set_attribute("/", "Motor Velocity", velocity*math.sqrt(2))
|
||||
set_attribute("/", "Wire Velocity", velocity)
|
||||
set_attribute("/", "Background Measures", bkgrd)
|
||||
set_attribute("/", "BPMs", bpms)
|
||||
set_attribute("/", "BLMs", blms)
|
||||
print "2"
|
||||
filename = get_exec_pars().path
|
||||
|
||||
|
||||
|
||||
class Timestamp(Readable):
|
||||
def read(self):
|
||||
return time.time()
|
||||
|
||||
|
||||
|
||||
|
||||
#End of scan checking
|
||||
scan_complete, cur_cycle, wire = None, None, None
|
||||
|
||||
def check_end_scan(record, scan):
|
||||
global scan_complete,cur_cycle
|
||||
if record[4]<1:
|
||||
print "Data aquisition completed"
|
||||
scan_complete=True
|
||||
scan.abort()
|
||||
record.cancel() #So it won't be saved
|
||||
else:
|
||||
position = record[0]
|
||||
if record[3] != cur_cycle:
|
||||
cur_cycle = record[3]
|
||||
get_context().dataManager.splitScanData(scan)
|
||||
#if plt is not None: for s in plt.getAllSeries(): s.clear()
|
||||
if plt is not None:
|
||||
for i in range (len(blms)):
|
||||
plt.getSeries(i).appendData(position, record[5 + i])
|
||||
|
||||
#Process background
|
||||
def do_background():
|
||||
#Store Background
|
||||
if bkgrd>0:
|
||||
|
||||
set_exec_pars(group = "background")
|
||||
#r = tscan ( channels, bkgrd, 0.01, group = "background")
|
||||
r = tscan ( channels, bkgrd, 0.01)
|
||||
print "BACKGROUND..."
|
||||
for i in range(len(r.getReadables())):
|
||||
d = r.getReadable(i)
|
||||
path = get_exec_pars().group + r.getReadables()[i].name
|
||||
print path
|
||||
set_attribute(path, "Mean", mean(d))
|
||||
set_attribute(path, "Sigma", stdev(d) )
|
||||
print "DONE"
|
||||
|
||||
#Scan
|
||||
def do_scan(index):
|
||||
global scan_complete, cur_cycle, wire
|
||||
wire = "y" if (index==1) or (scan_type in ["Y1", "Y2"]) else "x"
|
||||
|
||||
|
||||
if plt is not None:
|
||||
if wire == "x":
|
||||
plt.getAxis(plt.AxisId.X).setRange(scan_range[0], scan_range[1])
|
||||
else:
|
||||
plt.getAxis(plt.AxisId.X).setRange(scan_range[2], scan_range[3])
|
||||
|
||||
|
||||
scan_complete=False
|
||||
cur_cycle = 1.0
|
||||
|
||||
if plt is not None:
|
||||
for s in plt.getAllSeries():
|
||||
s.clear()
|
||||
plt.removeMarker(None)
|
||||
try:
|
||||
|
||||
#TODO: Check what the problem is
|
||||
#mscan (st, [w_pos(),] + st.getReadables() + [Timestamp(),], -1, -1, take_initial = True, after_read = check_end_scan)
|
||||
|
||||
l=[Sensor("w_pos")] ; l.extend(channels); l.append(Timestamp())
|
||||
#mscan (st, l, -1, -1, take_initial = True, after_read = check_end_scan)
|
||||
|
||||
#tscan([w_pos()] + getReadables() + [Timestamp(),], 10, 0.5)
|
||||
for i in range(cycles):
|
||||
#set_exec_pars(group=wire+"_{count}", reset=(i==0))
|
||||
tscan(l, 10, 0.5, group=wire+"_{count}", reset=(i==0))
|
||||
#tscan(l, 10, 0.5)
|
||||
except:
|
||||
print sys.exc_info()[1]
|
||||
|
||||
if not scan_complete:
|
||||
raise
|
||||
finally:
|
||||
#Combining data of multiple series
|
||||
#s=plt.getSeries(0)
|
||||
#indexes = sorted(range(len(s.x)),key=lambda x:s.x[x])
|
||||
#x,y = [s.x[x] for x in indexes], [s.y[x] for x in indexes]
|
||||
#plot(y, xdata = x)
|
||||
calculate()
|
||||
img_file = os.path.abspath(filename + "_" + get_exec_pars().group[0:1] + ".png")
|
||||
time.sleep(0.1) #Give some time to plot finish (async)
|
||||
if plt is not None:
|
||||
plt.saveSnapshot(img_file, "png")
|
||||
snapshots.append(img_file)
|
||||
|
||||
msg = ""
|
||||
ret = []
|
||||
def calculate():
|
||||
global msg
|
||||
stats = []
|
||||
for i in range(len(blms)):
|
||||
msg += "Wire " + wire + " - BLM " + str(i+1) + ":\n"
|
||||
try:
|
||||
bg = get_attributes("background/blm" + str(i+1))["Mean"] if bkgrd>0 else 0.0
|
||||
samples = [[], [], [], []]
|
||||
for cycle in range (cycles):
|
||||
pos_path = wire+"_" + ("%04d" % (cycle+1)) + "/w_pos"
|
||||
pos = load_data(pos_path)
|
||||
path = wire+"_" + ("%04d" % (cycle+1)) + "/blm" + str(i+1)
|
||||
data = load_data(path)
|
||||
sp = data #blm_remove_spikes(data)
|
||||
sig = sp if bg is None else [v-bg for v in sp]
|
||||
|
||||
rms_com, rms_sigma = [10.0, 20.0] #[profile_rms_stats(pos, sig,noise_std=0, n_sigma=3.5)
|
||||
set_attribute(path, "RMS COM", float("nan") if (rms_com is None) else rms_com)
|
||||
set_attribute(path, "RMS Sigma", float("nan") if (rms_sigma is None) else rms_sigma)
|
||||
|
||||
#print [com, rms]
|
||||
[off, amp, com, sigma] = [30.0, 40.0, 50.0, 60.0] #profile_gauss_stats(pos, sig, off=None, amp=None, com=None, sigma=None)
|
||||
set_attribute(path, "Gauss COM", float("nan") if (com is None) else com)
|
||||
set_attribute(path, "Gauss Sigma", float("nan") if (sigma is None) else sigma)
|
||||
|
||||
samples[0].append(rms_com);samples[1].append(rms_sigma);samples[2].append(com);samples[3].append(sigma)
|
||||
print get_exec_pars().path + " | "+ path
|
||||
ret.append([rms_com, rms_sigma, com, sigma, get_exec_pars().path + "|"+ pos_path, get_exec_pars().path + "|"+ path])
|
||||
#print [off, amp, com, sigma]
|
||||
|
||||
#from mathutils import Gaussian
|
||||
#g = Gaussian(amp, com, sigma)
|
||||
#gauss = [g.value(v)+off for v in pos]
|
||||
#plot([data, sp, sig, gauss], ["data", "sp", "signal", "gauss", ], xdata = pos, title="Fit blm" + str(i+1) + " - " + str(cycle+1))
|
||||
print "X"
|
||||
stats.append([])
|
||||
for sample in samples:
|
||||
sample = [v for v in sample if v is not None]
|
||||
stats[i].append( (mean(sample), stdev(sample)) if len(sample)>0 else (float("nan"), float("nan")) )
|
||||
if plt is not None:
|
||||
plt.addMarker(stats[i][2][0], None, "Gcom=" + "%.2f" % stats[i][2][0], plt.getSeries(i).color)
|
||||
plt.addMarker(stats[i][0][0], None, "Rcom=" + "%.2f" % stats[i][0][0], plt.getSeries(i).color.brighter())
|
||||
|
||||
msg += " RMS COM: " + "%.4f" % stats[i][0][0] + " +- " +"%.4f" % stats[i][0][1] + "\n" #unichr(0x03C3) + "="
|
||||
msg += " RMS Sigma: " + "%.4f" % stats[i][1][0] + " +- " + "%.4f" % stats[i][1][1] + "\n"
|
||||
msg += " Gauss COM: " + "%.4f" % stats[i][2][0] + " +- " + "%.4f" % stats[i][2][1] + "\n"
|
||||
msg += " Gauss Sigma: " + "%.4f" % stats[i][3][0] + " +- " + "%.4f" % stats[i][3][1] + "\n"
|
||||
|
||||
except Exception, e:
|
||||
print >> sys.stderr, traceback.format_exc()
|
||||
msg += str(e)+ "\n"
|
||||
|
||||
|
||||
print "Starting scan..."
|
||||
try:
|
||||
do_background()
|
||||
do_scan(0)
|
||||
if scan_type in ["Set1", "Set2"]:
|
||||
do_scan(1)
|
||||
finally:
|
||||
print "Closing scanner"
|
||||
|
||||
print "Closing stream"
|
||||
|
||||
|
||||
print msg
|
||||
|
||||
# save the entry in the logbook
|
||||
if do_elog:
|
||||
if get_option("Generated data file:\n" + filename +"\n\n" + msg + "\n\n" + "Save to ELOG?", "YesNo") == "Yes":
|
||||
log_msg = "Data file: " + filename
|
||||
log_msg = log_msg + "\nWire Scanner: " + prefix
|
||||
log_msg = log_msg + "\nScan Type: " + str(scan_type)
|
||||
log_msg = log_msg + "\nRange: " + str(scan_range)
|
||||
log_msg = log_msg + "\nCycles: " + str(cycles)
|
||||
log_msg = log_msg + "\nWire Velocity: " + str(velocity)
|
||||
log_msg = log_msg + "\nBackground Measures: " + str(bkgrd)
|
||||
log_msg = log_msg + "\nBPMs: " + str(bpms)
|
||||
log_msg = log_msg + "\nBLMs: " + str(blms)
|
||||
|
||||
log_msg = log_msg + "\n" + msg
|
||||
elog("Wire Scan", log_msg, snapshots)
|
||||
|
||||
|
||||
set_exec_pars(open=False)
|
||||
set_return(ret)
|
||||
@@ -1,6 +1,15 @@
|
||||
|
||||
#print locals()
|
||||
|
||||
###
|
||||
import java.util.logging.Logger as Logger
|
||||
logger = Logger.getLogger("back")
|
||||
|
||||
logger.info("Started")
|
||||
|
||||
#sleep(10.0)
|
||||
log("quit")
|
||||
print "quit"
|
||||
|
||||
|
||||
|
||||
|
||||
16
script/test/back2.py
Executable file
16
script/test/back2.py
Executable file
@@ -0,0 +1,16 @@
|
||||
|
||||
#print locals()
|
||||
|
||||
###
|
||||
import java.util.logging.Logger as Logger
|
||||
logger = Logger.getLogger("back")
|
||||
logger.info("Started")
|
||||
|
||||
#sleep(10.0)
|
||||
log("quit")
|
||||
print "quit"
|
||||
###
|
||||
print "quit"
|
||||
|
||||
|
||||
|
||||
15
script/test/back3.py
Executable file
15
script/test/back3.py
Executable file
@@ -0,0 +1,15 @@
|
||||
|
||||
#print locals()
|
||||
|
||||
###
|
||||
import java.util.logging.Logger as Logger
|
||||
logger = Logger.getLogger("back")
|
||||
logger.info("Started")
|
||||
|
||||
#sleep(10.0)
|
||||
log("quit")
|
||||
print "quit"
|
||||
###
|
||||
print "quit"
|
||||
|
||||
|
||||
16
script/test/back4.py
Executable file
16
script/test/back4.py
Executable file
@@ -0,0 +1,16 @@
|
||||
|
||||
#print locals()
|
||||
|
||||
###
|
||||
import java.util.logging.Logger as Logger
|
||||
logger = Logger.getLogger("back")
|
||||
logger.info("Started")
|
||||
|
||||
#sleep(10.0)
|
||||
log("quit")
|
||||
print "quit"
|
||||
###
|
||||
print "quit"
|
||||
|
||||
|
||||
|
||||
0
script/test/back5.py
Executable file
0
script/test/back5.py
Executable file
33
script/test/bs.py
Executable file
33
script/test/bs.py
Executable file
@@ -0,0 +1,33 @@
|
||||
import ch.psi.bsread.Receiver as Receiver
|
||||
import ch.psi.bsread.ReceiverConfig as ReceiverConfig
|
||||
import ch.psi.bsread.configuration.Channel as ReceiverChannel
|
||||
|
||||
|
||||
c1 = ReceiverChannel("Int32Scalar", 10)
|
||||
config = ReceiverConfig("tcp://sf-lc6-64:9999")
|
||||
#config.setReqbsuestedChannels([c1,])
|
||||
|
||||
receiver = Receiver(config)
|
||||
receiver.connect()
|
||||
|
||||
message = None
|
||||
# Its also possible to register callbacks for certain message parts.
|
||||
# These callbacks are triggered within the receive() function
|
||||
# (within the same thread) it is guaranteed that the sequence is ordered
|
||||
# main header, data header, values
|
||||
|
||||
# receiver.addDataHeaderHandler(header -> System.out.println(header));
|
||||
# receiver.addMainHeaderHandler(header -> System.out.println(header) );
|
||||
# receiver.addValueHandler(data -> System.out.println(data));
|
||||
try:
|
||||
while(True):
|
||||
message = receiver.receive()
|
||||
#print (message.getMainHeader())
|
||||
#print (message.getDataHeader())
|
||||
#print (message.getValues())
|
||||
print "----------------"
|
||||
for channel in message.getValues().keys():
|
||||
print channel , " = " , message.getValues()[channel].getValue().array().tolist()
|
||||
break
|
||||
finally:
|
||||
receiver.close()
|
||||
19
script/test/bs2.py
Executable file
19
script/test/bs2.py
Executable file
@@ -0,0 +1,19 @@
|
||||
import ch.psi.bsread.Receiver as Receiver
|
||||
import ch.psi.bsread.ReceiverConfig as ReceiverConfig
|
||||
import ch.psi.bsread.configuration.Channel as ReceiverChannel
|
||||
\
|
||||
c1 = ReceiverChannel("Int32Scalar", 10)
|
||||
config = ReceiverConfig(socket)
|
||||
|
||||
receiver = Receiver(config)
|
||||
receiver.connect()
|
||||
|
||||
try:
|
||||
while(True):
|
||||
message = receiver.receive()
|
||||
print "----------------"
|
||||
for channel in message.getValues().keys():
|
||||
print channel , " = " , message.getValues()[channel].getValue().array().tolist()
|
||||
break
|
||||
finally:
|
||||
receiver.close()
|
||||
40
script/test/bs3.py
Executable file
40
script/test/bs3.py
Executable file
@@ -0,0 +1,40 @@
|
||||
import ch.psi.pshell.bs.Scalar as Scalar
|
||||
import ch.psi.pshell.bs.Waveform as Waveform
|
||||
import ch.psi.pshell.bs.Stream as Stream
|
||||
import ch.psi.bsread.configuration.Channel as ReceiverChannel
|
||||
|
||||
|
||||
def str1():
|
||||
s1 = Stream("stream1", bs)
|
||||
channels = [ 'Int8Scalar', 'Int16Scalar', 'Int32Scalar', 'Int64Scalar',
|
||||
'UInt8Scalar', 'UInt16Scalar', 'UInt32Scalar', 'UInt64Scalar',
|
||||
'Float32Scalar', 'Float64Scalar', 'BoolScalar', 'StringScalar',]
|
||||
for c in channels:
|
||||
add_device(Scalar(c, s1, c, 10), True)
|
||||
add_device(s1, True)
|
||||
s1.start()
|
||||
|
||||
def str2():
|
||||
s2 = Stream("stream2", bs)
|
||||
channels = [ 'Int8Waveform', 'Int16Waveform', 'Int32Waveform', 'Int64Waveform',
|
||||
'UInt8Waveform', 'UInt16Waveform', 'UInt32Waveform', 'UInt64Waveform',
|
||||
'Float32Waveform', 'Float64Waveform', 'BoolWaveform']
|
||||
for c in channels:
|
||||
add_device(Waveform(c, s2, c, 10), True)
|
||||
add_device(s2, True)
|
||||
s2.start()
|
||||
|
||||
|
||||
#str1()
|
||||
parallelize(str1, str2)
|
||||
|
||||
|
||||
|
||||
|
||||
#s.start()
|
||||
|
||||
|
||||
|
||||
#s.stop()
|
||||
|
||||
#s.close()
|
||||
27
script/test/bs4.py
Executable file
27
script/test/bs4.py
Executable file
@@ -0,0 +1,27 @@
|
||||
import ch.psi.pshell.bs.Scalar as Scalar
|
||||
import ch.psi.pshell.bs.Waveform as Waveform
|
||||
import ch.psi.pshell.bs.Stream as Stream
|
||||
import ch.psi.bsread.configuration.Channel as ReceiverChannel
|
||||
|
||||
s = Stream("stream", bs)
|
||||
|
||||
channels = ['Int8Scalar',
|
||||
'Int16Scalar', 'Int32Scalar', 'Int64Scalar',
|
||||
'UInt8Scalar', 'UInt16Scalar', 'UInt32Scalar', 'UInt64Scalar',
|
||||
'Float32Scalar', 'Float64Scalar'
|
||||
#, 'BoolScalar', 'StringScalar',
|
||||
]
|
||||
for c in channels:
|
||||
add_device(Scalar(c, s, c, 10), True)
|
||||
|
||||
channels = [ 'Int8Waveform', 'Int16Waveform', 'Int32Waveform', 'Int64Waveform',
|
||||
'UInt8Waveform', 'UInt16Waveform', 'UInt32Waveform', 'UInt64Waveform',
|
||||
'Float32Waveform', 'Float64Waveform', 'BoolWaveform']
|
||||
#for c in channels:
|
||||
# add_device(Waveform(c, s, c, 10), True)
|
||||
|
||||
add_device(s, True)
|
||||
|
||||
set_device_alias(stream, "PulseID")
|
||||
|
||||
bscan(s , 100)
|
||||
25
script/test/bs5.py
Executable file
25
script/test/bs5.py
Executable file
@@ -0,0 +1,25 @@
|
||||
#st1 = Stream("st1", bs)
|
||||
st1 = Stream("st1", dispatcher)
|
||||
|
||||
s1=st1.addScalar("Int8Scalar", "Int8Scalar", 10, 0)
|
||||
w1=st1.addWaveform("Int32Waveform", "Int32Waveform", 10, 0)
|
||||
#st1.setFilter("Int8Scalar>50")
|
||||
|
||||
st1.initialize()
|
||||
st1.start()
|
||||
st1.waitCacheChange(10000)
|
||||
|
||||
|
||||
|
||||
#st1.setFilter("Int8Scalar>20")
|
||||
|
||||
try:
|
||||
#tscan (st1.getReadables(), 100, 0)
|
||||
|
||||
#The bscan command performs samples every stream element
|
||||
bscan (st1, -1, 5.0, layout = "sf") #Sampling 10 elements
|
||||
|
||||
#st1.start(True)
|
||||
#tscan ([s1,w1], 10 , 0.2)
|
||||
finally:
|
||||
st1.close()
|
||||
33
script/test/bs6.py
Executable file
33
script/test/bs6.py
Executable file
@@ -0,0 +1,33 @@
|
||||
st1 = Stream("st1", dispatcher)
|
||||
|
||||
|
||||
s1=st1.addScalar("Int8Scalar", "Int8Scalar", 10, 0)
|
||||
s2=st1.addScalar("Float64Scalar", "Float64Scalar", 10, 0)
|
||||
w1=st1.addWaveform("Int32Waveform", "Int32Waveform", 10, 0)
|
||||
mt1=st1.addMatrix("Int16Waveform", "Int16Waveform", 10, 0, 64, 32)
|
||||
st1.initialize()
|
||||
|
||||
try:
|
||||
#The stream can be used on any conventional scan. The next stream value is sampled.
|
||||
#Readable values belong to same pulse id.
|
||||
tscan (st1.getReadables(), 10 , 0.2)
|
||||
|
||||
#The bscan command performs samples every stream element
|
||||
#Readable values belong to same pulse id.
|
||||
bscan (st1, 10) #Sampling 10 elements
|
||||
|
||||
#An individual stream channel can be used in a conventional scan, but in this case the stream
|
||||
#must be explicitly started, and there is no guarantee the values belong to the same PulseID
|
||||
#(likely they are since as only cached values are taken).
|
||||
st1.start(True)
|
||||
tscan ([s1,s2], 10 , 0.2)
|
||||
|
||||
#If waveform individual stream channel is used, and no size is provided in constructor/config,
|
||||
#then it must be read previously to the scan to update the size value.
|
||||
st1.start(True)
|
||||
w1.update()
|
||||
tscan ([s1,w1,mt1], 10 , 0.2)
|
||||
|
||||
|
||||
finally:
|
||||
st1.close()
|
||||
76
script/test/bug.py
Executable file
76
script/test/bug.py
Executable file
@@ -0,0 +1,76 @@
|
||||
task = None
|
||||
running = False
|
||||
|
||||
for i in range (2):
|
||||
for j in range (2):
|
||||
task = None
|
||||
running = False
|
||||
print '.',
|
||||
running = False
|
||||
print "Next"
|
||||
|
||||
print '.',
|
||||
print '.',
|
||||
print '.',
|
||||
print '.',
|
||||
print "Next"
|
||||
|
||||
import ch.psi.utils.swing.SwingUtils as SwingUtils
|
||||
|
||||
print SwingUtils.getString(None, "Select:" , ["a","b","c"],'a');
|
||||
|
||||
def _startPlot(type):
|
||||
global running
|
||||
print "Starting plot: type " + str(type)
|
||||
running = True
|
||||
p = plot(None,name="")[0]
|
||||
s= p.getSeries(0)
|
||||
from random import randint
|
||||
while running:
|
||||
try:
|
||||
s.appendData(time.time(),randint(0,9))
|
||||
time.sleep(0.1)
|
||||
except:
|
||||
pass
|
||||
print "Done Plotting"
|
||||
|
||||
|
||||
def startPlot(type = 1):
|
||||
global task
|
||||
task = fork((_startPlot,(type,)),)
|
||||
|
||||
def stopPlot():
|
||||
global task, running
|
||||
running = False
|
||||
ret = join(task)
|
||||
|
||||
|
||||
for i in range (5):
|
||||
startPlot()
|
||||
try:
|
||||
time.sleep(1.0)
|
||||
finally:
|
||||
stopPlot()
|
||||
|
||||
|
||||
|
||||
"""
|
||||
from startup import *
|
||||
|
||||
def test():
|
||||
lscan(inp, (sin,out,arr), 0, 40, 20, 0.1)
|
||||
"""
|
||||
|
||||
|
||||
"""
|
||||
for i in range(1000):
|
||||
#caget("13SIM1:image1:ArrayData","[b")
|
||||
caget("TESTIOC:TESTWF2:MyWF","[b")
|
||||
#caget("TESTIOC:TESTSINUS:SinCalc",'d')
|
||||
print "->",
|
||||
#det.data.read()
|
||||
#sin.read()
|
||||
arr.read()
|
||||
print i
|
||||
"""
|
||||
|
||||
8
script/test/bug2.py
Executable file
8
script/test/bug2.py
Executable file
@@ -0,0 +1,8 @@
|
||||
'''
|
||||
Line Scan
|
||||
'''
|
||||
|
||||
#set_preference(Preference.ENABLED_PLOTS, [arr,])
|
||||
#TEST
|
||||
print get_exec_pars().path
|
||||
|
||||
10
script/test/bug3.py
Executable file
10
script/test/bug3.py
Executable file
@@ -0,0 +1,10 @@
|
||||
'''
|
||||
Line Scan
|
||||
'''
|
||||
|
||||
#set_preference(Preference.ENABLED_PLOTS, [arr,])
|
||||
#TEST
|
||||
print get_exec_pars().path
|
||||
|
||||
|
||||
print get_exec_pars().path
|
||||
21
script/test/diffcalc.py
Normal file
21
script/test/diffcalc.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import Jama.Matrix
|
||||
sys.path.append('/Users/gobbo_a/dev/pshell/config/home/script/Lib/diffcalc')
|
||||
|
||||
|
||||
import diffcmd.diffcalc_launcher
|
||||
def exit(code=0):
|
||||
if (code==0):
|
||||
raise Exception("Diffcalc execution finished")
|
||||
raise Exception("Diffcalc exit with code: " + str(code))
|
||||
diffcmd.diffcalc_launcher.exit=exit
|
||||
|
||||
import numjy
|
||||
print numjy.JAMA
|
||||
|
||||
from numjy import matrix
|
||||
|
||||
#sys.argv=['diffcalc' , 'sixcircle', "--python"] #, '--non-interactive']
|
||||
#from diffcmd.diffcalc_launcher import main
|
||||
#main()
|
||||
sys.argv=['diffcalc', "sixcircle", False]
|
||||
run("/Lib/diffcalc/diffcmd/start.py")
|
||||
95
script/test/diffcalc_test.py
Normal file
95
script/test/diffcalc_test.py
Normal file
@@ -0,0 +1,95 @@
|
||||
en.move(20.0)
|
||||
delta.config.maxSpeed = 50.0
|
||||
delta.speed = 50.0
|
||||
delta.move(1.0)
|
||||
|
||||
run("diffcalc_utils")
|
||||
|
||||
###################################################################################################\
|
||||
#Setup
|
||||
###################################################################################################
|
||||
|
||||
setup_sixc(sixc, en)
|
||||
# Set some limits
|
||||
setup_axis('gam', 0, 179)
|
||||
setup_axis('delta', 0, 179)
|
||||
setup_axis('delta', min=0)
|
||||
setup_axis('phi', cut=-180.0)
|
||||
|
||||
print_axis_setup()
|
||||
|
||||
###################################################################################################\
|
||||
#Orientation
|
||||
###################################################################################################
|
||||
help(ub.ub)
|
||||
ub.listub()
|
||||
|
||||
# Create a new ub calculation and set lattice parameters
|
||||
ub.newub('test')
|
||||
ub.setlat('cubic', 1, 1, 1, 90, 90, 90)
|
||||
|
||||
# Add 1st reflection (demonstrating the hardware adapter)
|
||||
settings.hardware.wavelength = 1
|
||||
ub.c2th([1, 0, 0]) # energy from hardware
|
||||
settings.hardware.position = 0, 60, 0, 30, 0, 0
|
||||
ub.addref([1, 0, 0])# energy and position from hardware
|
||||
|
||||
# Add 2nd reflection (this time without the harware adapter)
|
||||
ub.c2th([0, 1, 0], 12.39842)
|
||||
ub.addref([0, 1, 0], [0, 60, 0, 30, 0, 90], 12.39842)
|
||||
|
||||
# check the state
|
||||
ub.ub()
|
||||
ub.checkub()
|
||||
|
||||
|
||||
|
||||
###################################################################################################\
|
||||
#Constraints
|
||||
###################################################################################################
|
||||
|
||||
|
||||
help(hkl.con)
|
||||
hkl.con('qaz', 90)
|
||||
hkl.con('a_eq_b')
|
||||
hkl.con('mu', 0)
|
||||
hkl.con()
|
||||
|
||||
###################################################################################################\
|
||||
#Motion
|
||||
###################################################################################################
|
||||
print angles_to_hkl((0., 60., 0., 30., 0., 0.))
|
||||
|
||||
print hkl_to_angles(1, 0, 0)
|
||||
|
||||
sixc.write([0, 60, 0, 30, 90, 0])
|
||||
print "sixc=" , sixc.position
|
||||
wl.write(1.0)
|
||||
print "wl = ", wl.read()
|
||||
|
||||
|
||||
ub.lastub()
|
||||
ub.setu ([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
|
||||
ub.showref()
|
||||
ub.swapref(1,2)
|
||||
|
||||
|
||||
#print you.hkl
|
||||
#pos(get_hkl())
|
||||
hkl_group.read()
|
||||
|
||||
#you.hkl.simulateMoveTo([0,1,1])
|
||||
#sim(get_hkl(), [0,1,1])
|
||||
hkl_group.sim([0.0,1.0,1.0])
|
||||
|
||||
#pos(get_hkl(), [0,1,1])
|
||||
hkl_group.write([0.0,1.0,1.0])
|
||||
###################################################################################################\
|
||||
#Scans
|
||||
###################################################################################################
|
||||
|
||||
|
||||
lscan(l, [sin], 1.0, 1.5, 0.1)
|
||||
ascan([k,l], [sin], [1.0, 1.0], [1.2, 1.3], [0.1, 0.1], zigzag=True, parallel_positioning = False)
|
||||
vector = [[1.0,1.0,1.0], [1.0,1.0,1.1], [1.0,1.0,1.2], [1.0,1.0,1.4]]
|
||||
hklscan(vector, [sin, arr], 0.9)
|
||||
29
script/test/parallel.py
Normal file
29
script/test/parallel.py
Normal file
@@ -0,0 +1,29 @@
|
||||
#tutorial_path = "src/main/assembly/help/Tutorial_py/"
|
||||
#run(tutorial_path+"SimulatedDevices")
|
||||
def scan1():
|
||||
print "scan1"
|
||||
return lscan(ao1, ai1, 0, 40, 20, 0.1, title = "scan1")
|
||||
|
||||
def scan2():
|
||||
print "scan2"
|
||||
return lscan(ao2, wf1, 0, 40, 20, 0.1, title = "scan2", tag="tag1")
|
||||
|
||||
def scan3():
|
||||
print "scan3"
|
||||
return tscan(ai1, 10, 0.3, title = "scan3", group = "g1", persist=False)
|
||||
|
||||
def scan4():
|
||||
print "scan4"
|
||||
return tscan(wf1, 10, 0.3, title = "scan4", tag="tag2", group = "g2", plot_enable=False)
|
||||
|
||||
def scan5():
|
||||
print "scan5"
|
||||
return lscan(ao2, wf1, 0, 40, 20, 0.1, title = "scan5")
|
||||
|
||||
|
||||
#set_exec_pars(tag = "g5" )
|
||||
parallelize(scan1, scan2, scan3, scan4, scan5)
|
||||
#lscan(ao1, ai1, 0, 40, 20, 0.1, title = "scan1")
|
||||
|
||||
#set_exec_pars(tag = "g5" )
|
||||
#tscan(ai1, 10, 0.3, title = "scan6")
|
||||
346
script/test/sixcircle.py
Normal file
346
script/test/sixcircle.py
Normal file
@@ -0,0 +1,346 @@
|
||||
from __future__ import absolute_import
|
||||
import traceback
|
||||
|
||||
|
||||
import diffcalc
|
||||
from diffcalc import settings
|
||||
from diffcalc.hkl.you.geometry import SixCircle
|
||||
from diffcalc.hardware import HardwareAdapter
|
||||
from diffcalc.ub.persistence import UbCalculationNonPersister
|
||||
from diffcalc.gdasupport.minigda.scannable import *
|
||||
from diffcalc.gdasupport.minigda import command
|
||||
|
||||
from diffcalc.hardware import HardwareAdapter
|
||||
|
||||
|
||||
#import diffcalc.util # @UnusedImport
|
||||
#
|
||||
#
|
||||
# Disable error handling designed for interactive use
|
||||
#diffcalc.util.DEBUG = True
|
||||
|
||||
|
||||
### Create dummy scannables ###
|
||||
|
||||
Dummy = SingleFieldDummyScannable
|
||||
|
||||
|
||||
class PositionerScannable(ScannableBase):
|
||||
|
||||
def __init__(self, positioner):
|
||||
self.positioner = positioner
|
||||
self.name = positioner.name
|
||||
self.inputNames = [self.name]
|
||||
self.outputFormat = ['% 6.4f']
|
||||
self.level = 3
|
||||
|
||||
def isBusy(self):
|
||||
return self.positioner.state == State.Busy
|
||||
|
||||
def waitWhileBusy(self):
|
||||
self.positioner.waitReady(-1)
|
||||
|
||||
def asynchronousMoveTo(self, new_position):
|
||||
#print "Moving " , self.name, " to: ", new_position
|
||||
self.positioner.moveAsync(float(new_position), -1)
|
||||
|
||||
def getPosition(self):
|
||||
return self.positioner.getPosition()
|
||||
|
||||
|
||||
class PositionerScannableGroup(ScannableGroup):
|
||||
def __init__(self, name, motors):
|
||||
self.name = name
|
||||
[mu, delta, gam, eta, chi, phi] = motors
|
||||
self.mu = PositionerScannable(mu)
|
||||
self.delta = PositionerScannable(delta)
|
||||
self.gam = PositionerScannable(gam)
|
||||
self.eta = PositionerScannable(eta)
|
||||
self.chi = PositionerScannable(chi)
|
||||
self.phi = PositionerScannable(phi)
|
||||
ScannableGroup.__init__(self, self.name, [self.mu, self.delta, self.gam, self.eta, self.chi, self.phi])
|
||||
|
||||
class MotorGroupScannable(PositionerScannableGroup):
|
||||
def __init__(self, motor_group):
|
||||
self.motor_group = motor_group
|
||||
PositionerScannableGroup.__init__(self, motor_group.name, motor_group.motors)
|
||||
|
||||
|
||||
|
||||
|
||||
class ScannableAdapter(HardwareAdapter):
|
||||
def __init__(self, diffractometer, energy, energy_multiplier_to_kev=1):
|
||||
self.diffractometer = diffractometer
|
||||
self.energy = energy
|
||||
self.energy_multiplier_to_kev = energy_multiplier_to_kev
|
||||
input_names = diffractometer.getInputNames()
|
||||
HardwareAdapter.__init__(self, input_names)
|
||||
|
||||
#Returns the current physical POSITIONS
|
||||
def get_position(self):
|
||||
"""
|
||||
pos = getDiffractometerPosition() -- returns the current physical
|
||||
diffractometer position as a list in degrees
|
||||
"""
|
||||
return self.diffractometer.getPosition()
|
||||
|
||||
#returns energy in
|
||||
def get_energy(self):
|
||||
"""energy = get_energy() -- returns energy in kEv (NOT eV!) """
|
||||
multiplier = self.energy_multiplier_to_kev
|
||||
energy = self.energy.getPosition() * multiplier
|
||||
if energy is None:
|
||||
raise DiffcalcException("Energy has not been set")
|
||||
return energy
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self.diffractometer.getName()
|
||||
|
||||
class MotorGroupAdapter(ScannableAdapter):
|
||||
def __init__(self, diffractometer, energy, energy_multiplier_to_kev=1):
|
||||
self.sixc = MotorGroupScannable(sixc)
|
||||
self.en = PositionerScannable(en)
|
||||
self.en.level = 3
|
||||
ScannableAdapter.__init__(self, self.sixc, self.en, energy_multiplier_to_kev)
|
||||
|
||||
|
||||
en.move(20.0)
|
||||
delta.move(1.0)
|
||||
|
||||
you = None
|
||||
settings.hardware = MotorGroupAdapter(sixc, en)
|
||||
settings.geometry = SixCircle()
|
||||
settings.ubcalc_persister = UbCalculationNonPersister()
|
||||
settings.axes_scannable_group = settings.hardware.sixc
|
||||
settings.energy_scannable = settings.hardware.en
|
||||
settings.ubcalc_strategy = diffcalc.hkl.you.calc.YouUbCalcStrategy()
|
||||
settings.angles_to_hkl_function = diffcalc.hkl.you.calc.youAnglesToHkl
|
||||
from diffcalc.gdasupport import you
|
||||
reload(you)
|
||||
|
||||
#settings.hardware = DummyHardwareAdapter(('mu', 'delta', 'gam', 'eta', 'chi', 'phi'))
|
||||
|
||||
|
||||
# These must be imported AFTER the settings have been configured
|
||||
from diffcalc.dc import dcyou as dc
|
||||
from diffcalc.ub import ub
|
||||
from diffcalc import hardware
|
||||
from diffcalc.hkl.you import hkl
|
||||
|
||||
|
||||
|
||||
_wl = you.wl
|
||||
_hkl= you.hkl
|
||||
|
||||
|
||||
|
||||
# Set some limits
|
||||
hardware.setmin('gam', 0) #-179)
|
||||
hardware.setmax('gam', 179)
|
||||
|
||||
hardware.setmin('delta', 0)
|
||||
hardware.setmax('delta', 179)
|
||||
|
||||
|
||||
def demo_orient():
|
||||
|
||||
ub.listub()
|
||||
|
||||
# Create a new ub calculation and set lattice parameters
|
||||
ub.newub('test')
|
||||
ub.setlat('cubic', 1, 1, 1, 90, 90, 90)
|
||||
|
||||
# Add 1st reflection (demonstrating the hardware adapter)
|
||||
settings.hardware.wavelength = 1
|
||||
ub.c2th([1, 0, 0]) # energy from hardware
|
||||
settings.hardware.position = 0, 60, 0, 30, 0, 0
|
||||
ub.addref([1, 0, 0])# energy and position from hardware
|
||||
|
||||
# Add 2nd reflection (this time without the harware adapter)
|
||||
ub.c2th([0, 1, 0], 12.39842)
|
||||
ub.addref([0, 1, 0], [0, 60, 0, 30, 0, 90], 12.39842)
|
||||
|
||||
# check the state
|
||||
ub.ub()
|
||||
ub.checkub()
|
||||
|
||||
|
||||
def demo_motion():
|
||||
dc.angles_to_hkl((0., 60., 0., 30., 0., 0.))
|
||||
hkl.con('qaz', 90)
|
||||
hkl.con('a_eq_b')
|
||||
hkl.con('mu', 0)
|
||||
|
||||
hardware.setmin('delta', 0)
|
||||
hardware.setcut('phi', -180.0)
|
||||
dc.hkl_to_angles(1, 0, 0)
|
||||
hardware.hardware()
|
||||
|
||||
# These demos reproduce the outline in the developer guide
|
||||
def demo_all():
|
||||
demo_orient()
|
||||
demo_motion()
|
||||
|
||||
|
||||
try:
|
||||
demo_all()
|
||||
except:
|
||||
traceback.print_exc()
|
||||
|
||||
|
||||
|
||||
pos = command.Pos()
|
||||
scan = command.Scan(command.ScanDataPrinter())
|
||||
sim=command.sim
|
||||
|
||||
help(ub.ub)
|
||||
help(hkl.con)
|
||||
|
||||
|
||||
#pos(settings.hardware.sixc, [0, 60, 0, 30, 90, 0])
|
||||
pos(settings.hardware.sixc)
|
||||
pos(_wl, 1)
|
||||
pos(_wl)
|
||||
|
||||
|
||||
|
||||
ub.lastub()
|
||||
ub.setu ([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
|
||||
ub.showref()
|
||||
ub.swapref(1,2)
|
||||
|
||||
|
||||
print "---"
|
||||
#print you.hkl
|
||||
pos(_hkl)
|
||||
#you.hkl.simulateMoveTo([0,1,1])
|
||||
sim(_hkl, [0,1,1])
|
||||
pos(_hkl, [0,1,1])
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------------------------------
|
||||
|
||||
import ch.psi.pshell.device.PositionerConfig as PositionerConfig
|
||||
|
||||
import ch.psi.pshell.device.RegisterConfig as RegisterConfig
|
||||
import ch.psi.pshell.device.Register as Register
|
||||
|
||||
class HklPositoner (PositionerBase):
|
||||
def __init__(self, name, index, hkl_group):
|
||||
PositionerBase.__init__(self, name, PositionerConfig())
|
||||
self.setParent(hkl_group)
|
||||
self.index = index
|
||||
|
||||
def doRead(self):
|
||||
return self.getParent()._setpoint[self.index]
|
||||
|
||||
def doWrite(self, value):
|
||||
print "Setting " , self.getName(), "to: ", value
|
||||
pos = [None, None, None]
|
||||
pos[self.index] = value
|
||||
self.getParent().write(pos)
|
||||
|
||||
def doReadReadback(self):
|
||||
if java.lang.Thread.currentThread() != self.getParent()._updating_thread:
|
||||
self.getParent().update()
|
||||
return self.getParent()._readback[self.index]
|
||||
|
||||
class HklGroup(RegisterBase, Register.RegisterArray):
|
||||
def __init__(self):
|
||||
RegisterBase.__init__(self, "hkl", RegisterConfig())
|
||||
self.h, self.k, self.l = HklPositoner("h", 0, self), HklPositoner("k", 1, self), HklPositoner("l", 2, self)
|
||||
add_device(self.h, True)
|
||||
add_device(self.k, True)
|
||||
add_device(self.l, True)
|
||||
self._setpoint = self.doRead()
|
||||
self._updating = False
|
||||
|
||||
def getSize(self):
|
||||
return 3
|
||||
|
||||
def doRead(self):
|
||||
self._readback = _hkl.getPosition()
|
||||
self._updating_thread = java.lang.Thread.currentThread()
|
||||
try:
|
||||
self.h.update()
|
||||
self.k.update()
|
||||
self.l.update()
|
||||
except:
|
||||
self._updating_thread = None
|
||||
print "!!!"
|
||||
traceback.print_exc()
|
||||
print "---"
|
||||
return self._readback
|
||||
|
||||
def doWrite(self, pos):
|
||||
self._setpoint = pos
|
||||
print "Moving to: " + str(pos)
|
||||
_hkl.asynchronousMoveTo(pos)
|
||||
|
||||
|
||||
add_device(HklGroup(), True)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#h.polling = 250; k.polling = 250; l.polling = 250;
|
||||
hkl.polling = 250
|
||||
|
||||
|
||||
|
||||
def hklscan(vector, readables,latency = 0.0, passes = 1, **pars):
|
||||
"""
|
||||
HKL Scan:
|
||||
|
||||
Args:
|
||||
vector(list of lists): HKL values to be scanned
|
||||
readables(list of Readable): Sensors to be sampled on each step.
|
||||
latency(float, optional): settling time for each step before readout, defaults to 0.0.
|
||||
passes(int, optional): number of passes
|
||||
pars(keyworded variable length arguments, optional): scan optional named arguments:
|
||||
- title(str, optional): plotting window name.
|
||||
- hidden(bool, optional): if true generates no effects on user interface.
|
||||
- before_read (function, optional): callback on each step, before sampling. Arguments: positions, scan
|
||||
- after_read (function, optional): callback on each step, after sampling. Arguments: record, scan.
|
||||
- before_pass (function, optional): callback before each scan pass execution. Arguments: pass_num, scan.
|
||||
- after_pass (function, optional): callback after each scan pass execution. Arguments: pass_num, scan.
|
||||
- Aditional arguments defined by set_exec_pars.
|
||||
Returns:
|
||||
ScanResult object.
|
||||
|
||||
"""
|
||||
print "1"
|
||||
readables=to_list(string_to_obj(readables))
|
||||
print "2"
|
||||
pars["initial_move"] = False
|
||||
#names = [readable.name for readable in readables]
|
||||
#print "3"
|
||||
#scan = ManualScan([h, k, l], readables, dimensions = 1)
|
||||
#scan = ManualScan(["h", "k", "l"], names ,vector[0], vector[-1], [len(vector)-1] * 3, dimensions = 1)
|
||||
scan = ManualScan([h,k,l], readables ,vector[0], vector[-1], [len(vector)-1] * 3, dimensions = 1)
|
||||
print "4"
|
||||
if not "domain_axis" in pars.keys():
|
||||
pars["domain_axis"] = "Index"
|
||||
print "5"
|
||||
processScanPars(scan, pars)
|
||||
print "6"
|
||||
scan.start()
|
||||
try:
|
||||
for pos in vector:
|
||||
print "Writing ", pos
|
||||
hkl.write(pos)
|
||||
print "Done"
|
||||
time.sleep(1.0)
|
||||
scan.append ([h.take(), k.take(), l.take()], [h.getPosition(), k.getPosition(), l.getPosition()], [readable.read() for readable in readables ])
|
||||
finally:
|
||||
scan.end()
|
||||
return scan.result
|
||||
|
||||
|
||||
#lscan(l, [sin], 1.0, 1.5, 0.1)
|
||||
|
||||
#vector = [[1.0,1.0,1.0], [1.0,1.0,1.1], [1.0,1.0,1.2], [1.0,1.0,1.4]]
|
||||
#hklscan(vector, [sin, arr], 0.9) #, = "Index" )#, line_plots = [sin])
|
||||
35
script/test/test.groovy
Executable file
35
script/test/test.groovy
Executable file
@@ -0,0 +1,35 @@
|
||||
|
||||
set_exec_pars(["name":"newtest"])
|
||||
|
||||
tscan(sin, 10, 0.100)
|
||||
|
||||
|
||||
st1 = new ch.psi.pshell.bs.Stream("st1", dispatcher)
|
||||
|
||||
/*
|
||||
s1=st1.addScalar("Int8Scalar", "Int8Scalar", 10, 0)
|
||||
s2=st1.addScalar("Float64Scalar", "Float64Scalar", 10, 0)
|
||||
w1=st1.addWaveform("Int32Waveform", "Int32Waveform", 10, 0)
|
||||
mt1=st1.addMatrix("Int16Waveform", "Int16Waveform", 10, 0, 64, 32)
|
||||
st1.initialize()
|
||||
bscan (st1, 10)
|
||||
*/
|
||||
|
||||
|
||||
r1 = rscan(inp,[sin,inp] , [[0,5,5], [10,15,20], [20,25,5]] , 0.01, false, passes = 1)
|
||||
|
||||
lscan ([inp,motor], [sin,dev], [0,0], [10,1], 10,0.1,false)
|
||||
|
||||
|
||||
|
||||
//1D vector scan, plot to 1D Vector tab
|
||||
vector = [ 1, 3, 5, 10, 25, 40, 45, 47, 49]
|
||||
vscan(inp,[sin,dev],vector, false, 0.5)
|
||||
|
||||
//2D vector scan, plot to 2D Vector tab
|
||||
vector = [ [1,1] , [1,2] , [1,3] , [1,4] ,
|
||||
[1.5,2.5] ,
|
||||
[2,1] , [2,2] , [2,3] , [2,4] ,
|
||||
[2.5,2.5] ,
|
||||
[3,1] , [3,2] , [3,3] , [3,4] ]
|
||||
a= vscan([inp,motor],[sin,dev],vector,false, 0.1)
|
||||
109
script/test/test.js
Executable file
109
script/test/test.js
Executable file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
var st1 = new Stream("st1", dispatcher)
|
||||
s1=st1.addScalar("Int8Scalar", "Int8Scalar", 10, 0)
|
||||
s2=st1.addScalar("Float64Scalar", "Float64Scalar", 10, 0)
|
||||
w1=st1.addWaveform("Int32Waveform", "Int32Waveform", 10, 0)
|
||||
mt1=st1.addMatrix("Int16Waveform", "Int16Waveform", 10, 0, 64, 32)
|
||||
st1.initialize()
|
||||
bscan (st1, 10)
|
||||
*/
|
||||
|
||||
|
||||
r1 = rscan(inp,[sin,inp] , [[0,5,5], [10,15,20], [20,25,5]] , 0.01, false, passes = 1)
|
||||
|
||||
|
||||
lscan(inp, [sin,], 0, 40, 20, 0.01)
|
||||
|
||||
|
||||
|
||||
|
||||
load("nashorn:mozilla_compat.js")
|
||||
importClass(java.util.concurrent.FutureTask)
|
||||
|
||||
|
||||
print ("a")
|
||||
|
||||
function _getCallable(func, args){
|
||||
var callable = new java.util.concurrent.Callable() {
|
||||
call: function() {
|
||||
print ("HAHA")
|
||||
//print (func)
|
||||
print (args)
|
||||
return func(args)
|
||||
}
|
||||
}
|
||||
return callable
|
||||
}
|
||||
|
||||
|
||||
function fork(){
|
||||
print ("FORK")
|
||||
print (arguments.length)
|
||||
print (typeof arguments[0])
|
||||
var callables = []
|
||||
for(i =0; i<arguments.length; i++){
|
||||
var m = arguments[i]
|
||||
print (m)
|
||||
if (get_rank(m)>0){
|
||||
print("X")
|
||||
print (m.length)
|
||||
//print (m[0])
|
||||
print (m[1])
|
||||
callables.push(_getCallable(m[0], m[1]))
|
||||
}
|
||||
else
|
||||
callables.push(_getCallable(m))
|
||||
|
||||
}
|
||||
return Threading.fork(callables)
|
||||
}
|
||||
|
||||
|
||||
function join(futures){
|
||||
try{
|
||||
return Threading.join(futures)
|
||||
} catch(err){
|
||||
throw err.getCause()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function parallelize() {
|
||||
futures = fork.apply(this, arguments)
|
||||
return join(futures)
|
||||
}
|
||||
|
||||
function task1() {
|
||||
print("On 1")
|
||||
motor.moveRel(1.0)
|
||||
return motor.getPosition()
|
||||
}
|
||||
function task2() {
|
||||
print("On 2")
|
||||
motor2.moveRel(1.0)
|
||||
return motor2.getPosition()
|
||||
}
|
||||
|
||||
function task3() {
|
||||
print("On 3")
|
||||
return sin.read()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function moveRelative(args){
|
||||
motor = args[0]
|
||||
step = args[1]
|
||||
print ("Moving " + motor.getName() + " step = " + step)
|
||||
motor.moveRel(step)
|
||||
return motor.getPosition()
|
||||
}
|
||||
|
||||
ret = parallelize([moveRelative,[motor,-2]], [moveRelative,[motor2,-2]])
|
||||
//ret = fork([moveRelative,[motor,-2]], [moveRelative,[motor2,-2]])
|
||||
//ret = parallelize(task1,task2)
|
||||
//ret = fork(task1,task2)
|
||||
//ret = join(ret)
|
||||
print (ret)
|
||||
|
||||
@@ -1,2 +1,5 @@
|
||||
def test():
|
||||
print dev.read()
|
||||
#set_exec_pars(name = "test1")
|
||||
set_exec_pars(group = "g1")
|
||||
a= lscan(inp, (sin,out,arr), 0, 40, 20, 0.1, group = "g2")
|
||||
#set_exec_pars(name = "test2", open = False)
|
||||
a= lscan(inp, (sin,out,arr), 0, 40, 20, 0.1)
|
||||
|
||||
1
script/test/test.scan
Normal file
1
script/test/test.scan
Normal file
@@ -0,0 +1 @@
|
||||
[ "Change event series", [ ], [ [ "Channel", "TESTIOC:TESTSINUS:SinCalc?monitored=true", 2, 0.1, "Enabled" ] ], false, [ ], "", 50, 0.0, 0.1, true, true, true, true, "", "", "Default", "h5", 0, null, null, "Positioner", false ]
|
||||
69
script/test/test0.py
Executable file
69
script/test/test0.py
Executable file
@@ -0,0 +1,69 @@
|
||||
import sys
|
||||
import time
|
||||
|
||||
#To add library folders from within the script
|
||||
#sys.path.append("./site-packages")
|
||||
|
||||
|
||||
import requests
|
||||
r = requests.get('https://api.github.com', auth=('user', 'pass'))
|
||||
print r.status_code
|
||||
print r.headers['content-type']
|
||||
r.close()
|
||||
|
||||
|
||||
def calc2(a):
|
||||
return a*2
|
||||
time.sleep(0.1)
|
||||
#import os
|
||||
#print os.environ
|
||||
#import calc
|
||||
|
||||
|
||||
lib.load("calc")
|
||||
lib.load("cls")
|
||||
time.sleep(0.1)
|
||||
for x in range(3):
|
||||
print x
|
||||
while(True):
|
||||
print x*2
|
||||
break
|
||||
time.sleep(2)
|
||||
x=cls()
|
||||
x.execute()
|
||||
print dev.take()
|
||||
#print dev2.val
|
||||
time.sleep(1)
|
||||
print calc(4)
|
||||
|
||||
|
||||
|
||||
data = [1,2,3,4,5]
|
||||
path="group/data"
|
||||
|
||||
|
||||
save_dataset(path, data)
|
||||
read =load_data(path)
|
||||
|
||||
print read.tolist()
|
||||
|
||||
#plot(read)
|
||||
|
||||
|
||||
data = [ [1,2,3,4,5], [2,3,4,5,6], [3,4,5,6,7]]
|
||||
path="group/data2"
|
||||
|
||||
|
||||
save_dataset(path, data)
|
||||
read =load_data(path)
|
||||
|
||||
print read.tolist()
|
||||
|
||||
plot(read)
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
It lives!!!!
|
||||
"""
|
||||
44
script/test/test1.py
Executable file
44
script/test/test1.py
Executable file
@@ -0,0 +1,44 @@
|
||||
'''
|
||||
Line Scan
|
||||
'''
|
||||
|
||||
import ch.psi.pshell.data.LayoutSF as LayoutSF
|
||||
LayoutSF.setExperimentArguments([sin, out])
|
||||
|
||||
|
||||
print get_exec_pars().path
|
||||
def before_pass(pass_num):
|
||||
print "Starting pass: " , pass_num
|
||||
def after_pass(pass_num):
|
||||
print "Finished pass: " , pass_num
|
||||
|
||||
set_exec_pars(layout="sf")
|
||||
|
||||
a= lscan(inp, (sin,out,arr), 0, 40, 10, 0.2, passes = 2, before_pass = before_pass, after_pass=after_pass, title = "Test")
|
||||
ret= tscan((sin, create_averager(sin,3,0.1)), 10, 0.1, passes = 2, before_pass = before_pass, after_pass=after_pass)
|
||||
ret= mscan([],sin, 10, -1, passes = 2, before_pass = before_pass, after_pass=after_pass)
|
||||
p = get_exec_pars()
|
||||
print p.getPath()
|
||||
|
||||
print p.getScanPath()
|
||||
|
||||
|
||||
|
||||
path = get_exec_pars().group
|
||||
#save_dataset(path + "data", a.getReadable(0) )
|
||||
#set_attribute(path + "data", "Temp", 39.0)
|
||||
|
||||
set_attribute(path, "AttrString", "Value")
|
||||
set_attribute(path, "AttrInteger", 1)
|
||||
set_attribute(path, "AttrDouble", 2.0)
|
||||
set_attribute(path, "AttrBoolean", True)
|
||||
set_attribute(path, "AttrArr", [1,2,3])
|
||||
|
||||
set_attribute(path + "sin", "Temp", 39.0)
|
||||
|
||||
|
||||
#set_return([1.0, 3, [1,2,3,4]])
|
||||
|
||||
#set_return("T\"es\"t")
|
||||
#set_return([3.0,2])
|
||||
set_return(ret)
|
||||
1
script/test/test1.scan
Normal file
1
script/test/test1.scan
Normal file
@@ -0,0 +1 @@
|
||||
[ "Continuous", [ [ "Device", "motor", 0.0, 1.0, 10.0 ] ], [ [ "Device", "sin", 1, 0, "Enabled" ] ], true, [ ], "", 1, 0.0, 0.0, false, false, true, true, "", "", "Default", "h5", 0, null, null, "Positioner", true ]
|
||||
26
script/test/test1.xml
Executable file
26
script/test/test1.xml
Executable file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<configuration xmlns="http://www.psi.ch/~ebner/models/scan/1.0" numberOfExecution="1" failOnSensorError="true">
|
||||
<notification>
|
||||
<recipient error="true" success="false">alexandre.gobbo@psi.ch</recipient>
|
||||
</notification>
|
||||
<data fileName="testx"/>
|
||||
<description>My first test a</description>
|
||||
<variable name="var1" value="0.0"/>
|
||||
<scan>
|
||||
<dimension zigzag="false" dataGroup="false">
|
||||
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinearPositioner" name="TESTIOC:TESTCALCOUT:Input" asynchronous="false" id="id278043">
|
||||
<start>0.0</start>
|
||||
<end>31.0</end>
|
||||
<stepSize>1.0</stepSize>
|
||||
</positioner>
|
||||
<action xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScriptAction">
|
||||
<script>import time
|
||||
def process():
|
||||
time.sleep(0.1)</script>
|
||||
</action>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="TESTIOC:TESTCALCOUT:Output" id="id348623"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="TESTIOC:TESTSINUS:SinCalc" id="id367393"/>
|
||||
</dimension>
|
||||
</scan>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="id278043" y="id348623 id367393" title="Plot 1"/>
|
||||
</configuration>
|
||||
41
script/test/test10.py
Executable file
41
script/test/test10.py
Executable file
@@ -0,0 +1,41 @@
|
||||
"""
|
||||
Multi-peak search
|
||||
"""
|
||||
|
||||
from mathutils import estimate_peak_indexes, fit_gaussians, create_fit_point_list
|
||||
|
||||
start = 0
|
||||
end = 30
|
||||
step_size = 0.2
|
||||
|
||||
result= lscan(sout,sinp,start,end,[step_size,],0.01)
|
||||
|
||||
readable = result.getReadable(0)
|
||||
positions = result.getPositions(0)
|
||||
|
||||
threshold = (min(readable) + max(readable))/2
|
||||
min_peak_distance = 5.0
|
||||
|
||||
peaks = estimate_peak_indexes(readable, positions, threshold, min_peak_distance)
|
||||
print "Peak indexes: " + str(peaks)
|
||||
print "Peak x: " + str(map(lambda x:positions[x], peaks))
|
||||
print "Peak y: " + str(map(lambda x:readable[x], peaks))
|
||||
|
||||
|
||||
|
||||
gaussians = fit_gaussians(readable, positions, peaks)
|
||||
|
||||
|
||||
plots = plot([readable],["sin"],[positions], title="Data" )
|
||||
for i in range(len(peaks)):
|
||||
peak = peaks[i]
|
||||
(norm, mean, sigma) = gaussians[i]
|
||||
if abs(mean - positions[peak]) < min_peak_distance:
|
||||
print "Peak -> " + str(mean)
|
||||
plots[0].addMarker(mean, None, "N="+str(round(norm,2)), None)
|
||||
else:
|
||||
print "Invalid gaussian fit: " + str(mean)
|
||||
|
||||
|
||||
|
||||
|
||||
29
script/test/test11-Guard.xml
Executable file
29
script/test/test11-Guard.xml
Executable file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<configuration xmlns="http://www.psi.ch/~ebner/models/scan/1.0" failOnSensorError="true">
|
||||
<notification>
|
||||
<recipient>alexandre.gobbo@psi.ch</recipient>
|
||||
</notification>
|
||||
<data fileName="test1"/>
|
||||
<description>My first test</description>
|
||||
<variable name="var1" value="0.0"/>
|
||||
<scan>
|
||||
<dimension>
|
||||
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinearPositioner" name="TESTIOC:TESTCALCOUT:Input" id="id278043">
|
||||
<start>0.0</start>
|
||||
<end>31.0</end>
|
||||
<stepSize>1.0</stepSize>
|
||||
</positioner>
|
||||
<action xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScriptAction">
|
||||
<script>import time
|
||||
def process():
|
||||
time.sleep(0.1)</script>
|
||||
</action>
|
||||
<guard>
|
||||
<condition channel="TESTIOC:TESTCALCOUT:Output" value="0"/>
|
||||
</guard>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="TESTIOC:TESTCALCOUT:Output" id="id348623"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="TESTIOC:TESTSINUS:SinCalc" id="id367393"/>
|
||||
</dimension>
|
||||
</scan>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="id278043" y="id348623 id367393"/>
|
||||
</configuration>
|
||||
10
script/test/test11.py
Executable file
10
script/test/test11.py
Executable file
@@ -0,0 +1,10 @@
|
||||
"""
|
||||
Injecting parameters
|
||||
|
||||
Parameters: start(float), end(float), step(int)
|
||||
|
||||
Execute: run ("test11", {"start":10.0, "end":50.0, "step":40})
|
||||
"""
|
||||
a= lscan(inp, sin, start, end, step, 0.1)
|
||||
|
||||
|
||||
38
script/test/test12-region.xml
Executable file
38
script/test/test12-region.xml
Executable file
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<configuration xmlns="http://www.psi.ch/~ebner/models/scan/1.0" numberOfExecution="1" failOnSensorError="true">
|
||||
<notification>
|
||||
<recipient>alexandre.gobbo@psi.ch</recipient>
|
||||
</notification>
|
||||
<data fileName="test1"/>
|
||||
<description>My first test</description>
|
||||
<variable name="var1" value="0.0"/>
|
||||
<scan>
|
||||
<dimension>
|
||||
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="RegionPositioner" name="TESTIOC:TESTCALCOUT:Input" id="id477121">
|
||||
<region>
|
||||
<start>0.0</start>
|
||||
<end>31.0</end>
|
||||
<stepSize>1.0</stepSize>
|
||||
<function>
|
||||
<mapping xsi:type="VariableParameterMapping" name="var1" variable="V1"/>
|
||||
<mapping xsi:type="ChannelParameterMapping" channel="TESTIOC:TESTCALCOUT:Output" variable="V2"/>
|
||||
<script>def calculate(parameter):
|
||||
V2.setValue(0.0)
|
||||
return V2.getValue()</script>
|
||||
</function>
|
||||
</region>
|
||||
</positioner>
|
||||
<action xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScriptAction">
|
||||
<script>import time
|
||||
def process():
|
||||
time.sleep(0.1)</script>
|
||||
</action>
|
||||
<guard>
|
||||
<condition channel="TESTIOC:TESTCALCOUT:Output" value="0"/>
|
||||
</guard>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="TESTIOC:TESTCALCOUT:Output" id="id348623"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="TESTIOC:TESTSINUS:SinCalc" id="id367393"/>
|
||||
</dimension>
|
||||
</scan>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="id477121" y="id348623 id367393"/>
|
||||
</configuration>
|
||||
8
script/test/test12.py
Executable file
8
script/test/test12.py
Executable file
@@ -0,0 +1,8 @@
|
||||
"""
|
||||
Relative Scan
|
||||
"""
|
||||
|
||||
a= lscan(inp, (sin,out,arr), -2, 2, 20, 0.1, True)
|
||||
|
||||
|
||||
|
||||
8
script/test/test13.py
Executable file
8
script/test/test13.py
Executable file
@@ -0,0 +1,8 @@
|
||||
"""
|
||||
Relative Scan
|
||||
"""
|
||||
|
||||
a= lscan(inp, (sin,out,arr), -2, 2, 20, 0.1, True)
|
||||
|
||||
|
||||
|
||||
54
script/test/test13.xml
Executable file
54
script/test/test13.xml
Executable file
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<configuration xmlns="http://www.psi.ch/~ebner/models/scan/1.0" failOnSensorError="true">
|
||||
<notification>
|
||||
<recipient>alexandre.gobbo@psi.ch</recipient>
|
||||
</notification>
|
||||
<data fileName="test13"/>
|
||||
<description>My first test</description>
|
||||
<variable name="var1" value="0.0"/>
|
||||
<scan>
|
||||
<dimension>
|
||||
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="RegionPositioner" name="TESTIOC:TESTCALCOUT:Input" id="id763605">
|
||||
<region>
|
||||
<preAction xsi:type="ScriptAction">
|
||||
<script>import time
|
||||
def process():
|
||||
time.sleep(3.01)</script>
|
||||
</preAction>
|
||||
<start>0.0</start>
|
||||
<end>30.0</end>
|
||||
<stepSize>5.0</stepSize>
|
||||
</region>
|
||||
<region>
|
||||
<preAction xsi:type="ScriptAction">
|
||||
<script>import time
|
||||
def process():
|
||||
time.sleep(2.02)</script>
|
||||
</preAction>
|
||||
<start>50.0</start>
|
||||
<end>70.0</end>
|
||||
<stepSize>2.0</stepSize>
|
||||
</region>
|
||||
<region>
|
||||
<preAction xsi:type="ScriptAction">
|
||||
<script>import time
|
||||
def process():
|
||||
time.sleep(1.03)</script>
|
||||
</preAction>
|
||||
<start>70.0</start>
|
||||
<end>75.0</end>
|
||||
<stepSize>1.0</stepSize>
|
||||
</region>
|
||||
</positioner>
|
||||
<action xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScriptAction">
|
||||
<script>import time
|
||||
def process():
|
||||
time.sleep(0.1)</script>
|
||||
</action>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="TESTIOC:TESTCALCOUT:Output" id="id348623"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="TESTIOC:TESTSINUS:SinCalc" id="id367393"/>
|
||||
</dimension>
|
||||
</scan>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="id763605" y="id348623"/>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="id763605" y="id367393"/>
|
||||
</configuration>
|
||||
21
script/test/test14.py
Executable file
21
script/test/test14.py
Executable file
@@ -0,0 +1,21 @@
|
||||
RANGE_1 = (0.0, 80.0)
|
||||
SETPOINTS_2 = (1.0, 2.0, 3.0)
|
||||
motor.setSpeed(100.0)
|
||||
|
||||
#set_preference(Preference.ENABLED_PLOTS, [sin,])
|
||||
set_preference(Preference.PLOT_TYPES, {sin:1,sinp:1})
|
||||
|
||||
|
||||
|
||||
scan = ManualScan([motor.getName(), out.getName()], [sin.getName(), sinp.getName()] , [-1, SETPOINTS_2[0]], [-1, SETPOINTS_2[-1]], [-1, len(SETPOINTS_2)-1])
|
||||
#scan = ManualScan([motor.getName(), out.getName()], [sin.getName(), sinp.getName()] , [RANGE_1[0], SETPOINTS_2[0]], [RANGE_1[-1], SETPOINTS_2[-1]], [int(RANGE_1[1]-RANGE_1[0]), len(SETPOINTS_2)-1])
|
||||
scan.start()
|
||||
for setpoint1 in frange(RANGE_1[0], RANGE_1[1], 1.0, True):
|
||||
motor.move(setpoint1)
|
||||
for setpoint2 in SETPOINTS_2:
|
||||
out.put(setpoint2)
|
||||
scan.append ([setpoint1, setpoint2], [motor.read(), out.read()], [sin.read(), sinp.read()])
|
||||
|
||||
|
||||
|
||||
scan.end()
|
||||
26
script/test/test14.xml
Executable file
26
script/test/test14.xml
Executable file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<configuration xmlns="http://www.psi.ch/~ebner/models/scan/1.0" failOnSensorError="true">
|
||||
<notification>
|
||||
<recipient>alexandre.gobbo@psi.ch</recipient>
|
||||
</notification>
|
||||
<data fileName="test14"/>
|
||||
<description>My first test</description>
|
||||
<variable name="var1" value="0.0"/>
|
||||
<scan>
|
||||
<dimension>
|
||||
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="FunctionPositioner" name="TESTIOC:TESTCALCOUT:Input" id="id108088">
|
||||
<start>0.0</start>
|
||||
<end>20.0</end>
|
||||
<stepSize>1.0</stepSize>
|
||||
<function>
|
||||
<script>def calculate(parameter):
|
||||
return parameter*2</script>
|
||||
</function>
|
||||
</positioner>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="TESTIOC:TESTCALCOUT:Output" id="id348623"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="TESTIOC:TESTSINUS:SinCalc" id="id367393"/>
|
||||
</dimension>
|
||||
</scan>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="id108088" y="id348623"/>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="id108088" y="id367393"/>
|
||||
</configuration>
|
||||
15
script/test/test15.py
Executable file
15
script/test/test15.py
Executable file
@@ -0,0 +1,15 @@
|
||||
"""
|
||||
Area Scan with custom 1D plot
|
||||
"""
|
||||
set_preference(Preference.PLOT_TYPES, {'sin':1})
|
||||
|
||||
|
||||
|
||||
p = plot(None, title="1d")[0]
|
||||
def AfterReadout(record, scan):
|
||||
if record.setpoints[1] == scan.getStart()[1]:
|
||||
p.addSeries(LinePlotSeries(str(record.positions[0])))
|
||||
p.getSeries(p.numberOfSeries-1).appendData(record.positions[1], record.values[0])
|
||||
|
||||
|
||||
ascan((dev,out), (sin,arr), (0,10), (20,30), (20,20), 0.2, after_read=AfterReadout)
|
||||
34
script/test/test15.xml
Executable file
34
script/test/test15.xml
Executable file
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<configuration xmlns="http://www.psi.ch/~ebner/models/scan/1.0" failOnSensorError="true">
|
||||
<notification>
|
||||
<recipient>alexandre.gobbo@psi.ch</recipient>
|
||||
</notification>
|
||||
<data fileName="test2"/>
|
||||
<description>My second test</description>
|
||||
<variable name="var1" value="0.0"/>
|
||||
<scan>
|
||||
<dimension>
|
||||
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinearPositioner" name="TESTIOC:TESTCALCOUT:Input" id="id278043">
|
||||
<start>0.0</start>
|
||||
<end>31.0</end>
|
||||
<stepSize>1.0</stepSize>
|
||||
</positioner>
|
||||
<action xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScriptAction">
|
||||
<script>import time
|
||||
def process():
|
||||
time.sleep(0.1)</script>
|
||||
</action>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="TESTIOC:TESTCALCOUT:Output" id="id348623"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="TESTIOC:TESTSINUS:SinCalc" id="id367393"/>
|
||||
</dimension>
|
||||
<dimension>
|
||||
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinearPositioner" name="TESTIOC:TESTCALC:MyCalc" id="id643271">
|
||||
<start>0.0</start>
|
||||
<end>5.0</end>
|
||||
<stepSize>1.0</stepSize>
|
||||
</positioner>
|
||||
</dimension>
|
||||
</scan>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="id278043" y="id367393"/>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="MatrixPlot" x="id278043" y="id643271" z="id367393"/>
|
||||
</configuration>
|
||||
12
script/test/test16.py
Executable file
12
script/test/test16.py
Executable file
@@ -0,0 +1,12 @@
|
||||
|
||||
|
||||
#A single motor at current speed
|
||||
a= cscan(m1, (ai1,ai2), -2, 2 , steps=100, relative=True)
|
||||
|
||||
|
||||
#A single motor in a given time
|
||||
a= cscan(m1, (ai1,ai2), -2.0, 3.0, steps=100 ,time = 4.0, relative=True)
|
||||
|
||||
#Multiple motors in a given time
|
||||
a= cscan((m1, m2), (ai1,ai2), (-2.0, -3), (3.0, 5.0), steps=100,time = 4.0, relative=True)
|
||||
|
||||
34
script/test/test16.xml
Executable file
34
script/test/test16.xml
Executable file
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<configuration xmlns="http://www.psi.ch/~ebner/models/scan/1.0" failOnSensorError="true">
|
||||
<notification>
|
||||
<recipient>alexandre.gobbo@psi.ch</recipient>
|
||||
</notification>
|
||||
<data fileName="test2"/>
|
||||
<description>My second test</description>
|
||||
<variable name="var1" value="0.0"/>
|
||||
<scan>
|
||||
<dimension>
|
||||
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinearPositioner" name="TESTIOC:TESTCALCOUT:Input" id="id278043">
|
||||
<start>0.0</start>
|
||||
<end>31.0</end>
|
||||
<stepSize>1.0</stepSize>
|
||||
</positioner>
|
||||
<action xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScriptAction">
|
||||
<script>import time
|
||||
def process():
|
||||
time.sleep(0.1)</script>
|
||||
</action>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="TESTIOC:TESTCALCOUT:Output" id="id348623"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="TESTIOC:TESTSINUS:SinCalc" id="id367393"/>
|
||||
</dimension>
|
||||
<dimension>
|
||||
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinearPositioner" name="TESTIOC:TESTCALC:MyCalc" id="id643271">
|
||||
<start>0.0</start>
|
||||
<end>5.0</end>
|
||||
<stepSize>1.0</stepSize>
|
||||
</positioner>
|
||||
</dimension>
|
||||
</scan>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="id278043" y="id367393"/>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="MatrixPlot" x="id278043" y="id643271" z="id367393"/>
|
||||
</configuration>
|
||||
23
script/test/test17.py
Executable file
23
script/test/test17.py
Executable file
@@ -0,0 +1,23 @@
|
||||
"""
|
||||
Line Scan with 2 writables and triggering
|
||||
"""
|
||||
|
||||
index=0
|
||||
|
||||
x=0
|
||||
def AfterReadout(rec):
|
||||
global x
|
||||
print rec.getIndex() ,
|
||||
print " - ",
|
||||
print rec.values
|
||||
|
||||
|
||||
if rec.index==10 and x==0:
|
||||
x=1
|
||||
time.sleep(3.0)
|
||||
rec.invalidate()
|
||||
|
||||
|
||||
|
||||
|
||||
a= lscan((inp), (sin,out,arr), (0,), (40,), 20, 0.1, after_read=AfterReadout)
|
||||
21
script/test/test17.xml
Executable file
21
script/test/test17.xml
Executable file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<configuration xmlns="http://www.psi.ch/~ebner/models/scan/1.0" numberOfExecution="1" failOnSensorError="true">
|
||||
<notification>
|
||||
<recipient error="true" success="false">alexandre.gobbo@psi.ch</recipient>
|
||||
</notification>
|
||||
<data fileName="test1"/>
|
||||
<description>My first test</description>
|
||||
<variable name="var1" value="0.0"/>
|
||||
<scan>
|
||||
<dimension zigzag="false" dataGroup="false">
|
||||
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinearPositioner" name="TESTIOC:TESTCALCOUT:Input" asynchronous="false" id="id278043">
|
||||
<start>0.0</start>
|
||||
<end>31.0</end>
|
||||
<stepSize>0.01</stepSize>
|
||||
</positioner>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="TESTIOC:TESTCALCOUT:Output" id="id348623"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="TESTIOC:TESTSINUS:SinCalc" id="id367393"/>
|
||||
</dimension>
|
||||
</scan>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="id278043" y="id348623 id367393"/>
|
||||
</configuration>
|
||||
30
script/test/test18.py
Executable file
30
script/test/test18.py
Executable file
@@ -0,0 +1,30 @@
|
||||
"""
|
||||
Line Scan
|
||||
"""
|
||||
|
||||
attrs_dataset = None
|
||||
attrs_names = ["TESTIOC:TESTCALCOUT:Input",
|
||||
"TESTIOC:TESTCALCOUT:Output",
|
||||
"TESTIOC:TESTSINUS:SinCalc",
|
||||
"TESTIOC:TESTWF2:MyWF"]
|
||||
attrs_types = ["d", "d", "d", "[d"]
|
||||
attrs_lenghts = [0,0,0,10]
|
||||
|
||||
|
||||
def AfterReadout(rec):
|
||||
global attrs_dataset, attrs_names, attrs_type, attrs_lenghts
|
||||
if attrs_dataset is None:
|
||||
attrs_dataset = get_exec_pars().group() + "attributes"
|
||||
create_table(attrs_dataset, attrs_names, attrs_types, attrs_lenghts)
|
||||
record = []
|
||||
for i in range(len(attrs_names)):
|
||||
record.append(caget(attrs_names[i], attrs_types[i]))
|
||||
print record
|
||||
append_table(attrs_dataset, record)
|
||||
|
||||
a = lscan(m1, (ai1, ai2), 0, 0.1, 20, 0.01, after_read=AfterReadout)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
22
script/test/test18.xml
Executable file
22
script/test/test18.xml
Executable file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<configuration xmlns="http://www.psi.ch/~ebner/models/scan/1.0" numberOfExecution="1" failOnSensorError="true">
|
||||
<data fileName="test"/>
|
||||
<scan>
|
||||
<dimension zigzag="false" dataGroup="false">
|
||||
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="PseudoPositioner" id="id226053">
|
||||
<counts>4</counts>
|
||||
</positioner>
|
||||
</dimension>
|
||||
<dimension zigzag="false" dataGroup="false">
|
||||
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="PseudoPositioner" id="id236750">
|
||||
<counts>4</counts>
|
||||
</positioner>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Timestamp" id="id246209"/>
|
||||
</dimension>
|
||||
<manipulation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScriptManipulation" returnArray="false" id="id575126">
|
||||
<script>def process():
|
||||
return 0.0</script>
|
||||
</manipulation>
|
||||
</scan>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="MatrixPlot" x="id226053" y="id236750" z="id246209"/>
|
||||
</configuration>
|
||||
44
script/test/test19.py
Executable file
44
script/test/test19.py
Executable file
@@ -0,0 +1,44 @@
|
||||
import ch.psi.pshell.device.ReadonlyRegisterBase as ReadonlyRegisterBase
|
||||
import ch.psi.pshell.device.ReadonlyRegister.ReadonlyRegisterArray as ReadonlyRegisterArray
|
||||
|
||||
class Mean(Readable):
|
||||
def __init__(self, dev):
|
||||
self.dev =dev
|
||||
|
||||
def read(self):
|
||||
return mean(self.dev.take())
|
||||
|
||||
class Variance(Readable):
|
||||
def __init__(self, dev):
|
||||
self.dev =dev
|
||||
|
||||
def read(self):
|
||||
return variance(self.dev.take())
|
||||
|
||||
class Measures(ReadonlyRegisterBase, ReadonlyRegisterArray):
|
||||
def __init__(self, dev, count, interval=0):
|
||||
self.dev = dev
|
||||
self.count = count
|
||||
self.interval = interval
|
||||
self.initialize()
|
||||
|
||||
def getSize(self):
|
||||
return self.count
|
||||
|
||||
def doRead(self):
|
||||
measures = []
|
||||
for i in range(self.count):
|
||||
measures.append(self.dev.read())
|
||||
if self.interval>0 and i<(self.count-1):
|
||||
time.sleep(self.interval)
|
||||
return measures
|
||||
|
||||
|
||||
def average(dev, count, interval=0.0):
|
||||
#av = Measures(dev, count, interval)
|
||||
#return [av, Mean(av), Variance(av)]
|
||||
av = Averager(dev, count, int(interval*1000))
|
||||
av.initialize()
|
||||
return [av, av.samples, av.variance]
|
||||
|
||||
res= lscan(inp, average(sin,5,0.1), 0, 40, 20, 0.1)
|
||||
9
script/test/test2.js
Executable file
9
script/test/test2.js
Executable file
@@ -0,0 +1,9 @@
|
||||
function multiply(a, b) {
|
||||
a = (typeof a !== 'undefined') ? a : 3;
|
||||
b = (typeof b !== 'undefined') ? b : 1;
|
||||
return a * b;
|
||||
}
|
||||
|
||||
print (multiply(5, 2))
|
||||
print (multiply(5, 1))
|
||||
print (multiply(2))
|
||||
17
script/test/test2.py
Executable file
17
script/test/test2.py
Executable file
@@ -0,0 +1,17 @@
|
||||
"""
|
||||
Line Scan with 2 writables and triggering
|
||||
"""
|
||||
|
||||
index=0
|
||||
|
||||
def BeforeReadout():
|
||||
global index
|
||||
# print "Frame = " + str(index)
|
||||
index=index+1
|
||||
#log("trigger " + index)
|
||||
caput("TESTIOC:TESTBO:MyBO","On")
|
||||
caput("TESTIOC:TESTBO:MyBO","Off")
|
||||
|
||||
|
||||
a= lscan((m1,inp), (sin,out,arr), (0,0), (4,40), 20, 0.1, before_read=BeforeReadout)
|
||||
|
||||
1
script/test/test2.scan
Normal file
1
script/test/test2.scan
Normal file
@@ -0,0 +1 @@
|
||||
[ "Linear", [ [ "Device", "inp", 0.0, 10.0, 1.0 ] ], [ [ "Device", "sin", 2, 0.1, null ], [ "Device", "arr", null, 0.0, null ], [ "Channel", "TESTIOC:TESTCALCOUT:Output", 2, 0.1, null ], [ "Channel", "TESTIOC:TESTSINUS:SinCalc?monitored=true&op=samples&name=aux", 3, -1.0, "Line" ] ], false, [ ], "", 1, 1.0, 0.1, false, false, true, true, "", "", "Default", "h5", 0, null, null, "Positioner", false ]
|
||||
34
script/test/test2.xml
Executable file
34
script/test/test2.xml
Executable file
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<configuration xmlns="http://www.psi.ch/~ebner/models/scan/1.0" failOnSensorError="true">
|
||||
<notification>
|
||||
<recipient>alexandre.gobbo@psi.ch</recipient>
|
||||
</notification>
|
||||
<data fileName="test2"/>
|
||||
<description>My second test</description>
|
||||
<variable name="var1" value="0.1" description="HAHAHA"/>
|
||||
<scan>
|
||||
<dimension>
|
||||
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinearPositioner" name="TESTIOC:TESTCALCOUT:Input" id="id278043">
|
||||
<start>0.0</start>
|
||||
<end>31.0</end>
|
||||
<stepSize>1.0</stepSize>
|
||||
</positioner>
|
||||
<action xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScriptAction">
|
||||
<script>import time
|
||||
def process():
|
||||
time.sleep(0.1)</script>
|
||||
</action>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="TESTIOC:TESTCALCOUT:Output" id="id348623"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="TESTIOC:TESTSINUS:SinCalc" id="id367393"/>
|
||||
</dimension>
|
||||
<dimension>
|
||||
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinearPositioner" name="TESTIOC:TESTCALC:MyCalc" id="id643271">
|
||||
<start>0.0</start>
|
||||
<end>5.0</end>
|
||||
<stepSize>1.0</stepSize>
|
||||
</positioner>
|
||||
</dimension>
|
||||
</scan>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="id278043" y="id367393"/>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="MatrixPlot" x="id278043" y="id643271" z="id367393"/>
|
||||
</configuration>
|
||||
29
script/test/test20.py
Executable file
29
script/test/test20.py
Executable file
@@ -0,0 +1,29 @@
|
||||
from mathutils import deriv, interpolate, fit_polynomial, PolynomialFunction, get_values
|
||||
|
||||
|
||||
start = 0
|
||||
end = 10
|
||||
step_size = 0.1
|
||||
|
||||
result= lscan(out,sin,start,end,[step_size,],0.01)
|
||||
readable = result.getReadable(0)
|
||||
positions = result.getPositions(0)
|
||||
|
||||
pars_polynomial = (a0, a1, a2, a3, a4, a5, a6) = fit_polynomial(readable, positions, 6)
|
||||
fitted_polynomial_function = PolynomialFunction(pars_polynomial)
|
||||
|
||||
resolution = step_size/100
|
||||
fit_polinomial = []
|
||||
for x in frange(start,end,resolution, True):
|
||||
fit_polinomial.append(fitted_polynomial_function.value(x))
|
||||
x = frange(start, end+resolution, resolution)
|
||||
|
||||
d = deriv(fitted_polynomial_function,x)
|
||||
|
||||
d2 = deriv(readable,positions)
|
||||
f = interpolate(readable,positions)
|
||||
f2 = interpolate(readable,positions, "cubic")
|
||||
|
||||
|
||||
plot([get_values(f,frange(0,10,0.01)), get_values(f2,frange(0,10,0.01))], ["f", "f2"], title = "aux")
|
||||
plots = plot([readable, fit_polinomial, d, d2] , ["data", "polinomial", "deriv", "d2"], xdata = [positions,x,x, positions], title="Data")
|
||||
37
script/test/test21.py
Executable file
37
script/test/test21.py
Executable file
@@ -0,0 +1,37 @@
|
||||
from mathutils import *
|
||||
|
||||
#interpolation
|
||||
y = [0, 1, 4,10,50,25,12, 5, 3, 0]
|
||||
x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
types = "linear", "cubic", "akima", "loess", "neville", "newton"
|
||||
functions = [interpolate(y,x,t) for t in types]
|
||||
|
||||
plot_x = frange (0,9,0.01)
|
||||
values = [get_values(f,plot_x) for f in functions]
|
||||
plots=plot(values,types,plot_x)
|
||||
|
||||
#derivative
|
||||
for i in range(len(types)):
|
||||
try:
|
||||
d = deriv(functions[i])
|
||||
plots[i].addSeries(LinePlotSeries("Derivative"))
|
||||
plots[i].getSeries(1).setData(plot_x, get_values(d,plot_x))
|
||||
except:
|
||||
#not differentiable
|
||||
pass
|
||||
|
||||
#integration
|
||||
for i in range(len(types)):
|
||||
s = integrate(functions[i],x)
|
||||
plots[i].addMarker(x[-1], None, "Integral=" + str(round(s,4)), java.awt.Color.DARK_GRAY)
|
||||
|
||||
|
||||
|
||||
|
||||
#Direct calculation on arrays:
|
||||
|
||||
print "Deriv (linear interpolation): ", deriv(y,x)
|
||||
print "Deriv (cubic interpolation): ", deriv(y, x, "cubic")
|
||||
print "Integral (linear interpolation): ", integrate(y, None, x, "cubic")
|
||||
print "Integral (cubic interpolation): ", integrate(y, None, x, "cubic")
|
||||
print "Integral (linear interpolation in range [1,5]): ", integrate(y, [1,5], x)
|
||||
34
script/test/test22.py
Executable file
34
script/test/test22.py
Executable file
@@ -0,0 +1,34 @@
|
||||
tutorial_path = "src/main/assembly/help/Tutorial/"
|
||||
run(tutorial_path+"00_Devices")
|
||||
|
||||
|
||||
|
||||
import ch.psi.pshell.epics.CAS as CAS
|
||||
|
||||
cas = []
|
||||
|
||||
#CAS.setServerPort(5062)
|
||||
|
||||
CAS("TESTCAS:c1", ai1, 'double')
|
||||
cas1 = CAS("TESTCAS:c2", ai1, 'int')
|
||||
cas2 = CAS("TESTCAS:c3", ai1, 'string')
|
||||
cas3 = CAS("TESTCAS:c4", ao1, 'double')
|
||||
cas4 = CAS("TESTCAS:c5", dp1, 'string')
|
||||
cas5 = CAS("TESTCAS:c6", wf1, 'double')
|
||||
cas6 = CAS("TESTCAS:c7", wf1, 'int')
|
||||
cas7 = CAS("TESTCAS:c8", wf1, 'string')
|
||||
|
||||
print caget("TESTCAS:c1")
|
||||
print caget("TESTCAS:c2")
|
||||
print caget("TESTCAS:c3")
|
||||
print caget("TESTCAS:c4")
|
||||
print caget("TESTCAS:c5")
|
||||
print caget("TESTCAS:c6").tolist()
|
||||
print caget("TESTCAS:c7").tolist()
|
||||
print caget("TESTCAS:c8","[s").tolist()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
32
script/test/test23.py
Executable file
32
script/test/test23.py
Executable file
@@ -0,0 +1,32 @@
|
||||
|
||||
type = '[s'
|
||||
name = 'TESTCAS:c4'
|
||||
|
||||
|
||||
import java.beans.PropertyChangeListener as PropertyChangeListener
|
||||
#import java.beans.PropertyChangeEvent as PropertyChangeEvent
|
||||
|
||||
scalar = not type.startswith('[')
|
||||
#val = lambda x: x if scalar else x.tolist()
|
||||
val = lambda x: x
|
||||
class MonitorListener(PropertyChangeListener):
|
||||
def propertyChange(self, pce):
|
||||
print val(pce.getNewValue())
|
||||
|
||||
|
||||
|
||||
|
||||
channel = create_channel(name, type = type)
|
||||
|
||||
print val(channel.getValue())
|
||||
channel.setMonitored(True)
|
||||
changeListener = MonitorListener()
|
||||
channel.addPropertyChangeListener(changeListener)
|
||||
|
||||
try:
|
||||
time.sleep(sys.maxint)
|
||||
finally:
|
||||
channel.removePropertyChangeListener(changeListener)
|
||||
Epics.closeChannel(channel)
|
||||
print "ok"
|
||||
|
||||
16
script/test/test24.py
Executable file
16
script/test/test24.py
Executable file
@@ -0,0 +1,16 @@
|
||||
|
||||
plots = None
|
||||
def plot_hist(data):
|
||||
global plots
|
||||
(h,x) = histogram(data) #(h,x) = histogram(data, 0, 255) is more efficient: no neet to calculate min & max
|
||||
if plots is None:
|
||||
plots = plot(h, xdata = x, title = "Histo")
|
||||
else:
|
||||
plots[0].getSeries(0).setData(x,h)
|
||||
|
||||
while(True):
|
||||
data = img.getData().getRectSelection(0,0,500,250)
|
||||
plot_hist(data)
|
||||
if plots[0].displayable == False:
|
||||
break
|
||||
time.sleep(0.250)
|
||||
6
script/test/test25.py
Executable file
6
script/test/test25.py
Executable file
@@ -0,0 +1,6 @@
|
||||
x = [10,20,30,40,50,60]
|
||||
p = plot(None,name="Data 1")[0]
|
||||
p.addSeries(LinePlotSeries("Data2"))
|
||||
p.getSeries(0).setData(x, [1,2,3,4,5,6])
|
||||
p.getSeries(1).setData(x, [6,5,4,3,2,1])
|
||||
p.addMarker(35.0, None, "This is the answer", None)
|
||||
14
script/test/test26.py
Executable file
14
script/test/test26.py
Executable file
@@ -0,0 +1,14 @@
|
||||
###################################################################################################
|
||||
# Multipass and zigzag scans
|
||||
###################################################################################################
|
||||
|
||||
|
||||
#Linear with 2 passes
|
||||
a= lscan(m1, (ai1,wf1), -0.2, 0.2, 20, relative = True, passes = 4)
|
||||
|
||||
#Linear with 4 passes and zigzag
|
||||
a= lscan(m1, (ai1,wf1), -0.2, 0.2, 20, relative = True, passes = 4, zigzag = True)
|
||||
|
||||
|
||||
#Multi-dimentional zigzag
|
||||
x = ascan ([m1,m2], ai1, [0,0], [1, 1], [0.25,0.25], latency=0.01, zigzag=True)
|
||||
48
script/test/test27.py
Executable file
48
script/test/test27.py
Executable file
@@ -0,0 +1,48 @@
|
||||
import ch.psi.pshell.device.ArrayCalibration as ArrayCalibration
|
||||
import ch.psi.pshell.device.MatrixCalibration as MatrixCalibration
|
||||
|
||||
class Scalar(Readable):
|
||||
def read(self):
|
||||
return 1.0
|
||||
|
||||
class Array(ReadableArray):
|
||||
def read(self):
|
||||
return range(self.getSize())
|
||||
|
||||
def getSize(self):
|
||||
return 10
|
||||
|
||||
class Matrix(ReadableMatrix):
|
||||
def read(self):
|
||||
return [range(self.getWidth()),] * self.getHeight()
|
||||
|
||||
def getWidth(self):
|
||||
return 20
|
||||
|
||||
def getHeight(self):
|
||||
return 5
|
||||
|
||||
class ArrayCalibrated(Array, Readable.ReadableCalibratedArray):
|
||||
def getCalibration(self):
|
||||
return ArrayCalibration(5,1000)
|
||||
|
||||
class ArrayCalibrated1d(Array, Readable.ReadableCalibratedArray):
|
||||
def getCalibration(self):
|
||||
return ArrayCalibration(5,1000)
|
||||
|
||||
class MatrixCalibrated(Matrix, Readable.ReadableCalibratedMatrix):
|
||||
def getCalibration(self):
|
||||
return MatrixCalibration(2,4,100,200)
|
||||
|
||||
scalar = Scalar()
|
||||
array = Array()
|
||||
matrix = Matrix()
|
||||
arrayCalibrated = ArrayCalibrated()
|
||||
arrayCalibrated1d = ArrayCalibrated1d()
|
||||
matrixCalibrated = MatrixCalibrated()
|
||||
|
||||
|
||||
set_preference(Preference.PLOT_TYPES, {arrayCalibrated1d:1})
|
||||
|
||||
|
||||
a= lscan(out, [scalar, array, arrayCalibrated, arrayCalibrated1d, matrix, matrixCalibrated], 0, 40, 200)
|
||||
48
script/test/test28.py
Executable file
48
script/test/test28.py
Executable file
@@ -0,0 +1,48 @@
|
||||
import ch.psi.pshell.epics.CAS as CAS
|
||||
|
||||
|
||||
|
||||
class ScanDevice(ReadonlyAsyncRegisterBase, ReadonlyRegisterArray):
|
||||
def getSize(self):
|
||||
global scan_result
|
||||
return len(self.take())
|
||||
|
||||
def append(self, value):
|
||||
c = self.take()
|
||||
c.append(value)
|
||||
self.set(c)
|
||||
|
||||
def set(self, value):
|
||||
self.onReadout(to_array(value, 'd'))
|
||||
|
||||
|
||||
|
||||
if get_device("scan_pos") is None:
|
||||
add_device(ScanDevice("scan_pos"), True)
|
||||
add_device(ScanDevice("scan_val"), True)
|
||||
scan_pos.set([])
|
||||
scan_val.set([])
|
||||
|
||||
cas1 = CAS("PSHELL:scanpos",scan_pos, "double")
|
||||
cas2 = CAS("PSHELL:scanval",scan_val, "double")
|
||||
cas3 = CAS("PSHELL:var",ai1)
|
||||
|
||||
scan_pos.set([])
|
||||
scan_val.set([])
|
||||
|
||||
|
||||
|
||||
scan_pos.set([])
|
||||
scan_val.set([])
|
||||
|
||||
def after(rec):
|
||||
scan_pos.append(rec.positions[0])
|
||||
scan_val.append(rec.values[0])
|
||||
|
||||
res = lscan(ao1, ai1, 0, 40, 40, 0.1, after_read = after)
|
||||
#scan_pos.set(res.getPositions(0))
|
||||
#scan_val.set(res.getReadable(0))
|
||||
|
||||
set_return(res.print())
|
||||
|
||||
|
||||
16
script/test/test29.py
Executable file
16
script/test/test29.py
Executable file
@@ -0,0 +1,16 @@
|
||||
[py, px, pxy]=plot([None,None,None],["y","x", "xy"])
|
||||
|
||||
|
||||
|
||||
|
||||
#XY error plot
|
||||
pxy.setStyle(pxy.Style.ErrorXY)
|
||||
pxy.setLegendVisible(True)
|
||||
sxy = LinePlotErrorSeries("F4")
|
||||
pxy.addSeries(sxy)
|
||||
#sxy.appendData(1.0,0.5,1.5, 10.0, 9.0, 11.0)
|
||||
#sxy.appendData(10.0,9.0, 11.0, 6.1, 4.34, 7.54)
|
||||
#sxy.appendData(17.8, 17.0, 18.0, 4.5, 3.1, 5.8)
|
||||
|
||||
|
||||
sxy.setData([1,2,3,4,5],[4,6,3,2,1])
|
||||
5
script/test/test3.js
Executable file
5
script/test/test3.js
Executable file
@@ -0,0 +1,5 @@
|
||||
|
||||
run("jeputils")
|
||||
//Running a modole
|
||||
run_jep("cpython")
|
||||
|
||||
21
script/test/test3.py
Executable file
21
script/test/test3.py
Executable file
@@ -0,0 +1,21 @@
|
||||
"""
|
||||
Processing and plotting scan data
|
||||
"""
|
||||
|
||||
inp.write(0.0)
|
||||
scan1= lscan(inp, (sin,out,arr), 0, 40, 20, 0.1, False, "Scan 1")
|
||||
scan2= lscan(inp, (sin,out,arr), 0, 40, 20, 0.1, False, "Scan 2")
|
||||
|
||||
|
||||
from operator import add
|
||||
result = map(add, scan1.getReadable(0), scan2.getReadable(0))
|
||||
|
||||
#Alternative:
|
||||
#result=[]
|
||||
#for i in range(len(scan1.records)):
|
||||
# result.append(scan1.records[i].values[0]+scan2.records[i].values[0])
|
||||
|
||||
|
||||
plot(result)
|
||||
print result
|
||||
|
||||
1
script/test/test3.scan
Normal file
1
script/test/test3.scan
Normal file
@@ -0,0 +1 @@
|
||||
[ "Linear", [ ], [ ], [ ], [ ], "", 1, 1.0, 0.0, false, false, true, true, "", "", "Default", "h5", null, null, "Positioner" ]
|
||||
35
script/test/test3.xml
Executable file
35
script/test/test3.xml
Executable file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<configuration xmlns="http://www.psi.ch/~ebner/models/scan/1.0" numberOfExecution="1" failOnSensorError="true">
|
||||
<notification>
|
||||
<recipient>alexandre.gobbo@psi.ch</recipient>
|
||||
</notification>
|
||||
<data fileName="test3"/>
|
||||
<description>My third test</description>
|
||||
<variable name="var1" value="0.0"/>
|
||||
<scan>
|
||||
<dimension>
|
||||
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinearPositioner" name="TESTIOC:TESTCALCOUT:Input" id="id278043">
|
||||
<start>0.0</start>
|
||||
<end>31.0</end>
|
||||
<stepSize>1.0</stepSize>
|
||||
</positioner>
|
||||
<action xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScriptAction">
|
||||
<mapping channel="TESTIOC:TESTSINUS:SinCalc" variable="x"/>
|
||||
<script>import time
|
||||
def process(x):
|
||||
time.sleep(0.1)
|
||||
#print "==>" + str(x.getValue())
|
||||
</script>
|
||||
</action>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="TESTIOC:TESTCALCOUT:Output" id="id348623"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="TESTIOC:TESTSINUS:SinCalc" id="id367393"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Timestamp" id="id192931"/>
|
||||
</dimension>
|
||||
<manipulation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScriptManipulation" id="id173831">
|
||||
<mapping xsi:type="IDParameterMapping" refid="id367393" variable="v"/>
|
||||
<script>def process(v):
|
||||
return v+100.0</script>
|
||||
</manipulation>
|
||||
</scan>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="id192931" y="id348623 id173831"/>
|
||||
</configuration>
|
||||
98
script/test/test30.py
Executable file
98
script/test/test30.py
Executable file
@@ -0,0 +1,98 @@
|
||||
###################################################################################################
|
||||
# Example of least squares optimization
|
||||
# http://commons.apache.org/proper/commons-math/userguide/leastsquares.html
|
||||
###################################################################################################
|
||||
|
||||
|
||||
from mathutils import *
|
||||
from plotutils import *
|
||||
|
||||
[p1,p2] = plot([None, None], [None, None])
|
||||
|
||||
###################################################################################################
|
||||
#Fitting the quadratic function f(x) = a x2 + b x + c
|
||||
###################################################################################################
|
||||
x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
|
||||
y = [36.0, 66.0, 121.0, 183.0, 263.0, 365.0, 473.0, 603.0, 753.0, 917.0]
|
||||
num_samples = len(x)
|
||||
weigths = [ 1.0] * num_samples
|
||||
|
||||
p1.getSeries(0).setData(x, y)
|
||||
p1.getSeries(0)
|
||||
|
||||
class Model(MultivariateJacobianFunction):
|
||||
def value(self, variables):
|
||||
value = ArrayRealVector(num_samples)
|
||||
jacobian = Array2DRowRealMatrix(num_samples, 3)
|
||||
for i in range(num_samples):
|
||||
(a,b,c) = (variables.getEntry(0), variables.getEntry(1), variables.getEntry(2))
|
||||
model = a*x[i]*x[i] + b*x[i] + c
|
||||
value.setEntry(i, model)
|
||||
jacobian.setEntry(i, 0, x[i]*x[i]) # derivative with respect to p0 = a
|
||||
jacobian.setEntry(i, 1, x[i]) # derivative with respect to p1 = b
|
||||
jacobian.setEntry(i, 2, 1.0) # derivative with respect to p2 = c
|
||||
return Pair(value, jacobian)
|
||||
|
||||
model = Model()
|
||||
initial = [1.0, 1.0, 1.0] #parameters = a, b, c
|
||||
target = [v for v in y] #the target is to have all points at the positios
|
||||
|
||||
(parameters, residuals, rms, evals, iters) = optimize_least_squares(model, target, initial, weigths)
|
||||
|
||||
(a,b,c) = parameters
|
||||
|
||||
print "A: ", a , " B: ", b, " C: ", c
|
||||
print "RMS: " , rms, " evals: " , evals, " iters: " , iters
|
||||
for i in range (num_samples):
|
||||
print x[i], y[i], poly(x[i], [c,b,a])
|
||||
|
||||
plot_function(p1, PolynomialFunction((c,b,a)), "Fit", x)
|
||||
print "----------------------------------------------------------------------------\n"
|
||||
|
||||
|
||||
###################################################################################################
|
||||
#Fiting center of circle of known radius to observerd points
|
||||
###################################################################################################
|
||||
|
||||
|
||||
#Fiting center of circle of radius 70 to observerd points
|
||||
radius = 70.0
|
||||
x = [30.0, 50.0, 110.0, 35.0, 45.0]
|
||||
y = [68.0, -6.0, -20.0, 15.0, 97.0]
|
||||
num_samples = len(x)
|
||||
weigths = [ 1.0] * num_samples
|
||||
weigths = [0.1, 0.1, 1.0, 0.1, 1.0]
|
||||
|
||||
p2.getSeries(0).setData(x, y)
|
||||
p2.getSeries(0).setLinesVisible(False)
|
||||
p2.getSeries(0).setPointSize(4)
|
||||
|
||||
# the model function components are the distances to current estimated center,
|
||||
# they should be as close as possible to the specified radius
|
||||
class Model(MultivariateJacobianFunction):
|
||||
def value(self, variables):
|
||||
(cx,cy) = (variables.getEntry(0), variables.getEntry(1))
|
||||
value = ArrayRealVector(num_samples)
|
||||
jacobian = Array2DRowRealMatrix(num_samples, 2)
|
||||
for i in range(num_samples):
|
||||
model = math.hypot(cx-x[i], cy-y[i])
|
||||
value.setEntry(i, model)
|
||||
jacobian.setEntry(i, 0, (cx - x[i]) / model) # derivative with respect to p0 = x center
|
||||
jacobian.setEntry(i, 1, (cy - y[i]) / model) # derivative with respect to p1 = y center
|
||||
return Pair(value, jacobian)
|
||||
|
||||
model = Model() #modeled radius should be close to target radius
|
||||
initial = [mean(x), mean(y)] #parameters = cx, cy
|
||||
target = [radius,] * num_samples #the target is to have all points at the specified radius from the center
|
||||
|
||||
(parameters, residuals, rms, evals, iters) = optimize_least_squares(model, target, initial, weigths)
|
||||
|
||||
(cx, cy) = parameters
|
||||
|
||||
print "CX: ", cx , " CY: ", cy
|
||||
print "RMS: " , rms, " evals: " , evals, " iters: " , iters
|
||||
|
||||
|
||||
from plotutils import *
|
||||
plot_point(p2, cx, cy, name="Fit Cente")
|
||||
plot_circle(p2, cx, cy, radius, name="Fit")
|
||||
13
script/test/test31.py
Executable file
13
script/test/test31.py
Executable file
@@ -0,0 +1,13 @@
|
||||
tutorial_path = "src/main/assembly/help/Tutorial/"
|
||||
run(tutorial_path+"00_devices")
|
||||
|
||||
|
||||
|
||||
def after(rec):
|
||||
if rec.index==1:
|
||||
(p1,p2) = get_plots("Jitter Scan")
|
||||
p1.setScale(0.0, 2.0)
|
||||
p2.setScale(0.0, 1.0)
|
||||
|
||||
ascan((m1,m2), (ai1,ai2), (0.0,0.0), (0.5,0.5), (5,5), after_read=after, title = "Jitter Scan")
|
||||
|
||||
29
script/test/test32.py
Executable file
29
script/test/test32.py
Executable file
@@ -0,0 +1,29 @@
|
||||
from mathutils import *
|
||||
from plotutils import *
|
||||
|
||||
|
||||
x = [ 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0,18.0]
|
||||
y = [ 30.0, 22.0, 12.0, 10.0, 11.0, 14.0, 21.0, 32.0]
|
||||
v = [ 0.3, 0.8, 0.4, 0.3, 0.5, 0.4, 0.3, 0.2]
|
||||
|
||||
w = [ 1/ max(i,0.1) for i in v]
|
||||
|
||||
|
||||
|
||||
p=plot(None)[0]
|
||||
p.setStyle(p.Style.ErrorY)
|
||||
p.setLegendVisible(True)
|
||||
s1 = LinePlotErrorSeries("Observed Data")
|
||||
p.addSeries(s1)
|
||||
for i in range(len(x)):\
|
||||
s1.appendData(x[i], y[i], v[i])
|
||||
|
||||
|
||||
pars_polynomial= fit_polynomial(y, x, 2, None, w)
|
||||
function = PolynomialFunction(pars_polynomial)
|
||||
plot_function(p, function, "Fit" , frange (min(x), max(x), 0.1), False)
|
||||
|
||||
print "(a0,a1,a2) = " , pars_polynomial
|
||||
|
||||
for xp in x:
|
||||
print xp, poly(xp, pars_polynomial)
|
||||
50
script/test/test33.py
Executable file
50
script/test/test33.py
Executable file
@@ -0,0 +1,50 @@
|
||||
start = time.time()
|
||||
|
||||
#setup_plotting( enable_table=False)
|
||||
#set_exec_pars(accumulate = False, persist = False)
|
||||
#set_preference(Preference.PLOT_TYPES, {det.getDataMatrix():"ch.psi.pshell.plot.MatrixPlotRenderer"})
|
||||
#tscan(det.getDataMatrix(), 1000,0.00)
|
||||
|
||||
|
||||
|
||||
#for i in range(100000):
|
||||
# det.getDataMatrix().read()
|
||||
|
||||
arr = [1.0] * 1000
|
||||
arr = [arr,] * 1000
|
||||
|
||||
p = plot(arr)[0]
|
||||
print time.time() - start,
|
||||
print " ",
|
||||
start = time.time()
|
||||
|
||||
|
||||
#for i in range(100):
|
||||
# p.getSeries(0).setData(arr)
|
||||
#0.103999853134 10.1759998798 CPU=52
|
||||
#0.118000030518 9.76999998093 CPU=42
|
||||
|
||||
#p.setScale(0,500000)
|
||||
#for i in range(500000):
|
||||
# x = i % 1000
|
||||
# y = i % 1000 + i/1000
|
||||
# p.getSeries(0).appendData(x,y,i)
|
||||
#p.update(True);
|
||||
#0.115999937057 1.13800001144 CPU=52
|
||||
#0.101000070572 1.10399985313 CPU=22
|
||||
#Fixed range
|
||||
|
||||
#0.0950000286102 1.1289999485 CPU = 50
|
||||
#0.0909998416901 1.09500002861
|
||||
|
||||
|
||||
#p.setScale(0,500000)
|
||||
for i in range(1000):
|
||||
for j in range(1000):
|
||||
p.getSeries(0).appendData(i,j,i*1000+j)
|
||||
p.update(True);
|
||||
|
||||
#0.0999999046326 1.61400008202 CPU = 60
|
||||
#0.101000070572 1.72300004959
|
||||
print time.time() - start
|
||||
|
||||
35
script/test/test34.py
Executable file
35
script/test/test34.py
Executable file
@@ -0,0 +1,35 @@
|
||||
|
||||
class FitnessFunction(ReadonlyRegisterBase):
|
||||
def doRead(self):
|
||||
return 1000.0 - (math.pow(inp.take()-18, 2) + math.pow(out.take()-6, 2) + test.take())
|
||||
|
||||
add_device(FitnessFunction("fitness"), True)
|
||||
|
||||
inp.read();out.read();test.read()
|
||||
|
||||
|
||||
#Fitness Function
|
||||
r = ascan([inp, out], fitness, [0.0,0.0], [21.0,26.0], [1.1,1.1], title = "Fitness")
|
||||
|
||||
|
||||
#Binary Search
|
||||
strategy = "Normal" # or "Boundary" or "FullNeighborhood"
|
||||
r = bsearch([inp, out], fitness, [0.0,0.0], [21.0,26.0], [0.1, 0.1], maximum=True, strategy = strategy, latency = 0.01, title = "Binary Search")
|
||||
#Relative search:
|
||||
#inp.write(10.5);out.write(13.0)
|
||||
#r = bsearch([inp, out], fitness, [-10.5,-13.0], [10.5,13.0], [0.1, 0.1],relative = True, maximum=True, strategy = "Normal", title = "Binary Search")
|
||||
|
||||
print "--------------- Binary Search -----------------"
|
||||
print r
|
||||
print r.print()
|
||||
print len(r.getRecords())
|
||||
|
||||
|
||||
|
||||
inp.write(10.5)
|
||||
out.write(13.0)
|
||||
r = hsearch([inp, out], fitness,[0.0,0.0], [21.0,26.0], [1.0, 1.0], [0.1, 0.1], 1, relative = False, maximum=True, latency = 0.01, title = "Hill Climbing")
|
||||
print "--------------- Hill Climbing Search -----------------"
|
||||
print r
|
||||
print r.print()
|
||||
print len(r.getRecords())
|
||||
14
script/test/test35.py
Executable file
14
script/test/test35.py
Executable file
@@ -0,0 +1,14 @@
|
||||
tutorial_path = "src/main/assembly/help/Tutorial/"
|
||||
run(tutorial_path+"00_devices")
|
||||
|
||||
class FitnessFunction(ReadonlyRegisterBase):
|
||||
def doRead(self):
|
||||
return 1000.0 - (math.pow(ao1.take()-18, 2) + math.pow(ao2.take()-6, 2))
|
||||
|
||||
add_device(FitnessFunction("fitness"), True)
|
||||
|
||||
#a= lscan(ao1, (wf1), 5, 0, 0.1)
|
||||
#a= lscan(ao1, (wf1), 0, 5, 0.1)
|
||||
r = ascan([ao1, ao2], fitness, [0.0,0.0], [21.0,21.0], [1.1, 1.1], title = "Fitness")
|
||||
s= 1.1
|
||||
r = ascan([ao1, ao2], fitness, [0.0,0.0], [4.0,4.0], [s, s], title = "Fitness")
|
||||
86
script/test/test36.py
Executable file
86
script/test/test36.py
Executable file
@@ -0,0 +1,86 @@
|
||||
###################################################################################################
|
||||
# Calibrating array and matrix pseudo-devices
|
||||
###################################################################################################
|
||||
|
||||
|
||||
|
||||
class Waveform(ReadonlyRegisterBase, ReadonlyRegisterArray):
|
||||
def doRead(self):
|
||||
time.sleep(0.001)
|
||||
self.val = to_array(self.calc(), 'd')
|
||||
return self.val
|
||||
|
||||
def getSize(self):
|
||||
return len(self.take(-1)) #only reads if cache is None
|
||||
|
||||
class Image(ReadonlyRegisterBase, ReadonlyRegisterMatrix):
|
||||
def doRead(self):
|
||||
time.sleep(0.001)
|
||||
self.val = to_array(self.calc(), 'd')
|
||||
return self.val
|
||||
|
||||
def getWidth(self):
|
||||
return len(self.take(-1)[0])
|
||||
|
||||
def getHeight(self):
|
||||
return len(self.take(-1))
|
||||
|
||||
|
||||
|
||||
class SinusoidWaveform(Waveform):
|
||||
def calc(self):
|
||||
ret = []
|
||||
x = random.random()
|
||||
for i in range (20):
|
||||
ret.append(math.sin(x))
|
||||
x = x + 0.1
|
||||
return ret
|
||||
|
||||
class SinusoidImage(Image):
|
||||
def calc(self):
|
||||
(width, height) = (200, 100)
|
||||
ret = []
|
||||
x = random.random();
|
||||
base = []
|
||||
for i in range (width):
|
||||
base.append( math.sin(x))
|
||||
x = x + 0.05
|
||||
for i in range (height):
|
||||
noise = (random.random() - 0.5)/5.0
|
||||
ret.append([x+noise for x in base])
|
||||
return ret
|
||||
|
||||
add_device(SinusoidWaveform("wf1"), True)
|
||||
add_device(SinusoidImage("im1"), True)
|
||||
|
||||
|
||||
class ArrayCalibrated(ReadonlyRegisterBase, ReadonlyRegisterArray, ReadableCalibratedArray):
|
||||
def doRead(self):
|
||||
return wf1.read()
|
||||
|
||||
def getSize(self):
|
||||
return wf1.size
|
||||
|
||||
def getCalibration(self):
|
||||
return ArrayCalibration(5,1000)
|
||||
|
||||
|
||||
|
||||
class MatrixCalibrated(ReadonlyRegisterBase, ReadonlyRegisterMatrix, ReadableCalibratedMatrix):
|
||||
def doRead(self):
|
||||
return im1.read()
|
||||
|
||||
def getWidth(self):
|
||||
return im1.width
|
||||
|
||||
def getHeight(self):
|
||||
return im1.height
|
||||
|
||||
def getCalibration(self):
|
||||
return MatrixCalibration(2,4,100,200)
|
||||
|
||||
add_device(ArrayCalibrated()
|
||||
, True)
|
||||
add_device( MatrixCalibrated()
|
||||
, True)
|
||||
ArrayCalibrated.polling=100
|
||||
21
script/test/test37.py
Executable file
21
script/test/test37.py
Executable file
@@ -0,0 +1,21 @@
|
||||
tutorial_path = "src/main/assembly/help/Tutorial/"
|
||||
run(tutorial_path+"00_devices")
|
||||
|
||||
|
||||
|
||||
class ArrayCalibrated(ReadableArray, ReadableCalibratedArray):
|
||||
def read(self):
|
||||
return wf1.read()
|
||||
|
||||
def getSize(self):
|
||||
return wf1.size
|
||||
|
||||
def getCalibration(self):
|
||||
return ArrayCalibration(5,1000)
|
||||
|
||||
ac1 = ArrayCalibrated()
|
||||
|
||||
#The data window never displays 3d data, but the 3d data can be accesses during the scan in the Data tab.
|
||||
ascan((m1,m2), (ac1, wf1), (0.0,0.0), (2.0,1.0), (19,19))
|
||||
|
||||
|
||||
23
script/test/test38.py
Executable file
23
script/test/test38.py
Executable file
@@ -0,0 +1,23 @@
|
||||
from ijutils import *
|
||||
import java.awt.Color as Color
|
||||
|
||||
|
||||
ip2 = load_image("images/img2.png", title="Image2")
|
||||
|
||||
ip3 = new_image(256, 256, "color", fill_color = Color.WHITE)
|
||||
ip4 = new_image(256, 256, "color", fill_color =Color.WHITE)
|
||||
|
||||
copy_image_to(ip2, ip3, 25, 25)
|
||||
copy_image_to(sub_image(ip2, 11, 33, 24,24), ip4, 123, 123)
|
||||
|
||||
|
||||
#Correlate, convolve, deconvolve
|
||||
grayscale(ip3)
|
||||
grayscale(ip4)
|
||||
|
||||
cor = op_fft(ip3, ip4, "correlate", True)
|
||||
con = op_fft(ip3, ip4, "convolve", True)
|
||||
dec = op_fft(con, ip4, "deconvolve", True)
|
||||
|
||||
create_stack([ip3,ip4, grayscale(cor,False),grayscale(con,False),grayscale(dec,False)], title = "Correlation").show()
|
||||
|
||||
167
script/test/test39.py
Executable file
167
script/test/test39.py
Executable file
@@ -0,0 +1,167 @@
|
||||
x = to_array([0,1,2,3,4,5,6,7,8,9,10],'i')
|
||||
y = to_array([1,2,3,4,5,10, 50, 11, 4,3,1],'i')
|
||||
|
||||
|
||||
|
||||
|
||||
def to_array(obj, type = 'o'):
|
||||
"""Convert Python list to Java array.
|
||||
|
||||
Args:
|
||||
obj(list): Original data.
|
||||
type(str): array type 'b' = byte, 'h' = short, 'i' = int, 'l' = long, 'f' = float, 'd' = double,
|
||||
'c' = char, 'z' = boolean, 's' = String, 'o' = Object
|
||||
Returns:
|
||||
Java array.
|
||||
|
||||
"""
|
||||
if type[0] == '[':
|
||||
type = type[1:]
|
||||
arrayType = class_types.get("["+type)
|
||||
|
||||
if obj is None:
|
||||
return None
|
||||
if isinstance(obj,java.util.List):
|
||||
obj = obj.toArray(java.lang.reflect.Array.newInstance(Class.forName(class_types.get(type)),0))
|
||||
if type != 'o':
|
||||
obj = Convert.toPrimitiveArray(obj)
|
||||
if isinstance(obj,PyArray):
|
||||
if obj.typecode != type:
|
||||
print "DIF", obj.typecode, type
|
||||
ret = java.lang.reflect.Array.newInstance(Class.forName(class_types.get(type)),len(obj))
|
||||
if type == 's':
|
||||
for i in range(len(obj)): ret[i] = str(obj[i])
|
||||
elif type == 'c':
|
||||
for i in range(len(obj)): ret[i] = chr(obj[i])
|
||||
else:
|
||||
for i in range(len(obj)): ret[i] = obj[i]
|
||||
obj = ret
|
||||
if type not in ['o', 's']:
|
||||
obj = Convert.toPrimitiveArray(obj)
|
||||
return obj
|
||||
if is_list(obj):
|
||||
if type=='o' or type== 's':
|
||||
ret = java.lang.reflect.Array.newInstance(Class.forName(class_types.get(type)),len(obj))
|
||||
for i in range (len(obj)):
|
||||
if is_list(obj):
|
||||
ret[i] = to_array(obj[i],type)
|
||||
elif type == 's':
|
||||
ret[i] = str(obj[i])
|
||||
else:
|
||||
ret[i] = obj[i]
|
||||
return ret
|
||||
|
||||
if len(obj)>0 and is_list(obj[0]):
|
||||
if len(obj[0])>0 and is_list(obj[0][0]):
|
||||
ret = java.lang.reflect.Array.newInstance(Class.forName(arrayType),len(obj),len(obj[0]))
|
||||
for i in range(len(obj)):
|
||||
ret[i]=to_array(obj[i], type)
|
||||
return ret
|
||||
else:
|
||||
ret = java.lang.reflect.Array.newInstance(Class.forName(arrayType),len(obj))
|
||||
for i in range(len(obj)):
|
||||
ret[i]=to_array(obj[i], type)
|
||||
return ret
|
||||
return jarray.array(obj,type)
|
||||
return obj
|
||||
|
||||
|
||||
def plot(data, name = None, xdata = None, ydata=None, title=None):
|
||||
"""Request one or multiple plots of user data (1d, 2d or 3d)
|
||||
|
||||
Args:
|
||||
data: array or list of values. For multiple plots, array of arrays or lists of values.
|
||||
name(str or list of str, optional): plot name or list of names (if multiple plots).
|
||||
xdata: array or list of values. For multiple plots, array of arrays or lists of values.
|
||||
ydata: array or list of values. For multiple plots, array of arrays or lists of values.
|
||||
title(str, optional): plotting context name.
|
||||
|
||||
Returns:
|
||||
ArrayList of Plot objects.
|
||||
|
||||
"""
|
||||
if isinstance(data, ch.psi.pshell.data.Table):
|
||||
if is_list(xdata):
|
||||
xdata = to_array(xdata, 'd')
|
||||
return get_context().plot(data,xdata,name,title)
|
||||
if isinstance(data, ch.psi.pshell.scan.ScanResult):
|
||||
return get_context().plot(data,title)
|
||||
|
||||
|
||||
if (name is not None) and is_list(name):
|
||||
if len(name)==0:
|
||||
name=None;
|
||||
else:
|
||||
if (data==None):
|
||||
data = []
|
||||
for n in name:
|
||||
data.append([])
|
||||
plots = java.lang.reflect.Array.newInstance(Class.forName("ch.psi.pshell.data.PlotDescriptor"), len(data))
|
||||
for i in range (len(data)):
|
||||
plotName = None if (name is None) else name[i]
|
||||
x = xdata
|
||||
if is_list(x) and len(x)>0 and (is_list(x[i]) or isinstance(x[i] , java.util.List) or isinstance(x[i],PyArray)):
|
||||
x = x[i]
|
||||
y = ydata
|
||||
if is_list(y) and len(y)>0 and (is_list(y[i]) or isinstance(y[i] , java.util.List) or isinstance(y[i],PyArray)):
|
||||
y = y[i]
|
||||
plots[i] = PlotDescriptor(plotName , to_array(data[i], 'd'), to_array(x, 'd'), to_array(y, 'd'))
|
||||
return get_context().plot(plots,title)
|
||||
else:
|
||||
plot = PlotDescriptor(name, to_array(data, 'd'), to_array(xdata, 'd'), to_array(ydata, 'd'))
|
||||
return get_context().plot(plot,title)
|
||||
|
||||
|
||||
|
||||
|
||||
from mathutils import estimate_peak_indexes, fit_gaussians, create_fit_point_list, Gaussian,fit_harmonic,HarmonicOscillator
|
||||
import java.awt.Color as Color
|
||||
|
||||
def fit(ydata, xdata = None):
|
||||
if xdata is None:
|
||||
xdata = frange(0, len(ydata), 1)
|
||||
max_y= max(ydata)
|
||||
index_max = ydata.index(max_y)
|
||||
max_x= xdata[index_max]
|
||||
print "Max index:" + str(index_max),
|
||||
print " x:" + str(max_x),
|
||||
print " y:" + str(max_y)
|
||||
|
||||
gaussians = fit_gaussians(ydata, xdata, [index_max,])
|
||||
|
||||
print "PLOT"
|
||||
|
||||
ydata =to_array(ydata,'d')
|
||||
xdata= to_array(xdata,'d')
|
||||
|
||||
p = plot([ydata],["data"],[xdata], title="Fit" )[0]
|
||||
print "OK"
|
||||
|
||||
if gaussians[0] is None: #Fitting error
|
||||
p.addMarker(max_x, None, "Max="+str(round(max_x,2)), Color.GRAY)
|
||||
print "Fitting error - using max value"
|
||||
return (None, max_x, None)
|
||||
|
||||
(norm, mean, sigma) = gaussians[0]
|
||||
|
||||
fitted_gaussian_function = Gaussian(norm, mean, sigma)
|
||||
scale_x = [float(min(xdata)), float(max(xdata)) ]
|
||||
points = max((len(xdata)+1), 100)
|
||||
resolution = (scale_x[1]-scale_x[0]) / points
|
||||
fit_y = []
|
||||
fit_x = frange(scale_x[0],scale_x[1],resolution, True)
|
||||
for x in fit_x:
|
||||
fit_y.append(fitted_gaussian_function.value(x))
|
||||
p.addSeries(LinePlotSeries("fit"))
|
||||
p.getSeries(1).setData(fit_x, fit_y)
|
||||
|
||||
if abs(mean - xdata[index_max]) < ((scale_x[0] + scale_x[1])/2):
|
||||
print "Mean -> " + str(mean)
|
||||
p.addMarker(mean, None, "Mean="+str(round(norm,2)), Color.MAGENTA.darker())
|
||||
return (norm, mean, sigma)
|
||||
else:
|
||||
p.addMarker(max_x, None, "Max="+str(round(max_x,2)), Color.GRAY)
|
||||
print "Invalid gaussian fit: " + str(mean) + " - using max value"
|
||||
return (None, max_x, None)
|
||||
|
||||
fit(y,x)
|
||||
11
script/test/test4.py
Executable file
11
script/test/test4.py
Executable file
@@ -0,0 +1,11 @@
|
||||
"""
|
||||
Vector Scan
|
||||
"""
|
||||
|
||||
vector = [ [1,1] , [1,2] , [1,3] , [1,4] ,
|
||||
[1.5,2.5] ,
|
||||
[2,1] , [2,2] , [2,3] , [2,4] ,
|
||||
[2.5,2.5] ,
|
||||
[3,1] , [3,2] , [3,3] , [3,4] ]
|
||||
|
||||
a= vscan((dev,inp),(sin,out),vector,False, 0.1)
|
||||
1
script/test/test4.scan
Normal file
1
script/test/test4.scan
Normal file
@@ -0,0 +1 @@
|
||||
[ "Change event series", [ ], [ [ "Device", "sin", 2, 0.1, null ], [ "Device", "arr", null, 0.0, null ], [ "Channel", "TESTIOC:TESTCALCOUT:Output", 2, 0.1, null ], [ "Channel", "TESTIOC:TESTSINUS:SinCalc", 2, 0.1, null ] ], false, [ ], "", 2, 1.0, 0.1, true, true, true, true, "", "", "Default", "h5", 0, null, null, "Positioner", false ]
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user