New ScreenPanel
This commit is contained in:
14
script/10_LineScan.js
Executable file
14
script/10_LineScan.js
Executable file
@@ -0,0 +1,14 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Demonstrate the use of Line Scan: one or multiple positioners move together linearly.
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//Execute the scan: 100 steps, a1 from 0 to 40
|
||||
r1 = lscan(ao1, [ai1,ai2,wf1], 0, 40, 100, 0.01)
|
||||
|
||||
//Steps of size 1.0, a1 from 0 to 40
|
||||
r2 = lscan(ao1, [ai1,ai2,wf1], 0, 40, 1.0, 0.01)
|
||||
|
||||
//2 positioners moving together in 10 steps. Also sampling an image:
|
||||
r3 = lscan([ao1,ao2], [ai1,ai2,wf1,im1], [0, 0], [40, 100], 4, 0.01)
|
||||
|
||||
8
script/11_TimeScan.js
Executable file
8
script/11_TimeScan.js
Executable file
@@ -0,0 +1,8 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Demonstrate the use of Time Scan: time-based sensor sampling
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//Execute the scan: 100 samples, 10ms sampling interval
|
||||
r1 = tscan((ai1,ai2,wf1), 100, 0.01)
|
||||
|
||||
10
script/12_AreaScan.js
Executable file
10
script/12_AreaScan.js
Executable file
@@ -0,0 +1,10 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Area Scan: Multiple positioners, each one is one dimension.
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//The second sensor is an array. In the plot window it is overwritten in every same x position.
|
||||
//The data window never displays 3d data, but the 3d data can be accesses during the scan in the Data tab.
|
||||
r1 = ascan([m1,m2], [ai1,wf1], [0.0,0.0], [2.0,1.0], [10,10])
|
||||
|
||||
|
||||
20
script/13_VectorScan.js
Executable file
20
script/13_VectorScan.js
Executable file
@@ -0,0 +1,20 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Demonstrate use of Vector Scan: one or multiple positioners set according to a position vector.
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//1D vector scan, plot to 1D Vector tab
|
||||
vector = [ 1, 3, 5, 10, 25, 40, 45, 47, 49]
|
||||
r1 = vscan(ao1, [ai1,ai2], vector, false, 0.5, false, undefined, undefined, undefined, undefined, title = "1D Vector")
|
||||
|
||||
|
||||
|
||||
|
||||
//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] ]
|
||||
|
||||
r2 = vscan([m1,m2], [ai1,ai2], vector, false, 0.1, false, undefined, undefined, undefined, undefined, title = "2D Vector")
|
||||
11
script/14_RegionScan.js
Executable file
11
script/14_RegionScan.js
Executable file
@@ -0,0 +1,11 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Demonstrate the use of Region Scan: one positioner move linearly in multiple regions.
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
//Execute the scan: 3 regions with different number of steps
|
||||
r1 = rscan(ao1, [ai1,ai2], [[0,5,5], [10,15,20], [20,25,5]] , 0.01)
|
||||
|
||||
//Execute the scan: 3 regions with different step size
|
||||
r2 = rscan(ao1, [ai1,ai2], [[0,5,1.0], [10,15,0.2], [20,25,1.0]] , 0.01)
|
||||
17
script/15_ContinuousScan.js
Executable file
17
script/15_ContinuousScan.js
Executable file
@@ -0,0 +1,17 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Demonstrate the use of Continuous Scan Scan: a Linear Scan with continuous motor move and
|
||||
// sampling on the fly.
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
m1.move(0.0)
|
||||
|
||||
//A single motor at current speed
|
||||
r1 = cscan(m1, (ai1,ai2), -2, 3 , steps=10, undefined, undefined ,true)
|
||||
|
||||
//A single motor in a given time
|
||||
r2 = cscan(m1, (ai1,ai2), -2.0, 3.0, 100 , undefined , 4.0, true)
|
||||
|
||||
//Multiple motors in a given time
|
||||
r3 = cscan((m1, m2), (ai1,ai2), (-2.0, -3), (3.0, 5.0), steps=100, undefined, time = 4.0, relative=true)
|
||||
|
||||
46
script/16_HardwareScan.js
Executable file
46
script/16_HardwareScan.js
Executable file
@@ -0,0 +1,46 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Use of HardwareScan
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
CrlogicPositioner = Java.type('ch.psi.pshell.crlogic.CrlogicPositioner')
|
||||
CrlogicSensor = Java.type('ch.psi.pshell.crlogic.CrlogicSensor')
|
||||
|
||||
//sc1.stop()
|
||||
//sc1.setOneShot()
|
||||
//sc1.channels[0].setPreset(false)
|
||||
//sc1.channels[0].setPresetValue(0)
|
||||
//sc1.start()
|
||||
|
||||
config = {}
|
||||
config["class"] = "ch.psi.pshell.crlogic.CrlogicScan"
|
||||
config["prefix"] = "MTEST-HW3-CRL"
|
||||
config["ioc"] = "MTEST-VME-HW3.psi.ch"
|
||||
config["integrationTime"] = 0.01
|
||||
config["additionalBacklash"] = 0.0
|
||||
|
||||
pos = new CrlogicPositioner("CrlogicPositioner", "MTEST-HW3:MOT1", null)
|
||||
|
||||
sensors = [
|
||||
new CrlogicSensor("Trigger0", "TRIGGER0"),
|
||||
new CrlogicSensor("Trigger1", "TRIGGER1"),
|
||||
new CrlogicSensor("Scaler0", "SCALER0", true),
|
||||
new CrlogicSensor("Scaler1", "SCALER1", true),
|
||||
new CrlogicSensor("Timestamp", "TIMESTAMP"),
|
||||
]
|
||||
|
||||
|
||||
|
||||
//pos.initialize()
|
||||
//pos.move(0.0)
|
||||
|
||||
try {
|
||||
r1 = hscan(config, pos, sensors,0.0, 10.0, 0.1,1, false)
|
||||
}
|
||||
catch(err) {
|
||||
|
||||
}
|
||||
finally {
|
||||
pos.close()
|
||||
}
|
||||
|
||||
26
script/20101216_hyst_meas_Dy.txt
Executable file
26
script/20101216_hyst_meas_Dy.txt
Executable file
@@ -0,0 +1,26 @@
|
||||
wait_temp
|
||||
|
||||
set pol c+ off 0
|
||||
hyst cont Hx -6.0 6.0 2.0 E 1289.2 1297 ppe 90
|
||||
file Cr_hyst
|
||||
start
|
||||
|
||||
set pol c- off 1
|
||||
hyst cont Hx 6.0 -6.0 2.0 E 1289.2 1297 ppe 90
|
||||
file Cr_hyst
|
||||
start
|
||||
|
||||
hyst cont Hx -6.0 6.0 2.0 E 1289.2 1297 ppe 90
|
||||
file Cr_hyst
|
||||
start
|
||||
|
||||
set pol c+ off 0
|
||||
hyst cont Hx 6.0 -6.0 2.0 E 1289.2 1297 ppe 90
|
||||
file Cr_hyst
|
||||
start
|
||||
|
||||
set Hx 0.0
|
||||
otf 560 600 2
|
||||
file Cr_energy
|
||||
start repeat 4
|
||||
|
||||
402
script/20110203_Cr_xmcd_different_fields.txt
Executable file
402
script/20110203_Cr_xmcd_different_fields.txt
Executable file
@@ -0,0 +1,402 @@
|
||||
wait_temp
|
||||
|
||||
|
||||
set Hx -6.0
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
|
||||
start
|
||||
|
||||
|
||||
set Hx 6.0
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
|
||||
start
|
||||
|
||||
|
||||
set Hx 5.0
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
|
||||
start
|
||||
|
||||
|
||||
set Hx -5.0
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
|
||||
start
|
||||
|
||||
|
||||
|
||||
set Hx -4.0
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
|
||||
start
|
||||
|
||||
|
||||
set Hx 4.0
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
|
||||
start
|
||||
|
||||
|
||||
|
||||
set Hx 3.0
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
|
||||
start
|
||||
|
||||
|
||||
set Hx -3.0
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
|
||||
start
|
||||
|
||||
|
||||
set Hx -2.0
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
|
||||
start
|
||||
|
||||
|
||||
set Hx 2.0
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
|
||||
start
|
||||
|
||||
|
||||
|
||||
set Hx 1.0
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
|
||||
start
|
||||
|
||||
|
||||
|
||||
|
||||
set Hx -1.0
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
|
||||
start
|
||||
|
||||
|
||||
|
||||
|
||||
set Hx -0.5
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
|
||||
start
|
||||
|
||||
|
||||
set Hx 0.5
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c- off 1
|
||||
file Cr_energy
|
||||
start
|
||||
|
||||
otf 560 600 2
|
||||
set pol c+ off 0
|
||||
file Cr_energy
|
||||
at_end shutdown
|
||||
start
|
||||
|
||||
|
||||
57
script/20150418_0012_Tb_hyst_plus.xml
Executable file
57
script/20150418_0012_Tb_hyst_plus.xml
Executable file
@@ -0,0 +1,57 @@
|
||||
<?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="Tb_hyst_plus"/>
|
||||
<scan id="">
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="ACOAU-ACCU:OP-MODE" value="Light Available" operation="wait"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MA-ID:MODE" value="CIRC +" delay="1.0"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MA-ID:DONE" value="DONE" operation="wait"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MA-ID:ENERGY-OFFS" value="-9"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MA-ID:DONE" value="DONE" operation="wait"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MA-PC:CSCALER.INPB" value="1" operation="putq"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MA-PC-PS2:SET:DMD:RAMPRATE:TPM" value="1.15" operation="putq" delay="15.0"/>
|
||||
<dimension>
|
||||
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ArrayPositioner" name="X07MA-PHS-E:GO.A" readback="X07MA-PGM:CERBK" settlingTime="0.5" id="Energy">
|
||||
<positions>1236.9 1243.9</positions>
|
||||
</positioner>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="X07MA-ES1-AI:SIGNAL0" id="TEY"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="X07MA-ES1-AI:SIGNAL1" id="I0"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="X07MA-ES1-AI:SIGNAL2" id="trans"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="X07MA-ID:MODE" id="polarization"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="X07MA-ID:ALPHA" id="polAngle"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="X07MA-PC-TC:STS:T1" id="temperature"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="ARIDI-PCT:CURRENT" id="RingCurrent"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="X07MA-ES1-AI:SIGNAL4" id="fieldAnalogX"/>
|
||||
</dimension>
|
||||
<dimension>
|
||||
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="RegionPositioner" name="X07MA-PC:GO" readback="X07MA-PC-PS2:STS:PMCURRENT" settlingTime="0.0" id="field">
|
||||
<region>
|
||||
<preAction xsi:type="ChannelAction" channel="X07MA-PC-PS2:M:GO.A" value="-4.0" operation="putq"/>
|
||||
<start>0.0</start>
|
||||
<end>110.0</end>
|
||||
<stepSize>1.0</stepSize>
|
||||
</region>
|
||||
</positioner>
|
||||
</dimension>
|
||||
<postAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MA-PC-PS2:SET:DMD:RAMPRATE:TPM" value="2" operation="putq" delay="15.0"/>
|
||||
<manipulation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScriptManipulation" id="tey_norm">
|
||||
<mapping xsi:type="IDParameterMapping" refid="TEY" variable="c"/>
|
||||
<mapping xsi:type="IDParameterMapping" refid="I0" variable="d"/>
|
||||
<script>
|
||||
import math
|
||||
def process(c,d):
|
||||
return c/d
|
||||
</script>
|
||||
</manipulation>
|
||||
<manipulation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScriptManipulation" id="trans_norm">
|
||||
<mapping xsi:type="IDParameterMapping" refid="trans" variable="c"/>
|
||||
<mapping xsi:type="IDParameterMapping" refid="I0" variable="d"/>
|
||||
<script>
|
||||
import math
|
||||
def process(c,d):
|
||||
return c/d
|
||||
</script>
|
||||
</manipulation>
|
||||
</scan>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="field" y="tey_norm" title="TEY norm vs field"/>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="field" y="trans_norm" title="Transm. norm vs field"/>
|
||||
</configuration>
|
||||
21
script/20150418_1152_DyE_minus.xml
Executable file
21
script/20150418_1152_DyE_minus.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">
|
||||
<data format="txt" fileName="DyE_minus"/>
|
||||
<scan id="">
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="ACOAU-ACCU:OP-MODE" value="Light Available" operation="wait"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MA-ID:MODE" value="CIRC -" delay="1.0"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MA-ID:DONE" value="DONE" operation="wait"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MA-ID:ENERGY-OFFS" value="-4.0"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MA-ID:DONE" value="DONE" operation="wait"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="E1" value="1265"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="E2" value="1355"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="TIME" value="3"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="FOLDER" value="2015_04/20150418"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MA-PHS-E:GO.A" value="1265" operation="putq"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MA-PHS:alldone" value="1" operation="wait" delay="0.5"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="FILE" value="DyE_minus" delay="0.1"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MA-OP-VG13:WT_SET" value="Try open" delay="10.0"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="START" value="1"/>
|
||||
<postAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="START" value="STOP" operation="wait" delay="2.0"/>
|
||||
</scan>
|
||||
</configuration>
|
||||
13
script/20_Relative.js
Executable file
13
script/20_Relative.js
Executable file
@@ -0,0 +1,13 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Demonstrate use of Relative Line Scan.
|
||||
// The arguments start and end are relative to the current position.
|
||||
// After the scan the positioner(s) move back to the initial position.
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
print ("Initial position = " + m1.position)
|
||||
|
||||
r1 = lscan(m1, [ai1,ai2,wf1], start = -2, end =2, steps = 20, latency = undefined, relative = true)
|
||||
|
||||
|
||||
print ("Final position = " + m1.position)
|
||||
13
script/21_MultipassAndZigzag.js
Executable file
13
script/21_MultipassAndZigzag.js
Executable file
@@ -0,0 +1,13 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Multi-pass and zigzag scans
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//Linear with 2 passes
|
||||
a= lscan(m1, [ai1,wf1], -0.2, 0.2, 20, latency = 0.0, relative = true, passes = 4)
|
||||
|
||||
//Linear with 4 passes and zigzag
|
||||
a= lscan(m1, [ai1,wf1], -0.2, 0.2, 20, latency = 0.0, 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, relative = undefined, passes = undefined, zigzag=true)
|
||||
23
script/22_ScanCallbacks.js
Executable file
23
script/22_ScanCallbacks.js
Executable file
@@ -0,0 +1,23 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Demonstrate use of scan callbacks to trigger a detector at falling edge.
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
function BeforeReadout(position){
|
||||
ao1.write(1)
|
||||
ao1.write(0)
|
||||
//Example with an epics direct channel access
|
||||
//caput("CHANNEL_NAME", 1)
|
||||
//caput("CHANNEL_NAME", 0)
|
||||
print ("In position: " + position[0] + ", " + position[1])
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function AfterReadout(record, scan){
|
||||
print ("Aquired frame: " + record.index)
|
||||
}
|
||||
|
||||
a= lscan([m1,m2], [ai1, ai2], [0,0], [4,8], steps=20, latency = 0.01, relative = undefined,
|
||||
passes = undefined, zigzag = undefined,before_read=BeforeReadout, after_read=AfterReadout)
|
||||
21
script/23_Metadata.js
Executable file
21
script/23_Metadata.js
Executable file
@@ -0,0 +1,21 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Demonstrate adding attributs to scan groups and datasets.
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//Execute the scan: 200 steps, a1 from 0 to 40
|
||||
a= lscan(ao1, [ai1,ai2], 0, 40, 10, 0.01)
|
||||
|
||||
|
||||
//Setting attributes to the scan group
|
||||
path = get_exec_pars().group
|
||||
set_attribute(path, "AttrString", "Value")
|
||||
set_attribute(path, "AttrInteger", 1)
|
||||
set_attribute(path, "AttrDouble", 2.0)
|
||||
set_attribute(path, "AttrBoolean", true)
|
||||
|
||||
//Setting attributes to the scan datasets
|
||||
set_attribute(path + ao1.name, "AttrInteger", 2)
|
||||
set_attribute(path + ai1.name, "AttrInteger", 3)
|
||||
set_attribute(path + ai2.name, "AttrInteger", 4)
|
||||
|
||||
19
script/24_ScanDataManipulation.js
Executable file
19
script/24_ScanDataManipulation.js
Executable file
@@ -0,0 +1,19 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Processing and plotting scan data.
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
ao1.write(0.0)
|
||||
scan1= lscan(ao1, [ai1,ai2,wf1], 0, 40, 40, 0.01, false)
|
||||
scan2= lscan(ao1, [ai1,ai2,wf1], 0, 40, 40, 0.01, false)
|
||||
|
||||
|
||||
result=[]
|
||||
for (var i=0; i<scan1.records.length; i++){
|
||||
result.push(scan1.records[i].values[0]+scan2.records[i].values[0])
|
||||
}
|
||||
|
||||
|
||||
plot(result)
|
||||
print (result
|
||||
)
|
||||
36
script/25_PseudoDevices.js
Executable file
36
script/25_PseudoDevices.js
Executable file
@@ -0,0 +1,36 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Using pseudo-device to :
|
||||
// - Add calculations to scan data.
|
||||
// - Execute logic during scan
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var Clock = Java.extend(Readable)
|
||||
var clock = new Clock() {
|
||||
read: function (value) {
|
||||
return Date.now()
|
||||
},
|
||||
}
|
||||
set_device_alias(clock, "Clock")
|
||||
|
||||
var PseudoSensor = Java.extend(Readable)
|
||||
var averager = new PseudoSensor() {
|
||||
read: function (value) {
|
||||
arr = wf1.take() //Gets the CACHED waveform
|
||||
arr = to_array(arr) //Converts to a javascript array
|
||||
return arr.reduce(function(a, b) { return a + b; }) / arr.length
|
||||
},
|
||||
}
|
||||
set_device_alias(averager, "Averager")
|
||||
|
||||
var PseudoPositioner = Java.extend(Writable)
|
||||
var positioner = new PseudoPositioner() {
|
||||
write: function (value) {
|
||||
print ("Step = " + value)
|
||||
},
|
||||
}
|
||||
set_device_alias(positioner, "Positioner")
|
||||
|
||||
|
||||
a= lscan([ao1,positioner],[ai2,wf1,averager,clock],[0,0],[40,20],20,0.1)
|
||||
|
||||
|
||||
50
script/26_DeviceListener.js
Executable file
50
script/26_DeviceListener.js
Executable file
@@ -0,0 +1,50 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Create a device listener to interrupt the scan
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
InterruptedException = Java.type('java.lang.InterruptedException')
|
||||
|
||||
//Create a listener to the sensor, verifying the readback values.
|
||||
|
||||
var ListenerAI = Java.extend(DeviceListener)
|
||||
var listenerAI = new ListenerAI() {
|
||||
onValueChanged: function (device, value, former) {
|
||||
if (value > 1.02) {
|
||||
print ("Value over limit-> aborting")
|
||||
abort()
|
||||
}
|
||||
},
|
||||
}
|
||||
ai1.addListener(listenerAI)
|
||||
|
||||
|
||||
var ListenerAO = Java.extend(DeviceListener)
|
||||
var listenerAO = new ListenerAO() {
|
||||
onStateChanged: function (device, state, former) {
|
||||
|
||||
},
|
||||
onValueChanged: function (device, value, former) {
|
||||
print ("Moved to: " + value)
|
||||
},
|
||||
onValueChanginf: function (device, value, former) {
|
||||
if (value > 20) {
|
||||
throw "Forbidden move to " + value
|
||||
}
|
||||
print( "Moving to: " + value + " ... ")
|
||||
},
|
||||
}
|
||||
|
||||
ao1.addListener(listenerAO)
|
||||
|
||||
|
||||
|
||||
|
||||
try{
|
||||
lscan(ao1, (ai1), 0, 40, 200, 0.01)
|
||||
} catch (ex){
|
||||
print ("Aborted"
|
||||
)
|
||||
}
|
||||
finally{
|
||||
ai1.removeListener(listenerAI)
|
||||
ao1.removeListener(listenerAO)
|
||||
19
script/27_ResamplingRecord.js
Executable file
19
script/27_ResamplingRecord.js
Executable file
@@ -0,0 +1,19 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//Resampling a scan record if a fail condition is met.
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
index=0
|
||||
|
||||
function AfterReadout(rec){
|
||||
print (rec.getIndex() + " - " + to_array(rec.values))
|
||||
//Only accept records if ai2 is positive
|
||||
if (ai2.take() < 0){
|
||||
sleep(1.0)
|
||||
print("Invalidating")
|
||||
rec.invalidate()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
a= lscan(m1, [ai1,ai2], [0,], [0.4,], 20, 0.1, relative = undefined, passes = undefined, zigzag = undefined, before_read = undefined, after_read=AfterReadout)
|
||||
9
script/28_Averaging.js
Executable file
9
script/28_Averaging.js
Executable file
@@ -0,0 +1,9 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Scan averaging
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
av = create_averager(ai2, 50, 0.05)
|
||||
//set_preference(Preference.PLOT_TYPES, {av.name:'minmax'}) //This is to display min/max instead of sigma.
|
||||
res= lscan(ao1, [av, av.samples], 0, 40, 20, 0.1)
|
||||
|
||||
55
script/29_ArrayCalibration.js
Executable file
55
script/29_ArrayCalibration.js
Executable file
@@ -0,0 +1,55 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Calibrating array and matrix pseudo-devices
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
var ArrayCalibrated = Java.extend(ReadableArray, ReadableCalibratedArray)
|
||||
var ac1 = new ArrayCalibrated() {
|
||||
read: function () {
|
||||
return wf1.read()
|
||||
},
|
||||
getSize: function (value) {
|
||||
return wf1.size
|
||||
},
|
||||
getCalibration: function (value) {
|
||||
return new ArrayCalibration(5,1000)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
var ac2 = new ArrayCalibrated() {
|
||||
read: function () {
|
||||
return wf1.read()
|
||||
},
|
||||
getSize: function (value) {
|
||||
return wf1.size
|
||||
},
|
||||
getCalibration: function (value) {
|
||||
return new ArrayCalibration(5,1000)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
||||
var MatrixCalibrated = Java.extend(ReadableMatrix, ReadableCalibratedMatrix)
|
||||
var mc1 = new MatrixCalibrated() {
|
||||
read: function () {
|
||||
return im1.read()
|
||||
},
|
||||
getWidth: function (value) {
|
||||
return im1.width
|
||||
},
|
||||
getHeight: function (value) {
|
||||
return im1.height
|
||||
},
|
||||
getCalibration: function (value) {
|
||||
return new MatrixCalibration(2,4,100,200)
|
||||
},
|
||||
}
|
||||
|
||||
set_device_alias(ac1, "wf1_calib")
|
||||
set_device_alias(ac2, "wf1_calib_1d")
|
||||
set_device_alias(mc1, "im1_calib")
|
||||
|
||||
set_preference(Preference.PLOT_TYPES, {"wf1_calib_1d":1})
|
||||
|
||||
30
script/30_ScanPlotSetup.js
Executable file
30
script/30_ScanPlotSetup.js
Executable file
@@ -0,0 +1,30 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Demonstrate configuring scan plot options
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//This optional preference limits the displayed plots
|
||||
set_preference(Preference.ENABLED_PLOTS, [ai1, wf1])
|
||||
|
||||
//This optional preference displays wf1 as a 1d plot at each scan point, instead of a matrix plot
|
||||
set_preference(Preference.PLOT_TYPES, {wf1:1})
|
||||
|
||||
|
||||
//This optional preference disables printing the scan table
|
||||
//set_preference(Preference.PLOT_DISABLED, true)
|
||||
|
||||
//This optional preference disable all scan plotting
|
||||
//set_preference( Preference.TABLE_DISABLED, true)
|
||||
|
||||
//Execute the scan: 200 steps, a1 from 0 to 40
|
||||
a= lscan(ao1, [ai1,ai2,wf1], 0, 40, 100, 0.01)
|
||||
|
||||
|
||||
|
||||
|
||||
//This optional preference displays wf1 as a 1d plot at each scan point, instead of a matrix plot
|
||||
set_preference(Preference.PLOT_TYPES, {wf1:1})
|
||||
|
||||
ascan([m1,m2], [ai1,wf1], [0.0,0.0], [2.0,1.0], [4,4])
|
||||
|
||||
|
||||
24
script/31_UsersPlots.js
Executable file
24
script/31_UsersPlots.js
Executable file
@@ -0,0 +1,24 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Direct creation of plots
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
data_1d = [10.0, 20.0, 30.0, 40.0, 50.0]
|
||||
data_2d = [ data_1d, data_1d, data_1d, data_1d, data_1d]
|
||||
data_3d = [ data_2d, data_2d , data_2d, data_2d, data_2d]
|
||||
data_x = [1.0, 2.0, 3.0, 4.0, 5.0]
|
||||
data_y = [2.0, 4.0, 6.0, 8.0, 10.0]
|
||||
|
||||
//1d-plot with optional xdata
|
||||
plot(data_1d, name = undefined, xdata = data_x, ydata = undefined, title = "1d")
|
||||
|
||||
//2d-plot with optional xdata and ydata
|
||||
plot(data_2d, name = undefined, xdata = data_x, ydata = data_y, title = "2d")
|
||||
|
||||
//3d-plot
|
||||
plot(data_3d, name = undefined, xdata = undefined, ydata = undefined, title = "3d")
|
||||
|
||||
//3 plots in the save panel
|
||||
plot([data_1d, data_2d, data_3d], ["1d", "2d", "3d"])
|
||||
|
||||
|
||||
|
||||
29
script/32_MultipleSeries.js
Executable file
29
script/32_MultipleSeries.js
Executable file
@@ -0,0 +1,29 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Advanced plotting examples
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//2 series in the same plot
|
||||
var xdata = [10,20,30,40,50,60]
|
||||
var p = plot(null, name="Data 1")[0]
|
||||
p.addSeries(new LinePlotSeries("Data2"))
|
||||
p.getSeries(0).setData(xdata, [1,2,3,4,5,6])
|
||||
p.getSeries(1).setData(xdata, [6,5,4,3,2,1])
|
||||
p.addMarker(35.0, null, "This is the answer", Color.BLACK)
|
||||
|
||||
|
||||
//2 series in the same plot, setting range & appending point by point
|
||||
var p = plot(null,name="Data 1", title = "Plot 2")[0]
|
||||
p.getAxis(AxisId.X).setRange(0.0,80.0)
|
||||
p.getAxis(AxisId.Y).setRange(0.0,7.0)
|
||||
p.addSeries(new LinePlotSeries("Data2"))
|
||||
for (var i = 0; i< xdata.length; i++){
|
||||
p.getSeries(0).appendData(xdata[i], i)
|
||||
p.getSeries(1).appendData(xdata[i], 1.0/(i+1))
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
18
script/33_CustomScanPlot.js
Executable file
18
script/33_CustomScanPlot.js
Executable file
@@ -0,0 +1,18 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Custom plot: Example of creating a 1D plot for a 2D scan where each scanned row is a series
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//Setting the 1d preference would create in the place of the matrix plot, a 1d plot where
|
||||
//each scanned column is a series
|
||||
//setup_plotting(line_plots = (ai1,))
|
||||
|
||||
p = plot(null, name=undefined, xdata=undefined, ydata=undefined, title="1D Plot")[0]
|
||||
function AfterReadout(record, scan){
|
||||
if (record.setpoints[1] == scan.getStart()[1]){
|
||||
p.addSeries(new LinePlotSeries(record.positions[0].toString()))
|
||||
}
|
||||
p.getSeries(p.numberOfSeries-1).appendData(record.positions[1], record.values[0])
|
||||
}
|
||||
|
||||
ascan([ao1,ao2], [ai1], [0,10], [20,30], [20,20], 0.1, relative = undefined, passes = undefined, zigzag = undefined, before_read = undefined, after_read=AfterReadout)
|
||||
57
script/34_ErrorPlot.js
Executable file
57
script/34_ErrorPlot.js
Executable file
@@ -0,0 +1,57 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Example creating error plots
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
plots=plot([null,null,null],["y","x", "xy"])
|
||||
py = plots[0]
|
||||
px = plots[1]
|
||||
pxy = plots[2]
|
||||
|
||||
//Y error plot
|
||||
py.setStyle(LinePlotStyle.ErrorY)
|
||||
py.setLegendVisible(true)
|
||||
|
||||
sy1 = new LinePlotErrorSeries("F1")
|
||||
py.addSeries(sy1)
|
||||
sy1.appendData(1.0, 10.0, 9.0, 11.0)
|
||||
sy1.appendData(10.0, 6.1, 4.34, 7.54)
|
||||
sy1.appendData(17.8, 4.5, 3.1, 5.8)
|
||||
//One can define error instead of min/max (appendData(x, y, error))
|
||||
sy2 = new LinePlotErrorSeries("F2")
|
||||
py.addSeries(sy2)
|
||||
sy2.setLinesVisible(false)
|
||||
sy2.appendData(3.0, 7.0, 2.0);
|
||||
sy2.appendData(13.0, 13.0, 2.0);
|
||||
sy2.appendData(24.0, 16.1, 1.0);
|
||||
|
||||
//X error plot
|
||||
px.setStyle(LinePlotStyle.ErrorX)
|
||||
px.setLegendVisible(true)
|
||||
sx = new LinePlotErrorSeries("F3")
|
||||
px.addSeries(sx)
|
||||
sx.appendData(1.0, 10.0, 0.5, 1.5)
|
||||
sx.appendData(10.0, 6.1, 9.0, 10.3)
|
||||
sx.appendData(17.8, 4.5, 17.0, 18.0)
|
||||
//One can define error instead of min/max (appendData(x, y, error))
|
||||
sx2 = new LinePlotErrorSeries("F4")
|
||||
px.addSeries(sx2)
|
||||
sx2.setLinesVisible(false)
|
||||
sx2.appendData(1.0, 3.0, 1.0)
|
||||
sx2.appendData(10.0, 5.1, 1.0)
|
||||
sx2.appendData(17.8, 7.5, 0.5)
|
||||
|
||||
//XY error plot
|
||||
pxy.setStyle(LinePlotStyle.ErrorXY)
|
||||
pxy.setLegendVisible(true)
|
||||
sxy = new LinePlotErrorSeries("F5")
|
||||
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)
|
||||
//One can define error instead of min/max (appendData(x, y, errorX, errorY))
|
||||
sxy2 = new LinePlotErrorSeries("F6")
|
||||
pxy.addSeries(sxy2)
|
||||
sxy2.appendData(3.0, 7.0, 0.5, 4.0);
|
||||
sxy2.appendData(13.0, 13.0, 0.5, 3.0);
|
||||
sxy2.appendData(24.0, 16.1, 0.2, 2.0);
|
||||
12
script/35_LinePlotStyles.js
Executable file
12
script/35_LinePlotStyles.js
Executable file
@@ -0,0 +1,12 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Example changing plot styles
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
data = [0,3,5,1,3,5,3,4,3,2,1,0]
|
||||
plots = plot([data, data, data], ["normal", "step", "spline"])
|
||||
p1 = plots[0]
|
||||
p2 = plots[1]
|
||||
p3 = plots[2]
|
||||
p2.setStyle(LinePlotStyle.Step)
|
||||
p3.setStyle(LinePlotStyle.Spline)
|
||||
12
script/36_LogarithmicScales.js
Executable file
12
script/36_LogarithmicScales.js
Executable file
@@ -0,0 +1,12 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Displaying logarithmic scales
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
p = plot([10,500,1000,5000,1000], name = undefined, xdata = [0.1,1,10,100,1000, 10000])[0]
|
||||
p.getAxis(AxisId.X).logarithmic = true
|
||||
p.getAxis(AxisId.Y).setRange(1, 100000)
|
||||
p.getAxis(AxisId.Y).logarithmic = true
|
||||
|
||||
|
||||
|
||||
|
||||
27
script/37_SecondaryDomainAxis.js
Executable file
27
script/37_SecondaryDomainAxis.js
Executable file
@@ -0,0 +1,27 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Creating a secondary X axis, using the underlying JFreeChart libraey API
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
importClass(org.jfree.chart.axis.NumberAxis)
|
||||
importClass(org.jfree.chart.axis.LogarithmicAxis)
|
||||
|
||||
p = plot([1,2,3,4,5])[0]
|
||||
|
||||
x2 = new NumberAxis("Secondary X Axis") //Linear scale
|
||||
//x2 = new LogarithmicAxis("Secondary X Axis") //Logarithmic scale
|
||||
x2.setRange(0.1, 100)
|
||||
p.getAxis(AxisId.X).setRange(-2, 5) // So the relation between X1 and X2 is enforced
|
||||
|
||||
|
||||
jf = p.chart.plot
|
||||
jf.setDomainAxis(1, x2 )
|
||||
|
||||
//This is just for formatting te new axis fonts and colors, equals to the first axis
|
||||
jf.getDomainAxis(1).labelPaint = jf.getDomainAxis(0).labelPaint
|
||||
jf.getDomainAxis(1).labelFont = jf.getDomainAxis(0).labelFont
|
||||
jf.getDomainAxis(1).tickLabelPaint = jf.getDomainAxis(0).tickLabelPaint
|
||||
jf.getDomainAxis(1).tickLabelFont = jf.getDomainAxis(0).tickLabelFont
|
||||
|
||||
|
||||
|
||||
|
||||
16
script/40_SimultaneousScans.js
Executable file
16
script/40_SimultaneousScans.js
Executable file
@@ -0,0 +1,16 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Example on running simultaneous scans. They should not manipulate same writables
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
function scan1(){
|
||||
print ("scan1")
|
||||
return lscan(ao1, ai1, 0, 40, 20, 0.1)
|
||||
}
|
||||
|
||||
function scan2(){
|
||||
print ("scan2")
|
||||
return lscan(ao2, wf1, 0, 40, 20, 0.1, undefined, undefined, undefined, undefined, undefined, title = "scan2")
|
||||
}
|
||||
|
||||
parallelize(scan1, scan2)
|
||||
41
script/41_ManualScan.js
Executable file
41
script/41_ManualScan.js
Executable file
@@ -0,0 +1,41 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Manual scan: Manually setting positioners and reading back sensors, but still using
|
||||
// the standard data handling and plotting of built-in scans.
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
var MOTOR_RANGE = [0.0, 8.0]
|
||||
var OUTPUT_SETPOINTS = [1.0, 2.0, 3.0]
|
||||
var FIXED_X = true
|
||||
|
||||
|
||||
writables_names = to_array([m1.getName(), ao1.getName()], 's')
|
||||
readable_names = to_array([ai1.getName(), ai2.getName()], 's')
|
||||
start = to_array( [ FIXED_X ? MOTOR_RANGE[0] : -1, OUTPUT_SETPOINTS[0]] , 'd')
|
||||
stop =to_array([ FIXED_X ? MOTOR_RANGE[1] : -1, OUTPUT_SETPOINTS[OUTPUT_SETPOINTS.length-1]] , 'd')
|
||||
steps = to_array([Math.round(MOTOR_RANGE[1]-MOTOR_RANGE[0]), OUTPUT_SETPOINTS.length-1] , 'i')
|
||||
|
||||
print (to_array(writables_names))
|
||||
print (to_array(readable_names))
|
||||
print (to_array(start))
|
||||
print (to_array(stop))
|
||||
print (to_array(steps))
|
||||
|
||||
scan = new ManualScan(writables_names, readable_names, start, stop, steps, false)
|
||||
|
||||
|
||||
//This option is to plot the foe each output value one 1D series, instead of all in a matrix plot
|
||||
set_preference(Preference.PLOT_TYPES, {"ai1":1, "ai2":1})
|
||||
|
||||
|
||||
scan.start()
|
||||
m1.setSpeed(10.0)
|
||||
for (var setpoint1 = MOTOR_RANGE[0]; setpoint1 <=MOTOR_RANGE[1]; setpoint1+=1.0){
|
||||
m1.move(setpoint1)
|
||||
for (var setpoint2 in OUTPUT_SETPOINTS){
|
||||
ao1.write(setpoint2)
|
||||
scan.append (to_array([setpoint1, setpoint2], 'd'), to_array([m1.read(), ao1.read()], 'd'), to_array([ai1.read(), ai2.read()], 'd'))
|
||||
}
|
||||
}
|
||||
|
||||
scan.end()
|
||||
38
script/42_MaximumSearch.js
Executable file
38
script/42_MaximumSearch.js
Executable file
@@ -0,0 +1,38 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Using bsearch(Binary Search) and hsearch(Hill Climbing Search) to find optimum
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
var FitnessFunction = Java.extend(ReadonlyRegisterBase)
|
||||
add_device(new FitnessFunction("fitness") {
|
||||
doRead: function () {
|
||||
return 1000.0 - (Math.pow(ao1.take()-18, 2) + Math.pow(ao2.take()-6, 2))
|
||||
},
|
||||
}, true)
|
||||
|
||||
|
||||
|
||||
//Plot Fitness Function
|
||||
r = ascan([ao1, ao2], fitness, [0.0,0.0], [21.0,26.0], [1.0, 1.0], title = "Fitness")
|
||||
|
||||
//Binary Search
|
||||
strategy = "Normal" // or "Boundary" or "FullNeighborhood"
|
||||
r = bsearch([ao1, ao2], fitness, [0.0,0.0], [21.0,26.0], [0.1, 0.1], maximum=true, strategy = strategy, latency = 0.01, relative=false, before_read=undefined, after_read=undefined, title = "Binary Search")
|
||||
//Relative search:
|
||||
//ao1.write(10.5); ao2.write(13.0)
|
||||
//r = bsearch([ao1, ao2], fitness, [-10.5,-13.0], [10.5,13.0], [0.1, 0.1],maximum=true, strategy = strategy, latency = 0.01, relative = true, before_read=undefined, after_read=undefined, title = "Binary Search")
|
||||
|
||||
print ("--------------- Binary Search -----------------")
|
||||
print (r)
|
||||
print (r.print())
|
||||
print (r.getRecords().length)
|
||||
|
||||
|
||||
//Hill Climbing Search
|
||||
ao1.write(10.5)
|
||||
ao2.write(13.0)
|
||||
r = hsearch([ao1, ao2], fitness,[0.0,0.0], [21.0,26.0], [1.0, 1.0], [0.1, 0.1], 1, maximum=true, latency = 0.01, relative=false, before_read=undefined, after_read=undefined, title = "Hill Climbing")
|
||||
print ("--------------- Hill Climbing Search -----------------")
|
||||
print (r)
|
||||
print (r.print())
|
||||
print (r.getRecords().length)
|
||||
37
script/43_BeamSynchronousScan.js
Executable file
37
script/43_BeamSynchronousScan.js
Executable file
@@ -0,0 +1,37 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Scans with beam synchronous streams
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//Creating a stream, assuming a provided named "dispatcher".
|
||||
st1 = new Stream("st1", dispatcher)
|
||||
|
||||
//Adding channels to that stream
|
||||
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()
|
||||
}
|
||||
86
script/50_DataManipulation.js
Executable file
86
script/50_DataManipulation.js
Executable file
@@ -0,0 +1,86 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//Data Manipulation: Using the data access API to generate and retrieve data
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//Creating a 1D dataset from an array
|
||||
path="group/data1"
|
||||
data1d = [1.0, 2.0, 3.0, 4.0, 5.0]
|
||||
save_dataset(path, data1d)
|
||||
//Reading ii back
|
||||
read =load_data(path)
|
||||
print(to_array(read)
|
||||
)
|
||||
assert (data1d.toString() == to_array(read).toString() )
|
||||
plot(read)
|
||||
|
||||
//Creating a 2D dataset from an array with some attributes
|
||||
data2d = [ [1.0, 2.0, 3.0, 4.0, 5.0], [2.0, 3.0, 4.0, 5.0, 6.0, ], [3.0, 4.0, 5.0, 6.0, 7.0]]
|
||||
path="group/data2"
|
||||
save_dataset(path, data2d)
|
||||
set_attribute(path, "AttrString", "Value")
|
||||
set_attribute(path, "AttrInteger", 1)
|
||||
set_attribute(path, "AttrDouble", 2.0)
|
||||
set_attribute(path, "AttrBoolean", true)
|
||||
//Reading it back
|
||||
read =load_data(path)
|
||||
print(to_array(read)
|
||||
)
|
||||
plot(read)
|
||||
|
||||
//Creating a 3D dataset from an array
|
||||
data3d = [ [ [1,2,3,4,5], [2,3,4,5,6], [3,4,5,6,7]], [ [3,2,3,4,5], [4,3,4,5,6], [5,4,5,6,7]]]
|
||||
path="group/data3"
|
||||
save_dataset(path, data3d)
|
||||
//Reading it back
|
||||
read =load_data(path,0)
|
||||
print(to_array(read))
|
||||
read =load_data(path,1)
|
||||
print(to_array(read))
|
||||
|
||||
//Creating a INT dataset adding elements one by one
|
||||
path = "group/data4"
|
||||
create_dataset(path, 'i')
|
||||
for (var i=0; i<10; i++){
|
||||
append_dataset(path,i)
|
||||
}
|
||||
|
||||
|
||||
//Creating a 2D data FLOAT dataset adding lines one by one
|
||||
path = "group/data5"
|
||||
create_dataset(path, 'd', false, [0,0])
|
||||
for (var row in data2d){
|
||||
append_dataset(path, data2d[row])
|
||||
}
|
||||
|
||||
//Creating a Table (compund type)
|
||||
path = "group/data6"
|
||||
names = ["a", "b", "c", "d"]
|
||||
types = ["d", "d", "d", "[d"]
|
||||
lenghts = [0,0,0,5]
|
||||
table = [ [1,2,3,[0,1,2,3,4]],
|
||||
[2,3,4,[3,4,5,6,7]],
|
||||
[3,4,5,[6,7,8,9,4]] ]
|
||||
create_table(path, names, types, lenghts)
|
||||
for (var row in table){
|
||||
append_table(path, table[row])
|
||||
}
|
||||
flush_data()
|
||||
//Read it back
|
||||
read =load_data(path)
|
||||
print(read
|
||||
)
|
||||
|
||||
|
||||
//Writing scalars (datasets with rank 0)
|
||||
save_dataset("group/val1", 1)
|
||||
save_dataset("group/val2", 3.14)
|
||||
save_dataset("group/val3", "test")
|
||||
print (load_data("group/val1")
|
||||
)
|
||||
print (load_data("group/val2")
|
||||
)
|
||||
print (load_data("group/val3")
|
||||
)
|
||||
|
||||
|
||||
54
script/51_Parallelization.js
Executable file
54
script/51_Parallelization.js
Executable file
@@ -0,0 +1,54 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//// Using Parallelization API to execute tasks concurrently
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//Simple parallization
|
||||
function task1(){
|
||||
m1.moveRel(1.0)
|
||||
return m1.getPosition()
|
||||
}
|
||||
|
||||
function task2(){
|
||||
m2.moveRel(1.0)
|
||||
return m1.getPosition()
|
||||
}
|
||||
|
||||
function task3(){
|
||||
return ai1.read()
|
||||
}
|
||||
|
||||
ret = parallelize(task1, task2, task3)
|
||||
print (ret
|
||||
)
|
||||
|
||||
|
||||
//Fork amd join
|
||||
ret = fork(task1, task2, task3)
|
||||
print (ai1.read()
|
||||
)
|
||||
ret = join(ret)
|
||||
print (ret
|
||||
)
|
||||
|
||||
|
||||
|
||||
//Functions with parameters
|
||||
function moveRelative(motor, step){
|
||||
motor.moveRel(step)
|
||||
return motor.getPosition()
|
||||
}
|
||||
|
||||
ret = parallelize([moveRelative,[m1,-2]], [moveRelative,[m2,-2]])
|
||||
print (ret
|
||||
)
|
||||
|
||||
|
||||
//Exception in parallel task is thrown back to script
|
||||
try{
|
||||
parallelize([moveRelative,[ai1,1]], [moveRelative,[ai2,1]])
|
||||
}catch (ex){
|
||||
print ("Ok, caught exception:"
|
||||
)
|
||||
print(ex)
|
||||
}
|
||||
21
script/52_ParametersAndReturn.js
Executable file
21
script/52_ParametersAndReturn.js
Executable file
@@ -0,0 +1,21 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Setting script parameters and return value
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//Providing a map of global variables
|
||||
//run ("52_ParametersAndReturn", {"start":10.0, "end":50.0, "step":40})
|
||||
|
||||
|
||||
//Setting sys.argv:
|
||||
//run ("52_ParametersAndReturn", [10.0, 50.0, 2.0])
|
||||
|
||||
//In this case the parameters would be parsed as:
|
||||
//start = argv[0]
|
||||
//end = argv[1]
|
||||
//step = argv[2]
|
||||
|
||||
|
||||
a= lscan(ao1, ai1, start, end, step, 0.1)
|
||||
a.getReadable(0)
|
||||
set_return(a.getReadable(0))
|
||||
68
script/53_DirectEpicsAccess.js
Executable file
68
script/53_DirectEpicsAccess.js
Executable file
@@ -0,0 +1,68 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// EPICS direct channel access.
|
||||
// EPICS devices implemented are included in PShell, package ch.psi.pshell.epics.
|
||||
// However direct channel access builtin functions are available.
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
channel_name = "TESTIOC:TESTCALCOUT:Output"
|
||||
|
||||
//reading/writing to a channel
|
||||
print (caget(channel_name))
|
||||
caput(channel_name, 0.0)
|
||||
//Put with no wait
|
||||
caput(channel_name, 0.0)
|
||||
print (caget(channel_name))
|
||||
|
||||
//waiting for a channel value
|
||||
cawait(channel_name, 0.0, timeout = 10.0)
|
||||
|
||||
//If many IO it is better to keep the same CA connection
|
||||
channel = create_channel(channel_name, 'd')
|
||||
for (var i=0; i<10; i++){
|
||||
print (channel.get()
|
||||
)
|
||||
}
|
||||
channel.close()
|
||||
|
||||
|
||||
//The create_channel_device method return a device implements Readable and Writable and therefore can be used in scans
|
||||
channel = create_channel_device(channel_name, 'd', null, "My Channel")
|
||||
lscan(channel, ai2, 0, 10, 0.1)
|
||||
channel.close()
|
||||
|
||||
|
||||
//Or else we can use a Device
|
||||
ChannelDouble= Java.type('ch.psi.pshell.epics.ChannelDouble')
|
||||
channel = new ChannelDouble("My Channel", channel_name)
|
||||
channel.initialize()
|
||||
lscan(channel, ai2, 0, 10, 0.1)
|
||||
channel.close()
|
||||
|
||||
|
||||
|
||||
//Creating a table reading set of channels for each scan step.
|
||||
attrs_dataset = null
|
||||
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]
|
||||
|
||||
|
||||
function AfterReadout(rec){
|
||||
if (attrs_dataset == null){
|
||||
attrs_dataset = get_exec_pars().group + "attributes"
|
||||
create_table(attrs_dataset, attrs_names, attrs_types, attrs_lenghts)
|
||||
}
|
||||
record = []
|
||||
for (var i=0; i<attrs_names.length; i++){
|
||||
val = caget(attrs_names[i], attrs_types[i])
|
||||
record.push(val)
|
||||
}
|
||||
//print record
|
||||
append_table(attrs_dataset, record)
|
||||
}
|
||||
|
||||
a = lscan(m1, [ai1, ai2], 0, 0.1, 20, 0.01, undefined, undefined, undefined, undefined, after_read=AfterReadout)
|
||||
29
script/54_ChannelAccessServer.js
Executable file
29
script/54_ChannelAccessServer.js
Executable file
@@ -0,0 +1,29 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Creation of EPICS CA servers over register devices
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CAS = Java.type('ch.psi.pshell.epics.CAS')
|
||||
|
||||
cas = []
|
||||
|
||||
//CAS.setServerPort(5062)
|
||||
|
||||
cas1 = new CAS("TESTCAS:c1", ai1, 'double')
|
||||
cas2 = new CAS("TESTCAS:c2", ai1, 'int')
|
||||
cas3 = new CAS("TESTCAS:c3", ai1, 'string')
|
||||
cas4 = new CAS("TESTCAS:c4", ao1, 'double')
|
||||
cas5 = new CAS("TESTCAS:c5", dp1, 'string')
|
||||
cas6 = new CAS("TESTCAS:c6", wf1, 'double')
|
||||
cas7 = new CAS("TESTCAS:c7", wf1, 'int')
|
||||
cas8 = new 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")
|
||||
)
|
||||
51
script/55_Interlocks.js
Executable file
51
script/55_Interlocks.js
Executable file
@@ -0,0 +1,51 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Interlocks: example on creating and installing device interlock rules.
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//Motor and Positioners
|
||||
var MyInterlock1 = Java.extend(Interlock)
|
||||
var interlock1 = new MyInterlock1( [m1, p1]) {
|
||||
check: function (pos) {
|
||||
m=pos[0]
|
||||
p=pos[1]
|
||||
if ((p<500) && (m<5) && (m>4)){
|
||||
return false
|
||||
}
|
||||
return true
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
//Motor group
|
||||
var MyInterlock2 = Java.extend(Interlock)
|
||||
var interlock2 = new MyInterlock2( [mg1, p1]) {
|
||||
check: function (pos) {
|
||||
print(pos)
|
||||
mg=pos[0]
|
||||
p=pos[1]
|
||||
print(to_array(mg))
|
||||
if ((p<500) && (mg[0]<5) && (mg[1]>4)){
|
||||
return false
|
||||
}
|
||||
return true
|
||||
},
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
//Discrete Positioner
|
||||
var MyInterlock3 = Java.extend(Interlock)
|
||||
interlock3 = new MyInterlock3( [dp1, p1]) {
|
||||
check: function (pos) {
|
||||
dp=pos[0]
|
||||
p=pos[1]
|
||||
print ("DP " + dp)
|
||||
print ("P " + p)
|
||||
if ((p<500) && (dp=="Out")){
|
||||
return false
|
||||
}
|
||||
return true
|
||||
},
|
||||
}
|
||||
*/
|
||||
9
script/56_ExecutingCPython.js
Executable file
9
script/56_ExecutingCPython.js
Executable file
@@ -0,0 +1,9 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Executing CPython in external process.
|
||||
// Requires cpython.py to be put in the scripts folder, or else in the python path.
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//Executing a module
|
||||
ret = exec_cpython("cpython", [])
|
||||
print (ret
|
||||
98
script/57_EmbeddingCPython.js
Executable file
98
script/57_EmbeddingCPython.js
Executable file
@@ -0,0 +1,98 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Embedding CPython with JEP: USe of numpy, pandas and matpplotlib in the same process.
|
||||
// Requires cpython.py to be put in the scripts folder, or else in the python path.
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//Requirements to the use of JEP:
|
||||
// 1- PYTHONHOME is set to the python interpreter home folder.
|
||||
// 2- jep*.so is in LD_LIBRARY_PATH (e.g. in extensions folder )
|
||||
// 3- jep*.jar is in the CLASS_PATH (e.g. in extensions folder )
|
||||
//JEP works with python 2 and 3.
|
||||
|
||||
run("jeputils")
|
||||
|
||||
//In order to use matplotlib we must set Tk backend before importing plt
|
||||
eval_jep("import matplotlib")
|
||||
eval_jep("matplotlib.use('TkAgg')")
|
||||
|
||||
|
||||
//Evaluating statements
|
||||
eval_jep("import sys")
|
||||
eval_jep("import numpy as np")
|
||||
eval_jep("a = np.array((100, 100), )")
|
||||
eval_jep("print (a)")
|
||||
|
||||
eval_jep("\
|
||||
def stderr(str): \n\
|
||||
if sys.version_info < (3,0) :\n\
|
||||
exec(\"print >> sys.stderr, '\" + str + \"'\") \n\
|
||||
else: \n\
|
||||
exec(\"print ('\" + str + \"', file=sys.stderr)\") \n\
|
||||
")
|
||||
|
||||
eval_jep("stderr('Testing stderr')")
|
||||
|
||||
|
||||
//Accessing a numpy array
|
||||
a=get_jep("a")
|
||||
print (a.getData()
|
||||
)
|
||||
print (a.getDimensions()
|
||||
)
|
||||
|
||||
|
||||
//Setting numpy array with scan data
|
||||
steps = [3,4]
|
||||
dims = [steps[0]+1 , steps[1]+1 ]
|
||||
r = ascan([m1,m2], [ai1], [0.0,0.0], [0.2,0.2], steps)
|
||||
data = r.getReadable(0)
|
||||
a = new_numpy_array(data, dims,'d')
|
||||
print (to_array(a.getDimensions()))
|
||||
print (to_array(a.getData()))
|
||||
plot( Convert.reshape(a.getData(),a.getDimensions()),null, null, null, "Scan Data")
|
||||
|
||||
|
||||
//Calling a module function
|
||||
b = call_jep("numpy", "transpose", [a,])
|
||||
print (to_array(b.getDimensions()))
|
||||
print (to_array(b.getData()))
|
||||
plot( Convert.reshape(b.getData(),b.getDimensions()),null, null, null, title="Transposed")
|
||||
|
||||
|
||||
|
||||
|
||||
//More calculations calling numpy
|
||||
a = call_jep("numpy", "ones", [[400,200],'d'])
|
||||
for (var i=0; i<100; i++){
|
||||
b = call_jep("numpy", "ones", [[400,200],'d'])
|
||||
a = call_jep("numpy", "add", [a,b])
|
||||
s = call_jep("numpy", "sum", [a,])
|
||||
print (a.getData()[0] + " " + s
|
||||
)
|
||||
sleep(0.001)
|
||||
}
|
||||
|
||||
//Calling a local function
|
||||
data = [1,2,3,4,5,6,7,8,9,0]
|
||||
dims = [2,5]
|
||||
array = new_numpy_array(data, dims,'d') //Auxiliary function to create numpy arrays from lists or java arrays.
|
||||
ret = call_jep("cpython", "calc", [array,])
|
||||
print (ret.getDimensions() + " - " + ret.getData()
|
||||
)
|
||||
|
||||
|
||||
//Testing pandas
|
||||
ret = call_jep("cpython", "test_pandas")
|
||||
|
||||
|
||||
//Testing tkinter
|
||||
ret = call_jep("cpython", "test_tkinter")
|
||||
|
||||
|
||||
//Testing matplotlib
|
||||
ret = call_jep("cpython", "test_matplotlib", [0.1, 4, 0.4])
|
||||
|
||||
|
||||
//Running a modole
|
||||
run_jep("cpython")
|
||||
|
||||
68
script/60_Fitting.js
Executable file
68
script/60_Fitting.js
Executable file
@@ -0,0 +1,68 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Function fitting and peak search with mathutils.py
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
run("mathutils")
|
||||
|
||||
|
||||
start = 0
|
||||
end = 10
|
||||
step_size = 0.1
|
||||
|
||||
result= lscan(ao1,ai1,start,end,[step_size,],0.01)
|
||||
|
||||
readable = result.getReadable(0)
|
||||
positions = result.getPositions(0)
|
||||
|
||||
function get_function_data(func, start, end, resolution){
|
||||
ret = []
|
||||
for (var x=start; x<=end; x+=resolution){
|
||||
fit_polinomial.push(func.value(x))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pars_polynomial = fit_polynomial(readable, positions, 6)
|
||||
//(a0, a1, a2, a3, a4, a5, a6)
|
||||
fitted_polynomial_function = new PolynomialFunction(pars_polynomial)
|
||||
print (pars_polynomial)
|
||||
|
||||
pars_gaussian = fit_gaussian(readable, positions)
|
||||
normalization = pars_gaussian[0]
|
||||
mean_val = pars_gaussian[1]
|
||||
sigma = pars_gaussian [2]
|
||||
fitted_gaussian_function = new Gaussian(normalization, mean_val, sigma)
|
||||
print (normalization + " " + mean_val + " " + sigma)
|
||||
|
||||
pars_harmonic= fit_harmonic(readable, positions)
|
||||
amplitude = pars_harmonic[0]
|
||||
angular_frequency = pars_harmonic[1]
|
||||
phase = pars_harmonic[2]
|
||||
fitted_harmonic_function = new HarmonicOscillator(amplitude, angular_frequency, phase)
|
||||
print (amplitude+ " " + angular_frequency+ " " + phase)
|
||||
|
||||
|
||||
resolution = step_size/100
|
||||
fit_polinomial = []
|
||||
fit_gaussian = []
|
||||
fit_harmonic = []
|
||||
for (var x=start; x<=end; x+=resolution){
|
||||
fit_polinomial.push(fitted_polynomial_function.value(x))
|
||||
fit_gaussian.push(fitted_gaussian_function.value(x))
|
||||
fit_harmonic.push(fitted_harmonic_function.value(x))
|
||||
}
|
||||
x = range(start, end+resolution, resolution)
|
||||
|
||||
|
||||
peaks = calculate_peaks(fitted_polynomial_function, start, end)
|
||||
|
||||
plots = plot([readable, fit_polinomial, fit_gaussian, fit_harmonic] ,
|
||||
["data", "polinomial", "gaussian", "harmonic"], xdata = [positions,x,x,x], ydata=undefined, title="Data")
|
||||
|
||||
for (var p in peaks){
|
||||
print ("Max: " + p)
|
||||
plots[0].addMarker(p, null, "Max=" + Math.round(p,2), Color.LIGHT_GRAY)
|
||||
}
|
||||
|
||||
plots[0].addMarker(mean_val, null, "Mean=" + Math.round(mean_val,2), Color.LIGHT_GRAY)
|
||||
43
script/61_MultipleGaussianFit.js
Executable file
43
script/61_MultipleGaussianFit.js
Executable file
@@ -0,0 +1,43 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Multiple Gaussians peak search with mathutils.py
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
run("mathutils")
|
||||
|
||||
start = 0
|
||||
end = 50
|
||||
step_size = 0.2
|
||||
|
||||
result= lscan(ao1,ai1,start,end,[step_size,])
|
||||
|
||||
readable = result.getReadable(0)
|
||||
positions = result.getPositions(0)
|
||||
|
||||
min = Math.min.apply(null, readable)
|
||||
max = Math.max.apply(null, readable)
|
||||
|
||||
threshold = (min + max)/2
|
||||
min_peak_distance = 5.0
|
||||
|
||||
peaks = estimate_peak_indexes(readable, positions, threshold, min_peak_distance)
|
||||
print ("Peak indexes: " + peaks)
|
||||
print ("Peak x: " + peaks.map(function(x) {return positions[x]}))
|
||||
print ("Peak y: " + peaks.map(function(x) {return readable[x]}))
|
||||
|
||||
gaussians = fit_gaussians(readable, positions, peaks)
|
||||
|
||||
plots = plot([readable],["sin"],[positions], undefined, title="Data" )
|
||||
for (var i=0; i< peaks.length; i++){
|
||||
peak = peaks[i]
|
||||
pars_gaussian = gaussians[i]
|
||||
normalization = pars_gaussian[0]
|
||||
mean_val = pars_gaussian[1]
|
||||
sigma = pars_gaussian [2]
|
||||
if (Math.abs(mean_val - positions[peak]) < min_peak_distance){
|
||||
print ("Peak -> " + mean_val)
|
||||
plots[0].addMarker(mean_val, null, "N="+ Math.round(normalization,2), new Color(210,0,0))
|
||||
}else {
|
||||
print ("Invalid gaussian fit: " + mean_val)
|
||||
}
|
||||
}
|
||||
30
script/62_FFT.js
Executable file
30
script/62_FFT.js
Executable file
@@ -0,0 +1,30 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Demonstrate the use of fft function in mathutils.py
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
run("mathutils")
|
||||
|
||||
|
||||
|
||||
//The signal is composed by 3 sinusoids (100Hz, 200Hz, 400Hz) and a background noise (a sin waveform is A.sin(2.pi.f.t))
|
||||
function signal_generator(t){
|
||||
return Math.sin(100*2*Math.PI*t) + 0.5 * Math.sin(200*2*Math.PI*t) + 0.25 * Math.sin(400*2*Math.PI*t) + 0.5* Math.random()
|
||||
}
|
||||
|
||||
sampling_frequency = 1024.0
|
||||
number_of_samples = 1024
|
||||
|
||||
|
||||
time_vector = range(0, number_of_samples, 1).map(function(x) {return x / sampling_frequency})
|
||||
signal = time_vector.map(function(x) {return signal_generator(x)})
|
||||
tranform = fft(signal)
|
||||
|
||||
two_side_spectrum = get_modulus(tranform).map(function(x) {return x / number_of_samples})
|
||||
spectrum = two_side_spectrum.slice(1,two_side_spectrum.length/2 + 1).map(function(x) {return (x * x)})
|
||||
spectrum.splice(0,0,two_side_spectrum[0])
|
||||
|
||||
number_of_samples = tranform.length // Signal may have been padded to next power of two
|
||||
freq_vector = range(0, spectrum.length , 1).map(function(x) {return x * sampling_frequency / parseFloat(number_of_samples)})
|
||||
|
||||
plot([signal,spectrum], ["signal", "spectrum"],[time_vector, freq_vector])
|
||||
|
||||
50
script/63_OnlineSpectrumAnalyser.js
Executable file
50
script/63_OnlineSpectrumAnalyser.js
Executable file
@@ -0,0 +1,50 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Create an online spectrum analyser uysing mathutils.py
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
run("mathutils")
|
||||
|
||||
function plot_spectrum(signal, sampling_freq){
|
||||
if (!is_defined(plots)) plots = null
|
||||
signal = to_array(signal)
|
||||
number_of_samples = signal.length
|
||||
time_vector = range(0, number_of_samples, 1).map(function(x) {return x / sampling_freq})
|
||||
tranform = fft(signal)
|
||||
two_side_spectrum = get_modulus(tranform).map(function(x) {return x / number_of_samples})
|
||||
spectrum = two_side_spectrum.slice(1,two_side_spectrum.length/2 + 1).map(function(x) {return x * x})
|
||||
spectrum.splice(0,0,two_side_spectrum[0])
|
||||
number_of_samples = tranform.length // Signal may have been padded to next power of two
|
||||
freq_vector = range(0, spectrum.length , 1).map(function(x) {return x * sampling_freq / parseFloat(number_of_samples)})
|
||||
if (plots == null){
|
||||
plots = plot([signal,spectrum], ["signal", "spectrum"],[time_vector, freq_vector], undefined, title = "Spectrum")
|
||||
plots[0].getAxis(AxisId.Y).setRange(-1.5,2.5)
|
||||
plots[1].getAxis(AxisId.Y).setRange(0.0,1.1)
|
||||
} else {
|
||||
plots[0].getSeries(0).setData(time_vector,signal)
|
||||
plots[1].getSeries(0).setData(freq_vector,spectrum)
|
||||
}
|
||||
return plots
|
||||
}
|
||||
|
||||
function get_sample(samples, sampling_freq){
|
||||
return range(0,samples,1).map(function(t) {return Math.sin(200*2*Math.PI*t/sampling_freq) + Math.random()})
|
||||
//Simple example sampling a device:
|
||||
//set_exec_pars(undefined, undefined, undefined, undefined, persist=false)
|
||||
//set_preference(Preference.PLOT_DISABLED, true)
|
||||
//set_preference(Preference.TABLE_DISABLED, true)
|
||||
//return tscan(ai1, samples, 1/sampling_freq).getReadable(0)
|
||||
}
|
||||
|
||||
plots = null
|
||||
samples = 1024
|
||||
sampling_freq = 1024.0
|
||||
|
||||
while(true){
|
||||
signal = get_sample(samples, sampling_freq)
|
||||
plots = plot_spectrum(signal, sampling_freq, plots)
|
||||
sleep(0.1)
|
||||
if (plots[0].displayable == false){
|
||||
break
|
||||
}
|
||||
}
|
||||
39
script/64_NumericalAnalysis.js
Executable file
39
script/64_NumericalAnalysis.js
Executable file
@@ -0,0 +1,39 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Use of numerical analysis functions in mathutils
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
run("mathutils")
|
||||
|
||||
//interpolation
|
||||
var fy = [0, 1, 4,10,50,25,12, 5, 3, 0]
|
||||
var fx = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
types = ["linear", "cubic", "akima", "loess", "neville", "newton"]
|
||||
functions = types.map(function(t) {return interpolate(fy,fx,t)})
|
||||
|
||||
plot_x = range (0,9,0.01)
|
||||
values = functions.map(function(f) {return get_values(f,plot_x)})
|
||||
plots=plot(values,types,plot_x)
|
||||
|
||||
//derivative
|
||||
for (var i=0; i<types.length; i++){
|
||||
try{
|
||||
d = deriv(functions[i])
|
||||
plots[i].addSeries(new LinePlotSeries("derivative"))
|
||||
plots[i].getSeries(1).setData(plot_x, get_values(d,plot_x))
|
||||
} catch(ex){
|
||||
//not differentiable
|
||||
}
|
||||
}
|
||||
|
||||
//integration
|
||||
for (var i=0; i<types.length; i++){
|
||||
s = integrate(functions[i],fx)
|
||||
plots[i].addMarker(fx[fx.length-1]+0.1, null, "Integral=" + Math.round(s,4), plots[i].background).setLabelPaint(Color.BLACK)
|
||||
}
|
||||
|
||||
//Direct calculation on arrays:
|
||||
print ("Deriv (linear interpolation): ", deriv(fy,fx))
|
||||
print ("Deriv (cubic interpolation): ", deriv(fy, fx, "cubic"))
|
||||
print ("Integral (linear interpolation): ", integrate(fy, null, fx, "cubic"))
|
||||
print ("Integral (cubic interpolation): ", integrate(fy, null, fx, "cubic"))
|
||||
print ("Integral (linear interpolation in range [1,5]): ", integrate(fy, [1,5], fx))
|
||||
70
script/65_ConvexHull.js
Executable file
70
script/65_ConvexHull.js
Executable file
@@ -0,0 +1,70 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Example of convex hull plot
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
function add_convex_hull_plot(title, x,y, name, clear){
|
||||
if (!is_defined(name)) name = null
|
||||
if (!is_defined(clear)) clear = false
|
||||
plots = get_plots(title = title)
|
||||
p = null
|
||||
if (plots.length==0){
|
||||
p = plot(null,name=name, undefined, undefined, title = title)[0]
|
||||
p.getAxis(AxisId.X).setRange(-50,150)
|
||||
p.getAxis(AxisId.Y).setRange(-50,150)
|
||||
p.setLegendVisible(true)
|
||||
} else {
|
||||
p = plots[0]
|
||||
if (clear){
|
||||
p.clear()
|
||||
}
|
||||
p.addSeries(new LinePlotSeries(name))
|
||||
}
|
||||
s = p.getSeries(name)
|
||||
s.setLinesVisible(false)
|
||||
s.setPointSize(3)
|
||||
s.setData(x, y)
|
||||
|
||||
//In the first time the plot shows, it takes some time for the color to be assigned
|
||||
while (s.color == null){
|
||||
sleep(0.001)
|
||||
}
|
||||
|
||||
hull = new LinePlotSeries(name + " Hull", s.color)
|
||||
|
||||
//Bounding box
|
||||
//x1 = Math.min.apply(null, x)
|
||||
//x2 = Math.max.apply(null, x)
|
||||
//y1 = Math.min.apply(null, y)
|
||||
//y2 = Math.max.apply(null, y)
|
||||
//(hx,hy) = ([x1,x2, x2, x1, x1], [y1, y1, y2, y2, y1])
|
||||
|
||||
//Convex Hull
|
||||
ret = convex_hull(point_list=undefined, x=x, y=y)
|
||||
hx=ret[0]
|
||||
hy=ret[1]
|
||||
hx.push(hx[0])
|
||||
hy.push(hy[0])
|
||||
|
||||
p.addSeries(hull)
|
||||
hull.setLineWidth(2)
|
||||
hull.setData(hx,hy)
|
||||
hull.setColor(s.color)
|
||||
}
|
||||
|
||||
title = "Convex Hull"
|
||||
if (get_plots(title).length>0){
|
||||
get_plots(title)[0].clear()
|
||||
}
|
||||
|
||||
for (var step=1; step<=5; step++){
|
||||
x=[]
|
||||
y=[]
|
||||
for (var i=0; i<=50 ; i++){
|
||||
x.push(Math.random() * 100 / step)
|
||||
y.push(Math.random() * 100/ step)
|
||||
}
|
||||
add_convex_hull_plot (title, x,y,"Scan " + step)
|
||||
}
|
||||
|
||||
41
script/66_WeightedPolynomialFit.js
Executable file
41
script/66_WeightedPolynomialFit.js
Executable file
@@ -0,0 +1,41 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Example if fitting with weights
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
run("mathutils")
|
||||
run("plotutils")
|
||||
|
||||
|
||||
fx = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
|
||||
fy = [36.0, 66.0, 121.0, 183.0, 263.0, 365.0, 473.0, 603.0, 753.0, 917.0]
|
||||
num_samples = fx.length
|
||||
|
||||
p=plot(fy, "Observed Data", xdata=fx)[0]
|
||||
p.setLegendVisible(true)
|
||||
|
||||
pars_polynomial= fit_polynomial(fy, fx, 1, null)
|
||||
func = new PolynomialFunction(pars_polynomial)
|
||||
plot_function(p, func, "1st order", fx)
|
||||
|
||||
var w = []; size=num_samples; while(size--) w.push(1.0);
|
||||
w[5]=20.0
|
||||
pars_polynomial= fit_polynomial(fy, fx, 1, null, w)
|
||||
func = new PolynomialFunction(pars_polynomial)
|
||||
plot_function(p, func, "1st order Weighted: " + w , fx)
|
||||
|
||||
pars_polynomial= fit_polynomial(fy, fx, 2, null, w)
|
||||
func = new PolynomialFunction(pars_polynomial)
|
||||
plot_function(p, func, "2nd order" + w , fx)
|
||||
for (var xp in fx){
|
||||
print (fx[xp] + " " + poly(fx[xp], pars_polynomial))
|
||||
}
|
||||
|
||||
print ("")
|
||||
w = [ 10.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 10.0]
|
||||
pars_polynomial= fit_polynomial(fy, fx, 2, null, w)
|
||||
func = new PolynomialFunction(pars_polynomial)
|
||||
plot_function(p, func, "2n order Weighted: " + w , fx)
|
||||
for (var xp in fx){
|
||||
print (fx[xp] + " " + poly(fx[xp], pars_polynomial))
|
||||
}
|
||||
122
script/67_LeastSquares.js
Executable file
122
script/67_LeastSquares.js
Executable file
@@ -0,0 +1,122 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Example of least squares optimization
|
||||
// http://commons.apache.org/proper/commons-math/userguide/leastsquares.html
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
run("mathutils")
|
||||
run("plotutils")
|
||||
|
||||
|
||||
plots = plot([null, null], [null, null])
|
||||
p1=plots[0]
|
||||
p2=plots[1]
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//Fitting the quadratic function f(x) = a x2 + b x + c
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
var fx = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
|
||||
var fy = [36.0, 66.0, 121.0, 183.0, 263.0, 365.0, 473.0, 603.0, 753.0, 917.0]
|
||||
num_samples = fx.length
|
||||
weigths = []; size=num_samples; while(size--) weigths.push(1.0)
|
||||
|
||||
p1.getSeries(0).setData(fx, fy)
|
||||
p1.getSeries(0)
|
||||
|
||||
|
||||
var Model = Java.extend(MultivariateJacobianFunction)
|
||||
var model = new Model() {
|
||||
value: function (variables) {
|
||||
value = new ArrayRealVector(num_samples)
|
||||
jacobian = new Array2DRowRealMatrix(num_samples, 3)
|
||||
for (var i=0; i< num_samples; i++){
|
||||
a=variables.getEntry(0)
|
||||
b=variables.getEntry(1)
|
||||
c=variables.getEntry(2)
|
||||
model = a*fx[i]*fx[i] + b*fx[i] + c
|
||||
value.setEntry(i, model)
|
||||
jacobian.setEntry(i, 0, fx[i]*fx[i]) // derivative with respect to p0 = a
|
||||
jacobian.setEntry(i, 1, fx[i]) // derivative with respect to p1 = b
|
||||
jacobian.setEntry(i, 2, 1.0) // derivative with respect to p2 = c
|
||||
}
|
||||
return new Pair(value, jacobian)
|
||||
},
|
||||
}
|
||||
|
||||
initial = [1.0, 1.0, 1.0] //parameters = a, b, c
|
||||
target = fy.slice(0) //the target is to have all points at the positios
|
||||
|
||||
ret = optimize_least_squares(model, target, initial, weigths)
|
||||
|
||||
parameters = ret[0]
|
||||
residuals = ret[1]
|
||||
rms = ret[2]
|
||||
evals = ret[3]
|
||||
iters = ret[4]
|
||||
|
||||
a = parameters[0]
|
||||
b = parameters[1]
|
||||
c = parameters[2]
|
||||
|
||||
print ("A: " + a + " B: "+ b, " C: "+ c
|
||||
)
|
||||
print ("RMS: " + rms+ " evals: " + evals+ " iters: " + iters
|
||||
)
|
||||
for (var i=0; i<num_samples; i++){
|
||||
print (fx[i] + " " + fy[i] + " " + poly(fx[i] + " " + [c,b,a])
|
||||
)
|
||||
}
|
||||
|
||||
plot_function(p1, new PolynomialFunction([c,b,a]), "Fit", fx)
|
||||
print ("----------------------------------------------------------------------------\n"
|
||||
)
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//Fitting center of circle of known radius to observed points
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
radius = 70.0
|
||||
fx = [30.0, 50.0, 110.0, 35.0, 45.0]
|
||||
fy = [68.0, -6.0, -20.0, 15.0, 97.0]
|
||||
num_samples = fx.length
|
||||
weigths = [0.1, 0.1, 1.0, 0.1, 1.0]
|
||||
|
||||
p2.getSeries(0).setData(fx, fy)
|
||||
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
|
||||
var Model = Java.extend(MultivariateJacobianFunction)
|
||||
var model = new Model() {
|
||||
value: function (variables) {
|
||||
cx=variables.getEntry(0)
|
||||
cy=variables.getEntry(1)
|
||||
value = new ArrayRealVector(num_samples)
|
||||
jacobian = new Array2DRowRealMatrix(num_samples, 2)
|
||||
for (var i=0; i< num_samples; i++){
|
||||
var mod = hypot(cx-fx[i], cy-fy[i])
|
||||
value.setEntry(i, mod)
|
||||
jacobian.setEntry(i, 0, (cx - fx[i]) / mod) // derivative with respect to p0 = x center
|
||||
jacobian.setEntry(i, 1, (cy - fy[i]) / mod) // derivative with respect to p1 = y center
|
||||
}
|
||||
return new Pair(value, jacobian)
|
||||
},
|
||||
}
|
||||
|
||||
initial = [mean(fx), mean(fy)] //parameters = cx, cy
|
||||
target = []; size=num_samples; while(size--) target.push(radius); //the target is to have all points at the specified radius from the center
|
||||
|
||||
ret = optimize_least_squares(model, target, initial, weigths)
|
||||
parameters = ret[0]
|
||||
residuals = ret[1]
|
||||
rms = ret[2]
|
||||
evals = ret[3]
|
||||
iters = ret[4]
|
||||
cx = parameters[0]
|
||||
cy = parameters[1]
|
||||
|
||||
print ("CX: " + cx + " CY: "+ cy)
|
||||
print ("RMS: " + rms+ " evals: " + evals, " iters: " + iters)
|
||||
plot_point(p2, cx, cy, size = 5, color = null, name = "Fit Center")
|
||||
plot_circle(p2, cx, cy, radius, width = 1, color = null, name = "Fit")
|
||||
95
script/70_FiltersAndOverlays.js
Executable file
95
script/70_FiltersAndOverlays.js
Executable file
@@ -0,0 +1,95 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Demonstrate creation of an image filters and new source based on filter.
|
||||
// Also demonstrate creation of image histogram and use of overlays.
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
importClass(java.awt.Point)
|
||||
importClass(java.awt.Dimension)
|
||||
importClass(java.awt.Font)
|
||||
|
||||
Filter = Java.type('ch.psi.pshell.imaging.Filter')
|
||||
|
||||
Pen = Java.type('ch.psi.pshell.imaging.Pen')
|
||||
Line = Java.type('ch.psi.pshell.imaging.Overlays.Line')
|
||||
Rect = Java.type('ch.psi.pshell.imaging.Overlays.Rect')
|
||||
Crosshairs = Java.type('ch.psi.pshell.imaging.Overlays.Crosshairs')
|
||||
Text = Java.type('ch.psi.pshell.imaging.Overlays.Text')
|
||||
Utils = Java.type('ch.psi.pshell.imaging.Utils')
|
||||
|
||||
|
||||
var MyFilter = Java.extend(Filter)
|
||||
var filter = new MyFilter() {
|
||||
process: function (image, data) {
|
||||
image = Utils.grayscale(image)
|
||||
image = Utils.blur(image)
|
||||
image = Utils.sobel(image)
|
||||
return image
|
||||
},
|
||||
}
|
||||
|
||||
//Setting the filter to a source
|
||||
src2.setFilter(filter)
|
||||
|
||||
//Creating a new source with the filter
|
||||
src1.setFilter(null)
|
||||
|
||||
|
||||
add_device(new MyFilter("f1") {
|
||||
process: function (image, data) {
|
||||
image = Utils.grayscale(image)
|
||||
image = Utils.blur(image)
|
||||
image = Utils.sobel(image)
|
||||
return image
|
||||
},
|
||||
}, true)
|
||||
//f1.passive = true
|
||||
src1.addListener(f1)
|
||||
|
||||
|
||||
//Open renderers
|
||||
renderer_filter = show_panel(f1)
|
||||
renderer = show_panel(src1)
|
||||
|
||||
|
||||
//Overlays
|
||||
plots = null
|
||||
size = renderer.getImageSize()
|
||||
ov_text = new Text(new Pen(Color.GREEN.darker()), "Ploting Histogram", new Font("Verdana", Font.PLAIN, 12), new Point(20,20))
|
||||
ov_line = new Line(new Pen(Color.DARK_GRAY), new Point(0,size.height/2), new Point( size.width ,size.height/2))
|
||||
ov_rect = new Rect(new Pen(Color.DARK_GRAY), new Point(size.width/2 -15,size.height/2+10), new Dimension(30,30))
|
||||
ov_cross = new Crosshairs(new Pen(Color.DARK_GRAY), new Point(size.width/2 ,size.height/3), new Dimension(15,15))
|
||||
ov_rect.setSolid(true)
|
||||
ov_rect.setMovable(true)
|
||||
|
||||
//Histogram
|
||||
try{
|
||||
renderer.addOverlays([ov_text,ov_line, ov_rect, ov_cross])
|
||||
|
||||
while(true){
|
||||
|
||||
h = histogram(im1.read(), undefined, undefined, bin=0.1)
|
||||
hd=h[0]; xd = h[1]
|
||||
|
||||
image = Utils.grayscale(src1.getOutput())
|
||||
data = Convert.toUnsigned(image.getData().getDataBuffer().getData())
|
||||
h = histogram(data, range_min=0, range_max=255)
|
||||
hi=h[0]; xi = h[1]
|
||||
|
||||
if (plots == null){
|
||||
plots = plot([hd,hi], ["Data", "Image"],[xd, xi], title = "Histo")
|
||||
} else{
|
||||
plots[0].getSeries(0).setData(xd,hd)
|
||||
plots[1].getSeries(0).setData(xi,hi)
|
||||
}
|
||||
if (plots[0].displayable == false){
|
||||
break
|
||||
}
|
||||
|
||||
ov_cross.update(new Point((ov_cross.position.x+1) % size.width ,(ov_cross.position.y+1) % size.height))
|
||||
|
||||
sleep(0.1)
|
||||
}
|
||||
} finally {
|
||||
renderer.removeOverlays([ov_text,ov_line, ov_rect, ov_cross])
|
||||
}
|
||||
154
script/71_ImageJ.js
Executable file
154
script/71_ImageJ.js
Executable file
@@ -0,0 +1,154 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Example of using ImageJ functionalities through ijutils.
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
run("ijutils")
|
||||
|
||||
//Image Loading
|
||||
ip = load_image("images/img.png", title="Image")
|
||||
|
||||
//Basic image manipulation: creation, copying, padding, saving
|
||||
resized = resize(ip, 300,300)
|
||||
save_image(resized, get_context().setup.expandPath("{images}/resized.tiff") ,"tiff")
|
||||
crop=sub_image(ip,10,20,50,30)
|
||||
bin_im = binning(ip,2)
|
||||
new_im = new_image(256, 256, "color")
|
||||
copy_image_to(bin_im, new_im, 20, 20)
|
||||
pad_im = pad_image(ip, 1, 2, 3, 4, Color.RED)
|
||||
stack=create_stack([ip,resized,crop, bin_im, new_im, pad_im], undefined, title = "Basic Functions")
|
||||
save_image(stack, get_context().setup.expandPath("{images}/stack.tiff") ,"tiff")
|
||||
stack.show()
|
||||
|
||||
|
||||
//Decomposing color channels
|
||||
|
||||
create_stack([ get_channel(ip, "red"),
|
||||
get_channel(ip, "green"),
|
||||
get_channel(ip, "blue"),
|
||||
get_channel(ip, "alpha"),
|
||||
grayscale(get_channel(ip, "brightness"), false)], undefined, title = "Color Decomposition").show()
|
||||
|
||||
|
||||
//Basic functions (in_place)
|
||||
aux = ip.duplicate()
|
||||
aux.show()
|
||||
grayscale(aux)
|
||||
gaussian_blur(aux); aux.repaintWindow()
|
||||
invert(aux); aux.repaintWindow()
|
||||
smooth(aux); aux.repaintWindow()
|
||||
sharpen(aux); aux.repaintWindow()
|
||||
noise(aux, 100); aux.repaintWindow()
|
||||
|
||||
|
||||
//Changing LUT
|
||||
aux = ip.duplicate()
|
||||
aux = grayscale(aux, in_place=false)
|
||||
r=[]; g=[]; b=[]
|
||||
for (var i=0; i<256; i++){
|
||||
r.push(0)
|
||||
g.push(0)
|
||||
b.push(i)
|
||||
}
|
||||
set_lut(aux, r, g, b)
|
||||
aux.show()
|
||||
|
||||
|
||||
//Histogram
|
||||
plot(get_histogram(ip))
|
||||
|
||||
|
||||
aux = grayscale(ip, in_place = false)
|
||||
bin = ip.duplicate()
|
||||
ip_bin = auto_threshold(aux, undefined, undefined, in_place=false)
|
||||
create_stack([ ip_bin,
|
||||
binary_fill_holes(ip_bin, dark_background = false, in_place=false),
|
||||
binary_outline(ip_bin, dark_background = false, in_place=false),
|
||||
binary_outline(binary_fill_holes(ip_bin, dark_background = false, in_place=false), dark_background = false),
|
||||
binary_dilate(ip_bin, undefined, undefined, undefined, in_place=false),
|
||||
binary_erode(ip_bin, undefined, undefined, undefined, in_place=false),
|
||||
binary_open(ip_bin, undefined, undefined, undefined, in_place=false),
|
||||
binary_close(ip_bin, undefined, undefined, undefined, in_place=false),
|
||||
binary_skeletonize(ip_bin, in_place=false)], undefined, title = "Binarization").show()
|
||||
|
||||
|
||||
//EDM, const & image operations
|
||||
aux = grayscale(ip, in_place = false)
|
||||
ip_bin = auto_threshold(aux, undefined, undefined, in_place=false)
|
||||
binary_fill_holes(ip_bin)
|
||||
|
||||
edm = edm(ip_bin, dark_background=false, in_place=false)
|
||||
ws = watershed(ip_bin, dark_background=false, in_place=false)
|
||||
up = ultimate_points(ip_bin, dark_background=false, in_place=false)
|
||||
vr = veronoi(ip_bin, dark_background=false, in_place=false)
|
||||
edm_disp = remap(edm, min=null, max=null, in_place=false)
|
||||
ws_disp = grayscale(ws, in_place=false)
|
||||
up_disp = enhance_contrast(up, undefined, undefined, undefined, undefined, in_place=false)
|
||||
vr_disp = enhance_contrast(vr, undefined, undefined, undefined, undefined, in_place=false)
|
||||
create_stack([edm_disp, aux, ip_bin, ws_disp, up_disp, vr_disp], undefined, title = "EDM Operations").show()
|
||||
final_img = grayscale(ip_bin, in_place = false)
|
||||
op_const(final_img,"add", -200)
|
||||
op_image(final_img, vr_disp, 'or')
|
||||
op_image(final_img, up_disp, 'or')
|
||||
final_img.show()
|
||||
|
||||
aux = grayscale(ip, in_place = false)
|
||||
|
||||
create_stack([ aux,
|
||||
subtract_background(aux, undefined, undefined, undefined, undefined, undefined, undefined, undefined, in_place=false),
|
||||
smooth(aux, false),
|
||||
sharpen(aux, false),
|
||||
edges(aux, false),
|
||||
bandpass_filter(aux,0, 5, undefined, undefined, undefined, undefined, undefined, in_place=false),
|
||||
bandpass_filter(aux,5, 100, undefined, undefined, undefined, undefined, undefined, in_place=false),
|
||||
op_const(aux,"and", 127, false),
|
||||
convolve(aux, KERNEL_BLUR, false),
|
||||
convolve(aux, KERNEL_SHARPEN, false),
|
||||
convolve(aux, KERNEL_SHARPEN_2, false),
|
||||
|
||||
|
||||
convolve(aux, KERNEL_LIGHT, false),
|
||||
convolve(aux, KERNEL_DARK, false),
|
||||
convolve(aux, KERNEL_EDGE_DETECT, false),
|
||||
convolve(aux, KERNEL_EDGE_DETECT_2, false),
|
||||
convolve(aux, KERNEL_DIFFERENTIAL_EDGE_DETECT, false),
|
||||
convolve(aux, KERNEL_PREWITT, false),
|
||||
convolve(aux, KERNEL_SOBEL, false)
|
||||
], undefined, title = "General Operations").show()
|
||||
|
||||
|
||||
//Rank operators
|
||||
rank_opers = []
|
||||
oplist = ["mean", "min", "max", "variance", "median", "close_maxima", "open_maxima", "remove_outliers", "remove_nan", "despeckle"]
|
||||
for (var op in oplist){
|
||||
rank_opers.push(op_rank(aux,oplist[op],kernel_radius=1, undefined, undefined, in_place=false))
|
||||
}
|
||||
create_stack(rank_opers, undefined, title = "Rank Operations").show()
|
||||
|
||||
|
||||
//Reslicing
|
||||
//orig = load_image("{data}/img/img2.png")
|
||||
orig = resize(ip, 300,200)
|
||||
grayscale(orig)
|
||||
images=[]
|
||||
for (var i=0; i<20; i++){
|
||||
images.push(orig.duplicate())
|
||||
op_const(orig, "multiply", 0.9)
|
||||
}
|
||||
stack=create_stack(images, undefined, title = "Original Stack")
|
||||
//stack.show()
|
||||
r1 = reslice(stack, start_at="Left", undefined, undefined, undefined, undefined, title="Reslice Horizontally")
|
||||
r2 = reslice(stack, start_at="Top", undefined, undefined, undefined, undefined, title="Reslice Vertically")
|
||||
r1.show()
|
||||
r2.show()
|
||||
|
||||
|
||||
//Particle Analysis
|
||||
aux = grayscale(ip, in_place = false)
|
||||
auto_threshold(aux)
|
||||
//binary_fill_holes(aux)
|
||||
//aux.show()
|
||||
var ret=analyse_particles(aux, 100,1000, true, true, 0, print_table=true)
|
||||
var results=ret[0]
|
||||
var output_img=ret[1]
|
||||
output_img.show()
|
||||
|
||||
47
script/Averaging.py
Executable file
47
script/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)
|
||||
|
||||
|
||||
8
script/Calibration2
Executable file
8
script/Calibration2
Executable file
@@ -0,0 +1,8 @@
|
||||
import java.awt.Point
|
||||
import java.awt.Dimension
|
||||
|
||||
from ch.psi.pshell.imaging.Overlays import *
|
||||
|
||||
|
||||
r.addOverlay(Crosshairs(Pen(Color.ORANGE), java.awt.Point(p1.x),int(p1.y)), java.awt.Dimension(15,15)))
|
||||
r.
|
||||
12
script/CamtoolAccess.py
Executable file
12
script/CamtoolAccess.py
Executable file
@@ -0,0 +1,12 @@
|
||||
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.pshell.bs.Provider as Provider
|
||||
|
||||
|
||||
url = camtool.getInstance(camtool.getInstances()[0])["stream"]
|
||||
p=Provider(None, url)
|
||||
s1 = Stream("stream1", p)
|
||||
d = Scalar("x_fit_mean", s1, "x_fit_mean", 10)
|
||||
s1.start()
|
||||
|
||||
12
script/CamtoolAverager.py
Executable file
12
script/CamtoolAverager.py
Executable file
@@ -0,0 +1,12 @@
|
||||
camtool.start("simulation")
|
||||
time.sleep(1.0)
|
||||
d = camtool.stream.getChild("x_fit_mean")
|
||||
a = create_averager(d, 5, -1)
|
||||
a.monitored = True
|
||||
m=camtool.getDataMatrix()
|
||||
|
||||
|
||||
|
||||
tscan ((d,a, a.samples,m), 10, 0.5)
|
||||
|
||||
camtool.stop()
|
||||
8
script/DetailedScan.py
Executable file
8
script/DetailedScan.py
Executable file
@@ -0,0 +1,8 @@
|
||||
|
||||
#Parameters (global variables)s:
|
||||
# ranges: list of RangeSelection
|
||||
|
||||
for i in range(len(ranges)):
|
||||
min = ranges[i].min
|
||||
max = ranges[i].max
|
||||
lscan(sout,sinp,min,max,[0.1,],0.01, title = "Range " + str(i))
|
||||
42
script/DiagChannels.py
Executable file
42
script/DiagChannels.py
Executable file
@@ -0,0 +1,42 @@
|
||||
diag_channels = []
|
||||
diag_channels.append(out)
|
||||
|
||||
def get_diag_name(diag):
|
||||
return ch.psi.utils.Str.toTitleCase(diag.getName()).replace(" ", "")
|
||||
|
||||
def print_diag():
|
||||
for f in diag_channels:
|
||||
print "%-25s %s" % (get_diag_name(f) , str(f.read()))
|
||||
|
||||
def create_diag_datasets(parent = None):
|
||||
if parent is None:
|
||||
parent = get_exec_pars().group
|
||||
group = parent + "attrs/"
|
||||
for f in diag_channels:
|
||||
create_dataset(group+get_diag_name(f) , 's' if (type(f) is ch.psi.pshell.epics.ChannelString) else 'd')
|
||||
|
||||
def append_diag_datasets(parent = None):
|
||||
if parent is None:
|
||||
parent = get_exec_pars().group
|
||||
group = parent + "attrs/"
|
||||
for f in diag_channels:
|
||||
try:
|
||||
x = f.read()
|
||||
if x is None:
|
||||
x = '' if (type(f) is ch.psi.pshell.epics.ChannelString) else float('nan')
|
||||
append_dataset(group+get_diag_name(f), x)
|
||||
except:
|
||||
log("Error sampling " + str(get_diag_name(f)) + ": " + str(sys.exc_info()[1]))
|
||||
|
||||
|
||||
|
||||
def after_readout(rec):
|
||||
if get_exec_pars().persist:
|
||||
if rec.index == 0:
|
||||
create_diag_datasets()
|
||||
append_diag_datasets()
|
||||
|
||||
|
||||
|
||||
|
||||
a= lscan(inp, (arr), 0, 40, 10, 0.2, after_read=after_readout)
|
||||
86
script/EnergyScan.py
Executable file
86
script/EnergyScan.py
Executable file
@@ -0,0 +1,86 @@
|
||||
#Script imported from: MgE_plus.xml
|
||||
|
||||
#Parameters
|
||||
"""
|
||||
E1 = 710
|
||||
E2 = 720
|
||||
TIME = 1 #min
|
||||
DELAY = 10.0 #s
|
||||
MODE = 'CIRC +'
|
||||
OFFSET = -9.0
|
||||
FOLDER = '2015_04/20150417'
|
||||
FILE = 'Fe_plus'
|
||||
ALPHA=0
|
||||
"""
|
||||
|
||||
|
||||
print "\nStarting energy scan - Parameters: ",
|
||||
print E1,E2,TIME,DELAY,MODE ,OFFSET ,FOLDER ,FILE ,ALPHA
|
||||
|
||||
start = time.localtime()
|
||||
|
||||
folder = os.path.expanduser("~/Data1/") + FOLDER + "/";
|
||||
def getNewestFile():
|
||||
global folder
|
||||
import glob
|
||||
try:
|
||||
return max(glob.iglob(folder+'/*.txt'), key=os.path.getctime)
|
||||
except:
|
||||
return None
|
||||
newest = getNewestFile()
|
||||
|
||||
def wait_channel(name, value, type):
|
||||
print "Waiting " + str(name) + " = " + str(value)
|
||||
cawait(name, value, type = type)
|
||||
print "Done"
|
||||
|
||||
|
||||
#Pre-actions
|
||||
#wait_channel('ACOAU-ACCU:OP-MODE', 'Light Available', type = 's')
|
||||
caput('X07MA-ID:MODE', MODE)
|
||||
time.sleep(1.0)
|
||||
if MODE == 'LINEAR':
|
||||
caput('X07MA-ID:ALPHA', ALPHA)
|
||||
wait_channel('X07MA-ID:DONE', 'DONE', type = 's')
|
||||
caput('X07MA-ID:ENERGY-OFFS', OFFSET)
|
||||
wait_channel('X07MA-ID:DONE', 'DONE', type = 's')
|
||||
caput('E1', E1)
|
||||
caput('E2', E2)
|
||||
caput('TIME', TIME)
|
||||
caput('FOLDER', FOLDER)
|
||||
caputq('X07MA-PHS-E:GO.A', E1)
|
||||
wait_channel('X07MA-PHS:alldone', '1', type = 's')
|
||||
time.sleep(0.5)
|
||||
caput('FILE', FILE)
|
||||
time.sleep(0.1)
|
||||
caput('X07MA-OP-VG13:WT_SET', 'Try open')
|
||||
time.sleep(5.0)
|
||||
caput('X07MA-OP-VG13:WT_SET', 'Try open')
|
||||
time.sleep(DELAY)
|
||||
caput('START', '1')
|
||||
|
||||
#Post-actions
|
||||
wait_channel('START', 'STOP', type = 's')
|
||||
|
||||
time.sleep(2.0)
|
||||
print "Finished Energy scan"
|
||||
|
||||
|
||||
#File convertion
|
||||
newName = folder + time.strftime("%Y%m%d_%H%M_", start) + FILE + "_0000.txt";
|
||||
#name = caget("MSG").split(' ')[0]
|
||||
name = getNewestFile()
|
||||
|
||||
if name == newest:
|
||||
raise Exception("Data file not created")
|
||||
|
||||
if not os.path.isfile(name):
|
||||
raise Exception("Data file not found: " + name)
|
||||
|
||||
cmd = "/sls/X07MA/data/x07maop/bin/modify_otf.pl " + name + " " + newName;
|
||||
print("Converting data file: " + cmd);
|
||||
import os
|
||||
os.system(cmd)
|
||||
print("Success")
|
||||
|
||||
|
||||
54
script/ErrorPlots.py
Executable file
54
script/ErrorPlots.py
Executable file
@@ -0,0 +1,54 @@
|
||||
###################################################################################################
|
||||
# Example creating error plots
|
||||
###################################################################################################
|
||||
|
||||
|
||||
[py, px, pxy]=plot([None,None,None],["y","x", "xy"])
|
||||
|
||||
#Y error plot
|
||||
py.setStyle(py.Style.ErrorY)
|
||||
py.setLegendVisible(True)
|
||||
|
||||
sy1 = LinePlotErrorSeries("F1")
|
||||
py.addSeries(sy1)
|
||||
sy1.appendData(1.0, 10.0, 9.0, 11.0)
|
||||
sy1.appendData(10.0, 6.1, 4.34, 7.54)
|
||||
sy1.appendData(17.8, 4.5, 3.1, 5.8)
|
||||
#One can define error instead of min/max (appendData(x, y, error))
|
||||
sy2 = LinePlotErrorSeries("F2")
|
||||
py.addSeries(sy2)
|
||||
sy2.setLinesVisible(False)
|
||||
sy2.appendData(3.0, 7.0, 2.0);
|
||||
sy2.appendData(13.0, 13.0, 2.0);
|
||||
sy2.appendData(24.0, 16.1, 1.0);
|
||||
|
||||
#X error plot
|
||||
px.setStyle(px.Style.ErrorX)
|
||||
px.setLegendVisible(True)
|
||||
sx = LinePlotErrorSeries("F3")
|
||||
px.addSeries(sx)
|
||||
sx.appendData(1.0, 10.0, 0.5, 1.5)
|
||||
sx.appendData(10.0, 6.1, 9.0, 10.3)
|
||||
sx.appendData(17.8, 4.5, 17.0, 18.0)
|
||||
#One can define error instead of min/max (appendData(x, y, error))
|
||||
sx2 = LinePlotErrorSeries("F4")
|
||||
px.addSeries(sx2)
|
||||
sx2.setLinesVisible(False)
|
||||
sx2.appendData(1.0, 3.0, 1.0)
|
||||
sx2.appendData(10.0, 5.1, 1.0)
|
||||
sx2.appendData(17.8, 7.5, 0.5)
|
||||
|
||||
#XY error plot
|
||||
pxy.setStyle(pxy.Style.ErrorXY)
|
||||
pxy.setLegendVisible(True)
|
||||
sxy = LinePlotErrorSeries("F5")
|
||||
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)
|
||||
#One can define error instead of min/max (appendData(x, y, errorX, errorY))
|
||||
sxy2 = LinePlotErrorSeries("F6")
|
||||
pxy.addSeries(sxy2)
|
||||
sxy2.appendData(3.0, 7.0, 0.5, 4.0);
|
||||
sxy2.appendData(13.0, 13.0, 0.5, 3.0);
|
||||
sxy2.appendData(24.0, 16.1, 0.2, 2.0);
|
||||
9
script/Fe.cfg
Executable file
9
script/Fe.cfg
Executable file
@@ -0,0 +1,9 @@
|
||||
690 695 1
|
||||
695 705 0.5
|
||||
705 712 0.1
|
||||
712 718 0.3
|
||||
718 725 0.2
|
||||
725 735 0.5
|
||||
735 740 1
|
||||
|
||||
|
||||
78
script/Fit HarmonicOff.py
Executable file
78
script/Fit HarmonicOff.py
Executable file
@@ -0,0 +1,78 @@
|
||||
###################################################################################################
|
||||
# Fitting with offset using least square optimization
|
||||
###################################################################################################
|
||||
|
||||
from mathutils import *
|
||||
from plotutils import *
|
||||
|
||||
###################################################################################################
|
||||
#Fitting the gaussian function with offset f(x) = a + b * exp(-(pow((x - c), 2) / (2 * pow(d, 2))))
|
||||
###################################################################################################
|
||||
|
||||
xdata=[-200.30429237268825, -200.2650700434188, -200.22115208318002, -199.9457671375377, -199.86345548879072, -199.85213073174933, -199.35687977133284, -199.13811861090275, -197.97304970346386, -197.2952215624348, -195.09076092936948, -192.92276048970703, -191.96871876227698, -189.49577852322938, -187.9652790409825, -183.63756456925222, -180.04899765472996, -178.43839623242422, -174.07311671294445, -172.0410133577918, -165.90824309893102, -160.99771795989466, -159.30176653939253, -154.27688897558514, -152.0854103810786, -145.75652847587313, -140.80843828908465, -139.23982133191495, -134.27073891256106, -132.12649284133064, -125.95947209775511, -121.00309550337462, -119.26736932643232, -114.2706655484383, -112.07393889578914, -105.72295990367157, -100.8088439880125, -99.2034906238494, -94.30042325164636, -92.15010048151461, -85.92203653534293, -81.03913275494665, -79.27412793784428, -74.33487658582118, -72.06274362408762, -65.76562628131825, -60.91255356825276, -59.20334389560392, -54.33286972659312, -52.19387171350535, -45.94978737932291, -41.03014719193582, -39.301602568238906, -34.35572209014114, -32.04464301272608, -25.8221033382824, -20.922074315528747, -19.21590299233186, -14.31090212502093, -12.217203140101386, -5.9283722049240435, -0.9863587170369246, 0.7408048387279834, 5.71126832601389, 7.972628957879352, 14.204559894256546, 19.11839959633025, 20.8218087836657, 25.678748486941828, 27.822718344586864, 34.062659474970715, 38.9745656819391, 40.77409719734158, 45.72080631619803, 47.974156754056835, 54.23453768983539, 59.12020360609568, 60.77306570712026, 65.70734521458867, 67.8344660434617, 74.03187028154134, 78.96532114824849, 80.76070945985495, 85.74802197591286, 87.9140889204674, 94.18082276873524, 99.25790470037091, 100.68454787413205, 105.7213026221542, 107.79483801526698, 113.99555681638138, 119.0707052529143, 120.72715813056156, 125.77551384921307, 127.91257836719551, 134.2011330887875, 139.23043006997628, 140.71673537840158, 145.76288138835983, 147.80216629676042, 154.06420451405637, 159.0846626604798, 160.76183155710717, 165.73699067536242, 167.9265357747636, 173.96705069576544, 178.2522282751915, 179.9042617354548, 183.54586165856657, 185.23269803071796, 189.41678143751972, 191.87149157986588, 192.8741468985015, 195.0241934550453, 195.966634211846, 197.9821647518146, 198.99006812859284, 199.33202054855676, 199.91897441965887, 200.11536227958896, 200.22280936469997, 200.25181179127208]
|
||||
ydata=[11.0, 6.0, 8.0, 5.0, 11.0, 7.0, 18.0, 11.0, 12.0, 10.0, 8.0, 6.0, 16.0, 4.0, 12.0, 9.0, 15.0, 14.0, 8.0, 20.0, 15.0, 8.0, 9.0, 11.0, 13.0, 12.0, 13.0, 15.0, 13.0, 20.0, 10.0, 7.0, 17.0, 11.0, 20.0, 13.0, 13.0, 23.0, 14.0, 10.0, 17.0, 15.0, 20.0, 16.0, 14.0, 13.0, 18.0, 22.0, 9.0, 20.0, 12.0, 14.0, 17.0, 19.0, 14.0, 14.0, 23.0, 19.0, 15.0, 20.0, 20.0, 21.0, 20.0, 23.0, 22.0, 15.0, 10.0, 17.0, 21.0, 15.0, 23.0, 23.0, 25.0, 18.0, 16.0, 21.0, 22.0, 16.0, 16.0, 14.0, 19.0, 20.0, 18.0, 20.0, 23.0, 13.0, 16.0, 20.0, 25.0, 15.0, 15.0, 17.0, 22.0, 26.0, 19.0, 30.0, 25.0, 17.0, 17.0, 23.0, 16.0, 27.0, 21.0, 21.0, 26.0, 27.0, 21.0, 17.0, 20.0, 20.0, 21.0, 19.0, 25.0, 19.0, 13.0, 23.0, 20.0, 20.0, 18.0, 20.0, 19.0, 25.0]
|
||||
|
||||
|
||||
#Calling wr
|
||||
|
||||
weigths = [ 1.0] * len(xdata)
|
||||
|
||||
p = plot(ydata, "Data" , xdata)[0]
|
||||
p.setLegendVisible(True)
|
||||
|
||||
guess = None
|
||||
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)
|
||||
"""
|
||||
num_samples = len(x)
|
||||
if start_point is None:
|
||||
#start_point = [0.0, (max(y)- min(y))/2, x[estimate_peak_indexes(y, x)[0]], 1.0]
|
||||
start_point = [0.0,] + GaussianCurveFitter.ParameterGuesser(create_fit_point_list(y, x, weights)).guess().tolist()
|
||||
class Model(MultivariateJacobianFunction):
|
||||
def value(self, variables):
|
||||
value = ArrayRealVector(num_samples)
|
||||
jacobian = Array2DRowRealMatrix(num_samples, 4)
|
||||
for i in range(num_samples):
|
||||
(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, weigths)
|
||||
return parameters
|
||||
|
||||
|
||||
(off, amp, com, sigma) = fit_gaussian_offset(ydata, xdata, None, weigths)
|
||||
print "off: ", off , " amp: ", amp, " com: ", com, " sigma: ", sigma
|
||||
f = Gaussian(amp, com, sigma)
|
||||
gauss = [f.value(i)+off for i in xdata]
|
||||
s = LinePlotSeries("Fit with offset")
|
||||
p.addSeries(s)
|
||||
s.setData(xdata, gauss)
|
||||
|
||||
|
||||
(amp, com, sigma) = fit_gaussian(ydata, xdata, None, weigths)
|
||||
print "amp: ", amp, " com: ", com, " sigma: ", sigma
|
||||
f = Gaussian(amp, com, sigma)
|
||||
gauss = [f.value(i) for i in xdata]
|
||||
s = LinePlotSeries("Normal Fit")
|
||||
p.addSeries(s)
|
||||
s.setData(xdata, gauss)
|
||||
|
||||
106
script/FitGaussianOffset.py
Executable file
106
script/FitGaussianOffset.py
Executable file
@@ -0,0 +1,106 @@
|
||||
###################################################################################################
|
||||
# Fitting with offset using least square optimization
|
||||
###################################################################################################
|
||||
|
||||
from mathutils import *
|
||||
from plotutils import *
|
||||
|
||||
###################################################################################################
|
||||
#Fitting the gaussian function with offset f(x) = a + b * exp(-(pow((x - c), 2) / (2 * pow(d, 2))))
|
||||
###################################################################################################
|
||||
|
||||
xdata=[-200.30429237268825, -200.2650700434188, -200.22115208318002, -199.9457671375377, -199.86345548879072, -199.85213073174933, -199.35687977133284, -199.13811861090275, -197.97304970346386, -197.2952215624348, -195.09076092936948, -192.92276048970703, -191.96871876227698, -189.49577852322938, -187.9652790409825, -183.63756456925222, -180.04899765472996, -178.43839623242422, -174.07311671294445, -172.0410133577918, -165.90824309893102, -160.99771795989466, -159.30176653939253, -154.27688897558514, -152.0854103810786, -145.75652847587313, -140.80843828908465, -139.23982133191495, -134.27073891256106, -132.12649284133064, -125.95947209775511, -121.00309550337462, -119.26736932643232, -114.2706655484383, -112.07393889578914, -105.72295990367157, -100.8088439880125, -99.2034906238494, -94.30042325164636, -92.15010048151461, -85.92203653534293, -81.03913275494665, -79.27412793784428, -74.33487658582118, -72.06274362408762, -65.76562628131825, -60.91255356825276, -59.20334389560392, -54.33286972659312, -52.19387171350535, -45.94978737932291, -41.03014719193582, -39.301602568238906, -34.35572209014114, -32.04464301272608, -25.8221033382824, -20.922074315528747, -19.21590299233186, -14.31090212502093, -12.217203140101386, -5.9283722049240435, -0.9863587170369246, 0.7408048387279834, 5.71126832601389, 7.972628957879352, 14.204559894256546, 19.11839959633025, 20.8218087836657, 25.678748486941828, 27.822718344586864, 34.062659474970715, 38.9745656819391, 40.77409719734158, 45.72080631619803, 47.974156754056835, 54.23453768983539, 59.12020360609568, 60.77306570712026, 65.70734521458867, 67.8344660434617, 74.03187028154134, 78.96532114824849, 80.76070945985495, 85.74802197591286, 87.9140889204674, 94.18082276873524, 99.25790470037091, 100.68454787413205, 105.7213026221542, 107.79483801526698, 113.99555681638138, 119.0707052529143, 120.72715813056156, 125.77551384921307, 127.91257836719551, 134.2011330887875, 139.23043006997628, 140.71673537840158, 145.76288138835983, 147.80216629676042, 154.06420451405637, 159.0846626604798, 160.76183155710717, 165.73699067536242, 167.9265357747636, 173.96705069576544, 178.2522282751915, 179.9042617354548, 183.54586165856657, 185.23269803071796, 189.41678143751972, 191.87149157986588, 192.8741468985015, 195.0241934550453, 195.966634211846, 197.9821647518146, 198.99006812859284, 199.33202054855676, 199.91897441965887, 200.11536227958896, 200.22280936469997, 200.25181179127208]
|
||||
ydata=[11.0, 6.0, 8.0, 5.0, 11.0, 7.0, 18.0, 11.0, 12.0, 10.0, 8.0, 6.0, 16.0, 4.0, 12.0, 9.0, 15.0, 14.0, 8.0, 20.0, 15.0, 8.0, 9.0, 11.0, 13.0, 12.0, 13.0, 15.0, 13.0, 20.0, 10.0, 7.0, 17.0, 11.0, 20.0, 13.0, 13.0, 23.0, 14.0, 10.0, 17.0, 15.0, 20.0, 16.0, 14.0, 13.0, 18.0, 22.0, 9.0, 20.0, 12.0, 14.0, 17.0, 19.0, 14.0, 14.0, 23.0, 19.0, 15.0, 20.0, 20.0, 21.0, 20.0, 23.0, 22.0, 15.0, 10.0, 17.0, 21.0, 15.0, 23.0, 23.0, 25.0, 18.0, 16.0, 21.0, 22.0, 16.0, 16.0, 14.0, 19.0, 20.0, 18.0, 20.0, 23.0, 13.0, 16.0, 20.0, 25.0, 15.0, 15.0, 17.0, 22.0, 26.0, 19.0, 30.0, 25.0, 17.0, 17.0, 23.0, 16.0, 27.0, 21.0, 21.0, 26.0, 27.0, 21.0, 17.0, 20.0, 20.0, 21.0, 19.0, 25.0, 19.0, 13.0, 23.0, 20.0, 20.0, 18.0, 20.0, 19.0, 25.0]
|
||||
#ydata = [t-8.0 for t in ydata]
|
||||
#xdata = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]
|
||||
#ydata = [24.0, 36.0, 66.0, 121.0, 474.0, 989.0, 357.0, 175.0, 50.0, 40.0, 30.0, 22.0]
|
||||
|
||||
#xdata = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
|
||||
#ydata = [36.0, 66.0, 121.0, 183.0, 263.0, 365.0, 473.0, 603.0, 753.0, 917.0]
|
||||
|
||||
weigths = [ 1.0] * len(xdata)
|
||||
|
||||
p = plot(ydata, "Data" , xdata)[0]
|
||||
p.setLegendVisible(True)
|
||||
|
||||
guess = None
|
||||
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]
|
||||
print "Start point", start_point
|
||||
|
||||
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, weigths)
|
||||
print evals, iters
|
||||
return parameters
|
||||
|
||||
(off, amp, com, sigma) = fit_gaussian_offset(ydata, xdata, None, weigths)
|
||||
print "\nFit with Offset:\noff: ", off , " amp: ", amp, " com: ", com, " sigma: ", sigma
|
||||
f = Gaussian(amp, com, sigma)
|
||||
gauss = [f.value(i)+off for i in xdata]
|
||||
s = LinePlotSeries("Fit with offset")
|
||||
p.addSeries(s)
|
||||
s.setData(xdata, gauss)
|
||||
e=0
|
||||
for i in range(len(ydata)) : e = e + abs(ydata[i]-gauss[i])
|
||||
print "E = ", e
|
||||
|
||||
(amp, com, sigma) = fit_gaussian(ydata, xdata, None, weigths)
|
||||
print "\nNormal Fit:\namp: ", amp, " com: ", com, " sigma: ", sigma
|
||||
f = Gaussian(amp, com, sigma)
|
||||
gauss = [f.value(i) for i in xdata]
|
||||
s = LinePlotSeries("Normal Fit")
|
||||
p.addSeries(s)
|
||||
s.setData(xdata, gauss)
|
||||
e=0
|
||||
for i in range(len(ydata)) : e = e + abs(ydata[i]-gauss[i])
|
||||
print "E = ", e
|
||||
|
||||
|
||||
|
||||
run("CPython/GaussFit_wrapper")
|
||||
[off, amp, com, sigma] = gfitoff(xdata, ydata, off=None, amp=None, com=None, sigma=None)
|
||||
print "\nCPython Fit:\n", off , " amp: ", amp, " com: ", com, " sigma: ", sigma
|
||||
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(xdata, gauss)
|
||||
e=0
|
||||
for i in range(len(ydata)) : e = e + abs(ydata[i]-gauss[i])
|
||||
print "E = ", e
|
||||
42
script/Fitting.py
Executable file
42
script/Fitting.py
Executable file
@@ -0,0 +1,42 @@
|
||||
# Function fitting and peak search with mathutils.py
|
||||
from mathutils import fit_polynomial,fit_gaussian, fit_harmonic, calculate_peaks
|
||||
from mathutils import PolynomialFunction, Gaussian, HarmonicOscillator
|
||||
import java.awt.Color as Color
|
||||
import math
|
||||
|
||||
start = 0
|
||||
end = 10
|
||||
step_size = 0.1
|
||||
result= lscan(ao1,ai1,start,end,[step_size,],0.01)
|
||||
|
||||
readable = result.getReadable(0)
|
||||
positions = result.getPositions(0)
|
||||
|
||||
def get_function_data(function, start, end, resolution):
|
||||
ret = []
|
||||
for x in frange(start, end, resolution, True):
|
||||
fit_polinomial.append(function.value(x))
|
||||
|
||||
pars_polynomial = (a0, a1, a2, a3, a4, a5, a6) = fit_polynomial(readable, positions, 6)
|
||||
fitted_polynomial_function = PolynomialFunction(pars_polynomial)
|
||||
print pars_polynomial
|
||||
(normalization, mean_val, sigma) = fit_gaussian(readable, positions)
|
||||
fitted_gaussian_function = Gaussian(normalization, mean_val, sigma)
|
||||
print (normalization, mean_val, sigma)
|
||||
(amplitude, angular_frequency, phase) = fit_harmonic(readable, positions)
|
||||
fitted_harmonic_function = HarmonicOscillator(amplitude, angular_frequency, phase)
|
||||
print (amplitude, angular_frequency, phase)
|
||||
resolution = step_size/100
|
||||
fit_polinomial = []
|
||||
fit_gaussian = []
|
||||
fit_harmonic = []
|
||||
for x in frange(start,end,resolution, True):
|
||||
fit_polinomial.append(fitted_polynomial_function.value(x))
|
||||
fit_gaussian.append(fitted_gaussian_function.value(x))
|
||||
fit_harmonic.append(fitted_harmonic_function.value(x))
|
||||
x = frange(start, end+resolution, resolution)
|
||||
peaks = calculate_peaks(fitted_polynomial_function, start, end)
|
||||
plots = plot([readable, fit_polinomial, fit_gaussian, fit_harmonic] ,
|
||||
["data", "polinomial", "gaussian", "harmonic"], xdata = [positions,x,x,x], title="Data")
|
||||
for p in peaks:
|
||||
print "Max: " + str(p)
|
||||
6
script/GaussFit_wrapper.py
Executable file
6
script/GaussFit_wrapper.py
Executable file
@@ -0,0 +1,6 @@
|
||||
from jeputils import *
|
||||
|
||||
|
||||
def profile_gauss_stats(x, y, off=None, amp=None, com=None, sigma=None):
|
||||
ret = call_jep("cpython/GaussFit", "profile_gauss_stats", [to_npa(x), to_npa(y), off, amp, com, sigma])
|
||||
return ret if ret is None or is_list(ret) else ret.data
|
||||
36
script/Gaussians.py
Executable file
36
script/Gaussians.py
Executable file
@@ -0,0 +1,36 @@
|
||||
###################################################################################################
|
||||
# Multiple Gaussians peak search with mathutils.py
|
||||
###################################################################################################
|
||||
|
||||
|
||||
from mathutils import estimate_peak_indexes, fit_gaussians, create_fit_point_list
|
||||
import java.awt.Color as Color
|
||||
|
||||
start = 0
|
||||
end = 50
|
||||
step_size = 0.2
|
||||
|
||||
result= lscan(ao1,ai1,start,end,[step_size,])
|
||||
|
||||
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]
|
||||
(normalization, mean_val, sigma) = gaussians[i]
|
||||
if abs(mean_val - positions[peak]) < min_peak_distance:
|
||||
print "Peak -> " + str(mean_val)
|
||||
plots[0].addMarker(mean_val, None, "N="+str(round(normalization,2)), Color(210,0,0))
|
||||
else:
|
||||
print "Invalid gaussian fit: " + str(mean_val)
|
||||
15
script/HoloScan.py
Executable file
15
script/HoloScan.py
Executable file
@@ -0,0 +1,15 @@
|
||||
"""
|
||||
Arguments:
|
||||
|
||||
SENSORS (list)
|
||||
PHI_RANGE (tuple (min, max))
|
||||
THETA_RANGE (tuple (min, max))
|
||||
STEPS (tuple (phi, theta))
|
||||
LATENCY (double)
|
||||
RELATIVE (BOOLEAN)
|
||||
"""
|
||||
|
||||
|
||||
#set_preference(Preference.ENABLED_PLOTS, [phi, theta, scienta.dataMatrix, integration])
|
||||
set_preference(Preference.PLOT_TYPES, {integration:1})
|
||||
ascan((motor, motor2), SENSORS, (PHI_RANGE[0], THETA_RANGE[0]), (PHI_RANGE[1], THETA_RANGE[1]), STEPS, LATENCY, RELATIVE, before_read=trig_scienta)
|
||||
157
script/HystScan.py
Executable file
157
script/HystScan.py
Executable file
@@ -0,0 +1,157 @@
|
||||
#Script imported from: Fe_hyst_plus.xml
|
||||
|
||||
#Parameters
|
||||
START_FIELD = -0.2
|
||||
END_FIELD = 0.2
|
||||
ENERGIES = (707.90, 703.90)
|
||||
RAMP_RATE = 2.0
|
||||
ENERGY_CHANGE_SLEEP = 0.5
|
||||
|
||||
#Pre-actions
|
||||
#cawait('ACOAU-ACCU:OP-MODE', 'Light Available', type = 's')
|
||||
#caput('X07MA-ID:MODE', 'CIRC +')
|
||||
sleep(1.0)
|
||||
#cawait('X07MA-ID:DONE', 'DONE', ype = 's')
|
||||
#caput('X07MA-ID:ENERGY-OFFS', '-1.0')
|
||||
#cawait('X07MA-ID:DONE', 'DONE', type = 's')
|
||||
caputq('X07MA-PC:CSCALER.INPB', '1')
|
||||
caputq('X07MA-PC-PS2:SET:DMD:RAMPRATE:TPM', RAMP_RATE)
|
||||
#sleep(15.0)
|
||||
|
||||
if len(ENERGIES) ==2:
|
||||
dif_series = plot([],"Dif", title="Dif")[0].getSeries(0)
|
||||
else:
|
||||
dif_series = None
|
||||
|
||||
set_preference(Preference.ENABLED_PLOTS, ['field', 'tey_norm', 'trans_norm'])
|
||||
set_preference(Preference.PLOT_TYPES, {'tey_norm':1, 'trans_norm':1})
|
||||
|
||||
#scan = ManualScan(['field', 'Energy'], ['TEY', 'I0', 'trans', 'polarization', 'polAngle', 'temperature', 'RingCurrent', 'fieldAnalogX', 'tey_norm','trans_norm'])
|
||||
scan = ManualScan(['field', 'Energy'], ['TEY', 'I0', 'trans', 'polarization', 'polAngle', 'temperature', 'RingCurrent', 'fieldAnalogX', 'tey_norm','trans_norm'], [0.0, ENERGIES[0]], [0.0, ENERGIES[-1]], [0, len(ENERGIES)-1])
|
||||
scan.start()
|
||||
|
||||
#Stop condition
|
||||
ramp_done = Channel('X07MA-PC-MAG:X:RAMP:DONE', type = 'i')
|
||||
|
||||
#Creating channels: dimension 1
|
||||
#RegionPositioner field
|
||||
#field = Channel('X07MA-PC:GO', type = 'd')
|
||||
fieldReadback = Channel('X07MA-PC-PS2:STS:PMCURRENT', type = 'd')
|
||||
#Creating channels: dimension 2
|
||||
#ArrayPositioner Energy
|
||||
Energy = sim_energy #Channel('X07MA-PHS-E:GO.A', type = 'd')
|
||||
EnergyReadback = sim_energy_readback # Channel('X07MA-PGM:CERBK', type = 'd')
|
||||
#ScalarDetector TEY
|
||||
TEY = Channel('X07MA-ES1-AI:SIGNAL0', type = 'd')
|
||||
#ScalarDetector I0
|
||||
I0 = Channel('X07MA-ES1-AI:SIGNAL1', type = 'd')
|
||||
#ScalarDetector trans
|
||||
trans = Channel('X07MA-ES1-AI:SIGNAL2', type = 'd')
|
||||
#ScalarDetector polarization
|
||||
#polarization = Channel('X07MA-ID:MODE', type = 'd')
|
||||
#ScalarDetector polAngle
|
||||
#polAngle = Channel('X07MA-ID:ALPHA', type = 'd')
|
||||
#ScalarDetector temperature
|
||||
temperature = Channel('X07MA-PC-TC:STS:T1', type = 'd')
|
||||
#ScalarDetector RingCurrent
|
||||
RingCurrent = Channel('ARIDI-PCT:CURRENT', type = 'd')
|
||||
#ScalarDetector fieldAnalogX
|
||||
fieldAnalogX = Channel('X07MA-ES1-AI:SIGNAL4', type = 'd')
|
||||
|
||||
|
||||
print "Waiting for start field"
|
||||
"""
|
||||
#WORKAROUND TO BUG IN DRIVER
|
||||
if abs(fieldReadback.get() - START_FIELD) < 0.005:
|
||||
caput('X07MA-PC-PS2:M:GO.A', START_FIELD + 0.01)
|
||||
caput('X07MA-PC-PS2:M:GO.A', START_FIELD)
|
||||
#caputq('X07MA-PC-PS2:M:GO.A', START_FIELD)
|
||||
"""
|
||||
|
||||
caput("X07MA-PC-MAG:X:DMD", START_FIELD)
|
||||
caput("X07MA-PC-MAG:STARTRAMP.PROC", 1)
|
||||
ramp_done.wait_for_value(1.0)
|
||||
print "Set end field"
|
||||
caput("X07MA-PC-MAG:X:DMD", END_FIELD)
|
||||
caputq("X07MA-PC-MAG:STARTRAMP.PROC", 1)
|
||||
|
||||
|
||||
index = 0
|
||||
while(True):
|
||||
#ArrayPositioner Energy
|
||||
for setpoint2 in ENERGIES:
|
||||
Energy.put(setpoint2, timeout=None) # TODO: Set appropriate timeout
|
||||
sleep( ENERGY_CHANGE_SLEEP ) # Settling time
|
||||
|
||||
readback2 = EnergyReadback.get()
|
||||
if abs(readback2 - setpoint2) > 0.1 : # TODO: Check accuracy
|
||||
raise Exception('Actor Energy could not be set to the value ' + str(setpoint2))
|
||||
|
||||
#Detector field readback
|
||||
field_readback = fieldReadback.get()
|
||||
|
||||
#Detector TEY
|
||||
detector1 = TEY.get()
|
||||
#Detector I0
|
||||
detector2 = I0.get()
|
||||
#Detector trans
|
||||
detector3 = trans.get()
|
||||
#Detector polarization
|
||||
detector4 = sim_energy_readback.read() # polarization.get()
|
||||
#Detector polAngle
|
||||
detector5 = sim_energy_readback.read() #polAngle.get()
|
||||
#Detector temperature
|
||||
detector6 = temperature.get()
|
||||
#Detector RingCurrent
|
||||
detector7 = RingCurrent.get()
|
||||
#Detector fieldAnalogX
|
||||
detector8 = fieldAnalogX.get()
|
||||
|
||||
|
||||
#Manipulation tey_norm
|
||||
#Variable Mappings
|
||||
|
||||
#TODO: Move, if needed, this import to the file header: import math
|
||||
tey_norm = detector1/detector2
|
||||
|
||||
#Manipulation trans_norm
|
||||
#Variable Mappings
|
||||
|
||||
#TODO: Move, if needed, this import to the file header: import math
|
||||
trans_norm = detector3/detector2
|
||||
|
||||
|
||||
if dif_series is not None:
|
||||
if setpoint2 == ENERGIES[0]:
|
||||
first = tey_norm
|
||||
else:
|
||||
dif = tey_norm-first
|
||||
dif_series.appendData(field_readback,dif)
|
||||
print [field_readback, setpoint2]
|
||||
print [field_readback, readback2]
|
||||
print [detector1, detector2, detector3, detector4, detector5, detector6, detector7, detector8, tey_norm, trans_norm]
|
||||
scan.append ([field_readback, setpoint2], [field_readback, readback2], [detector1, detector2, detector3, detector4, detector5, detector6, detector7, detector8, tey_norm, trans_norm])
|
||||
|
||||
|
||||
print "Field = " + str(fieldReadback.get())
|
||||
if ramp_done.get() == 1: #If not ramping
|
||||
print "Not ramping, breaking execution"
|
||||
break
|
||||
index = index+1
|
||||
|
||||
#Closing channels
|
||||
Energy.close()
|
||||
EnergyReadback.close()
|
||||
TEY.close()
|
||||
I0.close()
|
||||
trans.close()
|
||||
#polarization.close()
|
||||
#polAngle.close()
|
||||
temperature.close()
|
||||
RingCurrent.close()
|
||||
fieldAnalogX.close()
|
||||
#field.close()
|
||||
fieldReadback.close()
|
||||
ramp_done.close()
|
||||
|
||||
scan.end()
|
||||
50
script/HystScan2.py
Executable file
50
script/HystScan2.py
Executable file
@@ -0,0 +1,50 @@
|
||||
#Script imported from: Fe_hyst_plus.xml
|
||||
|
||||
#Parameters
|
||||
START_FIELD = -1.0
|
||||
END_FIELD = 1.0
|
||||
ENERGIES = (707.90, 703.90, 700.90)
|
||||
RAMP_RATE = 2.0
|
||||
|
||||
|
||||
if len(ENERGIES) ==2:
|
||||
dif_series = plot([],"Dif", title="Dif")[0].getSeries(0)
|
||||
else:
|
||||
dif_series = None
|
||||
|
||||
set_preference(Preference.ENABLED_PLOTS, ['field', 'tey_norm', 'trans_norm'])
|
||||
set_preference(Preference.PLOT_TYPES, {'tey_norm':1, 'trans_norm':1})
|
||||
|
||||
scan = ManualScan(['field', 'Energy'], ['tey_norm','trans_norm'], [0.0, ENERGIES[0]], [0.0, ENERGIES[-1]], [0, len(ENERGIES)-1])
|
||||
scan.start()
|
||||
|
||||
#Stop condition
|
||||
|
||||
|
||||
|
||||
index = 0
|
||||
while(True):
|
||||
#Dimension 2
|
||||
#ArrayPositioner Energy
|
||||
for setpoint2 in ENERGIES:
|
||||
out.write(setpoint2) # TODO: Set appropriate timeout
|
||||
readback2 = out.read()
|
||||
|
||||
tey_norm = sin.read()
|
||||
if dif_series is not None:
|
||||
if setpoint2 == ENERGIES[0]:
|
||||
first = tey_norm
|
||||
else:
|
||||
dif = tey_norm-first
|
||||
dif_series.appendData(index,dif)
|
||||
|
||||
scan.append ([index, setpoint2], [index, readback2], [tey_norm, sinp.read()])
|
||||
|
||||
|
||||
index = index+1
|
||||
if index >1000:
|
||||
break
|
||||
|
||||
|
||||
|
||||
scan.end()
|
||||
38
script/ImageStats.py
Executable file
38
script/ImageStats.py
Executable file
@@ -0,0 +1,38 @@
|
||||
from ijutils import *
|
||||
from mathutils import fit_gaussian
|
||||
from ch.psi.pshell.imaging.Overlays import *
|
||||
import ch.psi.pshell.imaging.Pen as Pen
|
||||
|
||||
|
||||
image = img
|
||||
image = tst
|
||||
|
||||
def wait_next():
|
||||
camera.waitNext(250)
|
||||
|
||||
def get_centroid():
|
||||
bi = image.getImage()
|
||||
op = show_panel(bi, "Original")
|
||||
if bi is None:
|
||||
return None
|
||||
ip = load_image(bi)
|
||||
grayscale(ip)
|
||||
invert(ip)
|
||||
gaussian_blur(ip)
|
||||
auto_threshold(ip)
|
||||
|
||||
#binary_erode(ip)
|
||||
show_panel(ip.getBufferedImage(), "Image")
|
||||
(results,output_img)=analyse_particles(ip, 1000,20000, print_table=True)
|
||||
op.clearOverlays()
|
||||
show_panel(output_img.getBufferedImage(), "Outlines")
|
||||
if results.size()>0:
|
||||
print results
|
||||
centroid = (results.getValue("XM",0), results.getValue("YM",0))
|
||||
ov = Crosshairs(Pen(java.awt.Color.ORANGE), java.awt.Point(int(centroid[0]),int(centroid[1])), java.awt.Dimension(15,15))
|
||||
op.addOverlay(ov)
|
||||
return centroid
|
||||
|
||||
|
||||
|
||||
get_centroid()
|
||||
4
script/InitialScan.py
Executable file
4
script/InitialScan.py
Executable file
@@ -0,0 +1,4 @@
|
||||
ret = lscan(out,inp,0,100,[1.0,],0.01)
|
||||
|
||||
|
||||
set_return (ret.getReadable(0).toArray())
|
||||
152
script/Inventory.py
Executable file
152
script/Inventory.py
Executable file
@@ -0,0 +1,152 @@
|
||||
import requests
|
||||
|
||||
def inventory_request(url, attributes):
|
||||
"""
|
||||
Thin wrapper for PSI Inventory system (I4). This wrapper does nothing
|
||||
more than sanitises output (decompresses dict) and takes care of dict
|
||||
to json conversion for attributes and json to dict conversion for
|
||||
response.
|
||||
|
||||
Use: https://inventory.psi.ch/#action=Introspection for details
|
||||
|
||||
|
||||
Example usage:
|
||||
|
||||
Query:
|
||||
|
||||
query = {"query": [
|
||||
{"Field": "Holy List Name", "Operator": "Is", "Value": holy_name},
|
||||
{"Field": 'Type', "Operator": "Is", "Value": type}
|
||||
|
||||
], "columns": ["Label"]}
|
||||
attr = {"search": query}
|
||||
|
||||
r = inventory_request('https://inventory.psi.ch/DataAccess.asmx/FindObjects', attr)
|
||||
|
||||
Fetch atributes for part:
|
||||
|
||||
attributes = inventory_request('https://inventory.psi.ch/DataAccess.asmx/GetPartAttributes', {'psiLabel': part_id})
|
||||
|
||||
|
||||
|
||||
|
||||
:param url: Inventory URL endpoint
|
||||
:param attributes: Python dict of attributes
|
||||
:return:
|
||||
"""
|
||||
r = requests.post(url, json=attributes)
|
||||
|
||||
if not r.ok:
|
||||
raise ConnectionError("Inventory returned error: ", r.json())
|
||||
|
||||
return r.json()['d']
|
||||
|
||||
|
||||
def find_partid_by_holy(holy_name, type="DSCR"):
|
||||
"""
|
||||
:param holy_name:
|
||||
:param type:
|
||||
:return: Returns first partId that matches holy_name and type
|
||||
"""
|
||||
query = {"query": [
|
||||
{"Field": "Holy List Name", "Operator": "Is", "Value": holy_name},
|
||||
{"Field": 'Type', "Operator": "Is", "Value": type}
|
||||
|
||||
], "columns": ["Label"]}
|
||||
attr = {"search": query}
|
||||
|
||||
r = inventory_request('https://inventory.psi.ch/DataAccess.asmx/FindObjects', attr)
|
||||
try:
|
||||
id = r['Rows'][0][0]
|
||||
except:
|
||||
return None
|
||||
|
||||
return id
|
||||
|
||||
|
||||
def find_all_by_type(type="DSCR", column = "Holy List Name"):
|
||||
"""
|
||||
:param type: Type to match
|
||||
:param column: Label, Holy List Name, ...
|
||||
:return: List
|
||||
"""
|
||||
|
||||
query = {"query": [
|
||||
{"Field": 'Type', "Operator": "Is", "Value": type}
|
||||
|
||||
], "columns": [column]}
|
||||
attr = {"search": query}
|
||||
|
||||
r = inventory_request('https://inventory.psi.ch/DataAccess.asmx/FindObjects', attr)
|
||||
|
||||
rows = []
|
||||
for i in r['Rows']:
|
||||
rows.append(i[0])
|
||||
|
||||
return rows
|
||||
|
||||
def get_part_attributes_from_inventory(part_label = None, holy_name = None):
|
||||
if holy_name:
|
||||
part_label = find_partid_by_holy(holy_name, "DSCR")
|
||||
if not part_label: raise RuntimeError("Could not find inventory part for >>{}<<".format(holy_name))
|
||||
|
||||
return inventory_request('https://inventory.psi.ch/DataAccess.asmx/GetPartAttributes', {'psiLabel': part_label})
|
||||
|
||||
def get_logbook_from_inventory(part_label = None, holy_name = None):
|
||||
import re
|
||||
attributes = get_part_attributes_from_inventory(part_label, holy_name)
|
||||
|
||||
elog_link = None
|
||||
for a in attributes:
|
||||
if a['Name'] == 'Elog':
|
||||
try:
|
||||
elog_link = a['Value']
|
||||
elog_link = re.findall('http(?:s|)://[^\s]*')
|
||||
if elog_link:
|
||||
elog_link = elog_link[0]
|
||||
else:
|
||||
elog_link = None
|
||||
|
||||
except TypeError:
|
||||
elog_link = None
|
||||
|
||||
return elog_link
|
||||
|
||||
def get_calib_from_invetory(part_label = None, holy_name = None):
|
||||
horizontal_dist = 0.0
|
||||
vertical_dist = 0.0
|
||||
horizontal_tilt = 0.0
|
||||
vertical_tilt = 0.0
|
||||
|
||||
attributes = get_part_attributes_from_inventory(part_label, holy_name)
|
||||
|
||||
for a in attributes:
|
||||
if a['Name'] == 'Crystal angle in x (e-beam system) [deg]':
|
||||
try:
|
||||
horizontal_tilt = float(a['Value'])
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
if a['Name'] == 'Crystal angle in y (e-beam system) [deg]':
|
||||
try:
|
||||
vertical_tilt = float(a['Value'])
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
if a['Name'] == 'Mark distance in x (e-beam system) [mm]':
|
||||
try:
|
||||
horizontal_dist = float(a['Value']) * 1e3
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
if a['Name'] == 'Mark distance in y (e-beam system) [mm]':
|
||||
try:
|
||||
vertical_dist = float(a['Value']) * 1e3
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
return horizontal_dist, vertical_dist, horizontal_tilt, vertical_tilt
|
||||
|
||||
|
||||
|
||||
print get_calib_from_invetory(None, "SINEG01-DSCR190")
|
||||
142
script/K_spacing_prototype.xml
Executable file
142
script/K_spacing_prototype.xml
Executable file
@@ -0,0 +1,142 @@
|
||||
<?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_Kspacing"/>
|
||||
<variable name="K" value="0.0" description="Buffer K spacing"/>
|
||||
<variable name="N_cycle" value="1.0" description="Number of Cycles "/>
|
||||
<scan>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MB-OP2:START-CSMPL" value="0" operation="put" type="String" delay="0.2"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MB-XMAP:StopAll" value="1" operation="put" type="String" delay="0.2"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MB-XMAP:CollectMode" value="0" operation="put" type="String" delay="0.2"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MB-XMAP:Apply" value="1" operation="put" type="String" delay="0.2"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MB-XMAP:PresetReal" value="0" operation="put" type="String" delay="0.2"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MB-OP2:TOTAL-CYCLES" value="5" operation="put" type="String" delay="0.2"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MB-ES1-PP2:VO5" value="0" operation="put" type="String" delay="0.2"/>
|
||||
<preAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MB-OP-WV1:WT_SET" value="1" operation="put" type="String" delay="0.2"/>
|
||||
<dimension zigzag="false" dataGroup="false">
|
||||
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="RegionPositioner" name="X07MB-ES1:userCalc4.L" settlingTime="0.1" id="Energy">
|
||||
<region>
|
||||
<start>3990.0</start>
|
||||
<end>3995.0</end>
|
||||
<stepSize>1.0</stepSize>
|
||||
</region>
|
||||
<region>
|
||||
<start>1.0</start>
|
||||
<end>14.0</end>
|
||||
<stepSize>1.0</stepSize>
|
||||
<function>
|
||||
<mapping xsi:type="VariableParameterMapping" name="K" variable="K_v"/>
|
||||
<script>def calculate(parameter):
|
||||
E_0 = 4040.
|
||||
h = 6.626e-34
|
||||
k = parameter*1e10
|
||||
K_v=k*1e-10
|
||||
m = 9.109e-31
|
||||
hk= (h/(2.*3.14159)) * k
|
||||
E_joule =hk * hk / (2.*m)
|
||||
E_eV = E_joule/1.6021e-19 + E_0
|
||||
return E_eV
|
||||
|
||||
</script>
|
||||
</function>
|
||||
</region>
|
||||
</positioner>
|
||||
<positioner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="RegionPositioner" name="X07MB-OP2:TOTAL-CYCLES" settlingTime="0.01" id="Cyles">
|
||||
<region>
|
||||
<start>3990.0</start>
|
||||
<end>3995.0</end>
|
||||
<stepSize>1.0</stepSize>
|
||||
<function>
|
||||
<script>def calculate(parameter):
|
||||
e_1=3990
|
||||
e_2=3993
|
||||
cycle=1
|
||||
delta=(parameter-e_1+cycle)/parameter*0.001
|
||||
return 1+delta</script>
|
||||
</function>
|
||||
</region>
|
||||
<region>
|
||||
<start>0.0</start>
|
||||
<end>10.0</end>
|
||||
<stepSize>1.0</stepSize>
|
||||
<function>
|
||||
<mapping xsi:type="VariableParameterMapping" name="N_cycle" variable="N_cycle"/>
|
||||
<script>def calculate(parameter):
|
||||
N_cycle.value=N_cycle.value*1.5
|
||||
cycles_aim=parameter+N_cycle.value
|
||||
This_cycle=min([cycles_aim,150.])
|
||||
return This_cycle
|
||||
|
||||
|
||||
</script>
|
||||
</function>
|
||||
</region>
|
||||
</positioner>
|
||||
<action xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MB-XMAP:EraseStart" value="1" operation="putq" type="String" delay="0.2"/>
|
||||
<action xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MB-OP2:SMPL" value="1" operation="put" type="String" delay="0.2"/>
|
||||
<action xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MB-OP2:SMPL-DONE" value="1" operation="wait" type="Integer" delay="0.2"/>
|
||||
<action xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MB-XMAP:StopAll" value="1" operation="put" type="String" delay="0.3"/>
|
||||
<guard>
|
||||
<condition channel="ACOAU-ACCU:OP-MODE" value="6" type="Integer"/>
|
||||
</guard>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-ES-MA1:ScanX.VAL" id="ScanX_set"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-ES-MA1:ScanY.VAL" id="ScanY_set"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-OP-MO:E-SET" id="Energy_set"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-OP-MO:BEAM-OFS" id="Mono_offset"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="ARIDI-PCT:CURRENT" id="I_SLS"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-OP2-SAI_07:MEAN" id="I0_KEITHLEY1"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-OP-KEITH1:setGain" id="KEITHLEY1_GAIN"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-OP2-SAI_08:MEAN" id="I1_KEITHLEY2"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-OP-KEITH2:setGain" id="KEITHLEY2_GAIN"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-OP2-SAI_06:MEAN" id="KEITHLEY3"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-OP-KEITH3:setGain" id="KEITHLEY3_GAIN"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-XMAP:mca1.R0" id="D1_OKa"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-XMAP:mca2.R0" id="D2_OKa"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-XMAP:mca3.R0" id="D3_OKa"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-XMAP:mca4.R0" id="D4_OKa"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-XMAP:dxp1:InputCountRate" id="D1_ICR"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-XMAP:dxp1:OutputCountRate" id="D1_OCR"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-XMAP:mca1.ELTM" id="DD1_ELTM"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-XMAP:mca1.ERTM" id="DD1_ERTM"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-XMAP:mca1.DTIM" id="DD1_DTIM"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-XMAP:dxp2:InputCountRate" id="D2_ICR"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-XMAP:dxp2:OutputCountRate" id="D2_OCR"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-XMAP:mca2.ELTM" id="DD2_ELTM"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-XMAP:mca2.ERTM" id="DD2_ERTM"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-XMAP:mca2.DTIM" id="DD2_DTIM"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-XMAP:dxp3:InputCountRate" id="D3_ICR"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-XMAP:dxp3:OutputCountRate" id="D3_OCR"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-XMAP:mca3.ELTM" id="DD3_ELTM"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-XMAP:mca3.ERTM" id="DD3_ERTM"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-XMAP:mca3.DTIM" id="DD3_DTIM"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-XMAP:dxp4:InputCountRate" id="D4_ICR"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-XMAP:dxp4:OutputCountRate" id="D4_OCR"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-XMAP:mca4.ELTM" id="DD4_ELTM"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-XMAP:mca4.ERTM" id="DD4_ERTM"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" type="Double" name="X07MB-XMAP:mca4.DTIM" id="DD4_DTIM"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ArrayDetector" arraySize="2048" name="X07MB-XMAP:mca1.VAL" id="Spec_1"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ArrayDetector" arraySize="2048" name="X07MB-XMAP:mca2.VAL" id="Spec_2"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ArrayDetector" arraySize="2048" name="X07MB-XMAP:mca3.VAL" id="Spec_3"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ArrayDetector" arraySize="2048" name="X07MB-XMAP:mca4.VAL" id="Spec_4"/>
|
||||
</dimension>
|
||||
<postAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ChannelAction" channel="X07MB-OP2:START-CSMPL" value="1" operation="put" type="String" delay="0.1"/>
|
||||
<manipulation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScriptManipulation" id="K_calc">
|
||||
<mapping xsi:type="VariableParameterMapping" name="K" variable="K"/>
|
||||
<script>def process(K):
|
||||
return K
|
||||
|
||||
</script>
|
||||
</manipulation>
|
||||
</scan>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="Energy" y="D1_ICR D2_ICR D3_ICR D4_ICR" title="ICR "/>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="Energy" y="D1_OCR D2_OCR D3_OCR D4_OCR" title="OCR "/>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="Energy" y="D1_OKa" title="D1_OKa"/>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="Energy" y="D2_OKa" title="D2_OKa"/>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="Energy" y="D3_OKa" title="D3_OKa"/>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="Energy" y="D4_OKa" title="D4_OKa"/>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="Energy" y="I0_KEITHLEY1" title="KEITHLEY1 (I0)=f(Energy)"/>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="Energy" y="I1_KEITHLEY2" title="KEITHLEY2 (I1)=f(Energy)"/>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="Energy" y="KEITHLEY3" title="KEITHLEY3=f(Energy)"/>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="Energy" y="Cyles" title=" cycles vs energy "/>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="Energy" y="K_calc" title=" K= f(energy)"/>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="K_calc" y="Energy" title=" E=f(k)"/>
|
||||
</configuration>
|
||||
134
script/Laser_gun_alignment.py
Executable file
134
script/Laser_gun_alignment.py
Executable file
@@ -0,0 +1,134 @@
|
||||
# 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"
|
||||
|
||||
|
||||
def laser_on():
|
||||
print "Laser On"
|
||||
|
||||
def laser_off():
|
||||
print "Laser Off"
|
||||
|
||||
def is_laser_on():
|
||||
return False
|
||||
|
||||
def switch_off_magnets(magnets = None):
|
||||
print "switch_off_magnets"
|
||||
|
||||
|
||||
|
||||
gun_phase = cv
|
||||
|
||||
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
phi1= 95.0
|
||||
phi2 = 100.0
|
||||
dphi = 0.5
|
||||
settling_time = 0.5
|
||||
plot_image = False
|
||||
number_images = 5
|
||||
use_background = False
|
||||
multiple_background = False
|
||||
number_backgrounds = 5
|
||||
do_elog = False
|
||||
centroid_excursion_plot = True
|
||||
else:
|
||||
centroid_excursion_plot = False
|
||||
|
||||
#check_camtool()
|
||||
|
||||
laser_was_on = is_laser_on()
|
||||
original_phase = gun_phase.read()
|
||||
multiple_background = multiple_background and use_background
|
||||
print "Parameters: ", phi1, phi2, dphi, 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 (camtool.getCurrentCamera() != camera_name) or (camtool.getPipelinePars()["background_subtration"] != use_background):
|
||||
camtool.start(camera_name, None, use_background, None, None, None)
|
||||
setBackgroundSubtraction
|
||||
if use_background:
|
||||
laser_off()
|
||||
if not multiple_background:
|
||||
camtool.grabBackground(None, number_backgrounds)
|
||||
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 multiple_background:
|
||||
camtool.grabBackground(None, number_backgrounds)
|
||||
laser_on()
|
||||
if mode != "camtool":
|
||||
image_stats.update()
|
||||
|
||||
|
||||
def after_sample():
|
||||
if multiple_background:
|
||||
laser_off()
|
||||
|
||||
r = None
|
||||
if not multiple_background:
|
||||
laser_on()
|
||||
|
||||
try:
|
||||
if mode != "camtool":
|
||||
sensors = [image_stats.com_x_mean, image_stats.com_y_mean, image_stats.com_x_stdev, image_stats.com_y_stdev]
|
||||
else:
|
||||
sensors = [CamtoolValue("gr_x_fit_mean"), CamtoolValue("gr_y_fit_mean"), CamtoolValue("gr_x_fit_standard_deviation"), CamtoolValue("gr_y_fit_standard_deviation")]
|
||||
if plot_image and (mode == "camtool"):
|
||||
sensors.append(CamtoolImage())
|
||||
r = lscan(gun_phase, sensors , phi1, phi2, dphi, settling_time, before_read = before_sample, after_read = after_sample)
|
||||
#tscan(sensors, 10, 1.0, before_read = before_sample, after_read = after_sample)
|
||||
finally:
|
||||
pass
|
||||
|
||||
gun_phase.write(original_phase)
|
||||
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) + " Background: enabled=" + str(use_background) + " multiple=" + str(multiple_background) + " number=" + str(number_backgrounds)
|
||||
gsa_log_msg = gsa_log_msg + "\nPhase range: " + str(phi1) + " to " + str(phi2)
|
||||
gsa_log_msg = gsa_log_msg + "\nLaser position on cathod: " + str(caget("SLG-LCAM-C103:FIT-XPOS")) + "/" + str(caget("SLG-LCAM-C103:FIT-YPOS"))
|
||||
gsa_log_msg = gsa_log_msg + "\n\n" + r.print()
|
||||
if do_elog:
|
||||
elog("Laser alignment with phase scan", gsa_log_msg , get_plot_snapshots())
|
||||
"""
|
||||
set_return([r, hx, hy])
|
||||
|
||||
|
||||
|
||||
|
||||
13
script/ManipulatorScan.py
Executable file
13
script/ManipulatorScan.py
Executable file
@@ -0,0 +1,13 @@
|
||||
"""
|
||||
Arguments:
|
||||
|
||||
MOTOR (device)
|
||||
SENSORS (list)
|
||||
RANGE (tuple (min, max))
|
||||
STEPS (int or tuple)
|
||||
LATENCY (double)
|
||||
RELATIVE (BOOLEAN)
|
||||
"""
|
||||
|
||||
set_preference(Preference.PLOT_TYPES,{'integration':1});
|
||||
lscan(MOTOR, SENSORS, RANGE[0], RANGE[1], STEPS, LATENCY, RELATIVE, before_read=trig_scienta)
|
||||
15
script/Metadata.py
Executable file
15
script/Metadata.py
Executable file
@@ -0,0 +1,15 @@
|
||||
###################################################################################################
|
||||
# Demonstrate adding attributs to scan groups and datasets.
|
||||
###################################################################################################
|
||||
|
||||
|
||||
#Execute the scan: 200 steps, a1 from 0 to 40
|
||||
a= lscan(ao1, (ai1,ai2), 0, 40, 10, 0.01)
|
||||
|
||||
|
||||
#Setting attributes to the scan group
|
||||
path = get_exec_pars().scanPath
|
||||
set_attribute(path, "User", "Mr. Black")
|
||||
set_attribute(path, "Temperature", 38.0)
|
||||
set_attribute(path, "Test Mode", True)
|
||||
|
||||
18
script/MonitorScan.py
Executable file
18
script/MonitorScan.py
Executable file
@@ -0,0 +1,18 @@
|
||||
###################################################################################################
|
||||
# Demonstrate the use of Monitor Scan: sampling based on device change event
|
||||
###################################################################################################
|
||||
|
||||
set_device_alias(sc1, None)
|
||||
setup_plotting( line_plots =[sc1] )
|
||||
|
||||
|
||||
#Execute the scan: 50 samples
|
||||
r1 = mscan(sc1, [sc1], 50)
|
||||
|
||||
#Execute the scan: 50 samples, with a timeout of 2s, including a second device
|
||||
r2 = mscan(sc1, [sc1, sin], 50, 2.0)
|
||||
|
||||
#Execute the scan: sampling for 5s, an undefined number of sample
|
||||
#The second device is cached so the scan is entirely asynchronous (the trigger device is always cached).
|
||||
r3 = mscan(sc1, [sc1, sin.cache], -1, 5.0)
|
||||
|
||||
13
script/MultiPassAndZigzag.py
Executable file
13
script/MultiPassAndZigzag.py
Executable file
@@ -0,0 +1,13 @@
|
||||
###################################################################################################
|
||||
# Multi-pass and zigzag scans
|
||||
###################################################################################################
|
||||
|
||||
|
||||
#Linear with 2 passes
|
||||
a= lscan(m1, (ai1,wf1), -0.2, 0.2, 10, relative = True, passes = 4)
|
||||
|
||||
#Linear with 4 passes and zigzag
|
||||
a= lscan(m1, (ai1,wf1), -0.2, 0.2, 10, relative = True, passes = 4, zigzag = True)
|
||||
|
||||
#Multi-dimentional zigzag
|
||||
a = ascan ([m1,m2], ai1, [0,0], [1, 1], [0.25,0.25], latency=0.001, zigzag=True)
|
||||
64
script/MultiplePlot.py
Executable file
64
script/MultiplePlot.py
Executable file
@@ -0,0 +1,64 @@
|
||||
import random
|
||||
|
||||
|
||||
def clear_plot():
|
||||
title = "test"
|
||||
plots = get_plots(title = title)
|
||||
if len(plots)>0:
|
||||
plots[0].clear()
|
||||
|
||||
|
||||
def add_plot(x,y, name=None, clear = False):
|
||||
title = "test"
|
||||
plots = get_plots(title = title)
|
||||
p = None
|
||||
if len(plots)==0:
|
||||
p = plot(None,name=name, title = title)[0]
|
||||
p.getAxis(p.AxisId.X).setRange(-50,150)
|
||||
p.getAxis(p.AxisId.Y).setRange(-50,150)
|
||||
p.setLegendVisible(True)
|
||||
else:
|
||||
p = plots[0]
|
||||
if clear:
|
||||
p.clear()
|
||||
p.addSeries(LinePlotSeries(name))
|
||||
s = p.getSeries(name)
|
||||
s.setLinesVisible(False)
|
||||
s.setPointSize(3)
|
||||
s.setData(x, y)
|
||||
|
||||
#In the first time the plot shows, it takes some time for the color to be assigned
|
||||
while s.color is None:
|
||||
time.sleep(0.001)
|
||||
|
||||
hull = LinePlotSeries(name + " Hull", s.color)
|
||||
|
||||
"""
|
||||
#Bounding box
|
||||
x1,x2,y1,y2 = min(x), max(x), min(y), max(y)
|
||||
(hx,hy) = ([x1,x2, x2, x1, x1], [y1, y1, y2, y2, y1])
|
||||
"""
|
||||
|
||||
#Convex Hull
|
||||
(hx,hy) = convex_hull(x=x, y=y)
|
||||
hx.append(hx[0])
|
||||
hy.append(hy[0])
|
||||
|
||||
p.addSeries(hull)
|
||||
hull.setLineWidth(2)
|
||||
hull.setData(hx,hy)
|
||||
hull.setColor(s.color)
|
||||
|
||||
|
||||
|
||||
clear_plot()
|
||||
|
||||
x=[]
|
||||
y=[]
|
||||
for step in range(1,5):
|
||||
x=[]
|
||||
y=[]
|
||||
for i in range(20):
|
||||
x.append(random.random() * 100 / step)
|
||||
y.append(random.random() * 100/ step)
|
||||
add_plot (x,y,"Step " + str(step))
|
||||
38
script/PhotonEnergy.py
Executable file
38
script/PhotonEnergy.py
Executable file
@@ -0,0 +1,38 @@
|
||||
"""
|
||||
Arguments:
|
||||
|
||||
VECTOR (Double[][], Scan vector: Eph,Elow,Ehigh or Eph,Ecenter)
|
||||
SENSORS (list)
|
||||
LATENCY (double)
|
||||
MODE ('fixed' or 'swept')
|
||||
TYPE ('CIS' or 'CFS')
|
||||
STEP (double)
|
||||
"""
|
||||
EnergyDistribution = scienta.getSpectrum()
|
||||
AngleDistribution = scienta.getSpectrum()
|
||||
Scienta = scienta
|
||||
Eph = out
|
||||
if MODE == "swept":
|
||||
Scienta.setAcquisitionMode(ch.psi.pshell.epics.Scienta.AcquisitionMode.Swept)
|
||||
else:
|
||||
Scienta.setAcquisitionMode(ch.psi.pshell.epics.Scienta.AcquisitionMode.Fixed)
|
||||
|
||||
if len(VECTOR[0]) == 2:
|
||||
#FIXED
|
||||
Scienta.centerEnergy.write(VECTOR[0][1])
|
||||
writables = (Eph, Scienta.centerEnergy)
|
||||
else:
|
||||
#SWEPT
|
||||
Scienta.lowEnergy.write(VECTOR[0][1])
|
||||
Scienta.highEnergy.write(VECTOR[0][2])
|
||||
writables = (Eph, Scienta.lowEnergy, Scienta.highEnergy)
|
||||
|
||||
#adjust_sensors()
|
||||
#set_adc_averaging()
|
||||
#set_preference(Preference.PLOT_TYPES, {'Scienta spectrum':1})
|
||||
|
||||
try:
|
||||
vscan(writables, SENSORS, VECTOR, True, LATENCY,False)
|
||||
finally:
|
||||
if ENDSCAN:
|
||||
after_scan()
|
||||
20
script/Plot Styles.py
Executable file
20
script/Plot Styles.py
Executable file
@@ -0,0 +1,20 @@
|
||||
###################################################################################################
|
||||
# Example changing plot styles
|
||||
###################################################################################################
|
||||
|
||||
|
||||
#Logarithmic scales
|
||||
p = plot([10,500,1000,5000,1000], xdata = [0.1,1,10,100,1000, 10000])[0]
|
||||
p.getAxis(p.AxisId.X).logarithmic = True
|
||||
p.getAxis(p.AxisId.Y).setRange(1, 100000)
|
||||
p.getAxis(p.AxisId.Y).logarithmic = True
|
||||
|
||||
|
||||
#plot styles
|
||||
data = [0,3,5,1,3,5,3,4,3,2,1,0]
|
||||
[p1, p2, p3] = plot([data, data, data], ["normal", "step", "spline"])
|
||||
p2.setStyle(p1.Style.Step)
|
||||
p3.setStyle(p1.Style.Spline)
|
||||
|
||||
|
||||
|
||||
22
script/Plotting.py
Executable file
22
script/Plotting.py
Executable file
@@ -0,0 +1,22 @@
|
||||
###################################################################################################
|
||||
# Direct creation of plots
|
||||
###################################################################################################
|
||||
|
||||
data_1d = [10.0, 20.0, 30.0, 40.0, 50.0]
|
||||
data_2d = [ data_1d, data_1d, data_1d, data_1d, data_1d]
|
||||
data_3d = [ data_2d, data_2d , data_2d, data_2d, data_2d]
|
||||
data_x = [1.0, 2.0, 3.0, 4.0, 5.0]
|
||||
data_y = [2.0, 4.0, 6.0, 8.0, 10.0]
|
||||
|
||||
#1d-plot with optional xdata
|
||||
plot(data_1d, title = "1d", xdata = data_x)
|
||||
|
||||
#2d-plot with optional xdata and ydata
|
||||
plot(data_2d, title = "2d", xdata = data_x, ydata = data_y)
|
||||
|
||||
#3d-plot
|
||||
plot(data_3d, title = "3d")
|
||||
|
||||
#3 plots in the save panel
|
||||
plot([data_1d, data_2d, data_3d], ["1d", "2d", "3d"])
|
||||
|
||||
25
script/PseudoDevices.py
Executable file
25
script/PseudoDevices.py
Executable file
@@ -0,0 +1,25 @@
|
||||
###################################################################################################
|
||||
# Using pseudo-device to :
|
||||
# - Add calculations to scan data.
|
||||
# - Execute logic during scan
|
||||
###################################################################################################
|
||||
|
||||
|
||||
class Clock(Readable):
|
||||
def read(self):
|
||||
return time.clock()
|
||||
|
||||
class Average(Readable):
|
||||
def read(self):
|
||||
arr = wf1.take() #Gets the CACHED waveform
|
||||
return reduce(lambda x, y: x + y, arr) / len(arr)
|
||||
|
||||
class PseudoPositioner(Writable):
|
||||
def write(self,pos):
|
||||
print "Step = " + str(pos)
|
||||
|
||||
clock=Clock()
|
||||
av=Average()
|
||||
positioner=PseudoPositioner()
|
||||
setup_plotting(plot_list = [av,clock])
|
||||
a= lscan((ao1,positioner),(wf1, ai2,av,clock),(0,0),(40,20),20,0.1)
|
||||
18
script/RecordInvalidation.py
Executable file
18
script/RecordInvalidation.py
Executable file
@@ -0,0 +1,18 @@
|
||||
###################################################################################################
|
||||
#Resampling a scan record if no beam
|
||||
###################################################################################################
|
||||
|
||||
|
||||
index=0
|
||||
|
||||
|
||||
def before_sampling(rec):
|
||||
while beam_ok.read() == "No":
|
||||
time.sleep(0.1)
|
||||
|
||||
def after_sampling(rec):
|
||||
if beam_ok.read() == "No":
|
||||
rec.invalidate()
|
||||
|
||||
|
||||
a= lscan((m1), (ai1,ai2), (0,), (0.4,), 20, 0.2, before_read=before_sampling, after_read=after_sampling)
|
||||
16
script/ScanDataManipulation.py
Executable file
16
script/ScanDataManipulation.py
Executable file
@@ -0,0 +1,16 @@
|
||||
###################################################################################################
|
||||
# Processing and plotting scan data.
|
||||
###################################################################################################
|
||||
|
||||
|
||||
ao1.write(0.0)
|
||||
scan1= lscan(ao1, (ai1,ai2,wf1), 0, 40, 40, 0.01, False, title="Scan 1")
|
||||
scan2= lscan(ao1, (ai1,ai2,wf1), 0, 40, 40, 0.01, False, title="Scan 2")
|
||||
|
||||
|
||||
from operator import add
|
||||
result = map(add, scan1.getReadable(0), scan2.getReadable(0))
|
||||
|
||||
plot(result)
|
||||
print result
|
||||
|
||||
28
script/ScanTypes.py
Executable file
28
script/ScanTypes.py
Executable file
@@ -0,0 +1,28 @@
|
||||
#Line scan
|
||||
r1 = lscan(ao1, (ai1,wf1), 0, 40, 100, 0.01)
|
||||
|
||||
#Time scan
|
||||
r = tscan((m1,wf1), 100, 0.01)
|
||||
|
||||
#Area scan
|
||||
r = ascan((m1,m2), (ai1,wf1), (0.0,0.0), (1.0,0.5), (5,8))
|
||||
|
||||
#1D-vector scan
|
||||
vector = [ 1, 3, 5, 10, 25, 40, 45, 47, 49]
|
||||
r = vscan(ao1,(ai1,ai2),vector,False, 0.5, title = "1D Vector")
|
||||
|
||||
#2D-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] ]
|
||||
r = vscan((m1,m2),(ai1,ai2),vector,False, 0.01, title = "2D Vector")
|
||||
|
||||
#Region scan
|
||||
r = rscan(ao1, (ai1,ai2), [(0,5,5), (10,15,20), (20,25,5)] , 0.1)
|
||||
|
||||
#Continuous scan
|
||||
r = cscan(m1, (ai1,ai2), -2, 3 , steps=10, relative=True)
|
||||
|
||||
#And also hardware scan (hscan)...
|
||||
189
script/SimulatedDevices.groovy
Executable file
189
script/SimulatedDevices.groovy
Executable file
@@ -0,0 +1,189 @@
|
||||
import random
|
||||
|
||||
####################################################################################################
|
||||
# Simulated Devices
|
||||
####################################################################################################
|
||||
|
||||
class AnalogOutput(RegisterBase):
|
||||
def doRead(self):
|
||||
return self.val if hasattr(self, 'val') else 0.0
|
||||
|
||||
def doWrite(self, val):
|
||||
self.val = val
|
||||
|
||||
class AnalogInput(ReadonlyRegisterBase):
|
||||
def doRead(self):
|
||||
time.sleep(0.001)
|
||||
self.val = to_array(self.calc(), 'd')
|
||||
return self.val
|
||||
|
||||
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 Random(AnalogInput):
|
||||
def calc(self):
|
||||
return random.random()
|
||||
|
||||
|
||||
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 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
|
||||
|
||||
|
||||
#Defintion
|
||||
add_device(DummyMotor("m1"), True)
|
||||
add_device(DummyMotor("m2"), True)
|
||||
add_device(DummyRegister("reg1",3), True)
|
||||
add_device(AnalogOutput("ao1"), True)
|
||||
add_device(AnalogOutput("ao2"), True)
|
||||
add_device(SinusoidSample("ai1"), True)
|
||||
add_device(SinusoidTime("ai2"), True)
|
||||
add_device(Random("ai3"), True)
|
||||
add_device(SinusoidWaveform("wf1"), True)
|
||||
add_device(SinusoidImage("im1"), True)
|
||||
add_device(DummyPositioner("p1"),True)
|
||||
add_device(MotorGroupBase("mg1", m1, m2), True)
|
||||
add_device(MotorGroupDiscretePositioner("dp1", mg1), True)
|
||||
|
||||
|
||||
|
||||
#Initial Configuration
|
||||
if p1.config.unit is None:
|
||||
p1.config.minValue = 0.0 #Not persisted
|
||||
p1.config.maxValue = 1000.0
|
||||
p1.config.unit = "mm"
|
||||
p1.config.save()
|
||||
p1.initialize()
|
||||
|
||||
if dp1.config.positions is None:
|
||||
dp1.config.positions = ["Park","Ready","Out","Clear"]
|
||||
dp1.config.motor1 = ["0.0","4.0","8.0" ,"0.0"]
|
||||
dp1.config.motor2 = ["0.0","5.0","3.0" ,"NaN"]
|
||||
dp1.config.save()
|
||||
dp1.initialize()
|
||||
|
||||
|
||||
|
||||
#Update
|
||||
m1.setMonitored(True)
|
||||
m2.setMonitored(True)
|
||||
|
||||
|
||||
|
||||
|
||||
####################################################################################################
|
||||
# Simple Readable / Writable objects can be created and used in scans
|
||||
####################################################################################################
|
||||
class WritableScalar(Writable):
|
||||
def write(self, value):
|
||||
pass
|
||||
|
||||
class ReadableScalar(Readable):
|
||||
def read(self):
|
||||
return random.random()
|
||||
|
||||
|
||||
class ReadableWaveform(ReadableArray):
|
||||
def getSize(self):
|
||||
return 20
|
||||
|
||||
def read(self):
|
||||
ret = []
|
||||
for i in range (self.getSize()):
|
||||
ret.append(random.random())
|
||||
return ret
|
||||
|
||||
class ReadableImage(ReadableMatrix):
|
||||
def read(self):
|
||||
ret = []
|
||||
for i in range (self.getHeight()):
|
||||
ret.append([random.random()] * self.getWidth())
|
||||
return to_array(ret, 'd')
|
||||
|
||||
def getWidth(self):
|
||||
return 80
|
||||
|
||||
def getHeight(self):
|
||||
return 40
|
||||
|
||||
|
||||
|
||||
ws1 = WritableScalar()
|
||||
rs1 = ReadableScalar()
|
||||
rw1 = ReadableWaveform()
|
||||
ri1 = ReadableImage()
|
||||
|
||||
|
||||
####################################################################################################
|
||||
# Imaging
|
||||
####################################################################################################
|
||||
|
||||
configured = os.path.exists(Device.getConfigFileName("src1"))
|
||||
|
||||
add_device(RegisterMatrixSource("src1", im1), True)
|
||||
add_device(RegisterMatrixSource("src2", ri1), True)
|
||||
|
||||
src1.polling = 100
|
||||
src2.polling = 100
|
||||
|
||||
#Some configuration for so the imaging will work out of the box
|
||||
if not configured:
|
||||
import ch.psi.pshell.imaging.Colormap
|
||||
src1.config.colormapAutomatic = True
|
||||
src1.config.colormap = ch.psi.pshell.imaging.Colormap.Temperature
|
||||
src1.config.save()
|
||||
src2.config.colormapAutomatic = True
|
||||
src2.config.save()
|
||||
|
||||
|
||||
252
script/SimulatedDevices.js
Executable file
252
script/SimulatedDevices.js
Executable file
@@ -0,0 +1,252 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Simulated Devices
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var AnalogOutput = Java.extend(RegisterBase)
|
||||
var dev = new AnalogOutput("ao1") {
|
||||
i:double = 0.0,
|
||||
doRead: function () {
|
||||
return this.i
|
||||
},
|
||||
doWrite: function (value) {
|
||||
this.i=value
|
||||
},
|
||||
}
|
||||
add_device(dev, true)
|
||||
|
||||
|
||||
var AnalogOutput = Java.extend(RegisterBase)
|
||||
var dev = new AnalogOutput("ao2") {
|
||||
i:double = 0.0,
|
||||
doRead: function () {
|
||||
return this.i
|
||||
},
|
||||
doWrite: function (value) {
|
||||
this.i=value
|
||||
},
|
||||
}
|
||||
add_device(dev, true)
|
||||
|
||||
var SinusoidSample = Java.extend(ReadonlyRegisterBase)
|
||||
var dev = new SinusoidSample("ai1") {
|
||||
x:double = 0.0,
|
||||
doRead: function () {
|
||||
sleep(0.001)
|
||||
this.x += 0.1
|
||||
var noise = (Math.random() - 0.5) / 10.0
|
||||
return Math.sin(this.x) + noise
|
||||
},
|
||||
}
|
||||
add_device(dev, true)
|
||||
|
||||
|
||||
var SinusoidTime = Java.extend(ReadonlyRegisterBase)
|
||||
var dev = new SinusoidTime("ai2") {
|
||||
doRead: function () {
|
||||
sleep(0.001)
|
||||
var noise = (Math.random() - 0.5) / 10.0
|
||||
return Math.sin(Date.now()) + noise
|
||||
},
|
||||
}
|
||||
add_device(dev, true)
|
||||
|
||||
|
||||
var Random = Java.extend(ReadonlyRegisterBase)
|
||||
var dev = new Random("ai3") {
|
||||
doRead: function () {
|
||||
sleep(0.001)
|
||||
return Math.random()
|
||||
},
|
||||
}
|
||||
|
||||
add_device(dev, true)
|
||||
|
||||
|
||||
|
||||
|
||||
var SinusoidWaveform = Java.extend(ReadonlyRegisterBase, ReadonlyRegisterArray)
|
||||
var dev = new SinusoidWaveform("wf1") {
|
||||
doRead: function () {
|
||||
sleep(0.001)
|
||||
var ret = []
|
||||
var x = Math.random()
|
||||
for (var i = 0; i < 20; i++) {
|
||||
ret.push(Math.sin(x))
|
||||
x = x + 0.1
|
||||
}
|
||||
return to_array(ret, 'd')
|
||||
},
|
||||
|
||||
getSize: function () {
|
||||
//return wf1.take(-1).length
|
||||
return SinusoidWaveformSuper.take(-1).length
|
||||
},
|
||||
|
||||
}
|
||||
var SinusoidWaveformSuper = Java.super(dev)
|
||||
add_device(dev, true)
|
||||
|
||||
|
||||
var SinusoidImage = Java.extend(ReadonlyRegisterBase, ReadonlyRegisterMatrix)
|
||||
var dev = new SinusoidImage("im1") {
|
||||
doRead: function () {
|
||||
sleep(0.001)
|
||||
var ret = []
|
||||
var width = 200
|
||||
var height = 100
|
||||
var x = Math.random()
|
||||
var base = []
|
||||
for (var i = 0; i < width ; i++) {
|
||||
base.push(Math.sin(x))
|
||||
x = x + 0.05
|
||||
}
|
||||
for (var i = 0; i < height ; i++) {
|
||||
var noise = (Math.random() - 0.5)/5.0
|
||||
var row = []
|
||||
for (var j = 0; j < width ; j++) {
|
||||
row.push(base[j]+noise)
|
||||
}
|
||||
ret.push(row)
|
||||
}
|
||||
return to_array(ret, 'd')
|
||||
},
|
||||
|
||||
getWidth: function () {
|
||||
return SinusoidSuper.take(-1)[0].length
|
||||
},
|
||||
|
||||
|
||||
getHeight: function () {
|
||||
return SinusoidSuper.take(-1).length
|
||||
},
|
||||
|
||||
}
|
||||
var SinusoidSuper = Java.super(dev)
|
||||
add_device(dev, true)|
|
||||
|
||||
|
||||
|
||||
//Defintion
|
||||
add_device(new DummyMotor("m1"), true)
|
||||
add_device(new DummyMotor("m2"), true)
|
||||
add_device(new DummyRegister("reg1",3), true)
|
||||
add_device(new DummyPositioner("p1"),true)
|
||||
add_device(new MotorGroupBase("mg1", m1, m2), true)
|
||||
add_device(new MotorGroupDiscretePositioner("dp1", mg1), true)
|
||||
|
||||
|
||||
//Initial Configuration
|
||||
if (p1.config.unit == null) {
|
||||
p1.config.minValue = 0.0 //Not persisted
|
||||
p1.config.maxValue = 1000.0
|
||||
p1.config.unit = "mm"
|
||||
p1.config.save()
|
||||
p1.initialize()
|
||||
}
|
||||
|
||||
if (dp1.config.positions == null) {
|
||||
dp1.config.positions = ["Park","Ready","Out","Clear"]
|
||||
dp1.config.motor1 = ["0.0","4.0","8.0" ,"0.0"]
|
||||
dp1.config.motor2 = ["0.0","5.0","3.0" ,"NaN"]
|
||||
dp1.config.save()
|
||||
dp1.initialize()
|
||||
}
|
||||
|
||||
|
||||
//Update
|
||||
m1.setMonitored(true)
|
||||
m2.setMonitored(true)
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Simple Readable / Writable objects can be created and used in scans
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
var WritableScalar = Java.extend(Writable)
|
||||
var ws1 = new WritableScalar() {
|
||||
write: function (value) {
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
var ReadableScalar = Java.extend(Readable)
|
||||
var rs1 = new ReadableScalar() {
|
||||
read: function (value) {
|
||||
return Math.random()
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
var ReadableWaveform = Java.extend(ReadableArray)
|
||||
var rw1 = new ReadableWaveform() {
|
||||
|
||||
read: function (value) {
|
||||
ret = []
|
||||
for (var i=0; i< this.getSize(); i++){
|
||||
ret.push(Math.random())
|
||||
}
|
||||
return to_array(ret, 'd')
|
||||
},
|
||||
|
||||
getSize: function () {
|
||||
return 20
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
|
||||
var ReadableImage = Java.extend(ReadableMatrix)
|
||||
var ri1 = new ReadableImage() {
|
||||
read: function (value) {
|
||||
var ret = []
|
||||
for (var i=0; i< this.getHeight(); i++){
|
||||
var row = []
|
||||
for (var j=0; j< this.getWidth(); j++){
|
||||
row.push(Math.random())
|
||||
}
|
||||
ret.push(row)
|
||||
}
|
||||
return to_array(ret, 'd')
|
||||
},
|
||||
|
||||
getWidth: function () {
|
||||
return 80
|
||||
},
|
||||
|
||||
getHeight: function () {
|
||||
return 40
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Imaging
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
GenericDevice = Java.type('ch.psi.pshell.device.GenericDevice')
|
||||
File = Java.type('java.io.File')
|
||||
var f = new File(GenericDevice.getConfigFileName("m1"))
|
||||
configured = f.exists()
|
||||
|
||||
add_device(new RegisterMatrixSource("src1", im1), true)
|
||||
add_device(new RegisterMatrixSource("src2", ri1), true)
|
||||
|
||||
src1.polling = 100
|
||||
src2.polling = 100
|
||||
|
||||
//Some configuration for so the imaging will work out of the box
|
||||
if (!configured){
|
||||
Colormap = Java.type('ch.psi.pshell.imaging.Colormap')
|
||||
src1.config.colormapAutomatic = true
|
||||
src1.config.colormap = configured.Temperature
|
||||
src1.config.save()
|
||||
src2.config.colormapAutomatic = true
|
||||
src2.config.save()
|
||||
}
|
||||
|
||||
|
||||
22
script/TEST12.xml
Executable file
22
script/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/TestAlignmentScan.py
Executable file
127
script/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/TestAveragePlot.py
Executable file
9
script/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/TestBsMonitorScan.py
Executable file
37
script/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/TestBsread2.py
Executable file
3
script/TestBsread2.py
Executable file
@@ -0,0 +1,3 @@
|
||||
while(True):
|
||||
print bsget(["Int32Scalar", "Int8Scalar"])
|
||||
time.sleep(0.01)
|
||||
127
script/TestFitProfile.py
Executable file
127
script/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])
|
||||
30
script/TestMultiCycles.py
Executable file
30
script/TestMultiCycles.py
Executable file
@@ -0,0 +1,30 @@
|
||||
scan_complete=False
|
||||
|
||||
def check_end_scan(record, scan):
|
||||
global scan_complete
|
||||
if record.index>=50:
|
||||
print "Data aquisition completed"
|
||||
scan.abort()
|
||||
scan_complete=True
|
||||
record.cancel()
|
||||
elif (record.index>0) and (record.index % 10 == 0):
|
||||
get_context().dataManager.splitScanData(scan)
|
||||
|
||||
|
||||
|
||||
def do_scan():
|
||||
global scan_complete
|
||||
scan_complete=False
|
||||
try:
|
||||
mscan (sin, sin, -1, -1, after_read = check_end_scan)
|
||||
except:
|
||||
if not scan_complete:
|
||||
raise
|
||||
|
||||
|
||||
set_exec_pars(group="x_{count}");
|
||||
do_scan()
|
||||
|
||||
set_exec_pars(group="y_{count}", reset=True)
|
||||
do_scan()
|
||||
|
||||
6
script/TestPlot.py
Executable file
6
script/TestPlot.py
Executable file
@@ -0,0 +1,6 @@
|
||||
start = 0
|
||||
end = 10.0
|
||||
steps = 10
|
||||
|
||||
|
||||
r = lscan (out, sin, start, end, steps, 0.2)
|
||||
39
script/TestProsilica.py
Executable file
39
script/TestProsilica.py
Executable file
@@ -0,0 +1,39 @@
|
||||
|
||||
prosilica.writeParameter("FrameStartTriggerMode","Freerun")
|
||||
prosilica.writeParameter("PixelFormat","Bayer8" )
|
||||
prosilica.writeParameter("GainValue",0)
|
||||
prosilica.writeParameter("ExposureValue",15000)
|
||||
prosilica.writeParameter("FrameRate",5.000)
|
||||
|
||||
|
||||
|
||||
|
||||
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/TestPseudo.py
Executable file
8
script/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/TestRecordNull.py
Executable file
39
script/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)
|
||||
16
script/TestScan.py
Executable file
16
script/TestScan.py
Executable file
@@ -0,0 +1,16 @@
|
||||
print args
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
msg = None
|
||||
start = 0
|
||||
end = 10.0
|
||||
steps = 10
|
||||
else:
|
||||
msg = args[0]
|
||||
start = float(args[1])
|
||||
end = float(args[2])
|
||||
steps = int(args[3])
|
||||
|
||||
|
||||
print msg
|
||||
r = lscan (out, sin, start, end, steps, 0.2)
|
||||
|
||||
13
script/TestScanControlledVar.py
Executable file
13
script/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()
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user