From 3093557c99fdfa18462fc97b906119cde4eee7f1 Mon Sep 17 00:00:00 2001 From: gobbo_a Date: Mon, 10 Jun 2024 10:44:16 +0200 Subject: [PATCH] Jun 2024 --- config/config.properties | 6 +- config/devices.properties | 5 +- config/diffcalc/test.json | 29 +- config/plugins.properties | 4 + config/preferences.json | 9 +- config/sessions.properties | 3 +- config/setup.properties | 45 +-- config/variables.properties | 8 +- ...240314_115334_console_0000.tiff.properties | 20 ++ devices/CurrentCamera.properties | 12 +- devices/cam_server.properties | 10 +- devices/data2_0000.tiff.properties | 20 ++ devices/data3.tiff.properties | 20 ++ devices/data3_0000.tiff.properties | 20 ++ devices/det image_0000.tiff.properties | 20 ++ devices/det image_0001.tiff.properties | 20 ++ devices/det image_0002.tiff.properties | 20 ++ devices/det image_0005.tiff.properties | 20 ++ devices/det image_0006.tiff.properties | 20 ++ devices/det image_combined.tiff.properties | 20 ++ devices/h.properties | 3 +- devices/hkl_group.properties | 3 +- devices/im1.properties | 17 + devices/k.properties | 3 +- devices/l.properties | 3 +- devices/pe2.properties | 11 + devices/positioner.properties | 15 +- devices/scan 1output.tiff.properties | 20 ++ devices/scanner.properties | 3 +- devices/stack_0000.tiff.properties | 20 ++ devices/stack_0001.tiff.properties | 20 ++ devices/test_cfg.properties | 11 +- devices/test_positioner.properties | 11 + devices/testdev.properties | 5 + devices/tst.tiff.properties | 20 ++ plugins/DemoScan.form | 115 +++++++ plugins/DemoScan.java | 163 ++++++++++ plugins/PanelPlugin.form | 100 +++--- plugins/PanelPlugin.java | 92 ++++-- plugins/Scan.form | 115 +++++++ plugins/Scan.java | 162 ++++++++++ plugins/X.form | 28 ++ plugins/X.java | 98 ++++++ script/.DS_Store | Bin 30724 -> 30724 bytes script/BugReadCharWaveformasString.py | 2 +- script/DemoScan.py | 64 ++++ script/DemoScans.py | 102 ++++++ script/TeztTiff.py | 24 ++ script/cpy/Ophyd.py | 3 + script/cpy/TestDevListener.py | 33 ++ script/cpy/TestMatplotlib.py | 29 ++ script/cpy/TestOphydWrapper.py | 94 ++++++ script/cpy/TestStream.py | 6 + script/cpy/TestToArray.py | 97 ++++++ script/cpy/bluesky2.py | 12 +- script/cpy/local.py | 40 ++- script/cpython/Ophyd.py | 8 + script/cpython/TestData.py | 79 +++++ script/cpython/TestInterrupt.py | 27 ++ script/cpython/gfitoff.py | 8 +- script/cpython/linfit.py | 29 +- script/cpython/test2.py | 23 +- script/local.py | 4 +- script/test/TestCfg.py | 12 +- script/test/TestCombineImage.py | 24 ++ script/test/TestDataAPI.py | 22 ++ script/test/TestJEP.py | 5 +- script/test/TestJEP2.py | 267 ++++++++++++++++ script/test/TestOphyd.py | 28 ++ script/test/test7.xml | 3 +- script/test/test8.xml | 2 +- script/test/test_append_tiff.py | 19 ++ script/test/test_append_tiff2.py | 35 ++ script/test/test_direct_tiff_data.py | 78 +++++ script/test/test_metadata.py | 27 ++ script/test/test_positioner.py | 27 ++ script/test/test_receive_sender.py | 19 +- script/test/test_tiff_3d.py | 16 + script/tst_jep.py | 299 ++++++++++++++++++ 79 files changed, 2747 insertions(+), 189 deletions(-) create mode 100644 devices/20240314_115334_console_0000.tiff.properties create mode 100644 devices/data2_0000.tiff.properties create mode 100644 devices/data3.tiff.properties create mode 100644 devices/data3_0000.tiff.properties create mode 100644 devices/det image_0000.tiff.properties create mode 100644 devices/det image_0001.tiff.properties create mode 100644 devices/det image_0002.tiff.properties create mode 100644 devices/det image_0005.tiff.properties create mode 100644 devices/det image_0006.tiff.properties create mode 100644 devices/det image_combined.tiff.properties create mode 100644 devices/im1.properties create mode 100644 devices/pe2.properties create mode 100644 devices/scan 1output.tiff.properties create mode 100644 devices/stack_0000.tiff.properties create mode 100644 devices/stack_0001.tiff.properties create mode 100644 devices/test_positioner.properties create mode 100644 devices/testdev.properties create mode 100644 devices/tst.tiff.properties create mode 100644 plugins/DemoScan.form create mode 100644 plugins/DemoScan.java create mode 100644 plugins/Scan.form create mode 100644 plugins/Scan.java create mode 100644 plugins/X.form create mode 100644 plugins/X.java create mode 100644 script/DemoScan.py create mode 100644 script/DemoScans.py create mode 100644 script/TeztTiff.py create mode 100644 script/cpy/Ophyd.py create mode 100644 script/cpy/TestDevListener.py create mode 100644 script/cpy/TestMatplotlib.py create mode 100644 script/cpy/TestOphydWrapper.py create mode 100644 script/cpy/TestStream.py create mode 100644 script/cpy/TestToArray.py create mode 100644 script/cpython/Ophyd.py create mode 100644 script/cpython/TestData.py create mode 100644 script/cpython/TestInterrupt.py create mode 100644 script/test/TestCombineImage.py create mode 100644 script/test/TestDataAPI.py create mode 100644 script/test/TestJEP2.py create mode 100644 script/test/TestOphyd.py create mode 100644 script/test/test_append_tiff.py create mode 100644 script/test/test_append_tiff2.py create mode 100644 script/test/test_direct_tiff_data.py create mode 100644 script/test/test_metadata.py create mode 100644 script/test/test_positioner.py create mode 100644 script/test/test_tiff_3d.py create mode 100644 script/tst_jep.py diff --git a/config/config.properties b/config/config.properties index 6e6d293..09d78ac 100755 --- a/config/config.properties +++ b/config/config.properties @@ -1,4 +1,4 @@ -#Tue Oct 31 13:01:30 CET 2023 +#Mon Jun 10 10:43:14 CEST 2024 XScanAppendSuffix=true XScanCrlogicAbortable=true XScanCrlogicChannel=null @@ -20,6 +20,7 @@ dataScanReleaseRecords=false dataScanSaveOutput=false dataScanSaveScript=false dataScanSaveSetpoints=true +dataScanSaveTimestamps=false dataServerPort=5573 dataTransferHost= dataTransferMode=Off @@ -46,10 +47,11 @@ noBytecodeFiles=false notificationLevel=User notifiedTasks=Test1,TestDate, xxx parallelInitialization=false +pythonHome={home}/cpython saveCommandStatistics=true saveConsoleSessionFiles=false scanStreamerPort=5563 -serverEnabled=true +serverEnabled=false serverPort=8080 sessionHandling=On simulation=false diff --git a/config/devices.properties b/config/devices.properties index 613b605..7ad70d3 100755 --- a/config/devices.properties +++ b/config/devices.properties @@ -23,7 +23,7 @@ pip=ch.psi.pshell.camserver.PipelineStream|localhost:8889 simulation_sp|||true #rr=RotationReadback|TESTIOC:TESTCALCOUT:Output|||true #rp=ch.psi.pshell.epics.Positioner|TESTIOC:TESTCALCOUT:Input null rr||| #webcam=ch.psi.pshell.webcam.Webcam|:2|||true -deting=ch.psi.pshell.imaging.CameraSource|det||-500| +#deting=ch.psi.pshell.imaging.CameraSource|det||-500| #PiezoRoll1=ch.psi.pshell.epics.ControlledVariable|"TESTIOC:TESTCALCOUT:Input" TESTIOC:TESTCALCOUT:Output false|||true #$ser=ch.psi.pshell.serial.TcpDevice|||| #$beam_ok=ch.psi.pshell.epics.ChannelString|CHANNEL||| @@ -92,6 +92,7 @@ slit=ch.psi.pshell.device.Slit|motor motor2||| #$vhq4=ch.psi.pshell.epics.Vhq4|T-MMDV5||| #$ps=PowerSupply|T-MMDV5||| pe=ch.psi.pshell.epics.Positioner|"TESTIOC:TESTCALCOUT:Input" TESTIOC:TESTCALCOUT:Output|||true +pe2=ch.psi.pshell.device.DummyPositioner||||true cv=ch.psi.pshell.epics.ControlledVariable|TESTIOC:TESTCALCOUT:Input TESTIOC:TESTCALCOUT:Output|||true #detector=ch.psi.pshell.detector.DetectorBase|http://127.0.0.1:8090/||| #serial=ch.psi.pshell.serial.SerialPortDevice|||| @@ -129,7 +130,7 @@ gamma=ch.psi.pshell.device.DummyMotor||||true eta=ch.psi.pshell.device.DummyMotor||||true chi=ch.psi.pshell.device.DummyMotor||||true phi=ch.psi.pshell.device.DummyMotor||||true -#sixc=ch.psi.pshell.device.MotorGroupBase|mu delta gamma eta chi phi||| +sixc=ch.psi.pshell.device.MotorGroupBase|mu delta gamma eta chi phi||| #fivec=ch.psi.pshell.device.MotorGroupBase|delta gamma eta chi phi||| #fourc=ch.psi.pshell.device.MotorGroupBase|delta eta chi phi||| fourcv=ch.psi.pshell.device.MotorGroupBase|mu delta gamma eta||| diff --git a/config/diffcalc/test.json b/config/diffcalc/test.json index 85969a6..5c518d2 100644 --- a/config/diffcalc/test.json +++ b/config/diffcalc/test.json @@ -3,28 +3,33 @@ "crystal": "['cubic', 1, 1, 1, 90.0, 90.0, 90.0]", "reflist": { "1": { - "tag": null, - "hkl": "[1.0, 0.0, 0.0]", - "pos": "[0, 1.0, 0.0, 0.0, 0.0, 0.0]", - "energy": 12.39842, - "time": "2020-07-15T15:45:37.924000" - }, - "2": { - "tag": null, + "tag": "None", "hkl": "[0.0, 1.0, 0.0]", "pos": "[0, 60, 0, 30, 0, 90]", "energy": 12.39842, - "time": "2020-07-15T15:45:37.960000" + "time": "2023-11-03T14:09:46.383000" + }, + "2": { + "tag": "None", + "hkl": "[1.0, 0.0, 0.0]", + "pos": "[0.0, 1.0, 0.0, 0.0, 0.0, 0.0]", + "energy": 20.0, + "time": "2023-11-03T14:09:46.375000" } }, + "orientlist": {}, "tau": 0, "sigma": 0, "reference": { "n_hkl_configured": null, "n_phi_configured": "[0.0, 0.0, 1.0]" }, - "u": null, + "u": [ + "1.0, 0.0, 0.0", + "0.0, 1.0, 0.0", + "0.0, 0.0, 1.0" + ], "ub": null, - "or0": 1, - "or1": 2 + "or0": null, + "or1": null } \ No newline at end of file diff --git a/config/plugins.properties b/config/plugins.properties index 831e9c3..4c27e5d 100755 --- a/config/plugins.properties +++ b/config/plugins.properties @@ -1,3 +1,7 @@ +Scan.java=disabled +Redis.java=disabled +DemoScan.java=disabled +X.java=disabled sc.java=disabled Regine.java=disabled ScreenPanel11.java=disabled diff --git a/config/preferences.json b/config/preferences.json index c248958..9e00d5a 100644 --- a/config/preferences.json +++ b/config/preferences.json @@ -65,10 +65,10 @@ "hideScanPanel" : false, "hideOutputPanel" : false, "showXScanFileBrowser" : true, - "showQueueBrowser" : true, + "showQueueBrowser" : false, "backgroundRendering" : false, "showImageStatusBar" : true, - "persistRendererWindows" : false, + "persistRendererWindows" : true, "defaultRendererColormap" : "Grayscale", "linePlot" : "ch.psi.pshell.plot.LinePlotJFree", "matrixPlot" : "ch.psi.pshell.plot.MatrixPlotJFree", @@ -127,10 +127,7 @@ "deviceClassName" : "ch.psi.pshell.camserver.CamServerService", "panelClassName" : "ch.psi.pshell.swing.CamServerServicePanel" }, { - "deviceClassName" : "ch.psi.pshell.device.ReadonlyRegister$ReadonlyRegisterArray", - "panelClassName" : "ch.psi.pshell.swing.DeviceValueChart" - }, { - "deviceClassName" : "ch.psi.pshell.device.ReadonlyRegister$ReadonlyRegisterMatrix", + "deviceClassName" : "ch.psi.pshell.device.ReadonlyRegister", "panelClassName" : "ch.psi.pshell.swing.DeviceValueChart" } ], "scriptPopupDialog" : "Exception" diff --git a/config/sessions.properties b/config/sessions.properties index e54591a..9132994 100644 --- a/config/sessions.properties +++ b/config/sessions.properties @@ -1,3 +1,2 @@ -#Mon Apr 03 15:43:39 CEST 2023 -CurrentSession=177 +#Fri Nov 03 13:49:20 CET 2023 SessionCounter=177 diff --git a/config/setup.properties b/config/setup.properties index 6fc893c..e9c2d9b 100755 --- a/config/setup.properties +++ b/config/setup.properties @@ -1,27 +1,28 @@ -#Fri Jun 10 11:48:34 CEST 2022 -scriptPath={home}/script -sessionsPath={outp}/sessions -configFileDevices={config}/devices.properties -xscanPath={script}/test -queuePath={script}/queues -extensionsPath={home}/extensions -configFileUpdateStrategy={config}/update.properties -configPath={home}/config -configFileSessions={config}/sessions.properties -userSessionsPath={sessions}/user -dataPath={outp}/data -configFileVariables={config}/variables.properties -logPath={outp}/log -wwwPath={home}/www +#Wed Mar 20 10:42:57 CET 2024 +cPythonPath={home}/cpython configFile={config}/config.properties -configFileTasks={config}/tasks.properties +configFileDevices={config}/devices.properties configFileImageSources={config}/imaging.properties -pluginsPath={home}/plugins -consoleSessionsPath={sessions}/console -libraryPath={script}; {script}/Lib; src/main/assembly/script/tutorial; {script}/imaging configFilePlugins={config}/plugins.properties -contextPath={outp}/context -devicesPath={home}/devices +configFileSessions={config}/sessions.properties configFileSettings={config}/settings.properties -imagesPath={outp}/images +configFileTasks={config}/tasks.properties +configFileUpdateStrategy={config}/update.properties +configFileVariables={config}/variables.properties +configPath={home}/config +consoleSessionsPath={sessions}/console +contextPath={outp}/context +dataPath={outp}/data +devicesPath={home}/devices +extensionsPath={home}/extensions +imagesPath={data} +libraryPath={script}; {script}/Lib; src/main/assembly/script/tutorial; {script}/imaging +logPath={outp}/log +pluginsPath={home}/plugins +queuePath={script}/queues +scriptPath={home}/script scriptType=py +sessionsPath={outp}/sessions +userSessionsPath={sessions}/user +wwwPath={home}/www +xscanPath={script}/test diff --git a/config/variables.properties b/config/variables.properties index b780f7a..ad58070 100644 --- a/config/variables.properties +++ b/config/variables.properties @@ -1,7 +1,7 @@ -#Fri Sep 29 09:45:06 CEST 2023 +#Mon Jun 10 09:15:34 CEST 2024 CurrentSession=122 -DaySequentialNumber=26 -FileSequentialNumber=5986 -LastRunDate=230929 +DaySequentialNumber=1 +FileSequentialNumber=6920 +LastRunDate=240610 SessionCounter=127 xxx=[1, 2, 3, 4] diff --git a/devices/20240314_115334_console_0000.tiff.properties b/devices/20240314_115334_console_0000.tiff.properties new file mode 100644 index 0000000..a1c78f3 --- /dev/null +++ b/devices/20240314_115334_console_0000.tiff.properties @@ -0,0 +1,20 @@ +#Thu Mar 14 11:53:42 CET 2024 +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/CurrentCamera.properties b/devices/CurrentCamera.properties index 64cfc34..3000dd6 100755 --- a/devices/CurrentCamera.properties +++ b/devices/CurrentCamera.properties @@ -1,8 +1,8 @@ -#Tue Oct 31 10:08:05 CET 2023 +#Thu Mar 21 16:43:31 CET 2024 colormap=Flame colormapAutomatic=true colormapLogarithmic=false -colormapMax=9814.0 +colormapMax=1628.0 colormapMin=0.0 custom=12345 flipHorizontally=false @@ -23,9 +23,9 @@ rotation=0.0 rotationCrop=false scale=1.0 serverURL=http\://gfa-lc6-64\:8889 -spatialCalOffsetX=-638.5965043983313 -spatialCalOffsetY=-485.427166868422 -spatialCalScaleX=-35.21126791588346 -spatialCalScaleY=-48.38709170854271 +spatialCalOffsetX=-198.999999289148 +spatialCalOffsetY=-98.99999627491977 +spatialCalScaleX=-7.518797014727082 +spatialCalScaleY=-8.542713216994429 spatialCalUnits=mm transpose=false diff --git a/devices/cam_server.properties b/devices/cam_server.properties index 67d32c1..80d3874 100755 --- a/devices/cam_server.properties +++ b/devices/cam_server.properties @@ -1,4 +1,4 @@ -#Thu Sep 21 16:17:46 CEST 2023 +#Mon Feb 19 10:54:19 CET 2024 colormap=Flame colormapAutomatic=true colormapLogarithmic=false @@ -18,9 +18,9 @@ roiY=0 rotation=0.0 rotationCrop=false scale=1.0 -spatialCalOffsetX=-640.2010477461916 -spatialCalOffsetY=-487.87880023403306 -spatialCalScaleX=-35.2112662923995 -spatialCalScaleY=-48.387093592171716 +spatialCalOffsetX=-199.49874674479167 +spatialCalOffsetY=-99.3311027678703 +spatialCalScaleX=-7.518796992481203 +spatialCalScaleY=-8.542712973910431 spatialCalUnits=mm transpose=false diff --git a/devices/data2_0000.tiff.properties b/devices/data2_0000.tiff.properties new file mode 100644 index 0000000..7bb7136 --- /dev/null +++ b/devices/data2_0000.tiff.properties @@ -0,0 +1,20 @@ +#Thu Mar 14 17:31:59 CET 2024 +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/data3.tiff.properties b/devices/data3.tiff.properties new file mode 100644 index 0000000..16bc17a --- /dev/null +++ b/devices/data3.tiff.properties @@ -0,0 +1,20 @@ +#Thu Mar 14 18:00:17 CET 2024 +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/data3_0000.tiff.properties b/devices/data3_0000.tiff.properties new file mode 100644 index 0000000..151489b --- /dev/null +++ b/devices/data3_0000.tiff.properties @@ -0,0 +1,20 @@ +#Thu Mar 14 17:28:53 CET 2024 +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/det image_0000.tiff.properties b/devices/det image_0000.tiff.properties new file mode 100644 index 0000000..79243c2 --- /dev/null +++ b/devices/det image_0000.tiff.properties @@ -0,0 +1,20 @@ +#Thu Mar 14 09:17:36 CET 2024 +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/det image_0001.tiff.properties b/devices/det image_0001.tiff.properties new file mode 100644 index 0000000..c13bb8d --- /dev/null +++ b/devices/det image_0001.tiff.properties @@ -0,0 +1,20 @@ +#Thu Mar 14 09:17:39 CET 2024 +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/det image_0002.tiff.properties b/devices/det image_0002.tiff.properties new file mode 100644 index 0000000..6ff70e4 --- /dev/null +++ b/devices/det image_0002.tiff.properties @@ -0,0 +1,20 @@ +#Thu Mar 14 09:17:38 CET 2024 +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/det image_0005.tiff.properties b/devices/det image_0005.tiff.properties new file mode 100644 index 0000000..499d366 --- /dev/null +++ b/devices/det image_0005.tiff.properties @@ -0,0 +1,20 @@ +#Thu Mar 14 14:26:27 CET 2024 +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/det image_0006.tiff.properties b/devices/det image_0006.tiff.properties new file mode 100644 index 0000000..87a698f --- /dev/null +++ b/devices/det image_0006.tiff.properties @@ -0,0 +1,20 @@ +#Thu Mar 14 14:33:28 CET 2024 +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/det image_combined.tiff.properties b/devices/det image_combined.tiff.properties new file mode 100644 index 0000000..2dca0ee --- /dev/null +++ b/devices/det image_combined.tiff.properties @@ -0,0 +1,20 @@ +#Thu Mar 14 15:39:17 CET 2024 +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/h.properties b/devices/h.properties index 913260d..19a32a0 100644 --- a/devices/h.properties +++ b/devices/h.properties @@ -1,4 +1,5 @@ -#Wed Aug 15 09:55:09 CEST 2018 +#Fri Nov 03 14:09:46 CET 2023 +description=null maxValue=10.0 minValue=-10.0 offset=0.0 diff --git a/devices/hkl_group.properties b/devices/hkl_group.properties index 0aa7810..6c92039 100644 --- a/devices/hkl_group.properties +++ b/devices/hkl_group.properties @@ -1,2 +1,3 @@ -#Wed Apr 18 09:33:05 CEST 2018 +#Fri Nov 03 14:09:46 CET 2023 +description=null precision=4 diff --git a/devices/im1.properties b/devices/im1.properties new file mode 100644 index 0000000..7923944 --- /dev/null +++ b/devices/im1.properties @@ -0,0 +1,17 @@ +#Tue Nov 07 09:47:37 CET 2023 +defaultSpeed=NaN +description=null +estbilizationDelay=0 +maxSpeed=NaN +maxValue=NaN +minSpeed=NaN +minValue=NaN +monitorByPosition=false +offset=0.0 +precision=-1 +resolution=NaN +rotation=false +scale=1.0 +sign_bit=0 +startRetries=1 +unit=null diff --git a/devices/k.properties b/devices/k.properties index 913260d..19a32a0 100644 --- a/devices/k.properties +++ b/devices/k.properties @@ -1,4 +1,5 @@ -#Wed Aug 15 09:55:09 CEST 2018 +#Fri Nov 03 14:09:46 CET 2023 +description=null maxValue=10.0 minValue=-10.0 offset=0.0 diff --git a/devices/l.properties b/devices/l.properties index 913260d..19a32a0 100644 --- a/devices/l.properties +++ b/devices/l.properties @@ -1,4 +1,5 @@ -#Wed Aug 15 09:55:09 CEST 2018 +#Fri Nov 03 14:09:46 CET 2023 +description=null maxValue=10.0 minValue=-10.0 offset=0.0 diff --git a/devices/pe2.properties b/devices/pe2.properties new file mode 100644 index 0000000..b7dee84 --- /dev/null +++ b/devices/pe2.properties @@ -0,0 +1,11 @@ +#Wed Jan 17 16:52:10 CET 2024 +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/positioner.properties b/devices/positioner.properties index f073d6a..8121d9b 100755 --- a/devices/positioner.properties +++ b/devices/positioner.properties @@ -1,10 +1,11 @@ -#Fri Jul 24 14:51:57 CEST 2020 -minValue=-1000.0 -unit=mm -offset=0.0 +#Fri Nov 03 13:50:52 CET 2023 +description=null maxValue=1000.0 +minValue=-1000.0 +offset=0.0 precision=5 -rotation=false -sign_bit=0 -scale=1.0 resolution=Infinity +rotation=false +scale=1.0 +sign_bit=0 +unit=mm diff --git a/devices/scan 1output.tiff.properties b/devices/scan 1output.tiff.properties new file mode 100644 index 0000000..77f6d83 --- /dev/null +++ b/devices/scan 1output.tiff.properties @@ -0,0 +1,20 @@ +#Thu Mar 14 15:32:22 CET 2024 +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/scanner.properties b/devices/scanner.properties index 82bb0f4..afa612a 100644 --- a/devices/scanner.properties +++ b/devices/scanner.properties @@ -1,4 +1,5 @@ -#Thu Aug 02 17:12:34 CEST 2018 +#Thu Jan 18 14:16:35 CET 2024 +description=null maxValue=NaN minValue=NaN offset=0.0 diff --git a/devices/stack_0000.tiff.properties b/devices/stack_0000.tiff.properties new file mode 100644 index 0000000..5771888 --- /dev/null +++ b/devices/stack_0000.tiff.properties @@ -0,0 +1,20 @@ +#Thu Mar 14 17:04:25 CET 2024 +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/stack_0001.tiff.properties b/devices/stack_0001.tiff.properties new file mode 100644 index 0000000..d0d87d8 --- /dev/null +++ b/devices/stack_0001.tiff.properties @@ -0,0 +1,20 @@ +#Thu Mar 14 17:16:21 CET 2024 +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/test_cfg.properties b/devices/test_cfg.properties index 64a2c42..8328651 100644 --- a/devices/test_cfg.properties +++ b/devices/test_cfg.properties @@ -1,5 +1,14 @@ -#Fri Jun 22 09:13:00 CEST 2018 +#Wed Mar 13 10:00:19 CET 2024 +add_float=null +att_bool=null +att_float=null +att_int=null +att_test=null b=false +boolval=null d=1.0 +floatval=null i=5 +intval=null s=Test5 +strval=null diff --git a/devices/test_positioner.properties b/devices/test_positioner.properties new file mode 100644 index 0000000..016ee5d --- /dev/null +++ b/devices/test_positioner.properties @@ -0,0 +1,11 @@ +#Thu Nov 02 08:59:26 CET 2023 +description=null +maxValue=100.0 +minValue=-100.0 +offset=0.0 +precision=2 +resolution=NaN +rotation=false +scale=1.0 +sign_bit=0 +unit=null diff --git a/devices/testdev.properties b/devices/testdev.properties new file mode 100644 index 0000000..35aa7f7 --- /dev/null +++ b/devices/testdev.properties @@ -0,0 +1,5 @@ +#Wed Mar 13 10:00:36 CET 2024 +boolval=true +floatval=1.0 +intval=1 +strval=Test diff --git a/devices/tst.tiff.properties b/devices/tst.tiff.properties new file mode 100644 index 0000000..9599c3e --- /dev/null +++ b/devices/tst.tiff.properties @@ -0,0 +1,20 @@ +#Thu Feb 29 15:35:28 CET 2024 +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/plugins/DemoScan.form b/plugins/DemoScan.form new file mode 100644 index 0000000..d2213b4 --- /dev/null +++ b/plugins/DemoScan.form @@ -0,0 +1,115 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/plugins/DemoScan.java b/plugins/DemoScan.java new file mode 100644 index 0000000..34af250 --- /dev/null +++ b/plugins/DemoScan.java @@ -0,0 +1,163 @@ + +import ch.psi.pshell.ui.ScriptProcessor; +import ch.psi.pshell.ui.Task; +import ch.psi.utils.State; +import java.util.HashMap; +import java.util.Map; + +/** + * + */ +public class DemoScan extends ScriptProcessor { + + public DemoScan() { + initComponents(); + } + + + //Overridable callbacks + @Override + public void onInitialize(int runCount) { + + } + + @Override + public void onStateChange(State state, State former) { + + } + + @Override + public void onExecutedFile(String fileName, Object result) { + } + + @Override + public void onTaskFinished(Task task) { + } + + @Override + protected void onTimer() { + } + + @Override + protected void onLoaded() { + + } + + @Override + protected void onUnloaded() { + + } + + + @Override + protected void onStartingExecution(Map args) throws Exception{ + } + + @Override + protected void onFinishedExecution(Map args, Object ret, Throwable t) throws Exception{ + } + + + //Invoked by 'update()' to update components in the event thread + @Override + protected void doUpdate() { + } + + + @Override + public String getScript(){ + //TODO + return "DemoScan"; + } + + @Override + public Map getArgs(){ + Map ret = new HashMap<>(); + ret.put("START", spStart.getValue()); + ret.put("END", spEnd.getValue()); + ret.put("STEPS", spSteps.getValue()); + ret.put("PLOT", plot); + return ret; + } + + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jLabel1 = new javax.swing.JLabel(); + spStart = new javax.swing.JSpinner(); + spEnd = new javax.swing.JSpinner(); + jLabel2 = new javax.swing.JLabel(); + spSteps = new javax.swing.JSpinner(); + Steps = new javax.swing.JLabel(); + plot = new ch.psi.pshell.plot.LinePlotJFree(); + + jLabel1.setText("Start:"); + + spStart.setModel(new javax.swing.SpinnerNumberModel(0.0d, 0.0d, 10.0d, 1.0d)); + + spEnd.setModel(new javax.swing.SpinnerNumberModel(0.5d, 0.0d, 10.0d, 1.0d)); + + jLabel2.setText("End:"); + + spSteps.setModel(new javax.swing.SpinnerNumberModel(10, 0, 10, 1)); + + Steps.setText("Steps:"); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(25, 25, 25) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(spStart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(spEnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addComponent(Steps) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(spSteps, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(21, 21, 21) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel1) + .addComponent(spStart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(21, 21, 21) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel2) + .addComponent(spEnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(21, 21, 21) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(Steps) + .addComponent(spSteps, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) + .addContainerGap()) + ); + }// //GEN-END:initComponents + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JLabel Steps; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private ch.psi.pshell.plot.LinePlotJFree plot; + private javax.swing.JSpinner spEnd; + private javax.swing.JSpinner spStart; + private javax.swing.JSpinner spSteps; + // End of variables declaration//GEN-END:variables +} diff --git a/plugins/PanelPlugin.form b/plugins/PanelPlugin.form index c52670e..6e52b41 100755 --- a/plugins/PanelPlugin.form +++ b/plugins/PanelPlugin.form @@ -22,11 +22,11 @@ - + - + @@ -40,9 +40,21 @@ - + + + + + + + + + + + + + @@ -57,13 +69,9 @@ - - - - - - - + + + @@ -72,34 +80,47 @@ - - - - + - - - - - - - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + - - - - - - + + + @@ -108,12 +129,6 @@ - - - - - - @@ -209,5 +224,18 @@ + + + + + + + + + + + + + diff --git a/plugins/PanelPlugin.java b/plugins/PanelPlugin.java index 52e9fab..92a549c 100755 --- a/plugins/PanelPlugin.java +++ b/plugins/PanelPlugin.java @@ -81,6 +81,16 @@ public class PanelPlugin extends Panel { time = new ch.psi.pshell.plot.TimePlotJFree(); panelSetp = new ch.psi.pshell.swing.RegisterPanel(); panelRbck = new ch.psi.pshell.swing.DeviceValuePanel(); + try { + dvc = new ch.psi.pshell.swing.DeviceValueChart(); + } catch (java.lang.ClassNotFoundException e1) { + e1.printStackTrace(); + } catch (java.lang.InstantiationException e2) { + e2.printStackTrace(); + } catch (java.lang.IllegalAccessException e3) { + e3.printStackTrace(); + } + pvp = new ch.psi.pshell.swing.ProcessVariablePanel(); motorPanel2.setDeviceName("m1"); @@ -119,6 +129,11 @@ public class PanelPlugin extends Panel { panelRbck.setName("TESTIOC:TESTCALCOUT:Input"); // NOI18N + dvc.setDeviceName("sin"); + + pvp.setDeviceName("motor"); + pvp.setShowStop(false); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( @@ -129,7 +144,7 @@ public class PanelPlugin extends Panel { .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(scriptButton2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(motorPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jSpinner2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) @@ -141,8 +156,17 @@ public class PanelPlugin extends Panel { .addComponent(jRadioButton1))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton2) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jSpinner3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))) + .addGap(219, 219, 219) + .addComponent(jSpinner3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() + .addGap(6, 6, 6) + .addComponent(pvp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(line, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(layout.createSequentialGroup() + .addGap(6, 6, 6) + .addComponent(time, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addGroup(layout.createSequentialGroup() .addGap(86, 86, 86) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -150,51 +174,53 @@ public class PanelPlugin extends Panel { .addComponent(panelSetp, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(panelRbck, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addComponent(scriptButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(line, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(scriptButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(layout.createSequentialGroup() - .addGap(6, 6, 6) - .addComponent(time, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addContainerGap() + .addComponent(dvc, javax.swing.GroupLayout.PREFERRED_SIZE, 342, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(motorPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(18, 18, 18) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(scriptButton2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jSpinner2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jSpinner3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(layout.createSequentialGroup() - .addGap(21, 21, 21) - .addComponent(jRadioButton1) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jRadioButton2) + .addContainerGap() + .addComponent(motorPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(buttonExecShellCmd) - .addComponent(jButton2)))) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(scriptButton2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jSpinner2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jSpinner3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addGap(21, 21, 21) + .addComponent(jRadioButton1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jRadioButton2) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(buttonExecShellCmd) + .addComponent(jButton2)))) + .addGap(18, 18, 18) + .addComponent(pvp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addComponent(line, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(time, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(dvc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(panelSetp, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(panelRbck, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(44, 44, 44) .addComponent(scriptButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(25, 25, 25)) - .addGroup(layout.createSequentialGroup() - .addComponent(line, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(time, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(0, 12, Short.MAX_VALUE)) ); layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {panelRbck, panelSetp}); @@ -225,6 +251,7 @@ public class PanelPlugin extends Panel { // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton buttonExecShellCmd; private javax.swing.ButtonGroup buttonGroup1; + private ch.psi.pshell.swing.DeviceValueChart dvc; private javax.swing.JButton jButton2; private javax.swing.JRadioButton jRadioButton1; private javax.swing.JRadioButton jRadioButton2; @@ -235,6 +262,7 @@ public class PanelPlugin extends Panel { private ch.psi.pshell.swing.MotorPanel motorPanel2; private ch.psi.pshell.swing.DeviceValuePanel panelRbck; private ch.psi.pshell.swing.RegisterPanel panelSetp; + private ch.psi.pshell.swing.ProcessVariablePanel pvp; private ch.psi.pshell.swing.ScriptButton scriptButton1; private ch.psi.pshell.swing.ScriptButton scriptButton2; private ch.psi.pshell.plot.TimePlotJFree time; diff --git a/plugins/Scan.form b/plugins/Scan.form new file mode 100644 index 0000000..41abeb6 --- /dev/null +++ b/plugins/Scan.form @@ -0,0 +1,115 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/plugins/Scan.java b/plugins/Scan.java new file mode 100644 index 0000000..2b9b315 --- /dev/null +++ b/plugins/Scan.java @@ -0,0 +1,162 @@ + +import ch.psi.pshell.ui.ScriptProcessor; +import ch.psi.pshell.ui.Task; +import ch.psi.utils.State; +import java.util.HashMap; +import java.util.Map; + +/** + * + */ +public class Scan extends ScriptProcessor { + + public Scan() { + initComponents(); + } + + + //Overridable callbacks + @Override + public void onInitialize(int runCount) { + + } + + @Override + public void onStateChange(State state, State former) { + + } + + @Override + public void onExecutedFile(String fileName, Object result) { + } + + @Override + public void onTaskFinished(Task task) { + } + + @Override + protected void onTimer() { + } + + @Override + protected void onLoaded() { + + } + + @Override + protected void onUnloaded() { + + } + + + @Override + protected void onStartingExecution(Map args) throws Exception{ + } + + @Override + protected void onFinishedExecution(Map args, Object ret, Throwable t) throws Exception{ + } + + + //Invoked by 'update()' to update components in the event thread + @Override + protected void doUpdate() { + } + + + @Override + public String getScript(){ + return ("DemoScan"); + } + + @Override + public Map getArgs(){ + Map ret = new HashMap(); + ret.put("START", spStart.getValue()); + ret.put("END", spEnd.getValue()); + ret.put("STEPS", spSteps.getValue()); + ret.put("PLOT", plot); + return ret; + } + + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jLabel1 = new javax.swing.JLabel(); + spStart = new javax.swing.JSpinner(); + spEnd = new javax.swing.JSpinner(); + jLabel2 = new javax.swing.JLabel(); + spSteps = new javax.swing.JSpinner(); + jLabel3 = new javax.swing.JLabel(); + plot = new ch.psi.pshell.plot.LinePlotJFree(); + + jLabel1.setText("Start:"); + + spStart.setModel(new javax.swing.SpinnerNumberModel(0.0d, -10.0d, 10.0d, 1.0d)); + + spEnd.setModel(new javax.swing.SpinnerNumberModel(0.5d, -10.0d, 10.0d, 1.0d)); + + jLabel2.setText("End:"); + + spSteps.setModel(new javax.swing.SpinnerNumberModel(10, 1, 100, 1)); + + jLabel3.setText("Steps"); + + plot.setTitle(""); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(54, 54, 54) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel3) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(spSteps, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(spEnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(spStart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))) + .addGap(47, 47, 47) + .addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel1) + .addComponent(spStart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel2) + .addComponent(spEnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel3) + .addComponent(spSteps, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(7, 7, 7) + .addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + }// //GEN-END:initComponents + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private ch.psi.pshell.plot.LinePlotJFree plot; + private javax.swing.JSpinner spEnd; + private javax.swing.JSpinner spStart; + private javax.swing.JSpinner spSteps; + // End of variables declaration//GEN-END:variables +} diff --git a/plugins/X.form b/plugins/X.form new file mode 100644 index 0000000..d5e2826 --- /dev/null +++ b/plugins/X.form @@ -0,0 +1,28 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/plugins/X.java b/plugins/X.java new file mode 100644 index 0000000..0653fee --- /dev/null +++ b/plugins/X.java @@ -0,0 +1,98 @@ + +import ch.psi.pshell.ui.ScriptProcessor; +import ch.psi.pshell.ui.Task; +import ch.psi.utils.State; +import java.util.HashMap; +import java.util.Map; + +/** + * + */ +public class X extends ScriptProcessor { + + public static final String SCRIPT_NAME = "X"; + + public X() { + initComponents(); + } + + + //Overridable callbacks + @Override + public void onInitialize(int runCount) { + + } + + @Override + public void onStateChange(State state, State former) { + + } + + @Override + public void onExecutedFile(String fileName, Object result) { + } + + @Override + public void onTaskFinished(Task task) { + } + + @Override + protected void onTimer() { + } + + @Override + protected void onLoaded() { + + } + + @Override + protected void onUnloaded() { + + } + + + @Override + protected void onStartingExecution(Map args) throws Exception{ + } + + @Override + protected void onFinishedExecution(Map args, Object ret, Throwable t) throws Exception{ + } + + + //Invoked by 'update()' to update components in the event thread + @Override + protected void doUpdate() { + } + + + @Override + public String getScript(){ + return SCRIPT_NAME; + } + + @Override + public Map getArgs(){ + Map ret = new HashMap<>(); + return ret; + } + + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 303, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 176, Short.MAX_VALUE) + ); + }// //GEN-END:initComponents + + // Variables declaration - do not modify//GEN-BEGIN:variables + // End of variables declaration//GEN-END:variables +} diff --git a/script/.DS_Store b/script/.DS_Store index d57983178fb0275e0af994fceae5931f1f065ad7..fc420334d34b0c0e9677ac5ffb4657e3be7c5202 100644 GIT binary patch delta 216 zcmZqqz}WJEae_Z1-^PH4%#$zM>oBrS-r#S|&(6TWz{*g}kj#+CkjGFw*)T$wkz@0L ztW8XlABN~m{==5T#lQ$u0|Xr0n-5Bfvusx9dBV&nJGn47h6O0fGAUVnGrvFw|7LE5 zwE`R|#mPBI`T04Uml|mEPkybhz-T#HkHvj6zr#X)7LdfmLSaUu$z?2-oB0D$`8KEd zc`?Gp_Z^RN8hERz$$R5vRp HzG4CZcrZkT delta 225 zcmZqqz}WJEae_Z1@5X?K%#-;YTo~CV^8{EjvTycF+`+`k!N9=4GWnyO*yO78CT<1> zMj#&uIJh?(N{h2>R_A%b%qY3JL7&BJK9Ily5F z|KvCpYfb^6K5GUB_8F5Eq{SIcH#-Gn@J;TB=s^kn9^pF diff --git a/script/BugReadCharWaveformasString.py b/script/BugReadCharWaveformasString.py index 778d3cc..c294aae 100644 --- a/script/BugReadCharWaveformasString.py +++ b/script/BugReadCharWaveformasString.py @@ -1,4 +1,4 @@ -#BYTE waveform: OK +#BYTE waveform: OK # field(FTVL, 'BYTE') caput("TESTIOC:TESTBA:MyBA", "foo") print caget("TESTIOC:TESTBA:MyBA") diff --git a/script/DemoScan.py b/script/DemoScan.py new file mode 100644 index 0000000..be62e32 --- /dev/null +++ b/script/DemoScan.py @@ -0,0 +1,64 @@ +# Run detached as: +# pshell -p=DemoScan.java -d -sbar -tbar -l -dplt +from mathutils import fit_harmonic, HarmonicOscillator + + +if get_exec_pars().innerArgs is None: + print 1 + START = 0.0 + END = 0.400 + STEPS = 10 + PLOT = None +if PLOT is None: + PLOT = plot(None,title="HFit")[0] +PLOT.clear() + +sd = lscan(inp, (sin,out,arr), START, END, STEPS, 0.1) + + +ydata = sd[sin] +xdata = sd[inp] + +max_y= max(ydata) +index_max = ydata.index(max_y) +max_x= xdata[index_max] + +start,end = min(xdata), max(xdata) +(amplitude, angular_frequency, phase) = fit_harmonic(ydata, xdata) +fitted_harmonic_function = HarmonicOscillator(amplitude, angular_frequency, phase) + +print "amplitude = ", amplitude +print "angular frequency = ", angular_frequency +print "phase = ", phase + +f = angular_frequency/ (2* math.pi) +print "frequency = ", f + +resolution = 0.01 +fit_y = [] +for x in frange(start,end,resolution, True): + fit_y.append(fitted_harmonic_function.value(x)) +fit_x = frange(start, end+resolution, resolution) + + +PLOT.addSeries(LinePlotSeries("data")) +PLOT.addSeries(LinePlotSeries("fit")) +PLOT.getSeries(0).setData(xdata, ydata) +PLOT.getSeries(1).setData(fit_x, fit_y) + +#m = (phase + math.pi)/ angular_frequency +m = -phase / angular_frequency +if (m1): + pars, aux = [element_type], obj + for i in range(rank): + pars.append(len(aux)) + aux = aux[0] + #TODO: OVERLOADING BUG + #ret = reflect.Array.newInstance(*pars) + ret = Arr.newInstance(*pars) + for i in range(len(obj)): + ret[i]=to_array(obj[i], type) + obj = ret + elif is_list(obj): + if type=='o': + ret = reflect.Array.newInstance(element_type, len(obj)) + for i in range (len(obj)): + if is_list(obj[i]) or is_array(obj[i]): + ret[i] = to_array(obj[i],type) + else: + ret[i] = obj[i] + obj=ret + elif len(obj)>0 and (is_list(obj[0]) or is_array(obj[0])): + pars, aux = [element_type], obj + while len(aux)>0 and (is_list(aux[0]) or is_array(aux[0])): + pars.append(len(aux)) + aux = aux[0] + pars.append(0) + #ret = reflect.Array.newInstance(*pars) + ret = Arr.newInstance(*pars) + for i in range(len(obj)): + ret[i]=to_array(obj[i], type) + obj=ret + else: + obj= convert_1d_array(obj) + return obj + + +import random +ret = [] +for i in range (10): + ret.append(random.random()) + +try: + a1 = to_array(ret,'d') + print (a1) +except: + traceback.print_exc() diff --git a/script/cpy/bluesky2.py b/script/cpy/bluesky2.py index b8462a0..e255a54 100644 --- a/script/cpy/bluesky2.py +++ b/script/cpy/bluesky2.py @@ -9,12 +9,18 @@ motor.delay = 1.1 # simulate slow motor movement ch1 = EpicsSignal("TESTIOC:TESTSINUS:SinCalc") -#TODO: DEmonstrate use of waveform and areadetector (Manual scan setup with the indexes in name) +#TODO: Demonstrate use of waveform and areadetector (Manual scan setup with the indexes in name) #ch2 = EpicsSignal("TESTIOC:TESTWF2:MyWF", name="arr[10]") #ch3 = EpicsSignal("TESTIOC:TESTWF2:MyWF", name="img[3][2]")det3=ReaderWrapper(sin) """ + dets = [det1, det2] +det4=ReaderWrapper(arr) +det5=ReaderWrapper(get_device("det").getDataMatrix() ) +dets = [det1, det2, ch1, det3, det4, det5] #TODO: fix formatting for arrays +dets = [det1, det2, ch1, det3] + RE(count(dets, num=5, delay=0.5)) RE(scan(dets, motor, 0, 1, 5)) RE(rel_scan(dets, motor, -1, 1, 10)) @@ -23,8 +29,6 @@ RE(grid_scan(dets, motor1, -1.5, 1.5, 3, motor2, -0.1, 0.1, 5)) RE(list_grid_scan(dets, motor1, [1, 1, 2, 3, 5], motor2, [25, 16, 9])) -det4=ReaderWrapper(arr) -det5=ReaderWrapper(get_device("det").getDataMatrix() ) m1=MoverWrapper(get_device("motor")) -dets = [det1, det2, ch1, det3, det4, det5] + RE(scan(dets, m1, 0, 1, 5)) diff --git a/script/cpy/local.py b/script/cpy/local.py index 847b204..7711100 100644 --- a/script/cpy/local.py +++ b/script/cpy/local.py @@ -178,9 +178,7 @@ def on_abort(parent_thread): print ("Abort command: Run Engine pause request") RE.request_pause() return - tid=parent_thread.ident - exception = KeyboardInterrupt - ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(tid), ctypes.py_object(exception)) + _default_abort(parent_thread) def on_close(parent_thread): on_abort(parent_thread) @@ -399,13 +397,7 @@ class ReaderWrapper(): self.precision = self.dev.getPrecision() except: self.precision = None - self.description = {self.name: { \ - 'dtype':'number', \ - 'shape': self.shape, \ - 'source': self.source, \ - 'precision': self.precision \ - }} - + self.dtype = 'number' self.cfg_description = {"shape_str":{"dtype":"string", 'shape':(len(self.shape_str),), "source":""}, } self.configuration = {"shape_str":{"value":self.shape_str, "timestamp":time.time()}} self.name = self.name+self.shape_str @@ -422,7 +414,13 @@ class ReaderWrapper(): raise __exception__ return {self.name:{"value":__return__, "timestamp":time.time()}} - def describe(self): + def describe(self): + self.description = {self.name: { \ + 'dtype':self.dtype , \ + 'shape': self.shape, \ + 'source': self.source, \ + 'precision': self.precision \ + }} return self.description def describe_configuration(self): @@ -470,6 +468,26 @@ class MoverWrapper(ReaderWrapper): self.dev.stop() +#Wraps an Ophyd device as a Readable, so can be used in *scan commands +class Ophyd(Readable): + def __init__(self, dev): + for k in dev.describe().keys(): + Nameable.__init__(self, k, Readable.__interfaces__ ) + break + self.dev=dev + + def read(self): + v = self.dev.read() + if (v is None) or (len(v)==0): + return None + v = v[self.getName()] + try: + timestamp = int(v["timestamp"]*1000) + except: + timestamp = time.time() + ret = TimestampedValue (v["value"], timestamp) + return ret + RE = RunEngine({}, during_task=EventProcessingTask()) if CAN_PAUSE: diff --git a/script/cpython/Ophyd.py b/script/cpython/Ophyd.py new file mode 100644 index 0000000..bc2e2f6 --- /dev/null +++ b/script/cpython/Ophyd.py @@ -0,0 +1,8 @@ +from ophyd.sim import det1, det2, det3, det4, det, motor, motor1, motor2, motor3,img, sig, direct_img, pseudo1x3 +from ophyd import Signal +from ophyd.signal import EpicsSignal + + + +def read(name): + return globals()[name].read() diff --git a/script/cpython/TestData.py b/script/cpython/TestData.py new file mode 100644 index 0000000..3716b78 --- /dev/null +++ b/script/cpython/TestData.py @@ -0,0 +1,79 @@ +################################################################################################### +#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 (list(read)) +assert data1d==list(read) +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 ([list(a) for a in 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 ([list(a) for a in read]) +read =load_data(path,1) +print ([list(a) for a in read]) + +#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")) + + diff --git a/script/cpython/TestInterrupt.py b/script/cpython/TestInterrupt.py new file mode 100644 index 0000000..ff4ed86 --- /dev/null +++ b/script/cpython/TestInterrupt.py @@ -0,0 +1,27 @@ +import threading +from threading import Thread +from _thread import interrupt_main +import sys + +# task executed in a new thread +def task(): + # block for a moment + sleep(3) + # interrupt the main thread + print('Interrupting main thread now') + interrupt_main() + +# start the new thread +thread = Thread(target=task) +thread.start() + +print(threading.current_thread() == threading.main_thread()) +# handle being interrupted +try: + # wait around + while True: + print('Main thread waiting...') + sleep(0.5) +except KeyboardInterrupt: + # terminate main thread + print('Main interrupted! Exiting.') diff --git a/script/cpython/gfitoff.py b/script/cpython/gfitoff.py index 31a1e1b..8d6d0f7 100644 --- a/script/cpython/gfitoff.py +++ b/script/cpython/gfitoff.py @@ -27,4 +27,10 @@ def gfitoff(x, y, off=None, amp=None, com=None, sigma=None): def gauss_fn(x, a, b, c, d): - return a + b * np.exp(-(np.power((x - c), 2) / (2 * np.power(d, 2)))) \ No newline at end of file + return a + b * np.exp(-(np.power((x - c), 2) / (2 * np.power(d, 2)))) +""" +x=np.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]) +y=np.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]) +[off, amp, com, sigma] = gfitoff(x, y, off=None, amp=None, com=None, sigma=None) +print ([off, amp, com, sigma]) +""" \ No newline at end of file diff --git a/script/cpython/linfit.py b/script/cpython/linfit.py index 01644b1..3247e86 100644 --- a/script/cpython/linfit.py +++ b/script/cpython/linfit.py @@ -19,14 +19,39 @@ def test(): return np.ones(5) -def test2(name, x=None, y=None): +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() \ No newline at end of file + 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) + +#x=np.array([0,1,2,3,4,5,6,7,8,9]) +#y=np.array([1,2,3,6,9,6,3,2,1,0]) +#print( linfit(x,y) ) + + +#x=(0,1,2,3,4,5,6,7,8,9) +#y=(1,2,3,6,9,6,3,2,1,0) +#print( linfit(x,y) ) + + +#print_dict({"a":1, "b":2}) \ No newline at end of file diff --git a/script/cpython/test2.py b/script/cpython/test2.py index b65d4c7..5a65e17 100644 --- a/script/cpython/test2.py +++ b/script/cpython/test2.py @@ -1,14 +1,19 @@ -from jeputils import import_py +import matplotlib +matplotlib.use('TkAgg') -import_py("cpython/gfitoff", "gfitoff") +import matplotlib.pyplot as plt -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) +fig, ax = plt.subplots() +fruits = ['apple', 'blueberry', 'cherry', 'orange'] +counts = [40, 100, 30, 55] +bar_labels = ['red', 'blue', '_red', 'orange'] +bar_colors = ['tab:red', 'tab:blue', 'tab:red', 'tab:orange'] +ax.bar(fruits, counts, label=bar_labels, color=bar_colors) +ax.set_ylabel('fruit supply') +ax.set_title('Fruit supply by kind and color') +ax.legend(title='Fruit color') + +plt.show() \ No newline at end of file diff --git a/script/local.py b/script/local.py index 67abb6c..fef3d0c 100755 --- a/script/local.py +++ b/script/local.py @@ -125,7 +125,7 @@ def on_session_finished(id): ################################################################################################### # Image filters ################################################################################################### - +""" class DataFilter(Filter.DataFilter): def process(self, data): data=data.copy() @@ -148,7 +148,7 @@ image.addListener(image_filter) add_device(image_filter, True) image.refresh() - +""" diff --git a/script/test/TestCfg.py b/script/test/TestCfg.py index 0c8e7f6..37d727b 100644 --- a/script/test/TestCfg.py +++ b/script/test/TestCfg.py @@ -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") diff --git a/script/test/TestCombineImage.py b/script/test/TestCombineImage.py new file mode 100644 index 0000000..d8c1efe --- /dev/null +++ b/script/test/TestCombineImage.py @@ -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) + diff --git a/script/test/TestDataAPI.py b/script/test/TestDataAPI.py new file mode 100644 index 0000000..82c86b1 --- /dev/null +++ b/script/test/TestDataAPI.py @@ -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]) \ No newline at end of file diff --git a/script/test/TestJEP.py b/script/test/TestJEP.py index b39f6af..8b57b3f 100644 --- a/script/test/TestJEP.py +++ b/script/test/TestJEP.py @@ -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)) diff --git a/script/test/TestJEP2.py b/script/test/TestJEP2.py new file mode 100644 index 0000000..2eaf565 --- /dev/null +++ b/script/test/TestJEP2.py @@ -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 /lib/python3.X/site-packages/jep to LD_LIBRARY_PATH +# - Add /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 /lib folder to LD_LIBRARY_PATH +# - Set LD_PRELOAD=/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) + + diff --git a/script/test/TestOphyd.py b/script/test/TestOphyd.py new file mode 100644 index 0000000..46f0357 --- /dev/null +++ b/script/test/TestOphyd.py @@ -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) \ No newline at end of file diff --git a/script/test/test7.xml b/script/test/test7.xml index 94eba01..77e6bf6 100755 --- a/script/test/test7.xml +++ b/script/test/test7.xml @@ -18,8 +18,7 @@ + #print "==>" + str(x.getValue()) diff --git a/script/test/test8.xml b/script/test/test8.xml index b45e95c..facf9bb 100755 --- a/script/test/test8.xml +++ b/script/test/test8.xml @@ -24,6 +24,6 @@ def process(): - + diff --git a/script/test/test_append_tiff.py b/script/test/test_append_tiff.py new file mode 100644 index 0000000..7bfd114 --- /dev/null +++ b/script/test/test_append_tiff.py @@ -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))); diff --git a/script/test/test_append_tiff2.py b/script/test/test_append_tiff2.py new file mode 100644 index 0000000..cac49b2 --- /dev/null +++ b/script/test/test_append_tiff2.py @@ -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") + + + diff --git a/script/test/test_direct_tiff_data.py b/script/test/test_direct_tiff_data.py new file mode 100644 index 0000000..e54c387 --- /dev/null +++ b/script/test/test_direct_tiff_data.py @@ -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") + + diff --git a/script/test/test_metadata.py b/script/test/test_metadata.py new file mode 100644 index 0000000..816bcb1 --- /dev/null +++ b/script/test/test_metadata.py @@ -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}) diff --git a/script/test/test_positioner.py b/script/test/test_positioner.py new file mode 100644 index 0000000..9df5cd2 --- /dev/null +++ b/script/test/test_positioner.py @@ -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 \ No newline at end of file diff --git a/script/test/test_receive_sender.py b/script/test/test_receive_sender.py index 93548a7..27569c0 100644 --- a/script/test/test_receive_sender.py +++ b/script/test/test_receive_sender.py @@ -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() \ No newline at end of file + #st1.close() + pass + + + diff --git a/script/test/test_tiff_3d.py b/script/test/test_tiff_3d.py new file mode 100644 index 0000000..d03d463 --- /dev/null +++ b/script/test/test_tiff_3d.py @@ -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) \ No newline at end of file diff --git a/script/tst_jep.py b/script/tst_jep.py new file mode 100644 index 0000000..1a10de1 --- /dev/null +++ b/script/tst_jep.py @@ -0,0 +1,299 @@ +################################################################################################### +# 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 /lib/python3.X/site-packages/jep to LD_LIBRARY_PATH +# - Add /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 /lib folder to LD_LIBRARY_PATH +# - Set LD_PRELOAD=/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 java.util.ArrayList +import java.util.Collections +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 isinstance(args, java.util.List): + args=list(args) + + 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): + ret = obj + if isinstance(obj, jep.NDArray): + ret = obj.data + if len(obj.dimensions)>1: + ret=Convert.reshape(ret, obj.dimensions) + elif 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) or obj.getClass().getSimpleName().startswith("Unmodifiable"): #TODO: Is it a good check for immutability? + # ret=tuple(ret) + elif isinstance(obj, java.util.Map) or isinstance(obj,dict): + ret = {} + for k in obj.keys(): + ret[k] = rec_from_npa(obj[k]) + return ret + +#recursivelly converts all Java arrays to NumPy arrays +def rec_to_npa(obj): + ret = obj + if isinstance(obj, PyArray): + dimensions = Arr.getShape(obj) + if len(dimensions)>1: + obj = Convert.flatten(obj) + ret = to_npa(obj, dimensions = dimensions) + elif isinstance(obj, java.util.List) or isinstance(obj,tuple) or isinstance(obj,list): + ret = java.util.ArrayList() + for i in range(len(obj)): + ret.add(rec_to_npa(obj[i])) + #if isinstance(obj,tuple): + # ret = java.util.Collections.unmodifiableList(ret); + elif isinstance(obj, java.util.Map) or isinstance(obj,dict): + ret = java.util.HashMap() + for k in obj.keys(): + ret[k] = rec_to_npa(obj[k]) + return ret + +def call_py(module, function, reload_function, *args, **kwargs): + """ + Calls a CPython function recursively 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 + return call_py(module, function, reload_function, *args, **kwargs) + jep_wrapper.reload=True + _get_caller().f_globals[function] = jep_wrapper + return jep_wrapper + + +""" +eval_jep("from java.lang import System") +eval_jep("s = 'Hello World'"); +eval_jep("System.out.println(s)") +eval_jep("print(s)") +eval_jep("print(s[1:-1])") +eval_jep("import numpy") + +r1=call_jep("numpy", "ones", [5]) +r2=run_jep("cpython/gfitoff") +""" + +""" +import_py("CPython/gfitoff", "gfitoff") +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) +""" + + +import_py("CPython/linfit", "linfit") +import_py("CPython/linfit", "print_dict") +import_py("CPython/linfit", "get_tuple") +import_py("CPython/linfit", "test2") + +#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') + +x=[0,1,2,3,4,5,6,7,8,9] +y=[1,2,3,6,9,6,3,2,1,0] + +x=(0,1,2,3,4,5,6,7,8,9) +y=(1,2,3,6,9,6,3,2,1,0) + +a=java.util.ArrayList() +for i in x: + a.add(i) +(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)) +print("-----") +t=get_tuple() + +d={"a":1, "b":2} +r=print_dict(d) +