From 2649ee77aa90febccd2c5523ec1c1bcd914e8f48 Mon Sep 17 00:00:00 2001 From: sfop Date: Wed, 5 Oct 2016 16:15:07 +0200 Subject: [PATCH] Closedown --- config/plugins.properties | 2 +- plugins/Correlation.form | 55 ++++++------ plugins/Correlation.java | 56 +++++++----- script/Correlation/Correlation.py | 140 ++++++++++++++++++------------ 4 files changed, 147 insertions(+), 106 deletions(-) diff --git a/config/plugins.properties b/config/plugins.properties index c7b984d..e3970e7 100644 --- a/config/plugins.properties +++ b/config/plugins.properties @@ -1,6 +1,6 @@ Correlation.java=enabled Cameras.java=disabled -ScreenPanel.java=enabled +ScreenPanel.java=disabled Camtool.java=disabled LaserGunAlignment.java=enabled test2.java=disabled diff --git a/plugins/Correlation.form b/plugins/Correlation.form index 54ff670..5209a4f 100644 --- a/plugins/Correlation.form +++ b/plugins/Correlation.form @@ -19,9 +19,9 @@ - - - + + + @@ -46,18 +46,10 @@ - - - - - - - - - + @@ -66,19 +58,25 @@ - - + + + + - - - - + + + + + + + + + - @@ -105,12 +103,13 @@ - - - - - - + + + + + + + @@ -180,6 +179,7 @@ + @@ -189,6 +189,11 @@ + + + + + diff --git a/plugins/Correlation.java b/plugins/Correlation.java index d566b28..961cba7 100644 --- a/plugins/Correlation.java +++ b/plugins/Correlation.java @@ -15,7 +15,7 @@ public class Correlation extends Panel { public Correlation() { initComponents(); - this.setPersistedComponents(new Component[]{textDevX, textDevY, spinnerInterval, spinnerWindow}); + this.setPersistedComponents(new Component[]{textDevX, textDevY, spinnerInterval, spinnerWindow, checkBS}); } //Overridable callbacks @@ -81,6 +81,7 @@ public class Correlation extends Panel { buttonStop = new javax.swing.JButton(); jLabel5 = new javax.swing.JLabel(); textCorrelation = new javax.swing.JTextField(); + checkBS = new javax.swing.JCheckBox(); plot.setTitle(""); @@ -114,21 +115,18 @@ public class Correlation extends Panel { } }); + jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel5.setText("Correlation:"); textCorrelation.setEditable(false); textCorrelation.setHorizontalAlignment(javax.swing.JTextField.CENTER); + checkBS.setText("Beam Synchronous"); + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(buttonStart, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonStop, javax.swing.GroupLayout.PREFERRED_SIZE, 142, 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) @@ -140,20 +138,25 @@ public class Correlation extends Panel { .addComponent(jLabel4)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(textDevX, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(textDevY, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(textDevX, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(textDevY, javax.swing.GroupLayout.PREFERRED_SIZE, 200, 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(spinnerWindow, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(checkBS)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(jPanel1Layout.createSequentialGroup() - .addComponent(jLabel5) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(textCorrelation, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .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)))) ); - jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel2, jLabel3, jLabel4, jLabel5}); + 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, textCorrelation}); + jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerInterval, spinnerWindow}); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -174,11 +177,13 @@ public class Correlation extends Panel { .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)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 100, Short.MAX_VALUE) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel5) - .addComponent(textCorrelation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 100, Short.MAX_VALUE) + .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) .addComponent(buttonStart) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(buttonStop) @@ -192,9 +197,9 @@ 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) - .addGap(0, 0, 0) - .addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, 381, Short.MAX_VALUE) - .addGap(0, 0, 0)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, 363, Short.MAX_VALUE) + .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -220,6 +225,8 @@ public class Correlation extends Panel { 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); @@ -231,6 +238,7 @@ 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; diff --git a/script/Correlation/Correlation.py b/script/Correlation/Correlation.py index 47a18f0..1038d2a 100644 --- a/script/Correlation/Correlation.py +++ b/script/Correlation/Correlation.py @@ -6,77 +6,105 @@ from ch.psi.pshell.swing.Shell import STDOUT_COLOR import org.apache.commons.math3.stat.correlation.PearsonsCorrelation as PearsonsCorrelation if get_context().source == CommandSource.ui: - dx = "SINEG01-RLLE-REF10:SIG-PHASE-AVG" - dy = "SINEG01-RLLE-REF20:SIG-PHASE-AVG" - interval = 0.20 + #dx = "SINEG01-RLLE-REF10:SIG-PHASE-AVG" + #dy = "SINEG01-RLLE-REF20:SIG-PHASE-AVG" + dx = "SINEG01-RGUN-PUP10:SIG-AMPLT-AVG" + dy = "SINEG01-RGUN-PUP20:SIG-AMPLT-AVG" + interval = 0.10 window = 40 p = plot(None)[0] + bs = True for s in p.getAllSeries(): p.removeSeries(s) +_stream = None +instances = [] def _get_device(d): + global _stream if isinstance(d, basestring): try: - if get_device(d) is not None: return get_device(d) + if get_device(d) is not None: + return get_device(d) r = eval(d) - if isinstance(r, Device): return r + print d + if isinstance(r, Device): + return r except: pass - return Channel(d) + if bs == True: + if _stream == None: + _stream = Stream("corr_stream", dispatcher) + instances.append(_stream) + _stream.addScalar(d, d, int(interval*100), 0) + d = Channel(d) + else: + d = Channel(d) + instances.append(d) return d dx = _get_device(dx) dy = _get_device(dy) - -p.addSeries(LinePlotSeries("Data")) -sd=p.getSeries(0) -sd.setLinesVisible(False) - -sd.setPointSize(4) - -if globals().has_key("marker"): - p.removeMarker(marker) - -marker=None -corr = None - -while(True): - #Sample and plot data - x=dx.read() - 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 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) - #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") + +try: + if _stream != None: + _stream.initialize() + _stream.start() + p.addSeries(LinePlotSeries("Data")) + sd=p.getSeries(0) + sd.setLinesVisible(False) - #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) + sd.setPointSize(4) + + if globals().has_key("marker"): + p.removeMarker(marker) + + marker=None + corr = None + + + while(True): + #Sample and plot data + if bs == True: + _stream.waitValueNot(_stream.take(), 10000) + (x,y) = _stream.take().values + else: + x=dx.read() + 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 marker is not None: + p.removeMarker(marker) + marker = p.addMarker(x2+res, p.AxisId.X, s, p.getBackground()) + marker.setLabelPaint(STDOUT_COLOR) - time.sleep(interval) - \ No newline at end of file + #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") + + #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