From 0b8ceb6cf0d1c0c09fe047bba5f83cdd0721cd7b Mon Sep 17 00:00:00 2001 From: gobbo_a Date: Thu, 23 Oct 2025 16:33:17 +0200 Subject: [PATCH] --- config/Lock.dat | 1 + config/config.properties | 54 ++++----- config/preferences.json | 5 +- config/variables.properties | 8 +- config/xscan.properties | 4 +- devices/Time.properties | 11 ++ devices/im1_0001.tiff.properties | 20 ++++ devices/motor.properties | 17 +++ devices/positioner.properties | 10 ++ devices/resized.tiff.properties | 20 ++++ devices/scan_1_src1_0001.tiff.properties | 20 ++++ devices/src1_0000.tiff.properties | 20 ++++ devices/src1_0001.tiff.properties | 20 ++++ devices/src1_0002.tiff.properties | 20 ++++ script/cpython.py | 51 +++++++++ script/local.py | 20 ++++ script/startup_c.py | 139 +++++++++++++++++++++++ script/test_async_scan.py | 12 ++ script/test_bg_scan.py | 11 ++ script/test_cpy.py | 16 +++ script/test_cpy2.py | 12 ++ script/test_data.py | 79 +++++++++++++ script/test_data_txt.py | 12 ++ script/test_invalidate.py | 32 ++++++ script/test_jep.py | 88 ++++++++++++++ script/test_list.py | 9 ++ script/test_nested.py | 10 ++ script/test_next.py | 3 + script/test_scan.py | 10 ++ script/test_scan2.py | 15 +++ script/test_scan3.py | 4 + script/test_scan4.py | 4 + script/test_sleep.py | 2 + script/test_stack.py | 3 + 34 files changed, 729 insertions(+), 33 deletions(-) create mode 100644 config/Lock.dat create mode 100644 devices/Time.properties create mode 100644 devices/im1_0001.tiff.properties create mode 100644 devices/motor.properties create mode 100644 devices/positioner.properties create mode 100644 devices/resized.tiff.properties create mode 100644 devices/scan_1_src1_0001.tiff.properties create mode 100644 devices/src1_0000.tiff.properties create mode 100644 devices/src1_0001.tiff.properties create mode 100644 devices/src1_0002.tiff.properties create mode 100644 script/cpython.py create mode 100644 script/startup_c.py create mode 100644 script/test_async_scan.py create mode 100644 script/test_bg_scan.py create mode 100644 script/test_cpy.py create mode 100644 script/test_cpy2.py create mode 100644 script/test_data.py create mode 100644 script/test_data_txt.py create mode 100644 script/test_invalidate.py create mode 100644 script/test_jep.py create mode 100644 script/test_list.py create mode 100644 script/test_nested.py create mode 100644 script/test_next.py create mode 100644 script/test_scan.py create mode 100644 script/test_scan2.py create mode 100644 script/test_scan3.py create mode 100644 script/test_scan4.py create mode 100644 script/test_sleep.py create mode 100644 script/test_stack.py diff --git a/config/Lock.dat b/config/Lock.dat new file mode 100644 index 0000000..6db00aa --- /dev/null +++ b/config/Lock.dat @@ -0,0 +1 @@ +74573@ag.psi.ch \ No newline at end of file diff --git a/config/config.properties b/config/config.properties index 46e2543..9d4e353 100644 --- a/config/config.properties +++ b/config/config.properties @@ -1,20 +1,19 @@ -#Wed Aug 13 10:30:52 CEST 2025 +#Thu Oct 09 08:44:46 CEST 2025 autoSaveScanData=true +commandBusSize=-1 +commandBusTimeToLive=600000 +commandQueueSize=-1 +commandStatistics=false +commandTimeToLive=600000 +commandsQueueSize=-1 +commandsSaveStatistics=false +commandsTimeToLive=600000 +consoleJournal=false dataDepthDimension=0 +dataEmbeddedAttributes=false dataFormat=h5 -dataLayout=default +dataLayout=table dataPath={data}/{year}_{month}/{date}/{date}_{time}_{name} -dataScanAutoSave=true -dataScanFlushRecords=false -dataScanLazyTableCreation=false -dataScanPreserveTypes=false -dataScanReleaseRecords=false -dataScanSaveLogs=true -dataScanSaveOutput=false -dataScanSaveScript=false -dataScanSaveSetpoints=false -dataScanSaveTimestamps=false -dataScanStreamerPort=-1 dataServerPort=-1 dataTransferMode=Off dataTransferPath= @@ -23,42 +22,45 @@ depthDimension=0 disableDataFileLogs=false disableEmbeddedAttributes=false fdaSerialization=true -filePermissionsConfig=Default +filePermissionsConfig=Public filePermissionsData=Default -filePermissionsLogs=Default -filePermissionsScripts=Default +filePermissionsLogs=Public +filePermissionsScripts=Public hideServerMessages=false hostName= instanceName= -logDaysToLive=-1 -logLevel=Info +logDaysToLive=7 +logLevel=Fine logLevelConsole=Off -logPath={logs}/{date}_{time} +logPath={logs}/{date}_{time}.{mode} noBytecodeFiles=false notificationLevel=Off notificationTasks= notifiedTasks= parallelInitialization=false -pythonHome= +pythonHome=/Users/gobbo_a/dev/pshell/config/dev/python-3.13.7 pythonNoBytecodeFiles=false -saveCommandStatistics=false +saveCommandStatistics=true saveConsoleSessionFiles=false +scanAutoSave=true +scanDefaultTag=null scanFlushRecords=false scanLazyTableCreation=false scanPreserveTypes=false scanReleaseRecords=false scanSaveLogs=true -scanSaveOutput=false -scanSaveScript=false -scanSaveSetpoints=false +scanSaveMeta=true +scanSaveOutput=true +scanSaveScript=true +scanSaveSetpoints=true scanSaveTimestamps=false scanStreamerPort=-1 serverCommandsHidden=true -serverEnabled=false +serverEnabled=true serverHostName=null serverLight=true serverPort=8080 -sessionHandling=On +sessionHandling=Off simulation=false terminalEnabled=false terminalPort=3579 diff --git a/config/preferences.json b/config/preferences.json index 5ef937e..ee0520c 100644 --- a/config/preferences.json +++ b/config/preferences.json @@ -37,7 +37,7 @@ "fontTerminal" : { "name" : "Menlo", "style" : 0, - "size" : 14 + "size" : 12 }, "tabSize" : 4, "contentWidth" : 0, @@ -56,8 +56,7 @@ "scanPlotDisabled" : false, "scanTableDisabled" : false, "cachedDataPanel" : false, - "dataExtensions" : "h5 xml txt", - "dataSubFiles" : "", + "dataVisibleFiles" : "*", "showEmergencyStop" : false, "showHomingButtons" : false, "showJogButtons" : false, diff --git a/config/variables.properties b/config/variables.properties index dde5e87..a7f181a 100644 --- a/config/variables.properties +++ b/config/variables.properties @@ -1,4 +1,6 @@ -#Mon Aug 04 10:16:18 CEST 2025 +#Tue Oct 21 16:12:23 CEST 2025 +=2 DaySequentialNumber=1 -FileSequentialNumber=472 -LastRunDate=250804 +FileSequentialNumber=1797 +LastRunDate=251021 +r=2 diff --git a/config/xscan.properties b/config/xscan.properties index 7a61cc6..b5124e6 100644 --- a/config/xscan.properties +++ b/config/xscan.properties @@ -1,4 +1,4 @@ -#Thu Jun 12 14:01:18 CEST 2025 +#Wed Oct 08 16:10:12 CEST 2025 appendSuffix=true channelCreationRetries=1 continuousUpdate=false @@ -7,8 +7,10 @@ crlogicChannel= crlogicIoc= crlogicPrefix= crlogicSimulated=false +dataEmbeddedAttributes=false dataFormat=null dataLayout=null dataPath=null fdaSerialization=false moveTimeout=600 +txtSerialization=false diff --git a/devices/Time.properties b/devices/Time.properties new file mode 100644 index 0000000..244cae7 --- /dev/null +++ b/devices/Time.properties @@ -0,0 +1,11 @@ +#Wed Sep 10 08:56:16 CEST 2025 +description=null +maxValue=NaN +minValue=NaN +offset=0.0 +precision=-1 +resolution=NaN +rotation=false +scale=1.0 +sign_bit=0 +unit=null diff --git a/devices/im1_0001.tiff.properties b/devices/im1_0001.tiff.properties new file mode 100644 index 0000000..407cd20 --- /dev/null +++ b/devices/im1_0001.tiff.properties @@ -0,0 +1,20 @@ +#Wed Sep 24 17:32:30 CEST 2025 +flipHorizontally=false +flipVertically=false +grayscale=false +invert=false +rescaleFactor=1.0 +rescaleOffset=0.0 +roiHeight=-1 +roiWidth=-1 +roiX=0 +roiY=0 +rotation=0.0 +rotationCrop=false +scale=1.0 +spatialCalOffsetX=NaN +spatialCalOffsetY=NaN +spatialCalScaleX=NaN +spatialCalScaleY=NaN +spatialCalUnits=mm +transpose=false diff --git a/devices/motor.properties b/devices/motor.properties new file mode 100644 index 0000000..87c32ab --- /dev/null +++ b/devices/motor.properties @@ -0,0 +1,17 @@ +#Tue Sep 09 10:03:52 CEST 2025 +defaultSpeed=1.0 +description=null +estbilizationDelay=0 +maxSpeed=10.0 +maxValue=10.0 +minSpeed=0.1 +minValue=-10.0 +monitorByPosition=false +offset=0.0 +precision=2 +resolution=NaN +rotation=false +scale=1.0 +sign_bit=0 +startRetries=1 +unit=mm diff --git a/devices/positioner.properties b/devices/positioner.properties new file mode 100644 index 0000000..a7f9256 --- /dev/null +++ b/devices/positioner.properties @@ -0,0 +1,10 @@ +#Wed Sep 10 09:10:57 CEST 2025 +description=Test Calcout Output +maxValue=1000.0 +minValue=-1000.0 +offset=0.0 +precision=5 +resolution=Infinity +scale=1.0 +sign_bit=0 +unit=mm diff --git a/devices/resized.tiff.properties b/devices/resized.tiff.properties new file mode 100644 index 0000000..39d24be --- /dev/null +++ b/devices/resized.tiff.properties @@ -0,0 +1,20 @@ +#Wed Sep 24 17:33:53 CEST 2025 +flipHorizontally=false +flipVertically=false +grayscale=false +invert=false +rescaleFactor=1.0 +rescaleOffset=0.0 +roiHeight=-1 +roiWidth=-1 +roiX=0 +roiY=0 +rotation=0.0 +rotationCrop=false +scale=1.0 +spatialCalOffsetX=NaN +spatialCalOffsetY=NaN +spatialCalScaleX=NaN +spatialCalScaleY=NaN +spatialCalUnits=mm +transpose=false diff --git a/devices/scan_1_src1_0001.tiff.properties b/devices/scan_1_src1_0001.tiff.properties new file mode 100644 index 0000000..0219a5c --- /dev/null +++ b/devices/scan_1_src1_0001.tiff.properties @@ -0,0 +1,20 @@ +#Wed Sep 24 17:15:16 CEST 2025 +flipHorizontally=false +flipVertically=false +grayscale=false +invert=false +rescaleFactor=1.0 +rescaleOffset=0.0 +roiHeight=-1 +roiWidth=-1 +roiX=0 +roiY=0 +rotation=0.0 +rotationCrop=false +scale=1.0 +spatialCalOffsetX=NaN +spatialCalOffsetY=NaN +spatialCalScaleX=NaN +spatialCalScaleY=NaN +spatialCalUnits=mm +transpose=false diff --git a/devices/src1_0000.tiff.properties b/devices/src1_0000.tiff.properties new file mode 100644 index 0000000..3785676 --- /dev/null +++ b/devices/src1_0000.tiff.properties @@ -0,0 +1,20 @@ +#Wed Sep 24 17:24:53 CEST 2025 +flipHorizontally=false +flipVertically=false +grayscale=false +invert=false +rescaleFactor=1.0 +rescaleOffset=0.0 +roiHeight=-1 +roiWidth=-1 +roiX=0 +roiY=0 +rotation=0.0 +rotationCrop=false +scale=1.0 +spatialCalOffsetX=NaN +spatialCalOffsetY=NaN +spatialCalScaleX=NaN +spatialCalScaleY=NaN +spatialCalUnits=mm +transpose=false diff --git a/devices/src1_0001.tiff.properties b/devices/src1_0001.tiff.properties new file mode 100644 index 0000000..5018915 --- /dev/null +++ b/devices/src1_0001.tiff.properties @@ -0,0 +1,20 @@ +#Wed Sep 24 17:15:28 CEST 2025 +flipHorizontally=false +flipVertically=false +grayscale=false +invert=false +rescaleFactor=1.0 +rescaleOffset=0.0 +roiHeight=-1 +roiWidth=-1 +roiX=0 +roiY=0 +rotation=0.0 +rotationCrop=false +scale=1.0 +spatialCalOffsetX=NaN +spatialCalOffsetY=NaN +spatialCalScaleX=NaN +spatialCalScaleY=NaN +spatialCalUnits=mm +transpose=false diff --git a/devices/src1_0002.tiff.properties b/devices/src1_0002.tiff.properties new file mode 100644 index 0000000..0c86e23 --- /dev/null +++ b/devices/src1_0002.tiff.properties @@ -0,0 +1,20 @@ +#Wed Sep 24 17:15:27 CEST 2025 +flipHorizontally=false +flipVertically=false +grayscale=false +invert=false +rescaleFactor=1.0 +rescaleOffset=0.0 +roiHeight=-1 +roiWidth=-1 +roiX=0 +roiY=0 +rotation=0.0 +rotationCrop=false +scale=1.0 +spatialCalOffsetX=NaN +spatialCalOffsetY=NaN +spatialCalScaleX=NaN +spatialCalScaleY=NaN +spatialCalUnits=mm +transpose=false diff --git a/script/cpython.py b/script/cpython.py new file mode 100644 index 0000000..858028f --- /dev/null +++ b/script/cpython.py @@ -0,0 +1,51 @@ +################################################################################################### +# This moddule is called by demo scripts to execute and embed CPython. +# Must be put in the scripts folder, or else in the python path. +################################################################################################### +import numpy as np + + +def linfit(x, y): + """ + Return linear fit + """ + print(1, type(x), type(y), x, y) + p = np.polyfit(x, y, 1) + f = np.poly1d(p) + x_fit = np.linspace(min(x), max(x), 100) + y_fit = f(x_fit) + yhat = f(x) + ybar = np.sum(y)/len(y) + ssreg = np.sum((yhat - ybar)**2) + sstot = np.sum((y - ybar)**2) + R2 = ssreg / sstot + return (p, x_fit, y_fit, R2) + +def test(): + return np.ones(5) + + +def test2(name, x=None, y=None, **kwargs): + print (name,x,y) + ret = y*x + print (ret) + print(kwargs.get("z", 0.0)) + return ret + +def add(x,y,z): + return x+y+z + +def read_dev(dev): + return dev.read() + + + +def print_dict(d): + for k in d.keys(): + print (k, d[k]) + ret = {} + ret.update(d) + return ret + +def get_tuple(): + return (1,2,3) \ No newline at end of file diff --git a/script/local.py b/script/local.py index fafc516..2078650 100644 --- a/script/local.py +++ b/script/local.py @@ -166,6 +166,10 @@ rw1 = ReadableWaveform() ri1 = ReadableImage() +av = create_averager(ai2, 5, 0.05, name="av1") +av.setMonitored(True) +add_device(av, True) + #################################################################################################### # Imaging #################################################################################################### @@ -188,3 +192,19 @@ if not configured: + + +test_bg_scan_state = State.Ready +test_bg_scan_result = None + + +if get_context().isServerEnabled(): + #CAS.setServerPort(5062) + add_device(EpicsServerUrl("epics_server_url_old", "PSHELL_OP:SERVER_URL"), True) #TODO: Change dependencies to "SF-PSHELL_OP:SERVER_URL and remove + add_device(EpicsServerUrl("epics_server_url", "SF-PSHELL_OP:SERVER_URL"), True) + add_device(EpicsServerState("epics_server_state", "SF-PSHELL_OP:STATE"), True) + add_device(EpicsCmdAPI("epics_cmd", "SF-PSHELL_OP:CMD", as_string=False), True) + add_device(EpicsCmdAPI("epics_cmd_bg", "SF-PSHELL_OP:CMD_BG", as_string=False, background=True), True) + add_device(EpicsCmdAPI("epics_cmd_str", "SF-PSHELL_OP:CMD_STR", as_string=True), True) + add_device(EpicsCmdAPI("epics_cmd_str_bg", "SF-PSHELL_OP:CMD_STR_BG", as_string=True, background=True), True) + diff --git a/script/startup_c.py b/script/startup_c.py new file mode 100644 index 0000000..675771f --- /dev/null +++ b/script/startup_c.py @@ -0,0 +1,139 @@ + + + +################################################################################################### +#Utilities +################################################################################################### + +def get_setting(name=None): + """Get a persisted script setting value. + + Args: + name (str): name of the setting. + Returns: + String with setting value or None if setting is undefined. + If name is None then returns map with all settings. + """ + return Context.getSettings() if (name is None) else Context.getSetting(name) + +def set_setting(name, value): + """Set a persisted script setting value. + + Args: + name (str): name of the setting. + value (obj): value for the setting, converted to string (if None then remove the setting). + Returns: + None. + """ + Context.setSetting(name, value) + +def exec_cmd(cmd, stderr_raise_ex = True): + """Executes a shell command. If errors happens raises an exception. + + Args: + cmd (str or list of str): command process input and parameters. If stderr_raise_ex is set then raise exception if stderr is not null. + Returns: + Output of command process. + """ + import subprocess + result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE if stderr_raise_ex else subprocess.STDOUT) + ret=result.stdout.decode('utf-8') + err=result.stderr.decode('utf-8') + if stderr_raise_ex and (err is not None) and err!="": + raise Exception(err) + return ret + +def bsget(channel, modulo=1, offset=0, timeout = 5.0): + """Reads an values a bsread stream, using the default provider. + + Args: + channel(str or list of str): channel name(s) + module(int, optional): stream modulo + offset(int, optional): stream offset + timeout(float, optional): stream timeout in secs + Returns: + BS value or list of values + """ + channels = to_list(channel) + ret = Stream.readChannels(channels, modulo, offset, int(timeout * 1000)) + if is_string(channel): + return ret[0] + return ret + +def flatten(data): + """Flattens multi-dimentional or nested data. + + Args: + data (tuple, array, List or Array): input data + Returns: + Iterator on the flattened data. + """ + if is_array(data): + if not data.typecode.startswith('['): + return data + + import itertools + return itertools.chain(*data) + +def frange_gen(start, finish, step): + while ((step >= 0.0) and (start <= finish)) or ((step < 0.0) and (start >= finish)): + yield start + start += step + +def frange(start, finish, step, enforce_finish = False, inclusive_finish = False): + """Create a list with a range of float values (a float equivalent to "range"). + + Args: + start(float): start of range. + finish(float): end of range. + step(float): step size. + enforce_finish(boolean, optional): adds the final element even if range was not exact. + inclusive_finish(boolean, optional): if false finish is exclusive (like in "range"). + + Returns: + list + """ + step = float(step) + ret = list(frange_gen(start, finish, step)) + if len(ret) > 0: + if inclusive_finish == False: + if ret[-1]==finish: + del ret[-1] + if enforce_finish and ret[-1]!=finish: + ret.append(finish) + return ret + +def notify(subject, text, attachments = None, to=None): + """Send email message. + + Args: + subject(str): Message subject. + text(str): Message body. + attachments(list of str, optional): list of files to be attached (expansion tokens are allowed). + to (list ofd str, optional): recipients. If None uses the recipients defined in mail.properties. + Returns: + None + """ + Context.notify(subject, text, to_list(attachments), to_list(to)) + +def expand_path(path, timestamp=-1): + """Expand path containing tokens. + + Args: + path(str): path name. + timestamp(int): If not defined(-1), uses now. + Returns: + Expanded path name. + """ + + return Setup.expandPath(path, timestamp) + +def send_event(name, value=True): + """Send an interpreter event, which is propagated as a SSE. + + Args: + name(str): event name. + value(Object): event value. + """ + get_interpreter().sendEvent(name, value) + diff --git a/script/test_async_scan.py b/script/test_async_scan.py new file mode 100644 index 0000000..3f50422 --- /dev/null +++ b/script/test_async_scan.py @@ -0,0 +1,12 @@ +test_async_scan_state.assertReady() +test_async_scan_state = State.Busy +test_async_scan_result = None + +try: + r1 = lscan(ao1, (ai1,av1,wf1), 0, 40, 100, 0.05) + test_async_scan_result = "Ok" +except Exception as ex: + test_async_scan_result = str(ex) +finally: + test_async_scan_state = State.Ready + \ No newline at end of file diff --git a/script/test_bg_scan.py b/script/test_bg_scan.py new file mode 100644 index 0000000..38a2a6f --- /dev/null +++ b/script/test_bg_scan.py @@ -0,0 +1,11 @@ +test_bg_scan_state.assertReady() +test_bg_scan_state = State.Busy +test_bg_scan_result = None + +try: + r1 = lscan(ao1, (ai1,av1,wf1), 0, 40, 100, 0.05) + test_bg_scan_result = "Ok" +except: + test_bg_scan_result = str(sys.exc_info()[1]) +finally: + test_bg_scan_state = State.Ready diff --git a/script/test_cpy.py b/script/test_cpy.py new file mode 100644 index 0000000..2b04fa6 --- /dev/null +++ b/script/test_cpy.py @@ -0,0 +1,16 @@ +from jeputils import import_py + +import_py("cpython", "test") +import_py("cpython", "add") +import_py("cpython", "linfit") + + +print (test()) + +print (add(1,2,3)) + +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)) diff --git a/script/test_cpy2.py b/script/test_cpy2.py new file mode 100644 index 0000000..542581c --- /dev/null +++ b/script/test_cpy2.py @@ -0,0 +1,12 @@ +from jeputils import * +import ch.psi.pshell.utils.Convert as Convert +a = call_jep("numpy", "ones", [[400,200],'d']) + +while(True): + b = call_jep("numpy", "ones", [[400,200],'d']) + a = call_jep("cpython", "add", [a,b]) + s = call_jep("cpython", "sum", [a,]) + print a.getData()[0], s + sleep(0.01) + + diff --git a/script/test_data.py b/script/test_data.py new file mode 100644 index 0000000..a658964 --- /dev/null +++ b/script/test_data.py @@ -0,0 +1,79 @@ +################################################################################################### +#Data Manipulation: Using the data access API to generate and retrieve data +################################################################################################### + +FormatTIFF.setParallelWriting(False) +#Creating a 1D dataset from an array +print "---- 1 -------" +path="group/data1" +data1d = [1.0, 2.0, 3.0, 4.0, 5.0] +save_dataset(path, data1d) +flush_data() +#Reading ii back +read =load_data(path) +print read.tolist() +assert data1d==read.tolist() +plot(read) +set_attribute(path, "AttrString", "Value") +set_attribute(path, "AttrInteger", 1) +set_attribute(path, "AttrDouble", 2.0) +set_attribute(path, "AttrBoolean", True) + +#Creating a 2D dataset from an array with some attributes +print "---- 2 -------" +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 +print "---- 3 -------" +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() +set_attribute(path, "AttrString", "Value") +set_attribute(path, "AttrInteger", 1) +set_attribute(path, "AttrDouble", 2.0) +set_attribute(path, "AttrBoolean", True) + +#Creating a 2D dataset adding lines one by one +print "---- 4 -------" +path = "group/data4" +create_dataset(path, 'd', False, (0,0)) +for row in data2d: + append_dataset(path, row) +read =load_data(path) +print read.tolist() +plot(read) +set_attribute(path, "AttrString", "Value") +set_attribute(path, "AttrInteger", 1) +set_attribute(path, "AttrDouble", 2.0) +set_attribute(path, "AttrBoolean", True) + +#Creating a 3D dataset adding images one by one +print "---- 5 -------" +path = "group/data5" +create_dataset(path, 'd', False, (0,0,0)) +for i in range(len(data3d)): + append_dataset(path,data3d[i]) + +read =load_data(path,0) +print read.tolist() +read =load_data(path,1) +print read.tolist() +set_attribute(path, "AttrString", "Value") +set_attribute(path, "AttrInteger", 1) +set_attribute(path, "AttrDouble", 2.0) +set_attribute(path, "AttrBoolean", True) diff --git a/script/test_data_txt.py b/script/test_data_txt.py new file mode 100644 index 0000000..5a4afef --- /dev/null +++ b/script/test_data_txt.py @@ -0,0 +1,12 @@ +#set_exec_pars(format="txt") +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/data4" +create_dataset(path, 'd', False, (0,0)) +for row in data2d: + append_dataset(path, row) +read =load_data(path) +print read.tolist() +plot(read) +set_return(True) \ No newline at end of file diff --git a/script/test_invalidate.py b/script/test_invalidate.py new file mode 100644 index 0000000..f30df9c --- /dev/null +++ b/script/test_invalidate.py @@ -0,0 +1,32 @@ +mot=DummyMotor("motor") +reg= DummyRegister("register") +mot.initialize() +reg.initialize() +beam_ok = True + + + +def is_beam_ok(): + return beam_ok + +def wait_beam(): + if not is_beam_ok(): + print "Waiting for beam..." + while not is_beam_ok(): + time.sleep(0.1) + print "Beam ok" + + +def before_read(pos, scan): + wait_beam() + #... + +def after_read(rec, scan): + if not is_beam_ok(): + print "Beam is down invalidating record ", rec.index, " at position ", rec.setpoints + rec.invalidate() + return + #... + + +a= lscan(mot, reg, 0.0, 10.0, 0.1, latency=0.1, before_read=before_read, after_read=after_read) \ No newline at end of file diff --git a/script/test_jep.py b/script/test_jep.py new file mode 100644 index 0000000..131e1a3 --- /dev/null +++ b/script/test_jep.py @@ -0,0 +1,88 @@ +################################################################################################### +# 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. + +from jeputils import * + +#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): + if sys.version_info < (3,0) : + exec("print >> sys.stderr, '" + str + "'") + else: + exec("print ('" + str + "', file=sys.stderr)") +""") + +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[ai1] +a = to_npa(data, dims,'d') +print a.getDimensions() +print a.getData() +plot( Convert.reshape(a.getData(),a.getDimensions()),title="Scan Data") + +#Calling a module function +b = call_jep("numpy", "transpose", [a,]) +print b.getDimensions() +print b.getData() +plot( Convert.reshape(b.getData(),b.getDimensions()),title="Transposed") + + +#More calculations calling numpy +a = call_jep("numpy", "ones", [to_array([400,200]),'d']) +for i in range (100): + b = call_jep("numpy", "ones", [to_array([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, dims = [1,2,3,4,5,6,7,8,9,0], [2,5] +array = to_npa(data, dims,'d') #Auxiliary function to create numpy arrays from lists or java arrays. +ret = call_jep("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") + diff --git a/script/test_list.py b/script/test_list.py new file mode 100644 index 0000000..2260324 --- /dev/null +++ b/script/test_list.py @@ -0,0 +1,9 @@ + +a = [1,2,3] +d = to_array(a) +l=to_list(d) + +print (a) +print (l) +print (type(a)==type(l)) +print (a==l) diff --git a/script/test_nested.py b/script/test_nested.py new file mode 100644 index 0000000..ca17f98 --- /dev/null +++ b/script/test_nested.py @@ -0,0 +1,10 @@ +run("test_data_txt") +time.sleep(0.5) +run("test_data_txt") +time.sleep(0.5) +run("test_data_txt") +time.sleep(0.5) +run("test_data_txt") +time.sleep(0.5) +run("test_data_txt") +set_return(True) \ No newline at end of file diff --git a/script/test_next.py b/script/test_next.py new file mode 100644 index 0000000..8cdfaf0 --- /dev/null +++ b/script/test_next.py @@ -0,0 +1,3 @@ +import java.io.File + +App.getInstance().evalFileNext(java.io.File("test_next")) \ No newline at end of file diff --git a/script/test_scan.py b/script/test_scan.py new file mode 100644 index 0000000..5ff3ab9 --- /dev/null +++ b/script/test_scan.py @@ -0,0 +1,10 @@ +set_exec_pars(layout="table", open=True) +print "Scan 1" +r1 = lscan(ao1, (ai1,av1,wf1), 0, 40, 100, 0.01) +print "Scan 2" +r2 = lscan(m1, (m1.setpoint, ai1,ai2, av1), 0, 0.1, 10, relative=True) +print "Scan 3" +r3 = lscan(m1, (m1.setpoint, ai1, av1), 0, 0.1, 10, relative=True, diags = (ao1, ao2), snaps = (wf1,), monitors=(ai2,)) +if get_data_manager().getFormat().id == "tiff": + print "Scan 4" + r4 = lscan((ao1,ao2), (ai1,av1,wf1,im1), (0, 0), (40, 100), 4, 0.01) diff --git a/script/test_scan2.py b/script/test_scan2.py new file mode 100644 index 0000000..1bd6e94 --- /dev/null +++ b/script/test_scan2.py @@ -0,0 +1,15 @@ +run("test_data_txt") +#set_exec_pars(layout="default", open=True , meta = {"a":1}, then="run('test_sleep')") +print "Scan 1" +set_exec_pars(layout="default", open=True , meta = {"a":1}) + +r1 = lscan(ao1, (ai1,av1,wf1), 0, 40, 100, 0.01, meta=False) +#print "Scan 2" +#r2 = lscan(m1, (m1.setpoint, ai1,ai2, av1), 0, 0.1, 10, relative=True, meta = {"a":2}) +#print "Scan 3" +#r4 = lscan(m1, (m1.setpoint, ai1, av1), 0, 0.1, 10, relative=True, diags = (reg1, p1), snaps = (wf1,), monitors=(ai2,), meta = {"b":2}) +#print "Scan 4" +#r3 = lscan((ao1,ao2), (ai1,av1,wf1,im1), (0, 0), (40, 100), 4, 0.01) +#lscan((ao1,ao2), (ai1,av1,wf1,im1), (0, 0), (40, 100), 4, 0.01, depth_dim=2) + +set_return(r1) \ No newline at end of file diff --git a/script/test_scan3.py b/script/test_scan3.py new file mode 100644 index 0000000..a85d2e6 --- /dev/null +++ b/script/test_scan3.py @@ -0,0 +1,4 @@ +set_exec_pars(layout="table") + +r1 = lscan(m1, (ai1,ai2,wf1), 0, 0.1, 10, relative=True) +r1 = lscan(m1, (m1.readback, ai1,ai2,wf1), 0, 0.1, 10, relative=True) \ No newline at end of file diff --git a/script/test_scan4.py b/script/test_scan4.py new file mode 100644 index 0000000..b62afe8 --- /dev/null +++ b/script/test_scan4.py @@ -0,0 +1,4 @@ +set_exec_pars(layout="default") + +r1 = lscan(m1, (ai1,ai2,wf1), 0, 0.1, 10, relative=True) +r1 = lscan(m1, (m1.readback, ai1,ai2,wf1), 0, 0.1, 10, relative=True) \ No newline at end of file diff --git a/script/test_sleep.py b/script/test_sleep.py new file mode 100644 index 0000000..dfc95b4 --- /dev/null +++ b/script/test_sleep.py @@ -0,0 +1,2 @@ +print "Sleeping" +sleep(1.0) diff --git a/script/test_stack.py b/script/test_stack.py new file mode 100644 index 0000000..3300923 --- /dev/null +++ b/script/test_stack.py @@ -0,0 +1,3 @@ +set_exec_pars(layout="table") +#tscan((ai1, src1.dataMatrix), 5, 0.1) +tscan((ai1, src1.dataMatrix), 5, 0.1, stack=True) \ No newline at end of file