diff --git a/config/config.properties b/config/config.properties index a04db67..2728ebb 100755 --- a/config/config.properties +++ b/config/config.properties @@ -1,10 +1,10 @@ -#Fri Nov 25 11:17:47 CET 2016 +#Mon Nov 28 08:33:33 CET 2016 autoSaveScanData=true createSessionFiles=false dataLayout=default dataPath={data}/{year}/{month}/{day}/{date}_{time}_{name} dataProvider=default -dataScanFlushRecords=true +dataScanFlushRecords=false dataScanStrategy=default dataServerPort=-1 devicePoolFile={config}/devices.properties diff --git a/config/setup.properties b/config/setup.properties index f90ceb0..5cadb80 100755 --- a/config/setup.properties +++ b/config/setup.properties @@ -9,7 +9,7 @@ contextPath={outp}/context dataPath={outp}/data devicesPath={home}/devices extensionsPath={home}/extensions -imagesPath={outp}/images +imagesPath={data}/{year}/{month}/{day} libraryPath={script}; {script}/Lib logPath={outp}/log pluginsPath={home}/plugins diff --git a/devices/CurrentCamera.properties b/devices/CurrentCamera.properties index 5764e67..a07ec9f 100644 --- a/devices/CurrentCamera.properties +++ b/devices/CurrentCamera.properties @@ -1,10 +1,10 @@ -#Fri Nov 25 12:14:09 CET 2016 -colormap=Grayscale +#Mon Nov 28 15:14:50 CET 2016 +colormap=Temperature colormapAutomatic=true colormapMax=0.0 colormapMin=0.0 -flipHorizontally=false -flipVertically=false +flipHorizontally=true +flipVertically=true grayscale=false imageHeight=2160 imageWidth=2560 @@ -18,9 +18,9 @@ roiY=0 rotation=0.0 rotationCrop=false scale=1.0 -spatialCalOffsetX=-50.0 -spatialCalOffsetY=-50.0 -spatialCalScaleX=-1.0 -spatialCalScaleY=-1.0 +spatialCalOffsetX=-1280.0 +spatialCalOffsetY=-1075.0 +spatialCalScaleX=-8.823529411764707 +spatialCalScaleY=-8.83489784649365 spatialCalUnits=mm transpose=false diff --git a/plugins/Correlation.form b/plugins/Correlation.form index 68d6bdf..4b68be9 100644 --- a/plugins/Correlation.form +++ b/plugins/Correlation.form @@ -17,11 +17,10 @@ - + - - - + + @@ -54,33 +53,31 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + @@ -109,15 +106,24 @@ - - - - - + + + + + + + + + + + + + + + + - - - + @@ -173,17 +179,9 @@ - - - - - - - - - + @@ -198,6 +196,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/Correlation.java b/plugins/Correlation.java index b0695f9..98a2983 100644 --- a/plugins/Correlation.java +++ b/plugins/Correlation.java @@ -8,6 +8,7 @@ import ch.psi.pshell.ui.Panel; import ch.psi.utils.State; import java.awt.Component; import java.util.HashMap; +import java.util.List; /** * @@ -52,25 +53,56 @@ public class Correlation extends Panel { } } catch (Exception ex){ System.err.println(ex.getMessage()); - } + } } @Override protected void onTimer(){ - String correlation=""; + if (isRunning()){ + updateResults(); + } + } + + //DecimalFormat formatter = new DecimalFormat("0.##E0"); + void updateResults(){ try{ - correlation = String.format("%1.4f", Double.valueOf((Double)getController().getInterpreterVariable("corr"))); + textCorrelation.setText(String.format("%1.4f", Double.valueOf((Double)getController().getInterpreterVariable("corr")))); } catch (Exception ex){ - correlation = ""; + textCorrelation.setText(""); } - textCorrelation.setText(correlation); + try{ + List pars = (List)getController().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(""); + } + + try{ + List pars = (List)getController().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); - buttonStop.setEnabled(state==State.Busy); + 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); @@ -83,6 +115,10 @@ public class Correlation extends Panel { } } + + boolean isRunning(){ + return buttonStart.getText().equals("Stop"); + } @Override public void onExecutedFile(String fileName, Object result) { @@ -109,10 +145,13 @@ public class Correlation extends Panel { jLabel4 = new javax.swing.JLabel(); spinnerWindow = new javax.swing.JSpinner(); buttonStart = new javax.swing.JButton(); - buttonStop = new javax.swing.JButton(); jLabel5 = new javax.swing.JLabel(); textCorrelation = new javax.swing.JTextField(); checkBS = new javax.swing.JCheckBox(); + jLabel6 = new javax.swing.JLabel(); + textLinear = new javax.swing.JTextField(); + jLabel7 = new javax.swing.JLabel(); + textQuadratic = new javax.swing.JTextField(); plot.setTitle(""); @@ -139,14 +178,7 @@ public class Correlation extends Panel { } }); - buttonStop.setText("Stop"); - buttonStop.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonStopActionPerformed(evt); - } - }); - - jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); + jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); jLabel5.setText("Correlation:"); textCorrelation.setEditable(false); @@ -154,6 +186,18 @@ public class Correlation extends Panel { checkBS.setText("Beam Synchronous"); + 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); + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( @@ -161,33 +205,38 @@ public class Correlation extends Panel { .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jLabel1) - .addComponent(jLabel2) - .addComponent(jLabel3) - .addComponent(jLabel4)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(textDevX, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(textDevY, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE) - .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(checkBS))) - .addGroup(jPanel1Layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) - .addComponent(textCorrelation) - .addComponent(buttonStart, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonStop, javax.swing.GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE) - .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) + .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) + .addComponent(textDevX, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE) + .addComponent(textDevY, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE) + .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(checkBS) + .addComponent(textLinear, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE) + .addComponent(textQuadratic, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)) + .addGap(0, 0, Short.MAX_VALUE)) + .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)) ); 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, textDevX, textDevY, textLinear, textQuadratic}); + jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() @@ -209,15 +258,21 @@ public class Correlation extends Panel { .addComponent(spinnerWindow, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(checkBS) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 75, Short.MAX_VALUE) - .addComponent(jLabel5) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(textCorrelation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 75, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 66, 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, 89, Short.MAX_VALUE) .addComponent(buttonStart) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonStop) - .addGap(41, 41, 41)) + .addGap(45, 45, 45)) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); @@ -227,9 +282,8 @@ public class Correlation extends Panel { .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.UNRELATED) - .addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, 357, Short.MAX_VALUE) - .addContainerGap()) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, 371, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -243,30 +297,32 @@ public class Correlation extends Panel { ); }// //GEN-END:initComponents - private void buttonStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStopActionPerformed - try { - abort(); - } catch (InterruptedException ex) { - showException(ex); - } - }//GEN-LAST:event_buttonStopActionPerformed - private void buttonStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStartActionPerformed try { - 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("bs", checkBS.isSelected()); - - args.put("p", plot); - runAsync("Correlation/Correlation", args).handle((ok, ex) -> { - if (ex != null) { - ex.printStackTrace(); - } - return ok; - }); + 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("bs", checkBS.isSelected()); + + args.put("p", plot); + runAsync("Correlation/Correlation", args).handle((ok, ex) -> { + if (ex != null) { + ex.printStackTrace(); + } + return ok; + }); + ///buttonStart.setText("Stop"); + } } catch (Exception ex) { showException(ex); @@ -275,13 +331,14 @@ public class Correlation extends Panel { // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton buttonStart; - private javax.swing.JButton buttonStop; private javax.swing.JCheckBox checkBS; 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; @@ -289,5 +346,7 @@ public class Correlation extends Panel { 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/Correlation.py b/script/Correlation/Correlation.py index 487a940..1e0addf 100644 --- a/script/Correlation/Correlation.py +++ b/script/Correlation/Correlation.py @@ -8,8 +8,8 @@ import org.apache.commons.math3.stat.correlation.PearsonsCorrelation as Pearsons if get_context().source == CommandSource.ui: #dx = "SINEG01-RLLE-REF10:SIG-PHASE-AVG" #dy = "SINEG01-RLLE-REF20:SIG-PHASE-AVG" - dx = "SINEG01-RGUN-PUP10:SIG-AMPLT-AVG 4" - dy = "SINEG01-RGUN-PUP20:SIG-AMPLT-AVG 4" + #dx = "SINEG01-RGUN-PUP10:SIG-AMPLT-AVG 4" + #dy = "SINEG01-RGUN-PUP20:SIG-AMPLT-AVG 4" #dx = "SINDI01-RKLY-DCP10:REF-AMPLT" #dy = "SINDI01-RKLY-DCP10:REF-PHASE" @@ -17,8 +17,12 @@ if get_context().source == CommandSource.ui: #dx = "SINDI01-RLLE-REF10:SIG-PHASE-AVG" #dy = "SINDI01-RLLE-REF20:SIG-PHASE-AVG" - #dx = "SINDI01-RLLE-STA:SLAVE1-CPUTIMER" - #dy = "SINDI01-RLLE-STA:SLAVE1-DLTIMER" + dx = "SINDI01-RLLE-STA:SLAVE1-CPUTIMER" + dy = "SINDI01-RLLE-STA:SLAVE1-DLTIMER" + + #dx = "SINEG01-DICT215:B1_CHARGE" + #dy = "SINEG01-DBPM314:Q1" + #dx=gsx.getReadback() #dy=gsy.getReadback() @@ -26,8 +30,12 @@ if get_context().source == CommandSource.ui: window = 40 p = plot(None)[0] bs = True -print dx -print dy +#print dx +#print dy +corr = None +pars_lin = None +pars_quad = None + for s in p.getAllSeries(): p.removeSeries(s) @@ -99,13 +107,12 @@ try: sd.setLinesVisible(False) sd.setPointSize(4) - - if globals().has_key("marker"): - p.removeMarker(marker) - - marker=None - corr = None - + + if get_context().source == CommandSource.ui: + if globals().has_key("marker"): + p.removeMarker(marker) + marker=None + while(True): #Sample and plot data @@ -129,10 +136,11 @@ try: corr= PearsonsCorrelation().correlation(to_array(ax,'d'), to_array(ay,'d')) s = "Correlation=" + str(round(corr,4)) #print s - if marker is not None: - p.removeMarker(marker) - marker = p.addMarker(x2+res, p.AxisId.X, s, p.getBackground()) - marker.setLabelPaint(STDOUT_COLOR) + if get_context().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) #Calculate, print and plot linear fit pars_lin = (a0,a1) = fit_polynomial(ay, ax, 1)