diff --git a/devices/Beam phase.properties b/devices/Beam phase.properties
index 94dc4ad..1b0f9d3 100644
--- a/devices/Beam phase.properties
+++ b/devices/Beam phase.properties
@@ -1,9 +1,9 @@
-#Tue Oct 31 08:29:24 CET 2017
+#Mon Nov 06 09:33:43 CET 2017
maxValue=360.0
minValue=-360.0
offset=0.0
precision=3
resolution=0.1
-rotation=false
+rotation=true
scale=1.0
unit=deg
diff --git a/devices/CurrentCamera.properties b/devices/CurrentCamera.properties
index 2a1aa9f..f90a8df 100644
--- a/devices/CurrentCamera.properties
+++ b/devices/CurrentCamera.properties
@@ -1,19 +1,19 @@
-#Thu Nov 02 08:45:36 CET 2017
+#Thu Nov 09 10:26:13 CET 2017
\u0000\u0000\u0000\u0000=
\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000=
\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000=
-colormap=Flame
+colormap=Rainbow
colormapAutomatic=false
-colormapMax=45.0
-colormapMin=0.0
+colormapMax=376.0
+colormapMin=50.0
flipHorizontally=false
flipVertically=false
grayscale=false
-imageHeight=-1
-imageWidth=-1
+imageHeight=652
+imageWidth=589
invert=false
-regionStartX=0
-regionStartY=0
+regionStartX=332
+regionStartY=103
rescaleFactor=1.0
rescaleOffset=0.0
roiHeight=-1
@@ -24,9 +24,9 @@ rotation=0.0
rotationCrop=false
scale=1.0
serverURL=localhost\:10000
-spatialCalOffsetX=-796.492903878568
-spatialCalOffsetY=-947.4732834064881
-spatialCalScaleX=-8.699279822948917
-spatialCalScaleY=-8.747949755590955
-spatialCalUnits=mm
+spatialCalOffsetX=-299.5085076886633
+spatialCalOffsetY=-310.4762027834781
+spatialCalScaleX=-29.103002431441325
+spatialCalScaleY=-26.490066364247312
+spatialCalUnits=
transpose=false
diff --git a/devices/cam2.properties b/devices/cam2.properties
index 8ca6428..9ebefe1 100644
--- a/devices/cam2.properties
+++ b/devices/cam2.properties
@@ -1,4 +1,4 @@
-#Thu Nov 02 08:42:13 CET 2017
+#Thu Nov 09 09:40:25 CET 2017
colormap=Flame
colormapAutomatic=true
colormapMax=255.0
@@ -6,13 +6,13 @@ colormapMin=0.0
flipHorizontally=false
flipVertically=false
grayscale=false
-imageHeight=-1
-imageWidth=-1
+imageHeight=1024
+imageWidth=1280
invert=false
offsetX=0.0
offsetY=0.0
-regionStartX=0
-regionStartY=0
+regionStartX=1
+regionStartY=1
rescaleFactor=1.0
rescaleOffset=0.0
roiHeight=-1
diff --git a/devices/cam3.properties b/devices/cam3.properties
index 852d33b..0910499 100644
--- a/devices/cam3.properties
+++ b/devices/cam3.properties
@@ -1,4 +1,4 @@
-#Thu Nov 02 08:42:13 CET 2017
+#Thu Nov 09 10:18:08 CET 2017
colormap=Flame
colormapAutomatic=true
colormapMax=255.0
@@ -6,11 +6,11 @@ colormapMin=0.0
flipHorizontally=false
flipVertically=false
grayscale=false
-imageHeight=-1
-imageWidth=-1
+imageHeight=1024
+imageWidth=1280
invert=false
-regionStartX=0
-regionStartY=0
+regionStartX=1
+regionStartY=1
rescaleFactor=1.0
rescaleOffset=0.0
roiHeight=-1
diff --git a/devices/cam_server.properties b/devices/cam_server.properties
index 58aa04f..95e13be 100644
--- a/devices/cam_server.properties
+++ b/devices/cam_server.properties
@@ -1,4 +1,4 @@
-#Thu Nov 02 08:46:19 CET 2017
+#Thu Nov 09 09:03:48 CET 2017
colormap=Flame
colormapAutomatic=true
colormapMax=NaN
@@ -16,9 +16,9 @@ roiY=0
rotation=0.0
rotationCrop=false
scale=1.0
-spatialCalOffsetX=-796.492903878568
-spatialCalOffsetY=-947.4732834064881
-spatialCalScaleX=-8.699279822948917
-spatialCalScaleY=-8.747949755590955
+spatialCalOffsetX=-50.03909304143862
+spatialCalOffsetY=-50.048875855327466
+spatialCalScaleX=-1.0
+spatialCalScaleY=-1.0
spatialCalUnits=mm
transpose=false
diff --git a/plugins/Correlation2.form b/plugins/Correlation2.form
new file mode 100644
index 0000000..9a81870
--- /dev/null
+++ b/plugins/Correlation2.form
@@ -0,0 +1,267 @@
+
+
+
diff --git a/plugins/Correlation2.java b/plugins/Correlation2.java
new file mode 100644
index 0000000..fc3e4b1
--- /dev/null
+++ b/plugins/Correlation2.java
@@ -0,0 +1,393 @@
+/*
+ * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
+ */
+
+import ch.psi.pshell.plot.Plot;
+import ch.psi.pshell.ui.App;
+import ch.psi.pshell.ui.Panel;
+import ch.psi.utils.State;
+import java.awt.Component;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ *
+ */
+public class Correlation2 extends Panel {
+
+ public Correlation2() {
+ initComponents();
+ this.setPersistedComponents(new Component[]{textDevX, textDevY, spinnerInterval, spinnerWindow, comboTypeX, comboTypeY});
+ plot.getAxis(Plot.AxisId.X).setLabel(null);
+ plot.getAxis(Plot.AxisId.Y).setLabel(null);
+ }
+
+ //Overridable callbacks
+ @Override
+ public void onInitialize(int runCount) {
+ super.onInitialize(runCount);
+ this.startTimer(100, 10);
+ if (App.hasArgument("dx")) {
+ textDevX.setText(App.getArgumentValue("dx"));
+ }
+ if (App.hasArgument("dy")) {
+ textDevY.setText(App.getArgumentValue("dy"));
+ }
+ try{
+ if (App.hasArgument("dxtype")) {
+ comboTypeX.setSelectedIndex(Integer.valueOf(App.getArgumentValue("dxtype")));
+ }
+ } catch (Exception ex){
+ System.err.println(ex.getMessage());
+ }
+ try{
+ if (App.hasArgument("dytype")) {
+ comboTypeY.setSelectedIndex(Integer.valueOf(App.getArgumentValue("dytype")));
+ }
+ } catch (Exception ex){
+ System.err.println(ex.getMessage());
+ }
+ try{
+ if (App.hasArgument("interval")) {
+ spinnerInterval.setValue(Double.valueOf(App.getArgumentValue("interval")));
+ }
+ } catch (Exception ex){
+ System.err.println(ex.getMessage());
+ }
+ try{
+ if (App.hasArgument("window")) {
+ spinnerWindow.setValue(Integer.valueOf(App.getArgumentValue("window")));
+ }
+ } catch (Exception ex){
+ System.err.println(ex.getMessage());
+ }
+ }
+
+ @Override
+ protected void onTimer(){
+ if (isRunning()){
+ updateResults();
+ }
+ }
+
+ //DecimalFormat formatter = new DecimalFormat("0.##E0");
+ void updateResults(){
+ try{
+ textCorrelation.setText(String.format("%1.4f", Double.valueOf((Double)getContext().getInterpreterVariable("corr"))));
+ } catch (Exception ex){
+ textCorrelation.setText("");
+ }
+
+ if (checkLinear.isSelected()){
+ try{
+ List pars = (List)getContext().getInterpreterVariable("pars_lin");
+ //textLinear.setText(String.format("%1.3fx%+1.3f", (Double)(pars.get(1)), (Double)(pars.get(0))));
+ textLinear.setText(String.format("%1.6gx%+1.6g",pars.get(1), pars.get(0)));
+ } catch (Exception ex){
+ textLinear.setText("");
+ }
+ }
+
+ if (checkQuadratic.isSelected()){
+ try{
+ List pars = (List)getContext().getInterpreterVariable("pars_quad");
+ //textQuadratic.setText(String.format("%1.2fx\u00B2 %+1.2fx%+1.2f", (Double)(pars.get(0)), (Double)(pars.get(1)), (Double)(pars.get(0))));
+ textQuadratic.setText(String.format("%1.3gx\u00B2%+1.3gx%+1.3g", pars.get(0), pars.get(1), pars.get(0)));
+ //textQuadratic.setText(formatter.format(pars.get(2))+ formatter.format(pars.get(1)) + formatter.format(pars.get(0)));
+
+ } catch (Exception ex){
+ textQuadratic.setText("");
+ }
+ }
+ }
+
+ @Override
+ public void onStateChange(State state, State former) {
+ buttonStart.setEnabled((state==State.Ready) || (state==State.Busy));
+ if (isRunning()){
+ if (state==State.Ready){
+ buttonStart.setText("Start");
+ }
+ } else {
+ if (state==State.Busy){
+ buttonStart.setText("Stop");
+ }
+ }
+ textDevX.setEnabled(state==State.Ready);
+ textDevY.setEnabled(state==State.Ready);
+ spinnerInterval.setEnabled(state==State.Ready);
+ spinnerWindow.setEnabled(state==State.Ready);
+ comboTypeX.setEnabled(state==State.Ready);
+ comboTypeY.setEnabled(state==State.Ready);
+ checkLinear.setEnabled(state==State.Ready);
+ checkQuadratic.setEnabled(state==State.Ready);
+
+ if ((former==State.Initializing) && (state == State.Ready)){
+ if (App.hasArgument("start")) {
+ buttonStartActionPerformed(null);
+ }
+ }
+
+ }
+
+ boolean isRunning(){
+ return buttonStart.getText().equals("Stop");
+ }
+
+ @Override
+ public void onExecutedFile(String fileName, Object result) {
+ }
+
+
+ //Callback to perform update - in event thread
+ @Override
+ protected void doUpdate() {
+ }
+
+ @SuppressWarnings("unchecked")
+ // //GEN-BEGIN:initComponents
+ private void initComponents() {
+
+ plot = new ch.psi.pshell.plot.LinePlotJFree();
+ jPanel1 = new javax.swing.JPanel();
+ jLabel1 = new javax.swing.JLabel();
+ textDevX = new javax.swing.JTextField();
+ textDevY = new javax.swing.JTextField();
+ jLabel2 = new javax.swing.JLabel();
+ jLabel3 = new javax.swing.JLabel();
+ spinnerInterval = new javax.swing.JSpinner();
+ jLabel4 = new javax.swing.JLabel();
+ spinnerWindow = new javax.swing.JSpinner();
+ buttonStart = new javax.swing.JButton();
+ jLabel5 = new javax.swing.JLabel();
+ textCorrelation = new javax.swing.JTextField();
+ jLabel6 = new javax.swing.JLabel();
+ textLinear = new javax.swing.JTextField();
+ jLabel7 = new javax.swing.JLabel();
+ textQuadratic = new javax.swing.JTextField();
+ checkLinear = new javax.swing.JCheckBox();
+ checkQuadratic = new javax.swing.JCheckBox();
+ comboTypeX = new javax.swing.JComboBox();
+ comboTypeY = new javax.swing.JComboBox();
+
+ plot.setTitle("");
+
+ jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
+ jLabel1.setText("X device:");
+
+ jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
+ jLabel2.setText("Y device:");
+
+ jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
+ jLabel3.setText("Interval (s):");
+
+ spinnerInterval.setModel(new javax.swing.SpinnerNumberModel(Double.valueOf(0.1d), Double.valueOf(0.001d), null, Double.valueOf(1.0d)));
+
+ jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
+ jLabel4.setText("Window size:");
+
+ spinnerWindow.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(50), Integer.valueOf(3), null, Integer.valueOf(1)));
+
+ buttonStart.setText("Start");
+ buttonStart.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ buttonStartActionPerformed(evt);
+ }
+ });
+
+ jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
+ jLabel5.setText("Correlation:");
+
+ textCorrelation.setEditable(false);
+ textCorrelation.setHorizontalAlignment(javax.swing.JTextField.CENTER);
+
+ jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
+ jLabel6.setText("Liner fit:");
+
+ textLinear.setEditable(false);
+ textLinear.setHorizontalAlignment(javax.swing.JTextField.CENTER);
+
+ jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
+ jLabel7.setText("Quadratric fit:");
+
+ textQuadratic.setEditable(false);
+ textQuadratic.setHorizontalAlignment(javax.swing.JTextField.CENTER);
+
+ checkLinear.setSelected(true);
+ checkLinear.setText("Linear fit");
+
+ checkQuadratic.setText("Quadratic fit");
+
+ comboTypeX.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Channel", "Stream", "Camera" }));
+
+ comboTypeY.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Channel", "Stream", "Camera" }));
+
+ javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
+ jPanel1.setLayout(jPanel1Layout);
+ jPanel1Layout.setHorizontalGroup(
+ jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(jPanel1Layout.createSequentialGroup()
+ .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(buttonStart, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ .addGroup(jPanel1Layout.createSequentialGroup()
+ .addContainerGap()
+ .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING)
+ .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING)
+ .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING)
+ .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
+ .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
+ .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
+ .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(jPanel1Layout.createSequentialGroup()
+ .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(comboTypeY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(comboTypeX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(textCorrelation, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
+ .addComponent(spinnerInterval, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(spinnerWindow, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(textLinear, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
+ .addComponent(textQuadratic, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
+ .addComponent(checkLinear)
+ .addComponent(checkQuadratic))
+ .addContainerGap())
+ .addComponent(textDevX)
+ .addComponent(textDevY)))
+ );
+
+ jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel2, jLabel3, jLabel4});
+
+ jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerInterval, spinnerWindow});
+
+ jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel5, jLabel6, jLabel7});
+
+ jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {textCorrelation, textLinear, textQuadratic});
+
+ jPanel1Layout.setVerticalGroup(
+ jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(jPanel1Layout.createSequentialGroup()
+ .addContainerGap()
+ .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabel1)
+ .addComponent(textDevX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(comboTypeX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabel2)
+ .addComponent(textDevY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGap(3, 3, 3)
+ .addComponent(comboTypeY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGap(18, 18, 18)
+ .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabel3)
+ .addComponent(spinnerInterval, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabel4)
+ .addComponent(spinnerWindow, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGap(18, 18, 18)
+ .addComponent(checkLinear)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(checkQuadratic)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
+ .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
+ .addComponent(textCorrelation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(jLabel5))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
+ .addComponent(jLabel6)
+ .addComponent(textLinear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
+ .addComponent(jLabel7)
+ .addComponent(textQuadratic, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
+ .addComponent(buttonStart)
+ .addGap(45, 45, 45))
+ );
+
+ javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
+ this.setLayout(layout);
+ layout.setHorizontalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addContainerGap()
+ .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, 345, Short.MAX_VALUE))
+ );
+ layout.setVerticalGroup(
+ layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addContainerGap()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addContainerGap())))
+ );
+ }// //GEN-END:initComponents
+
+ private void buttonStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStartActionPerformed
+ try {
+ if (isRunning()){
+ abort();
+ updateResults();
+ //buttonStart.setText("Start");
+ } else {
+ textCorrelation.setText("");
+ textLinear.setText("");
+ textQuadratic.setText("");
+ HashMap args = new HashMap();
+ args.put("dx", textDevX.getText());
+ args.put("dy", textDevY.getText());
+ args.put("interval", spinnerInterval.getValue());
+ args.put("window", spinnerWindow.getValue());
+ args.put("dxtype", comboTypeX.getSelectedIndex());
+ args.put("dytype", comboTypeY.getSelectedIndex());
+ args.put("linear_fit", checkLinear.isSelected());
+ args.put("quadratic_fit", checkQuadratic.isSelected());
+
+ args.put("p", plot);
+ runAsync("Correlation/Correlation2", args).handle((ok, ex) -> {
+ if (ex != null) {
+ ex.printStackTrace();
+ }
+ return ok;
+ });
+ ///buttonStart.setText("Stop");
+ }
+
+ } catch (Exception ex) {
+ showException(ex);
+ }
+ }//GEN-LAST:event_buttonStartActionPerformed
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JButton buttonStart;
+ private javax.swing.JCheckBox checkLinear;
+ private javax.swing.JCheckBox checkQuadratic;
+ private javax.swing.JComboBox comboTypeX;
+ private javax.swing.JComboBox comboTypeY;
+ private javax.swing.JLabel jLabel1;
+ private javax.swing.JLabel jLabel2;
+ private javax.swing.JLabel jLabel3;
+ private javax.swing.JLabel jLabel4;
+ private javax.swing.JLabel jLabel5;
+ private javax.swing.JLabel jLabel6;
+ private javax.swing.JLabel jLabel7;
+ private javax.swing.JPanel jPanel1;
+ private ch.psi.pshell.plot.LinePlotJFree plot;
+ private javax.swing.JSpinner spinnerInterval;
+ private javax.swing.JSpinner spinnerWindow;
+ private javax.swing.JTextField textCorrelation;
+ private javax.swing.JTextField textDevX;
+ private javax.swing.JTextField textDevY;
+ private javax.swing.JTextField textLinear;
+ private javax.swing.JTextField textQuadratic;
+ // End of variables declaration//GEN-END:variables
+}
diff --git a/script/Correlation/Correlation2.py b/script/Correlation/Correlation2.py
new file mode 100644
index 0000000..133514b
--- /dev/null
+++ b/script/Correlation/Correlation2.py
@@ -0,0 +1,194 @@
+import math
+import sys, traceback
+from mathutils import fit_polynomial, PolynomialFunction
+from plotutils import plot_line, plot_function
+from ch.psi.pshell.swing.Shell import STDOUT_COLOR
+import org.apache.commons.math3.stat.correlation.PearsonsCorrelation as PearsonsCorrelation
+import ch.psi.pshell.bs.PipelineServer as PipelineServer
+
+
+TYPE_CHANNEL = 0
+TYPE_STREAM = 1
+TYPE_CAMERA= 2
+
+if get_exec_pars().source == CommandSource.ui:
+ dx = "SINDI01-RLLE-STA:SLAVE1-CPUTIMER"
+ #dx = "SLG-LCAM-C042 x_rms"
+ dxtype = TYPE_STREAM
+ dxtype = TYPE_CHANNEL
+ #dxtype = TYPE_CAMERA
+ #dy = "SINDI01-RLLE-STA:SLAVE1-DLTIMER"
+ dy = "SLG-LCAM-C042 y_rms"
+ dytype = TYPE_STREAM
+ dytype = TYPE_CHANNEL
+ dytype = TYPE_CAMERA
+ interval = 0.10
+ window = 40
+ p = plot(None)[0]
+ linear_fit = True
+ quadratic_fit = True
+print dx, dxtype
+print dy, dytype
+
+corr = None
+pars_lin = None
+pars_quad = None
+
+
+
+bs = TYPE_STREAM in [dxtype, dytype]
+
+
+for s in p.getAllSeries():
+ p.removeSeries(s)
+
+_stream = None
+_camname = None
+
+instances = []
+
+def _get_device(d, type):
+ global _stream, _camname
+ egu = None
+ if isinstance(d, basestring):
+ name = d.strip()
+ d = None
+ try:
+ d = get_device(name)
+ if d is None:
+ d = eval(name)
+ #print name
+ if d is not None:
+ if not isinstance(r, Device):
+ d = None
+ else:
+ try:
+ egu = d.unit
+ except:
+ pass
+ except:
+ pass
+ if d is None:
+ offset = 0
+
+ if type==TYPE_STREAM:
+ if " " in name:
+ tokens = name.split(" ")
+ name = tokens[0]
+ offset = int(tokens[1])
+ if _stream == None:
+ _stream = Stream("corr_stream", dispatcher)
+ instances.append(_stream)
+ d = _stream.addScalar(name, name, int(interval*100), offset)
+ elif type==TYPE_CHANNEL:
+ d = Channel(name)
+ d.set_monitored(True)
+ elif type==TYPE_CAMERA:
+ tokens = name.split(" ")
+ _camname = tokens[0]
+ field = tokens[1]
+ return field, ""
+ else:
+ raise Exception("Invalid type: " + str(type))
+ if not isinstance(d, basestring):
+ instances.append(d)
+ try:
+ egu = caget(name+".EGU",'s')
+ except:
+ pass
+ else:
+ try:
+ egu = d.unit
+ except:
+ pass
+ return d, egu
+
+dx, egux = _get_device(dx, dxtype)
+dy, eguy = _get_device(dy, dytype)
+
+p.getAxis(p.AxisId.X).setLabel(egux)
+p.getAxis(p.AxisId.Y).setLabel(eguy)
+
+
+try:
+ if _stream != None:
+ _stream.initialize()
+ _stream.start(True)
+ if _camname != None:
+ cam_server.start(_camname )
+ cam_server.stream.waitCacheChange(10000);
+ if dxtype==TYPE_CAMERA:
+ dx=cam_server.stream.getChild(dx)
+ if dytype==TYPE_CAMERA:
+ dy=cam_server.stream.getChild(dy)
+
+ p.addSeries(LinePlotSeries("Data"))
+ sd=p.getSeries(0)
+ sd.setLinesVisible(False)
+
+ sd.setPointSize(4)
+
+ if get_exec_pars().source == CommandSource.ui:
+ if globals().has_key("marker"):
+ p.removeMarker(marker)
+ marker=None
+
+
+ while(True):
+ #Sample and plot data
+ if bs == True:
+ _stream.waitValueNot(_stream.take(), 10000)
+ bsdata = list(_stream.take().values)
+
+ if dxtype==TYPE_CHANNEL:
+ x=dx.read()
+ elif dxtype==TYPE_STREAM:
+ x=bsdata.pop(0)
+ elif dxtype==TYPE_CAMERA:
+ x=dx.read()
+
+ if dytype==TYPE_CHANNEL:
+ y=dy.read()
+ elif dytype==TYPE_STREAM:
+ y=bsdata.pop(0)
+ elif dytype==TYPE_CAMERA:
+ y=dy.read()
+
+ sd.appendData(x, y)
+ if len(sd.x) > window:
+ #Remove First Element
+ sd.token.remove(0)
+ ax = sd.x
+ ay = sd.y
+ if len(ax)>2:
+ x1, x2 = min(ax), max(ax)
+ res = (x2-x1)/100
+ if x1!=x2:
+ #Display correlation
+ corr= PearsonsCorrelation().correlation(to_array(ax,'d'), to_array(ay,'d'))
+ s = "Correlation=" + str(round(corr,4))
+ #print s
+ if get_exec_pars().source == CommandSource.ui:
+ if marker is not None:
+ p.removeMarker(marker)
+ marker = p.addMarker(x2+res, p.AxisId.X, s, p.getBackground())
+ marker.setLabelPaint(STDOUT_COLOR)
+ if linear_fit:
+ #Calculate, print and plot linear fit
+ pars_lin = (a0,a1) = fit_polynomial(ay, ax, 1)
+ #print "Fit lin a1:" , a1, " a0:",a0
+ y1 = poly(x1, pars_lin)
+ y2 = poly(x2, pars_lin)
+ plot_line(p, x1, y1, x2, y2, width = 2, color = Color.BLUE, name = "Fit Linear")
+ if quadratic_fit:
+ #Calculate, print and plot quadratic fit
+ pars_quad = (a0,a1,a2) = fit_polynomial(ay, ax, 2)
+ #print "Fit quad a2:" , a2, "a1:" , a1, " a0:",a0
+ fitted_quad_function = PolynomialFunction(pars_quad)
+ ax = frange(x1, x2, res, True)
+ plot_function(p, fitted_quad_function, "Fit Quadratic", ax, color=Color.GREEN)
+ if bs != True:
+ time.sleep(interval)
+finally:
+ for dev in instances:
+ dev.close()
\ No newline at end of file
diff --git a/script/Photonics/PhaseShifterScan.py b/script/Photonics/PhaseShifterScan.py
index 992954b..51f0e66 100644
--- a/script/Photonics/PhaseShifterScan.py
+++ b/script/Photonics/PhaseShifterScan.py
@@ -1,5 +1,5 @@
CAMERA = "SARBD01-DSCR110"
-GAP = "SARUN10-UPHS060"
+GAP = "SARUN04-UPHS060"
SAMPLES = 20
TOLERANCE = 0.01
TIMEOUT = 10.0
@@ -9,6 +9,7 @@ cam_server.start(CAMERA + "_sp1", True)
intensity = cam_server.stream.getChild("intensity")
+
gap = Channel(GAP + ":GAP_SP", alias = "gap")
readout = Channel(GAP + ":GAP")
@@ -22,7 +23,7 @@ def before(position, scan):
if time.time() - start > TIMEOUT:
raise Exception ("Timeout waiting gap change")
-ret = lscan (gap, av, 17.5, 20, 40, latency=1.0, before_read=before)
+ret = lscan (gap, av, 17.5, 19.5, 40, latency=10.0, before_read=before)
#run("CPython/wrapper")
diff --git a/script/Photonics/PhaseShifterScan_DV.py b/script/Photonics/PhaseShifterScan_DV.py
new file mode 100644
index 0000000..678fdfb
--- /dev/null
+++ b/script/Photonics/PhaseShifterScan_DV.py
@@ -0,0 +1,40 @@
+#CAMERA = "SARBD01-DSCR110"
+GAP = "SARUN04-UPHS060"
+SAMPLES = 20
+TOLERANCE = 0.01
+TIMEOUT = 10.0
+
+#shared stream - make sure the camera is running on a screenpanel on the same console!
+#cam_server.start(CAMERA + "_sp1", True)
+
+#intensity = cam_server.stream.getChild("intensity")
+intensity = Channel("SARFE10-PBPG050:PHOTON-ENERGY-PER-PULSE-US")
+
+gap = Channel(GAP + ":GAP_SP", alias = "gap")
+readout = Channel(GAP + ":GAP")
+
+#av = create_averager(intensity, SAMPLES, interval = -1, name = None)
+av = create_averager(intensity, SAMPLES, 0.1)
+
+def before(position, scan):
+ caput(GAP + ":GO", 1)
+ start = time.time()
+ while abs(readout.read() - gap.read()) > TOLERANCE:
+ time.sleep(0.1)
+ if time.time() - start > TIMEOUT:
+ raise Exception ("Timeout waiting gap change")
+
+ret = lscan (gap, av, 17.5, 19.5, 40, latency=10.0, before_read=before)
+
+
+#run("CPython/wrapper")
+#xdata = ret.getPositions(0)
+#ydata = ret.getReadable(0)
+#(fit_amplitude, fit_phase_deg, fit_offset, ph_crest, fit_x, fit_y) = hfitoff(ydata , xdata)
+#print fit_amplitude, fit_phase_deg, fit_offset
+#plt = get_plots()[0]
+#if plt is not None:
+# plt.addSeries(LinePlotErrorSeries("fit"))
+# plt.getSeries(1).setData(fit_x, fit_y)
+# plt.getSeries(1).setPointsVisible(False)
+# plt.setLegendVisible(True)
diff --git a/script/local.py b/script/local.py
index 14d2f2e..4f41b98 100755
--- a/script/local.py
+++ b/script/local.py
@@ -239,6 +239,10 @@ def elog(title, message, attachments = [], author = None, category = "Info", dom
if (err is not None) and err!="":
raise Exception(err)
print out
+ try:
+ return int(out[out.find("ID=") +3 : ])
+ except:
+ print out
###################################################################################################