Jun 2024
This commit is contained in:
@@ -10,7 +10,11 @@ class DevConfig(DeviceConfig):
|
||||
|
||||
class Dev(DeviceBase):
|
||||
def __init__(self, name):
|
||||
#DeviceBase.__init__(self, name, DevConfig())
|
||||
DeviceBase.__init__(self, name, DeviceConfig({"i":1, "d":1.0, "b":True, "s": "Test"}))
|
||||
raise Exception("test ex")
|
||||
add_device(Dev("test_cfg"), True)
|
||||
DeviceBase.__init__(self, name, DeviceConfig({"intval":1, "floatval":1.0, "boolval":True, "strval": "Test"}))
|
||||
add_device(Dev("testdev"), True)
|
||||
|
||||
print testdev.config
|
||||
print testdev.config.getValue("intval")
|
||||
print testdev.config.getValue("floatval")
|
||||
print testdev.config.getValue("boolval")
|
||||
print testdev.config.getValue("strval")
|
||||
|
||||
24
script/test/TestCombineImage.py
Normal file
24
script/test/TestCombineImage.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from ijutils import *
|
||||
|
||||
|
||||
def get_file(index):
|
||||
scan = "/Users/gobbo_a/dev/pshell/config/home/data/2024_03/20240319/20240319_105604_TeztTiff/scan 1/"
|
||||
return scan + ("det image_%04d.tiff" % (index))
|
||||
|
||||
imgs_per_row=3
|
||||
imgs_per_col=2
|
||||
|
||||
images = []
|
||||
for i in range(6):
|
||||
images.append(get_file(i))
|
||||
|
||||
composite =create_composite_image(images[0], imgs_per_row, imgs_per_col)
|
||||
display_composite_image(composite)
|
||||
|
||||
p=None
|
||||
for i in range(len(images)):
|
||||
x,y = i%imgs_per_row, i/imgs_per_row
|
||||
append_composite_image(composite, images[i], x, y)
|
||||
display_composite_image(composite)
|
||||
time.sleep(0.5)
|
||||
|
||||
22
script/test/TestDataAPI.py
Normal file
22
script/test/TestDataAPI.py
Normal file
@@ -0,0 +1,22 @@
|
||||
baseurl = "https://data-api.psi.ch/sf"
|
||||
filename = "/Users/gobbo_a/dev/back/test.h5"
|
||||
channels = ["SARFE10-PSSS059:FIT-COM", "S10BC01-DBPM010:Q1"]
|
||||
start = "2023-12-10T08:50:00.000Z" #args.start.astimezone(pytz.timezone('UTC')).strftime("%Y-%m-%dT%H:%M:%S.%fZ") # isoformat() # "2019-12-13T09:00:00.000000000Z"
|
||||
end = "2023-12-10T08:50:05.000Z" # args.end.astimezone(pytz.timezone('UTC')).strftime("%Y-%m-%dT%H:%M:%S.%fZ") # .isoformat() # "2019-12-13T09:00:00.100000000Z"
|
||||
|
||||
|
||||
api = DataAPI(baseurl)
|
||||
ret = api.queryData(channels, start, end)
|
||||
print ret
|
||||
|
||||
channel_data = ret[0]["data"]
|
||||
y1=[v["value"] for v in channel_data]
|
||||
x1=[v["globalSeconds"] for v in channel_data]
|
||||
|
||||
|
||||
channel_data = ret[1]["data"]
|
||||
y2=[v["value"] for v in channel_data]
|
||||
x2=[v["globalSeconds"] for v in channel_data]
|
||||
|
||||
|
||||
plot([y1, y2], channels, xdata=[x1, x2])
|
||||
@@ -3,8 +3,9 @@ from jeputils import import_py
|
||||
import_py("CPython/linfit", "linfit")
|
||||
import_py("CPython/gfitoff", "gfitoff")
|
||||
|
||||
x=[0,1,2,3,4,5,6,7,8,9]
|
||||
y=[1,2,3,6,9,6,3,2,1,0]
|
||||
x=to_array([0,1,2,3,4,5,6,7,8,9], 'd')
|
||||
y=to_array([1,2,3,6,9,6,3,2,1,0], 'd')
|
||||
|
||||
(p, x_fit, y_fit, R2) = linfit(x,y)
|
||||
#print "Fit: ", (p, x_fit, y_fit, R2)
|
||||
plot((y,y_fit), name=("data", "fit"),xdata=(x,x_fit))
|
||||
|
||||
267
script/test/TestJEP2.py
Normal file
267
script/test/TestJEP2.py
Normal file
@@ -0,0 +1,267 @@
|
||||
###################################################################################################
|
||||
# Facade to JEP: Embedded Python
|
||||
###################################################################################################
|
||||
|
||||
#Matplotlib won't work out of the box because it's default backend (Qt) uses signals, which only works in
|
||||
#the main thread. Ideally should find a fix, in order to mark the running thread as the main.
|
||||
#As a workaround, one can use the Tk backend:
|
||||
#
|
||||
#import matplotlib
|
||||
#matplotlib.use('TkAgg')
|
||||
|
||||
|
||||
#In principle just add JEP jar and library to the extensions folder.
|
||||
#
|
||||
#Alternatively on Linux:
|
||||
# Python 2:
|
||||
# - Add <python home>/lib/python3.X/site-packages/jep to LD_LIBRARY_PATH
|
||||
# - Add <python home>/lib/python3.X/site-packages/jep/jep-X.X.X.jar to the class path
|
||||
#
|
||||
#Python3:
|
||||
# - Add JEP library folder to LD_LIBRARY_PATH
|
||||
# - If using OpenJDK, add also python <python home>/lib folder to LD_LIBRARY_PATH
|
||||
# - Set LD_PRELOAD=<python home>/lib/libpython3.5m.so
|
||||
|
||||
|
||||
import sys
|
||||
import os
|
||||
import jep.Jep
|
||||
import jep.SharedInterpreter
|
||||
import jep.NDArray
|
||||
import java.lang.Thread
|
||||
import org.python.core.PyArray as PyArray
|
||||
import java.lang.String as String
|
||||
import java.util.List
|
||||
import java.util.Map
|
||||
import java.util.HashMap
|
||||
import ch.psi.pshell.scripting.ScriptUtils as ScriptUtils
|
||||
|
||||
|
||||
from startup import to_array, get_context, _get_caller, Convert, Arr
|
||||
|
||||
__jep = {}
|
||||
|
||||
def __get_jep():
|
||||
t = java.lang.Thread.currentThread()
|
||||
if not t in __jep:
|
||||
init_jep()
|
||||
return __jep[t]
|
||||
|
||||
def __close_jep():
|
||||
t = java.lang.Thread.currentThread()
|
||||
if t in __jep:
|
||||
__jep[t].close()
|
||||
|
||||
def init_jep():
|
||||
#TODO: Should do it but generates errors
|
||||
#__close_jep()
|
||||
j = jep.SharedInterpreter()
|
||||
try:
|
||||
#Faster, but statements must be complete
|
||||
j.setInteractive(False)
|
||||
except:
|
||||
pass # Removed in 4.2
|
||||
__jep[java.lang.Thread.currentThread()] = j
|
||||
j.eval("import sys")
|
||||
#sys.argv is not present in JEP and may be needed for certain modules (as Tkinter)
|
||||
j.eval("sys.argv = ['PShell']");
|
||||
#Add standard script path to python path
|
||||
j.eval("sys.path.append('" + get_context().setup.getScriptPath() + "')")
|
||||
|
||||
#Redirect stdout
|
||||
j.eval("class JepStdout:\n" +
|
||||
" def write(self, str):\n" +
|
||||
" self.str += str\n" +
|
||||
" def clear(self):\n" +
|
||||
" self.str = ''\n" +
|
||||
" def flush(self):\n" +
|
||||
" pass\n")
|
||||
j.eval("sys.stdout=JepStdout()");
|
||||
j.eval("sys.stderr=JepStdout()");
|
||||
j.eval("sys.stdout.clear()")
|
||||
j.eval("sys.stderr.clear()")
|
||||
|
||||
#Import reload on Python 3
|
||||
j.eval("try:\n" +
|
||||
" reload # Python 2.7\n" +
|
||||
"except NameError:\n" +
|
||||
" try:\n" +
|
||||
" from importlib import reload # Python 3.4+\n" +
|
||||
" except ImportError:\n" +
|
||||
" from imp import reload # Python 3.0 - 3.3\n")
|
||||
|
||||
def __print_stdout():
|
||||
j=__get_jep()
|
||||
output = None
|
||||
err = None
|
||||
try:
|
||||
output = j.getValue("sys.stdout.str")
|
||||
err = j.getValue("sys.stderr.str")
|
||||
j.eval("sys.stdout.clear()")
|
||||
j.eval("sys.stderr.clear()")
|
||||
except:
|
||||
pass
|
||||
if (output is not None) and len(output)>0:
|
||||
print output
|
||||
if (err is not None) and len(err)>0:
|
||||
print >> sys.stderr, err
|
||||
|
||||
def run_jep(script_name, vars = {}):
|
||||
global __jep
|
||||
script = get_context().scriptManager.library.resolveFile(script_name)
|
||||
if script is None :
|
||||
script= os.path.abspath(script_name)
|
||||
j=__get_jep()
|
||||
|
||||
for v in vars:
|
||||
j.set(v, vars[v])
|
||||
try:
|
||||
j.runScript(script)
|
||||
finally:
|
||||
__print_stdout()
|
||||
|
||||
def eval_jep(line):
|
||||
j=__get_jep()
|
||||
try:
|
||||
j.eval(line)
|
||||
finally:
|
||||
__print_stdout()
|
||||
|
||||
def set_jep(var, value):
|
||||
j=__get_jep()
|
||||
j.set(var, value)
|
||||
|
||||
def get_jep(var):
|
||||
j=__get_jep()
|
||||
return j.getValue(var)
|
||||
|
||||
def call_jep(module, function, args = [], kwargs = {}, reload=False):
|
||||
j=__get_jep()
|
||||
if "/" in module:
|
||||
script = get_context().scriptManager.library.resolveFile(module)
|
||||
if "\\" in script:
|
||||
#Windows paths
|
||||
module_path = script[0:script.rfind("\\")]
|
||||
module = script[script.rfind("\\")+1:]
|
||||
else:
|
||||
#Linux paths
|
||||
module_path = script[0:script.rfind("/")]
|
||||
module = script[script.rfind("/")+1:]
|
||||
eval_jep("import sys")
|
||||
eval_jep("sys.path.append('" + module_path + "')")
|
||||
if module.endswith(".py"):
|
||||
module = module[0:-3]
|
||||
|
||||
f = module+"_" + function+"_"+str(j.hashCode())
|
||||
try:
|
||||
if reload:
|
||||
eval_jep("import " + module)
|
||||
eval_jep("_=reload(" + module+")")
|
||||
eval_jep("from " + module + " import " + function + " as " + f)
|
||||
if (kwargs is not None) and (len(kwargs)>0):
|
||||
#invoke with kwargs only available in JEP>3.8
|
||||
hm=java.util.HashMap()
|
||||
hm.update(kwargs)
|
||||
#The only way to get the overloaded method...
|
||||
m = j.getClass().getMethod("invoke", [String, ScriptUtils.getType("[o"), java.util.Map])
|
||||
ret = m.invoke(j, [f, to_array(args,'o'), hm])
|
||||
else:
|
||||
ret = j.invoke(f, args)
|
||||
finally:
|
||||
__print_stdout()
|
||||
return ret
|
||||
|
||||
#Converts pythonlist or Java array to numpy array
|
||||
def to_npa(data, dimensions = None, type = None):
|
||||
if (not isinstance(data, PyArray)) or (type is not None):
|
||||
data = to_array(data,'d' if type is None else type)
|
||||
if dimensions is None:
|
||||
return jep.NDArray(data)
|
||||
return jep.NDArray(data, dimensions)
|
||||
|
||||
#recursivelly converts all NumPy arrays to Java arrys
|
||||
def rec_from_npa(obj):
|
||||
if isinstance(obj, jep.NDArray):
|
||||
ret = obj.data
|
||||
if len(obj.dimensions)>1:
|
||||
ret=Convert.reshape(ret, obj.dimensions)
|
||||
return ret
|
||||
if isinstance(obj, java.util.List) or isinstance(obj,tuple) or isinstance(obj,list):
|
||||
ret=[]
|
||||
for i in range(len(obj)):
|
||||
ret.append(rec_from_npa(obj[i]))
|
||||
if isinstance(obj,tuple):
|
||||
return type(ret)
|
||||
return ret
|
||||
if isinstance(obj, java.util.Map) or isinstance(obj,dict):
|
||||
ret = {} if isinstance(obj,dict) else java.util.HashMap()
|
||||
for k in obj.keys():
|
||||
ret[k] = rec_from_npa(obj[k])
|
||||
return ret
|
||||
return obj
|
||||
|
||||
#recursivelly converts all Java arrays to NumPy arrys
|
||||
def rec_to_npa(obj):
|
||||
if isinstance(obj, PyArray):
|
||||
dimensions = Arr.getShape(obj)
|
||||
if len(dimensions)>1:
|
||||
obj = Convert.flatten(obj)
|
||||
return to_npa(obj, dimensions = dimensions)
|
||||
if isinstance(obj, java.util.List) or isinstance(obj,tuple) or isinstance(obj,list):
|
||||
ret=[]
|
||||
for i in range(len(obj)):
|
||||
ret.append(rec_to_npa(obj[i]))
|
||||
if isinstance(obj,tuple):
|
||||
return tuple(ret)
|
||||
return ret
|
||||
if isinstance(obj, java.util.Map) or isinstance(obj,dict):
|
||||
ret = {} if isinstance(obj,dict) else java.util.HashMap()
|
||||
for k in obj.keys():
|
||||
ret[k] = rec_to_npa(obj[k])
|
||||
return ret
|
||||
return obj
|
||||
|
||||
def call_py(module, function, reload_function, *args, **kwargs):
|
||||
"""
|
||||
Calls a CPython function recursively crecursively converting Java arrays in arguments to NumPy,
|
||||
and NumPy arrays in return values to Java arrays.
|
||||
"""
|
||||
ret = call_jep(module, function, rec_to_npa(args), rec_to_npa(kwargs), reload=reload_function)
|
||||
return rec_from_npa(ret)
|
||||
|
||||
def import_py(module, function):
|
||||
"""
|
||||
Adds a CPython function to globals, creating a wrapper call to JEP, with
|
||||
recurvive convertion of Java arrays in arguments to NumPy arrays,
|
||||
and NumPy arrays in return values to Java arrays.
|
||||
"""
|
||||
def jep_wrapper(*args, **kwargs):
|
||||
reload_function = jep_wrapper.reload
|
||||
jep_wrapper.reload = False
|
||||
print module, function, reload_function
|
||||
return call_py(module, function, reload_function, *args, **kwargs)
|
||||
jep_wrapper.reload=True
|
||||
_get_caller().f_globals[function] = jep_wrapper
|
||||
return jep_wrapper
|
||||
|
||||
|
||||
|
||||
import_py("CPython/linfit", "linfit")
|
||||
import_py("CPython/gfitoff", "gfitoff")
|
||||
|
||||
x=[0,1,2,3,4,5,6,7,8,9]
|
||||
y=[1,2,3,6,9,6,3,2,1,0]
|
||||
(p, x_fit, y_fit, R2) = linfit(x,y)
|
||||
#print "Fit: ", (p, x_fit, y_fit, R2)
|
||||
plot((y,y_fit), name=("data", "fit"),xdata=(x,x_fit))
|
||||
|
||||
|
||||
from mathutils import Gaussian
|
||||
x=to_array([-200.30429237268825, -200.2650700434188, -200.22115208318002, -199.9457671375377, -199.86345548879072, -199.85213073174933, -199.35687977133284, -199.13811861090275, -197.97304970346386, -197.2952215624348, -195.09076092936948, -192.92276048970703, -191.96871876227698, -189.49577852322938, -187.9652790409825, -183.63756456925222, -180.04899765472996, -178.43839623242422, -174.07311671294445, -172.0410133577918, -165.90824309893102, -160.99771795989466, -159.30176653939253, -154.27688897558514, -152.0854103810786, -145.75652847587313, -140.80843828908465, -139.23982133191495, -134.27073891256106, -132.12649284133064, -125.95947209775511, -121.00309550337462, -119.26736932643232, -114.2706655484383, -112.07393889578914, -105.72295990367157, -100.8088439880125, -99.2034906238494, -94.30042325164636, -92.15010048151461, -85.92203653534293, -81.03913275494665, -79.27412793784428, -74.33487658582118, -72.06274362408762, -65.76562628131825, -60.91255356825276, -59.20334389560392, -54.33286972659312, -52.19387171350535, -45.94978737932291, -41.03014719193582, -39.301602568238906, -34.35572209014114, -32.04464301272608, -25.8221033382824, -20.922074315528747, -19.21590299233186, -14.31090212502093, -12.217203140101386, -5.9283722049240435, -0.9863587170369246, 0.7408048387279834, 5.71126832601389, 7.972628957879352, 14.204559894256546, 19.11839959633025, 20.8218087836657, 25.678748486941828, 27.822718344586864, 34.062659474970715, 38.9745656819391, 40.77409719734158, 45.72080631619803, 47.974156754056835, 54.23453768983539, 59.12020360609568, 60.77306570712026, 65.70734521458867, 67.8344660434617, 74.03187028154134, 78.96532114824849, 80.76070945985495, 85.74802197591286, 87.9140889204674, 94.18082276873524, 99.25790470037091, 100.68454787413205, 105.7213026221542, 107.79483801526698, 113.99555681638138, 119.0707052529143, 120.72715813056156, 125.77551384921307, 127.91257836719551, 134.2011330887875, 139.23043006997628, 140.71673537840158, 145.76288138835983, 147.80216629676042, 154.06420451405637, 159.0846626604798, 160.76183155710717, 165.73699067536242, 167.9265357747636, 173.96705069576544, 178.2522282751915, 179.9042617354548, 183.54586165856657, 185.23269803071796, 189.41678143751972, 191.87149157986588, 192.8741468985015, 195.0241934550453, 195.966634211846, 197.9821647518146, 198.99006812859284, 199.33202054855676, 199.91897441965887, 200.11536227958896, 200.22280936469997, 200.25181179127208],'d')
|
||||
y=to_array([11.0, 6.0, 8.0, 5.0, 11.0, 7.0, 18.0, 11.0, 12.0, 10.0, 8.0, 6.0, 16.0, 4.0, 12.0, 9.0, 15.0, 14.0, 8.0, 20.0, 15.0, 8.0, 9.0, 11.0, 13.0, 12.0, 13.0, 15.0, 13.0, 20.0, 10.0, 7.0, 17.0, 11.0, 20.0, 13.0, 13.0, 23.0, 14.0, 10.0, 17.0, 15.0, 20.0, 16.0, 14.0, 13.0, 18.0, 22.0, 9.0, 20.0, 12.0, 14.0, 17.0, 19.0, 14.0, 14.0, 23.0, 19.0, 15.0, 20.0, 20.0, 21.0, 20.0, 23.0, 22.0, 15.0, 10.0, 17.0, 21.0, 15.0, 23.0, 23.0, 25.0, 18.0, 16.0, 21.0, 22.0, 16.0, 16.0, 14.0, 19.0, 20.0, 18.0, 20.0, 23.0, 13.0, 16.0, 20.0, 25.0, 15.0, 15.0, 17.0, 22.0, 26.0, 19.0, 30.0, 25.0, 17.0, 17.0, 23.0, 16.0, 27.0, 21.0, 21.0, 26.0, 27.0, 21.0, 17.0, 20.0, 20.0, 21.0, 19.0, 25.0, 19.0, 13.0, 23.0, 20.0, 20.0, 18.0, 20.0, 19.0, 25.0],'d')
|
||||
[off, amp, com, sigma] = gfitoff(x, y, off=None, amp=None, com=None, sigma=None)
|
||||
#print "Fit: ", [off, amp, com, sigma]
|
||||
g = Gaussian(amp, com, sigma)
|
||||
plot([y, [g.value(i)+off for i in x]], ["data", "fit"], xdata = x)
|
||||
|
||||
|
||||
28
script/test/TestOphyd.py
Normal file
28
script/test/TestOphyd.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from jeputils import *
|
||||
|
||||
read_ophyd = import_py("CPython/Ophyd", "read")
|
||||
|
||||
|
||||
class Ophyd(Readable):
|
||||
def __init__(self, name):
|
||||
self.dev=name
|
||||
|
||||
def getName(self):
|
||||
return self.dev
|
||||
|
||||
def read(self):
|
||||
v = read_ophyd(self.name)
|
||||
if (v is None) or (len(v)==0):
|
||||
return None
|
||||
v = v[self.name]
|
||||
try:
|
||||
timestamp = int(v["timestamp"]*1000)
|
||||
except:
|
||||
timestamp = time.time()
|
||||
ret = TimestampedValue (v["value"], timestamp)
|
||||
return ret
|
||||
|
||||
|
||||
dets = [Ophyd("det1"), Ophyd("det2")]
|
||||
|
||||
tscan(dets, 10, 0.1)
|
||||
@@ -18,8 +18,7 @@
|
||||
<script>import time
|
||||
def process(x):
|
||||
time.sleep(0.1)
|
||||
#print "==>" + str(x.getValue())
|
||||
</script>
|
||||
#print "==>" + str(x.getValue())</script>
|
||||
</action>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="TESTIOC:TESTCALCOUT:Output" id="id348623"/>
|
||||
<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ScalarDetector" name="TESTIOC:TESTSINUS:SinCalc" id="id367393"/>
|
||||
|
||||
@@ -24,6 +24,6 @@ def process():
|
||||
</dimension>
|
||||
</scan>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlot" x="id278043" y="id348623 id367393"/>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="MatrixPlotArray" y="id278043" z="id980818" type="3D"/>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="MatrixPlotArray" y="id278043" z="id980818" type="2D"/>
|
||||
<visualization xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="LinePlotArray" y="id980818" maxSeries="2" offset="3" size="5"/>
|
||||
</configuration>
|
||||
|
||||
19
script/test/test_append_tiff.py
Normal file
19
script/test/test_append_tiff.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import javax.imageio.ImageIO as ImageIO
|
||||
|
||||
def get_file(index):
|
||||
scan = "/Users/gobbo_a/dev/pshell/config/home/data/2024_03/20240314/20240314_141635_console/scan 1/"
|
||||
return scan + ("det image_%04d.tiff" % (index))
|
||||
|
||||
images = []
|
||||
for i in range(4):
|
||||
filename = get_file(i)
|
||||
images.append(ImageIO.read(File(filename)))
|
||||
|
||||
combinedImage = BufferedImage(400, 200, BufferedImage.TYPE_INT_RGB);
|
||||
g = combinedImage.getGraphics();
|
||||
g.drawImage(images[0], 0, 0, None);
|
||||
g.drawImage(images[1], 200, 0, None);
|
||||
g.drawImage(images[2], 0, 100, None);
|
||||
g.drawImage(images[3], 200, 100, None);
|
||||
|
||||
ImageIO.write(combinedImage, "TIFF", File(get_file(5)));
|
||||
35
script/test/test_append_tiff2.py
Normal file
35
script/test/test_append_tiff2.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from ijutils import *
|
||||
|
||||
def get_file(index):
|
||||
scan = "/Users/gobbo_a/dev/pshell/config/home/data/2024_03/20240319/20240319_105604_TeztTiff/scan 1/"
|
||||
return scan + ("det image_%04d.tiff" % (index))
|
||||
|
||||
imgs_per_row=2
|
||||
imgs_per_col=2
|
||||
|
||||
images = []
|
||||
for i in range(4):
|
||||
filename = get_file(i)
|
||||
images.append(ImagePlus(filename))
|
||||
|
||||
proc=images[0].getProcessor()
|
||||
combined_image = ImagePlus("Combined Image", proc.createProcessor(proc.getWidth()*imgs_per_row, imgs_per_col * proc.getHeight()))
|
||||
|
||||
p=None
|
||||
for i in range(len(images)):
|
||||
proc = images[i].getProcessor()
|
||||
x,y = i%imgs_per_row, i/imgs_per_row
|
||||
combined_image.getProcessor().insert(proc, x * proc.getWidth(), y * proc.getHeight())
|
||||
|
||||
data = Convert.transpose(get_ip_array(combined_image))
|
||||
if p is None:
|
||||
p=plot(data, title="Combined")[0]
|
||||
else:
|
||||
p.getSeries(0).setData(data)
|
||||
time.sleep(1.0)
|
||||
|
||||
#plot(Convert.transpose(get_ip_array(combined_image)))
|
||||
#save_image(combined_image, get_file(6), "tiff")
|
||||
|
||||
|
||||
|
||||
78
script/test/test_direct_tiff_data.py
Normal file
78
script/test/test_direct_tiff_data.py
Normal file
@@ -0,0 +1,78 @@
|
||||
###################################################################################################
|
||||
#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 read.tolist()
|
||||
assert data1d==read.tolist()
|
||||
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 read.tolist()
|
||||
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 read.tolist()
|
||||
read =load_data(path,1)
|
||||
print read.tolist()
|
||||
|
||||
#Creating a INT dataset adding elements one by one
|
||||
path = "group/data4"
|
||||
create_dataset(path, 'i')
|
||||
for i in range(10):
|
||||
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 row in data2d:
|
||||
append_dataset(path, row)
|
||||
|
||||
|
||||
#Creating a Table (compund type)
|
||||
path = "group/data6"
|
||||
names = ["a", "b", "c", "d"]
|
||||
table_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, table_types, lenghts)
|
||||
for row in table:
|
||||
append_table(path, 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")
|
||||
|
||||
|
||||
27
script/test/test_metadata.py
Normal file
27
script/test/test_metadata.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from ijutils import *
|
||||
|
||||
|
||||
def before_read(position, scan):
|
||||
ProviderTIFF.setMetadata({"index": scan.recordIndex})
|
||||
|
||||
|
||||
num_images = 4
|
||||
r=tscan((sin, det.dataMatrix), num_images, 0.1, before_read=before_read)
|
||||
|
||||
data_folder = expand_path("{data}/" + r.path.replace(" | ", "/"))
|
||||
|
||||
imgs_per_row=2
|
||||
imgs_per_col=num_images/2
|
||||
|
||||
combined_image = None
|
||||
for i in range(num_images):
|
||||
filename = data_folder + ("/%s_%04d.tiff" % (det.dataMatrix.getName(),i,))
|
||||
img = ImagePlus(filename)
|
||||
proc=img.getProcessor()
|
||||
if not combined_image:
|
||||
combined_image = ImagePlus("Combined Image", proc.createProcessor(proc.getWidth()*imgs_per_row, imgs_per_col * proc.getHeight()))
|
||||
x,y = i%imgs_per_row, i/imgs_per_row
|
||||
combined_image.getProcessor().insert(proc, x * proc.getWidth(), y * proc.getHeight())
|
||||
|
||||
filename = data_folder + ("/%s_combined.tiff" % (det.dataMatrix.getName(),))
|
||||
save_image(combined_image, filename, "tiff", metadata={"index": -1})
|
||||
27
script/test/test_positioner.py
Normal file
27
script/test/test_positioner.py
Normal file
@@ -0,0 +1,27 @@
|
||||
class Test (PositionerBase):
|
||||
def __init__(self, name):
|
||||
PositionerBase.__init__(self, name, PositionerConfig())
|
||||
self.rbk = 0.0
|
||||
self.stp = 0.0
|
||||
self.moving = False
|
||||
|
||||
def doRead(self):
|
||||
return self.stp
|
||||
|
||||
def doWrite(self, value):
|
||||
if value!=self.stp:
|
||||
self.stp=value
|
||||
self.moving = True
|
||||
|
||||
def doReadReadback(self):
|
||||
if self.moving:
|
||||
off = self.stp - self.rbk
|
||||
if abs(off)<=1:
|
||||
self.rbk = self.stp
|
||||
self.moving = False
|
||||
else:
|
||||
self.rbk = self.rbk +1.0 if (self.stp > self.rbk) else self.rbk -1.0
|
||||
return self.rbk
|
||||
|
||||
add_device(Test("test_positioner"), True)
|
||||
test_positioner.polling=1000
|
||||
@@ -3,17 +3,20 @@ url="tcp://localhost:9999"
|
||||
|
||||
st1 = Stream("st1", url, SocketType.PULL)
|
||||
#st1.parent.config.headerReservingAllocator = True
|
||||
st1.parent.config.analizeHeader = False
|
||||
|
||||
|
||||
st1.initialize()
|
||||
st1.start()
|
||||
st1.waitCacheChange(60000)
|
||||
|
||||
|
||||
#show_panel(st1)
|
||||
|
||||
|
||||
add_device(st1)
|
||||
try:
|
||||
bscan (st1, 5, 5, save=False)
|
||||
#bscan (st1, 5, 5, save=False)
|
||||
#show_panel(st1)
|
||||
pass
|
||||
finally:
|
||||
st1.close()
|
||||
#p.close()
|
||||
#st1.close()
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
16
script/test/test_tiff_3d.py
Normal file
16
script/test/test_tiff_3d.py
Normal file
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
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 read.tolist()
|
||||
read =load_data(path,1)
|
||||
print read.tolist()
|
||||
|
||||
"""
|
||||
|
||||
#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)
|
||||
Reference in New Issue
Block a user