This commit is contained in:
boccioli_m
2015-05-20 11:39:56 +02:00
commit f4607f105a
45 changed files with 1030 additions and 0 deletions

11
.gitignore vendored Normal file
View File

@@ -0,0 +1,11 @@
/context
/data
/extensions
/log
/plugins
/sessions
/www
script/cachedir
script/Lib
script/*.class
script/*.pyc

26
config/config.properties Normal file
View File

@@ -0,0 +1,26 @@
#Wed May 20 11:37:11 CEST 2015
autoSaveScanData=true
createSessionFiles=false
dataFile={data}/{year}_{month}/{date}/{date}_{time}_{context}
dataFileName={data}/{year}_{month}/{date}/{date}_{time}_{context}
dataFilesCreation=true
dataPath={data}/{year}_{month}/{date}/{date}_{time}_{context}
dataProvider=default
dataScanFlushRecords=false
dataScanStrategy=default
devicePoolFile={config}/devices.properties
deviceUpdateStrategyFile={config}/update.properties
imageSourcesFile={config}/imaging.properties
logDaysToLive=-1
logLevel=Fine
logLevelConsole=Off
scriptType=py
serverEnabled=false
serverPort=8080
simulation=false
tasksFile={config}/tasks.properties
terminalEnabled=false
terminalPort=3579
versionTrackingEnabled=true
versionTrackingLogin=
versionTrackingRemote=

20
config/devices.properties Normal file
View File

@@ -0,0 +1,20 @@
#mot=ch.psi.pshell.epics.ChannelDouble MTEST-GOBBO:MOT1 5
dev=ch.psi.pshell.dev.DummyRegister 6
#dev2=ch.psi.pshell.dev.MyDevice
$vhq=ch.psi.pshell.epics.ChannelDouble T-MMDV5:IST:2 Read 6
outc=ch.psi.pshell.epics.ChannelDouble TESTIOC:TESTCALCOUT:Output
inpc=ch.psi.pshell.epics.ChannelDouble TESTIOC:TESTCALCOUT:Input
out=ch.psi.pshell.epics.ChannelDouble TESTIOC:TESTCALCOUT:Output 6
inp=ch.psi.pshell.epics.ChannelDouble TESTIOC:TESTCALCOUT:Input 6
sin=ch.psi.pshell.epics.ChannelDouble TESTIOC:TESTSINUS:SinCalc 6
arr=ch.psi.pshell.epics.ChannelDoubleArray TESTIOC:TESTWF2:MyWF 6
pv=ch.psi.pshell.epics.ProcessVariable TESTIOC:TESTCALCOUT:Input
$motor=ch.psi.pshell.epics.Motor MTEST-GOBBO:MOT1
$motor2=ch.psi.pshell.epics.Motor MTEST-GOBBO:MOT2
table=ch.psi.pshell.dev.MotorGroupBase motor motor2
manip=ch.psi.pshell.epics.Manipulator
tab=ch.psi.pshell.dev.MotorGroupDiscretePositioner table
#img=ch.psi.pshell.epics.ChannelByteArray 13SIM1:image1:ArrayData -1 1048576
det=ch.psi.pshell.epics.AreaDetector 13SIM1:cam1 13SIM1:image1
$scienta=ch.psi.pshell.epics.Scienta 13SIM1:cam1 13SIM1:image1
$slit=ch.psi.pshell.epics.Slit MOT1 MOT2 false

View File

@@ -0,0 +1,3 @@
img=ch.psi.pshell.imaging.CameraSource det
sc=ch.psi.pshell.imaging.CameraSource scienta
tst=ch.psi.pshell.imaging.FileSource C:\\Users\\gobbo_a\\Pictures\\psi.png

15
config/jcae.properties Normal file
View File

@@ -0,0 +1,15 @@
ch.psi.jcae.ContextFactory.addressList=129.129.144.80 129.129.130.188 129.129.145.206:54321
ch.psi.jcae.ContextFactory.maxArrayBytes=10000000
ch.psi.jcae.ChannelFactory.timeout=2000
ch.psi.jcae.ChannelFactory.retries=2
ch.psi.jcae.ChannelBeanFactory.timeout=10000
ch.psi.jcae.ChannelBeanFactory.waitTimeout=1800000
ch.psi.jcae.ChannelBeanFactory.waitRetryPeriod=30000
ch.psi.jcae.ChannelBeanFactory.retries=4
ch.psi.jcae.impl.DefaultChannelService.timeout=3000
ch.psi.jcae.impl.DefaultChannelService.waitTimeout=60000
ch.psi.jcae.impl.DefaultChannelService.waitRetryPeriod=5000
ch.psi.jcae.impl.DefaultChannelService.retries=4

View File

@@ -0,0 +1,3 @@
#Tue Feb 24 18:03:08 CET 2015
.\\home\\plugins\\plugin-1.0-SNAPSHOT.jar=disabled
.\\home\\plugins\\plugin-0.0.jar=disabled

1
config/tasks.properties Normal file
View File

@@ -0,0 +1 @@
#back=5

22
config/update.properties Normal file
View File

@@ -0,0 +1,22 @@
mot=
dev=
dev2=
vhq=
outc=
inpc=
out=
inp=monitored
sin=monitored polled:1000
arr=
pv=
motor=monitored
motor2=monitored
table=
manip=monitored
tab=
img=
det=monitored
scienta=
slit=monitored
det.data=
scienta.data=

13
devices/det.properties Normal file
View File

@@ -0,0 +1,13 @@
#Wed Mar 04 17:47:23 CET 2015
grayscale=false
colormap=Grayscale
pollingBackground=false
scale=1.0
colormapAutomatic=false
dataMonitoring=false
pollingInterval=0
colormapMin=0.0
dataPolling=0
mirrored=false
colormapMax=255.0
rotation=0.0

23
devices/img.properties Normal file
View File

@@ -0,0 +1,23 @@
#Fri Apr 10 16:55:30 CEST 2015
colormap=Grayscale
colormapAutomatic=false
colormapMax=255.0
colormapMin=0.0
colormapRangeMax=NaN
colormapRangeMin=NaN
colormapTemperature=false
dataMonitoring=true
dataPolling=0
flipHorizontally=false
flipVertically=false
grayscale=false
invert=false
mirrored=false
monitored=false
polling=0
pollingBackground=false
pollingInterval=0
rescaleFactor=1.0
rescaleOffset=0.0
rotation=0.0
scale=1.0

5
devices/inpc.properties Normal file
View File

@@ -0,0 +1,5 @@
#Tue Mar 03 09:23:33 CET 2015
precision=-1
accessType=ReadWrite
channel=TESTIOC\:TESTCALCOUT\:Input
simulation=false

8
devices/manip.properties Normal file
View File

@@ -0,0 +1,8 @@
#Tue Mar 17 16:26:08 CET 2015
accessType=ReadWrite
position_pvs=TESTIOC-MA\:RETRACTED|TESTIOC-MA\:YAG |TESTIOC-MA\:NE |TESTIOC-MA\:TRCL|TESTIOC-MA\:SHIELD|TESTIOC-MA\:CLAMP|TESTIOC-MA\:HEATER|TESTIOC-MA\:SAMPLE
positions=Retracted |YAG |Normal emission|Transfer \t | Shield |Clamping screw |Heater screw |Sample access
positions_pvs=asd|zxc
precision=-1
readback_pv=TESTIOC-MA\:STS
stop_pv=TESTIOC-MA-STOP\:ALL

14
devices/motor.properties Normal file
View File

@@ -0,0 +1,14 @@
#Fri Mar 20 14:20:05 CET 2015
accessType=ReadWrite
channel=MTEST-GOBBO\:MOT1
defaultSpeed=1.0
maxSpeed=100.0
maxValue=200.0
minSpeed=0.001
minValue=0.0
offset=0.0
precision=3
resolution=NaN
scale=1.0
simulation=false
unit=null

14
devices/motor2.properties Normal file
View File

@@ -0,0 +1,14 @@
#Tue Mar 17 17:39:39 CET 2015
accessType=ReadWrite
channel=MTEST-GOBBO\:MOT2
defaultSpeed=10.0
maxSpeed=100.0
maxValue=100.0
minSpeed=0.001
minValue=0.0
offset=0.0
precision=5
resolution=NaN
scale=1.0
simulation=false
unit=null

5
devices/outc.properties Normal file
View File

@@ -0,0 +1,5 @@
#Tue Mar 03 09:23:33 CET 2015
precision=-1
accessType=ReadWrite
channel=TESTIOC\:TESTCALCOUT\:Output
simulation=false

11
devices/pv.properties Normal file
View File

@@ -0,0 +1,11 @@
#Tue Mar 17 17:38:52 CET 2015
accessType=ReadWrite
channel=TESTIOC\:TESTCALCOUT\:Input
maxValue=10.0
minValue=0.0
offset=1.0
precision=2
resolution=-1.0
scale=2.0
simulation=false
unit=mm

17
devices/sc.properties Normal file
View File

@@ -0,0 +1,17 @@
#Thu Mar 19 10:34:42 CET 2015
colormap=Grayscale
colormapAutomatic=false
colormapMax=255.0
colormapMin=0.0
dataMonitoring=false
dataPolling=0
flipHorizontally=false
flipVertically=false
grayscale=false
invert=false
pollingBackground=false
pollingInterval=0
rescaleFactor=1.0
rescaleOffset=0.0
rotation=0.0
scale=1.0

View File

@@ -0,0 +1,13 @@
#Thu Mar 05 10:21:14 CET 2015
grayscale=false
colormap=Grayscale
pollingBackground=false
scale=1.0
colormapAutomatic=false
dataMonitoring=false
pollingInterval=0
colormapMin=0.0
dataPolling=0
colormapMax=255.0
mirrored=false
rotation=0.0

View File

@@ -0,0 +1,12 @@
#Thu Apr 02 12:00:17 CEST 2015
accessType=ReadWrite
defaultSpeed=1.0
maxSpeed=1.0
maxValue=20.0
minSpeed=0.001
minValue=-10.0
offset=0.0
precision=2
resolution=NaN
scale=1.0
unit=mm

View File

@@ -0,0 +1,12 @@
#Thu Apr 02 12:00:17 CEST 2015
accessType=ReadWrite
defaultSpeed=1.0
maxSpeed=1.0
maxValue=20.0
minSpeed=0.001
minValue=-10.0
offset=0.0
precision=2
resolution=NaN
scale=1.0
unit=mm

14
devices/tab.properties Normal file
View File

@@ -0,0 +1,14 @@
#Tue Mar 17 16:26:08 CET 2015
accessType=ReadWrite
motor1=0.0 | 4.0 | 8.0 | 0.0
motor10=null
motor2=0.0 | 5.0 | 3.0 | NaN
motor3=null
motor4=null
motor5=null
motor6=null
motor7=null
motor8=null
motor9=null
positions=Park | Ready | Out | Clear
precision=-1

12
devices/tst.properties Normal file
View File

@@ -0,0 +1,12 @@
#Wed Mar 18 14:35:37 CET 2015
flipHorizontally=false
flipVertically=false
grayscale=false
invert=false
mirrored=false
pollingBackground=false
pollingInterval=0
rescaleFactor=1.0
rescaleOffset=0.0
rotation=0.0
scale=1.0

58
script/data.py Normal file
View File

@@ -0,0 +1,58 @@
data = [1,2,3,4,5]
path="group/data"
save_dataset(path, data)
read =load_data(path)
print read.tolist()
#plot(read)
data = [ [1,2,3,4,5], [2,3,4,5,6], [3,4,5,6,7]]
path="group/data2"
save_dataset(path, data)
set_attribute(path, "AttrString", "Value")
set_attribute(path, "AttrInteger", 1)
set_attribute(path, "AttrDouble", 2.0)
set_attribute(path, "AttrBoolean", True)
read =load_data(path)
print read.tolist()
plot(read)
path = "group/data3"
create_dataset(path, 'i')
for i in range(10):
save_data_item(path,i)
path = "group/data4"
create_dataset(path, 'd', False, (0,0))
for row in data:
save_data_item(path, row)
path = "group/data5"
names = ["a", "b", "c", "d"]
types = ["d", "d", "d", "[d"]
lenghts = [0,0,0,5]
dims = [0,0,0,0]
data = [ [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, dims)
for row in data:
save_table_item(path, row)
flush_data()
read =load_data(path)
print read

42
script/import.py Normal file
View File

@@ -0,0 +1,42 @@
#Script imported from: test1.xml
#Variables
var1 = 0.0
#TODO: Set the diplay names of positioners and detectors
scan = ManualScan(['id278043'], ['id348623', 'id367393'] , [0.0], [31.0], [31])
scan.start()
#Creating channels: dimension 1
#LinearPositioner id278043
id278043 = Channel('TESTIOC:TESTCALCOUT:Input', type = 'd')
#ScalarDetector id348623
id348623 = Channel('TESTIOC:TESTCALCOUT:Output', type = 'd')
#ScalarDetector id367393
id367393 = Channel('TESTIOC:TESTSINUS:SinCalc', type = 'd')
#Dimension 1
#LinearPositioner id278043
for setpoint1 in frange(0.0, 31.0, 1.0, True):
if setpoint1 > 31.0 or setpoint1 < 0.0:
break
id278043.put(setpoint1, timeout=None) # TODO: Set appropriate timeout
readback1 = id278043.get()
if abs(readback1 - setpoint1) > 0.5 : # TODO: Check accuracy
raise Exception('Actor id278043 could not be set to the value ' + str(setpoint1))
#Dimension Actions
#Script action
#TODO: Move, if needed, this import to the file header: import time
time.sleep(0.1)
#Detector id348623
detector1 = id348623.get()
#Detector id367393
detector2 = id367393.get()
scan.append ([setpoint1], [readback1], [detector1, detector2])
#Closing channels
id278043.close()
id348623.close()
id367393.close()
scan.end()

55
script/import2.py Normal file
View File

@@ -0,0 +1,55 @@
#Script imported from: test2.xml
#Variables
var1 = 0.0
#TODO: Set the diplay names of positioners and detectors
scan = ManualScan(['id643271', 'id278043'], ['id348623', 'id367393'] , [0.0, 0.0], [5.0, 31.0], [5, 31])
scan.start()
#Creating channels: dimension 1
#LinearPositioner id643271
id643271 = Channel('TESTIOC:TESTCALC:MyCalc', type = 'd')
#Creating channels: dimension 2
#LinearPositioner id278043
id278043 = Channel('TESTIOC:TESTCALCOUT:Input', type = 'd')
#ScalarDetector id348623
id348623 = Channel('TESTIOC:TESTCALCOUT:Output', type = 'd')
#ScalarDetector id367393
id367393 = Channel('TESTIOC:TESTSINUS:SinCalc', type = 'd')
#Dimension 1
#LinearPositioner id643271
for setpoint1 in frange(0.0, 5.0, 1.0, True):
if setpoint1 > 5.0 or setpoint1 < 0.0:
break
id643271.put(setpoint1, timeout=None) # TODO: Set appropriate timeout
readback1 = id643271.get()
if abs(readback1 - setpoint1) > 0.5 : # TODO: Check accuracy
raise Exception('Actor id643271 could not be set to the value ' + str(setpoint1))
#Dimension 2
#LinearPositioner id278043
for setpoint2 in frange(0.0, 31.0, 1.0, True):
if setpoint2 > 31.0 or setpoint2 < 0.0:
break
id278043.put(setpoint2, timeout=None) # TODO: Set appropriate timeout
readback2 = id278043.get()
if abs(readback2 - setpoint2) > 0.5 : # TODO: Check accuracy
raise Exception('Actor id278043 could not be set to the value ' + str(setpoint2))
#Dimension Actions
#Script action
#TODO: Move, if needed, this import to the file header: import time
time.sleep(0.01)
#Detector id348623
detector1 = id348623.get()
#Detector id367393
detector2 = id367393.get()
scan.append ([setpoint1, setpoint2], [readback1, readback2], [detector1, detector2])
#Closing channels
id278043.close()
id348623.close()
id367393.close()
id643271.close()
scan.end()

31
script/import5.py Normal file
View File

@@ -0,0 +1,31 @@
#Script imported from: test5.xml
set_flush_records(False)
#set_preference("scanPlotDisabled",True)
set_preference("scanTableDisabled",True)
#TODO: Set the diplay names of positioners and detectors
scan = ManualScan(['id236750', 'id226053'], ['id246209'] , [0.0, 0.0], [1000.0, 1000.0], [1000, 1000])
scan.start()
#Creating channels: dimension 1
#PseudoPositioner id236750
#Timestamp id246209
#Creating channels: dimension 2
#PseudoPositioner id226053
#Dimension 1
#PseudoPositioner id236750
for setpoint1 in range(0, 1000):
readback1 = setpoint1
#Detector id246209
detector1 = java.lang.System.currentTimeMillis()
#Dimension 2
#PseudoPositioner id226053
for setpoint2 in range(0, 1000):
readback2 = setpoint2
scan.append ([setpoint1, setpoint2], [readback1, readback2], [detector1])
#Closing channels
scan.end()

52
script/import7.py Normal file
View File

@@ -0,0 +1,52 @@
#Script imported from: test7.xml
#Variables
var1 = 0.0
#TODO: Set the diplay names of positioners and detectors
scan = ManualScan(['id278043'], ['id348623', 'id367393', 'id192931', 'id173831'] , [0.0], [31.0], [31])
scan.start()
#Creating channels: dimension 1
#LinearPositioner id278043
id278043 = Channel('TESTIOC:TESTCALCOUT:Input', type = 'd')
#ScalarDetector id348623
id348623 = Channel('TESTIOC:TESTCALCOUT:Output', type = 'd')
#ScalarDetector id367393
id367393 = Channel('TESTIOC:TESTSINUS:SinCalc', type = 'd')
#Timestamp id192931
#Dimension 1
#LinearPositioner id278043
for setpoint1 in frange(0.0, 31.0, 1.0, True):
if setpoint1 > 31.0 or setpoint1 < 0.0:
break
id278043.put(setpoint1, timeout=None) # TODO: Set appropriate timeout
readback1 = id278043.get()
if abs(readback1 - setpoint1) > 0.5 : # TODO: Check accuracy
raise Exception('Actor id278043 could not be set to the value ' + str(setpoint1))
#Dimension Actions
#Script action
#Variable Mappings
x = Channel('TESTIOC:TESTSINUS:SinCalc', type = 'd')
#TODO: Move, if needed, this import to the file header: import time
time.sleep(0.1)
#print "==>" + str(x.getValue())
#Detector id348623
detector1 = id348623.get()
#Detector id367393
detector2 = id367393.get()
#Detector id192931
detector3 = float(java.lang.System.currentTimeMillis())
#Manipulation id173831
#Variable Mappings
v = detector2
id173831 = v+100.0
scan.append ([setpoint1], [readback1], [detector1, detector2, detector3, id173831])
#Closing channels
id278043.close()
id348623.close()
id367393.close()
scan.end()

27
script/local.py Normal file
View File

@@ -0,0 +1,27 @@
#det.data.monitored=True
import random
class SimulatedOutput(Writable):
def getName(self):
return "SimulatedOutput"
def write(self, value):
pass
class SimulatedInput(Readable):
def __init__(self):
self.x = 0.0
def getName(self):
return "SimulatedInput"
def read(self):
self.x = self.x + 0.2
noise = (random.random() - 0.5) / 20.0
return math.sin(self.x) + noise
sout = SimulatedOutput()
sinp = SimulatedInput()

42
script/parallel.py Normal file
View File

@@ -0,0 +1,42 @@
#Simple parallization
def task1():
return out.read()
def task2():
return inp.read()
def task3():
time.sleep(0.1)
return sin.read()
ret = parallelize(task1, task2, task3)
print ret
#Fork amd join
ret = fork(task1, task2, task3)
time.sleep(0.1)
ret = join(ret)
print ret
#Functions with parameters
def devRead(dev, msg):
print msg + " -> " + dev.getName()
return dev.read()
ret = parallelize((devRead,(out,"1")), (devRead,(inp,"2")), (devRead,(sin,"3")))
print ret
#Exception in parallel task
def taskExcept(msg):
raise Exception ("Error in parallel task " + msg)
ret = parallelize((taskExcept,("1")), (taskExcept,(inp,"2")) )
print ret

3
script/scan.py Normal file
View File

@@ -0,0 +1,3 @@
def calc(a):
return a*2

60
script/test0.py Normal file
View File

@@ -0,0 +1,60 @@
import sys
import time
#To add library folders from within the script
#sys.path.append("./site-packages")
import requests
r = requests.get('https://api.github.com', auth=('user', 'pass'))
print r.status_code
print r.headers['content-type']
r.close()
def calc2(a):
return a*2
time.sleep(0.1)
#import os
#print os.environ
#import calc
time.sleep(0.1)
for x in range(3):
print x
while(True):
print x*2
break
time.sleep(2)
data = [1,2,3,4,5]
path="group/data"
save_dataset(path, data)
read =load_data(path)
print read.tolist()
#plot(read)
data = [ [1,2,3,4,5], [2,3,4,5,6], [3,4,5,6,7]]
path="group/data2"
save_dataset(path, data)
read =load_data(path)
print read.tolist()
plot(read)
"""
It lives!!!!
"""

14
script/test1.py Normal file
View File

@@ -0,0 +1,14 @@
"""
Line Scan
"""
#setPreference("enabledPlots",(sin,out))
a= lscan(inp, (sin,out,arr), 0, 40, 20, 0.1)
path = get_current_data_group()
set_attribute(path, "AttrString", "Value")
set_attribute(path, "AttrInteger", 1)
set_attribute(path, "AttrDouble", 2.0)
set_attribute(path, "AttrBoolean", True)

41
script/test10.py Normal file
View File

@@ -0,0 +1,41 @@
"""
Multi-peak search
"""
from mathutils import estimate_peak_indexes, fit_gaussians, create_fit_point_list
start = 0
end = 30
step_size = 0.2
result= lscan(sout,sinp,start,end,[step_size,],0.01)
readable = result.getReadable(0)
positions = result.getPositions(0)
threshold = (min(readable) + max(readable))/2
min_peak_distance = 5.0
peaks = estimate_peak_indexes(readable, positions, threshold, min_peak_distance)
print "Peak indexes: " + str(peaks)
print "Peak x: " + str(map(lambda x:positions[x], peaks))
print "Peak y: " + str(map(lambda x:readable[x], peaks))
gaussians = fit_gaussians(readable, positions, peaks)
plots = plot([readable],["sin"],[positions] )
for i in range(len(peaks)):
peak = peaks[i]
(norm, mean, sigma) = gaussians[i]
if abs(mean - positions[peak]) < min_peak_distance:
print "Peak -> " + str(mean)
plots[0].addMarker(mean, None, "N="+str(round(norm,2)), None)
else:
print "Invalid gaussian fit: " + str(mean)

11
script/test11.py Normal file
View File

@@ -0,0 +1,11 @@
"""
Parameters
"""
start = float(args[0])
end = float(args[1])
step = int(args[2])
a= lscan(inp, sin, start, end, step, 0.1)

8
script/test12.py Normal file
View File

@@ -0,0 +1,8 @@
"""
Relative Scan
"""
a= lscan(inp, (sin,out,arr), -2, 2, 20, 0.1, True)

8
script/test13.py Normal file
View File

@@ -0,0 +1,8 @@
"""
Relative Scan
"""
a= lscan(inp, (sin,out,arr), -2, 2, 20, 0.1, True)

16
script/test2.py Normal file
View File

@@ -0,0 +1,16 @@
"""
Line Scan with 2 writables and triggering
"""
index=0
def BeforeReadout():
global index
print "Frame = " + str(index)
index=index+1
#log("trigger " + index)
caput("TESTIOC:TESTBO:MyBO","On")
caput("TESTIOC:TESTBO:MyBO","Off")
a= lscan((motor,inp), (sin,out,arr), (0,0), (4,40), 20, 0.1, before_read=BeforeReadout)

21
script/test3.py Normal file
View File

@@ -0,0 +1,21 @@
"""
Processing and plotting scan data
"""
inp.write(0.0)
scan1= lscan(inp, (sin,out,arr), 0, 40, 20, 0.1, False, "Scan 1")
scan2= lscan(inp, (sin,out,arr), 0, 40, 20, 0.1, False, "Scan 2")
from operator import add
result = map(add, scan1.getReadable(0), scan2.getReadable(0))
#Alternative:
#result=[]
#for i in range(len(scan1.records)):
# result.append(scan1.records[i].values[0]+scan2.records[i].values[0])
plot(result)
print result

11
script/test4.py Normal file
View File

@@ -0,0 +1,11 @@
"""
Vector Scan
"""
vector = [ [1,1] , [1,2] , [1,3] , [1,4] ,
[1.5,2.5] ,
[2,1] , [2,2] , [2,3] , [2,4] ,
[2.5,2.5] ,
[3,1] , [3,2] , [3,3] , [3,4] ]
a= vscan((dev,inp),(sin,out),vector,0.1)

5
script/test5.py Normal file
View File

@@ -0,0 +1,5 @@
"""
Area Scan
"""
ascan((dev,out), (sin,out,arr), (0,10), (20,30), (20,20))

36
script/test6.py Normal file
View File

@@ -0,0 +1,36 @@
"""
Creating pseudo-devices
"""
import time
sin_val=None
class Sensor(ch.psi.pshell.dev.Readable):
def read(self):
global sin_val
return sin_val + time.clock()
def getName(self):
return "Sensor"
class Positioner(ch.psi.pshell.dev.Writable):
def write(self,pos):
print pos
def getName(self):
return "Positioner"
class Listener (ch.psi.pshell.dev.DeviceListener):
def onStateChanged(self, device, state, former):
pass
def onValueChanged(self, device, value, former):
global sin_val
sin_val=value
sensor=Sensor()
positioner=Positioner()
listener = Listener()
sin.addListener(listener)
try:
a= lscan((inp,positioner),(sin,sensor),(0,0),(40,10),20,0.1)
finally:
sin.removeListener(listener)

114
script/test7.py Normal file
View File

@@ -0,0 +1,114 @@
"""
Function fitting and peak search directly with org.apache.commons.math3
"""
import org.apache.commons.math3.util.FastMath as FastMath
import org.apache.commons.math3.stat.regression.SimpleRegression as SimpleRegression
import org.apache.commons.math3.analysis.polynomials.PolynomialFunction as PolynomialFunction
import org.apache.commons.math3.analysis.function.Gaussian as Gaussian
import org.apache.commons.math3.analysis.function.HarmonicOscillator as HarmonicOscillator
import org.apache.commons.math3.analysis.solvers.LaguerreSolver as LaguerreSolver
import org.apache.commons.math3.fitting.GaussianCurveFitter as GaussianCurveFitter
import org.apache.commons.math3.fitting.PolynomialCurveFitter as PolynomialCurveFitter
import org.apache.commons.math3.fitting.HarmonicCurveFitter as HarmonicCurveFitter
import org.apache.commons.math3.fitting.WeightedObservedPoint as WeightedObservedPoint
import org.apache.commons.math3.analysis.differentiation.FiniteDifferencesDifferentiator as FiniteDifferencesDifferentiator
import org.apache.commons.math3.analysis.differentiation.DerivativeStructure as DerivativeStructure
start = 0
end = 2
step_size = 0.1
result= lscan(inp,(sin,out),start,end,[step_size,],0.1)
readable = result.getReadable(0)
positions = result.getPositions(0)
simple_regression= SimpleRegression()
values = []
for record in result.records:
simple_regression.addData(record.positions[0], record.values[0])
values.append(WeightedObservedPoint(1, record.positions[0], record.values[0]))
order = 6
#polynomial_fitter = PolynomialCurveFitter.create(0).withStartPoint([ 5.0, 5.0, 5.0])
polynomial_fitter = PolynomialCurveFitter.create(order)
gaussian_fitter = GaussianCurveFitter.create();
harmonic_fitter = HarmonicCurveFitter.create();
best = polynomial_fitter.fit(values)
fitted_polynomial_function = PolynomialFunction(best)
(normalization, mean, sigma) = gaussian_fitter.fit(values)
print (normalization, mean, sigma)
fitted_gaussian_function = Gaussian(normalization, mean, sigma)
print "Mean: " + str(mean)
(amplitude, angular_frequency, phase) = harmonic_fitter.fit(values)
print (amplitude, angular_frequency, phase)
fitted_harmonic_function = HarmonicOscillator(amplitude, angular_frequency, phase)
#differentiator = FiniteDifferencesDifferentiator(order+2, 0.25) #points, step size
#derivative = differentiator.differentiate(fitted_polynomial)
derivative = fitted_polynomial_function.derivative()
print fitted_polynomial_function.coefficients
print derivative.coefficients
regression = []
fit_polinomial = []
fit_gaussian = []
fit_harmonic = []
fit_polinomial_derivative = []
resolution = step_size/100
for x in frange(start,end,resolution, True):
regression.append(simple_regression.predict(x))
fit_polinomial.append(fitted_polynomial_function.value(x))
fit_gaussian.append(fitted_gaussian_function.value(x))
fit_harmonic.append(fitted_harmonic_function.value(x))
fit_polinomial_derivative.append(derivative.value(x))
x = frange(start, end+resolution, resolution)
def calculate_peaks(function, start_value = sys.float_info.min, end_value = sys.float_info.max, positive=True):
derivative = function.derivative()
derivative2 = derivative.derivative()
ret = []
solver = LaguerreSolver()
for complex in solver.solveAllComplex(derivative.coefficients, start_value):
r = complex.real
if start_value < r < end_value:
if (positive and (derivative2.value(r) < 0)) or ( (not positive) and (derivative2.value(r) > 0)):
ret.append(r)
return ret
peaks = calculate_peaks(fitted_polynomial_function)
plots = plot([readable, regression, fit_polinomial, fit_gaussian, fit_harmonic, fit_polinomial_derivative] ,
["sin", "regression", "fit polinomial", "fit gaussian", "fit harmonic ", "fit polinomial derivative"],
xdata = [positions,x,x,x,x,x] )
for p in peaks:
print "Max: " + str(p)
plots[0].addMarker(p, None, "Max", None)
#plots[0].addMarker(mean, None, "Gaussian Mean", None)
print result

36
script/test8.py Normal file
View File

@@ -0,0 +1,36 @@
"""
Multi-peak search
"""
from mathutils import estimate_peak_indexes, fit_gaussians
start = 0
end = 5
step_size = 0.1
result= lscan(inp,sin,start,end,[step_size,],0.1)
readable = result.getReadable(0)
positions = result.getPositions(0)
threshold = (min(readable) + max(readable))/2
min_peak_distance = 0.5
peaks = estimate_peak_indexes(readable, positions, threshold, min_peak_distance)
print peaks
gaussians = fit_gaussians(readable, positions, peaks)
plots = plot([readable],["sin"],[positions] )
for i in range(len(peaks)):
peak = peaks[i]
(norm, mean, sigma) = gaussians[i]
if abs(mean - positions[peak]) < min_peak_distance:
print "Peak -> " + str(mean)
plots[0].addMarker(mean, None, "N="+str(round(norm,2)), None)
else:
print "Invalid gaussian fit: " + str(mean)

58
script/test9.py Normal file
View File

@@ -0,0 +1,58 @@
"""
Function fitting and peak search with mathutils facade
"""
from mathutils import fit_polynomial,fit_gaussian, fit_harmonic, calculate_peaks
from mathutils import PolynomialFunction, Gaussian, HarmonicOscillator
import math
start = 0
end = 10
step_size = 0.1
result= lscan(sout,sinp,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, sigma) = fit_gaussian(readable, positions, True)
fitted_gaussian_function = Gaussian(normalization, mean, sigma)
print (normalization, mean, 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)
plots = plot([readable, fit_polinomial, fit_gaussian, fit_harmonic] ,
["data", "polinomial", "gaussian", "harmonic"], xdata = [positions,x,x,x] )
for p in peaks:
print "Max: " + str(p)
plots[0].addMarker(p, None, "Max=" + str(round(p,2)), None)
import java.awt.Color
plots[0].addMarker(mean, None, "Mean=" + str(round(mean,2)), java.awt.Color.LIGHT_GRAY)

7
script/testall.py Normal file
View File

@@ -0,0 +1,7 @@
args.clear(); args.addAll([0,40,20])
scripts = ["test11", "test1", "test2", "test3", "test4", "test5", "test6", "test7", "test8", "test9", "test10", "import", "import2", "import7", "data", "test0"]
for script in scripts:
set_status("Running: " + script)
execfile(controller.setup.getScriptPath()+"/" + script + ".py")