From 2ebcdf46bed749051ea06c1c875f81e640dbbeec Mon Sep 17 00:00:00 2001 From: sfop Date: Wed, 7 Sep 2016 19:04:49 +0200 Subject: [PATCH] Closedown --- config/devices.properties | 2 +- devices/CurrentCamera.properties | 20 ++++---- devices/cam1.properties | 6 +-- devices/cam2.properties | 6 +-- plugins/Cameras.java | 86 ++++++++++++++++++++++---------- script/SchottkyICT.py | 5 +- 6 files changed, 80 insertions(+), 45 deletions(-) diff --git a/config/devices.properties b/config/devices.properties index e2b7e89..15af9d7 100755 --- a/config/devices.properties +++ b/config/devices.properties @@ -1,4 +1,3 @@ -#SINEG01-DBPM340:Q=ch.psi.pshell.device.Averager|SINEG01-DBPM340:Q|||true gun_solenoid=ch.psi.pshell.epics.Positioner|SINEG01-MSOL130:I-SET SINEG01-MSOL130:I-READ|||true gun_phase=ch.psi.pshell.epics.Positioner|SINEG01-RSYS:SET-BEAM-PHASE SINEG01-RSYS:GET-BEAM-PHASE|||true #SINSB01_phase=ch.psi.pshell.epics.Positioner|VA-SINSB01-RSYS100:SET-BEAM-PHASE VA-SINSB01-RSYS100:GET-BEAM-PHASE|||true @@ -24,3 +23,4 @@ gsy=ch.psi.pshell.epics.Positioner|SINEG01-MSOL130:Y_SP SINEG01-MSOL130:Y|||true gsrx=ch.psi.pshell.epics.Positioner|SINEG01-MSOL130:ROT_X_SP SINEG01-MSOL130:ROT_X|||true gsry=ch.psi.pshell.epics.Positioner|SINEG01-MSOL130:ROT_Y_SP SINEG01-MSOL130:ROT_Y|||true #camtool=Camtool|SINEG01-DSCR190||-500| +#SINEG01-DBPM340:Q=ch.psi.pshell.device.Averager|SINEG01-DBPM340:Q|||true diff --git a/devices/CurrentCamera.properties b/devices/CurrentCamera.properties index a38762f..fae1736 100644 --- a/devices/CurrentCamera.properties +++ b/devices/CurrentCamera.properties @@ -1,13 +1,13 @@ -#Wed Sep 07 14:25:45 CEST 2016 +#Wed Sep 07 15:48:15 CEST 2016 colormap=Temperature colormapAutomatic=true -colormapMax=2475.851 -colormapMin=2189.861 -flipHorizontally=true +colormapMax=25.102 +colormapMin=12.575 +flipHorizontally=false flipVertically=true grayscale=false -imageHeight=1628 -imageWidth=1280 +imageHeight=1200 +imageWidth=1246 invert=false rescaleFactor=1.0 rescaleOffset=0.0 @@ -18,9 +18,9 @@ roiY=0 rotation=0.0 rotationCrop=true scale=1.0 -spatialCalOffsetX=-1251.0 -spatialCalOffsetY=-1504.0 -spatialCalScaleX=0.008333333333333333 -spatialCalScaleY=0.004081632653061225 +spatialCalOffsetX=-1191.0 +spatialCalOffsetY=-1176.0 +spatialCalScaleX=0.014285714285714285 +spatialCalScaleY=0.020833333333333332 spatialCalUnits=mm transpose=false diff --git a/devices/cam1.properties b/devices/cam1.properties index 1198dc1..85acb57 100644 --- a/devices/cam1.properties +++ b/devices/cam1.properties @@ -1,4 +1,4 @@ -#Thu Sep 01 09:58:11 CEST 2016 +#Wed Sep 07 15:31:33 CEST 2016 colormap=Grayscale colormapAutomatic=true colormapMax=30000.0 @@ -6,8 +6,8 @@ colormapMin=0.0 flipHorizontally=false flipVertically=false grayscale=false -imageHeight=1628 -imageWidth=1280 +imageHeight=0 +imageWidth=0 invert=false offsetX=0.0 offsetY=0.0 diff --git a/devices/cam2.properties b/devices/cam2.properties index e8b4cab..b8b0bc9 100644 --- a/devices/cam2.properties +++ b/devices/cam2.properties @@ -1,4 +1,4 @@ -#Thu Sep 01 09:58:11 CEST 2016 +#Wed Sep 07 15:31:33 CEST 2016 colormap=Grayscale colormapAutomatic=true colormapMax=255.0 @@ -6,8 +6,8 @@ colormapMin=0.0 flipHorizontally=false flipVertically=false grayscale=false -imageHeight=1680 -imageWidth=1744 +imageHeight=0 +imageWidth=0 invert=false offsetX=0.0 offsetY=0.0 diff --git a/plugins/Cameras.java b/plugins/Cameras.java index 0d0493e..5e41c56 100644 --- a/plugins/Cameras.java +++ b/plugins/Cameras.java @@ -31,6 +31,7 @@ import ch.psi.pshell.imaging.Pen; import ch.psi.pshell.imaging.Renderer; import ch.psi.pshell.imaging.Renderer.Profile; import ch.psi.pshell.imaging.RendererListener; +import ch.psi.pshell.imaging.Source; import ch.psi.pshell.imaging.Utils; import ch.psi.pshell.scripting.InterpreterResult; import ch.psi.pshell.scripting.ScriptManager; @@ -83,27 +84,50 @@ public class Cameras extends Panel { @Override public void onInitialize(int runCount) { comboCameras.setEnabled(false); - cameraConfigFiles = IO.listFiles(configFolder, new String[]{"json"}); - Arrays.sort(cameraConfigFiles, (a, b) -> a.compareTo(b)); - DefaultComboBoxModel model = new DefaultComboBoxModel(); - for (File file : cameraConfigFiles) { - String prefix = IO.getPrefix(file); - if (!prefix.startsWith("#")) { - model.addElement(prefix); - } - } - comboCameras.setModel(model); - comboCameras.setEnabled(true); - comboCameras.setSelectedItem(-1); - if (model.getSize() > 0) { - try { - //setCamera((String)comboCameras.getSelectedItem()); - if (App.hasArgument("cam")) { - comboCameras.setSelectedItem(App.getArgumentValue("cam")); + if (App.hasArgument("s")){ + renderer.setDevice((Source)getDevice("image")); + renderer.setAutoScroll(true); + ((Source)getDevice("image")).addListener(new ImageListener() { + @Override + public void onImage(Object o, BufferedImage bi, Data data) { + if (bi == null) { + fitOv = null; + } else { + Overlay[] profile = renderer.getProfileOverlays(); + profile = ((profile != null) && (profile.length==4)) ? getFitOverlays(bi) : null; + renderer.updateOverlays(profile, fitOv); + fitOv = profile; + } + } + @Override + public void onError(Object o, Exception excptn) { + } + } + ); + + } else { + cameraConfigFiles = IO.listFiles(configFolder, new String[]{"json"}); + Arrays.sort(cameraConfigFiles, (a, b) -> a.compareTo(b)); + DefaultComboBoxModel model = new DefaultComboBoxModel(); + for (File file : cameraConfigFiles) { + String prefix = IO.getPrefix(file); + if (!prefix.startsWith("#")) { + model.addElement(prefix); } - } catch (Exception ex) { - ex.printStackTrace(); } + comboCameras.setModel(model); + comboCameras.setEnabled(true); + comboCameras.setSelectedItem(-1); + if (model.getSize() > 0) { + try { + //setCamera((String)comboCameras.getSelectedItem()); + if (App.hasArgument("cam")) { + comboCameras.setSelectedItem(App.getArgumentValue("cam")); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } } startTimer(2000); } @@ -284,9 +308,19 @@ public class Cameras extends Panel { protected void onTimer() { textState.setText((camera == null) ? "" : camera.getState().toString()); buttonConfig.setEnabled(camera != null); + if (App.hasArgument("s")){ + System.out.println("Refresh"); + try { + ((Source)getDevice("image")).initialize(); + } catch (IOException ex) { + Logger.getLogger(Cameras.class.getName()).log(Level.SEVERE, null, ex); + } catch (InterruptedException ex) { + Logger.getLogger(Cameras.class.getName()).log(Level.SEVERE, null, ex); + } + } } - Pen fitPen = new Pen(new Color(0, 192, 0)); + Pen fitPen = new Pen(new Color(0, 192, 0), 2); Overlay[] getFitOverlays(BufferedImage img){ Overlays.Polyline hpoly = null; Overlays.Polyline vpoly = null; @@ -297,7 +331,7 @@ public class Cameras extends Panel { if (profile.hasVertical()) { try { int[] sum = Utils.integrateVertically(img); - int[] x = Arr.indexesInt(sum.length); + int[] x = Arr.indexesInt(sum.length); double[] gaussian = fitGaussian(sum, x); if (gaussian!=null){ System.out.println("Norm: " + gaussian[0] + " Mean: " + gaussian[1] + " Sigma: " + gaussian[2]); @@ -305,12 +339,13 @@ public class Cameras extends Panel { double[] fit = getFitFunction(gaussian, x); int[] y = new int[x.length]; for (int i = 0; i < x.length; i++) { - y[i] = (int) (img.getHeight() - 1 - (((double) fit[i]) / 255 / factor)/2); -System.out.println("x=" + x[i] , "y=" + y[i], "f=" + fit[i]); + y[i] = (int) (img.getHeight() - 1 - (((double) fit[i]) / 255 / factor)); } vpoly = new Overlays.Polyline(fitPen, x, y); + } else { + System.out.println("Fit failure"); } - + } catch (Exception ex) { ex.printStackTrace(); } @@ -325,7 +360,7 @@ System.out.println("x=" + x[i] , "y=" + y[i], "f=" + fit[i]); int[] y = new int[x.length]; for (int i = 0; i < x.length; i++) { - y[i] = (int) (((double) fit[i]) / 255 / factor)/2; + y[i] = (int) (((double) fit[i]) / 255 / factor); } hpoly = new Overlays.Polyline(fitPen, y, x); } @@ -365,7 +400,6 @@ double[] fitGaussianScript(int[] y, int[] x){ double[]fitGaussian(int[] y, int[] x){ try{ - ScriptManager sm = Controller.getInstance().getScriptManager(); ArrayProperties pY = ArrayProperties.get(y); GaussianCurveFitter fitter = GaussianCurveFitter.create().withStartPoint(new double[]{(pY.max-pY.min)/2,x[pY.maxIndex],1.0}).withMaxIterations(1000); ArrayListvalues = new ArrayList<>(); diff --git a/script/SchottkyICT.py b/script/SchottkyICT.py index f119958..b25b445 100644 --- a/script/SchottkyICT.py +++ b/script/SchottkyICT.py @@ -13,9 +13,10 @@ import datetime knob = Channel("SINEG01-RSYS:SET-BEAM-PHASE", 'd', alias = "RF phase") instrument = Channel("SINEG01-DICT215:CHARGE", 'd', alias = "Bunch Charge (ICT)") -lscan(knob, [instrument], -120., 60., 10.,2.0) +r = lscan(knob, [instrument], -120., 60., 10.,2.0) -#elog("Title", "" , get_plot_snapshots()) + +elog("SchottkyICT", "Data file: " + get_context().path + "\n\n" + r.print() , get_plot_snapshots()) #use_bpm = True #