diff --git a/config/devices.properties b/config/devices.properties index 8791863..bbbb115 100755 --- a/config/devices.properties +++ b/config/devices.properties @@ -53,3 +53,4 @@ gsry=ch.psi.pshell.epics.Positioner|SINEG01-MSOL130:ROT_Y_SP SINEG01-MSOL130:ROT #adc_xh1=ch.psi.pshell.epics.ChannelInteger|SARFE10-PBPG050:HAMP-014-x-h1-DATA-SUM|||true #adc_yh2=ch.psi.pshell.epics.ChannelInteger|SARFE10-PBPG050:HAMP-011-y-h2-DATA-SUM|||true #blm_raw_test=ch.psi.pshell.epics.ChannelDoubleArray|SINDI02-DBLM025:LOSS_SIGNAL_RAW|||true +mps_beam_ok=ch.psi.pshell.epics.ChannelInteger|SGE-EMED-LLRF:ALL_OK_L1_MA||| diff --git a/config/plugins.properties b/config/plugins.properties index 8a67572..58ac4a5 100644 --- a/config/plugins.properties +++ b/config/plugins.properties @@ -8,6 +8,7 @@ ScreenPanel2.java=disabled ScreenPanel3.java=disabled SfCamera.java=enabled WireScan.java=disabled +WireScanCalibration.java=disabled SchottkyScan.java=disabled Correlation.java=disabled Cameras.java=disabled diff --git a/devices/CurrentCamera.properties b/devices/CurrentCamera.properties index 7a4d527..10e56bf 100644 --- a/devices/CurrentCamera.properties +++ b/devices/CurrentCamera.properties @@ -1,8 +1,10 @@ -#Mon Jun 25 12:57:35 CEST 2018 -colormap=Flame +#Wed Jul 25 17:06:36 CEST 2018 +\u0000= +\u0000\u0000\u0000\u0000= +colormap=Rainbow colormapAutomatic=true -colormapMax=4000.0 -colormapMin=0.0 +colormapMax=6000.0 +colormapMin=81.0 flipHorizontally=false flipVertically=false grayscale=false @@ -21,10 +23,10 @@ rotation=0.0 rotationCrop=false scale=1.0 serverURL=null -spatialCalOffsetX=-938.4756464214289 -spatialCalOffsetY=-887.658980452227 -spatialCalScaleX=-8.510638192507606 -spatialCalScaleY=-8.235816808193258 +spatialCalOffsetX=-50.03903200624512 +spatialCalOffsetY=-50.048780487804876 +spatialCalScaleX=-1.0 +spatialCalScaleY=-1.0 spatialCalUnits=null t= transpose=false diff --git a/devices/Image Averager.properties b/devices/Image Averager.properties index 48196a8..1309a17 100644 --- a/devices/Image Averager.properties +++ b/devices/Image Averager.properties @@ -1,7 +1,7 @@ -#Fri Jun 08 11:47:53 CEST 2018 +#Tue Jul 24 05:27:46 CEST 2018 colormap=Flame -colormapAutomatic=true -colormapMax=1000.0 +colormapAutomatic=false +colormapMax=2000.0 colormapMin=0.0 flipHorizontally=false flipVertically=false @@ -16,9 +16,9 @@ roiY=0 rotation=0.0 rotationCrop=false scale=1.0 -spatialCalOffsetX=-143.6163777820679 -spatialCalOffsetY=-118.46093411080528 -spatialCalScaleX=-15.559672914702317 -spatialCalScaleY=-11.299434661865234 +spatialCalOffsetX=88.97726578456339 +spatialCalOffsetY=-97.2092928484633 +spatialCalScaleX=-0.766283555464311 +spatialCalScaleY=-0.7662836119186046 spatialCalUnits=null transpose=false diff --git a/devices/Time.properties b/devices/Time.properties index 305bf0c..ad20cd6 100644 --- a/devices/Time.properties +++ b/devices/Time.properties @@ -1,4 +1,4 @@ -#Thu Jul 13 12:56:15 CEST 2017 +#Wed Jul 25 10:35:40 CEST 2018 maxValue=NaN minValue=NaN offset=0.0 @@ -6,4 +6,5 @@ precision=-1 resolution=NaN rotation=false scale=1.0 +sign_bit=0 unit=null diff --git a/devices/WireScanner motor.properties b/devices/WireScanner motor.properties index be6a1ef..e6e0760 100644 --- a/devices/WireScanner motor.properties +++ b/devices/WireScanner motor.properties @@ -1,5 +1,5 @@ -#Mon Jun 25 14:59:33 CEST 2018 -defaultSpeed=707.1067811865476 +#Wed Jun 27 13:42:28 CEST 2018 +defaultSpeed=6000.0 estbilizationDelay=0 hasEnable=false homingType=None diff --git a/devices/cam_server.properties b/devices/cam_server.properties index e84a532..12e7277 100644 --- a/devices/cam_server.properties +++ b/devices/cam_server.properties @@ -1,4 +1,4 @@ -#Mon Jun 04 15:57:42 CEST 2018 +#Wed Jul 25 14:36:06 CEST 2018 colormap=Flame colormapAutomatic=true colormapMax=NaN @@ -16,9 +16,9 @@ roiY=0 rotation=0.0 rotationCrop=false scale=1.0 -spatialCalOffsetX=-861.4939970777481 -spatialCalOffsetY=-820.4883730911062 -spatialCalScaleX=-18.90359092620482 -spatialCalScaleY=-19.37984500632817 +spatialCalOffsetX=-50.03909304143862 +spatialCalOffsetY=-50.048875855327466 +spatialCalScaleX=-1.0 +spatialCalScaleY=-1.0 spatialCalUnits=mm transpose=false diff --git a/devices/charge.properties b/devices/charge.properties index ca0c3a1..cbeb1ac 100644 --- a/devices/charge.properties +++ b/devices/charge.properties @@ -1,8 +1,9 @@ -#Thu May 03 16:23:33 CEST 2018 +#Fri Jun 29 17:40:53 CEST 2018 maxValue=NaN minValue=NaN offset=0.0 precision=1 resolution=NaN scale=1.0 +sign_bit=0 unit=pC diff --git a/devices/energy_B1.properties b/devices/energy_B1.properties index e3e670b..223ff7c 100644 --- a/devices/energy_B1.properties +++ b/devices/energy_B1.properties @@ -1,8 +1,9 @@ -#Thu May 03 16:25:04 CEST 2018 +#Fri Jun 29 17:40:53 CEST 2018 maxValue=NaN minValue=NaN offset=0.0 precision=3 resolution=NaN scale=1.0 +sign_bit=0 unit=MeV diff --git a/devices/gsrx.properties b/devices/gsrx.properties index 2324d5f..f367fe8 100644 --- a/devices/gsrx.properties +++ b/devices/gsrx.properties @@ -1,4 +1,4 @@ -#Tue Jun 13 10:51:13 CEST 2017 +#Fri Jun 29 17:40:53 CEST 2018 maxValue=1.0 minValue=-1.0 offset=0.0 @@ -6,4 +6,5 @@ precision=3 resolution=NaN rotation=false scale=1.0 +sign_bit=0 unit=mrad diff --git a/devices/gsry.properties b/devices/gsry.properties index 2324d5f..f367fe8 100644 --- a/devices/gsry.properties +++ b/devices/gsry.properties @@ -1,4 +1,4 @@ -#Tue Jun 13 10:51:13 CEST 2017 +#Fri Jun 29 17:40:53 CEST 2018 maxValue=1.0 minValue=-1.0 offset=0.0 @@ -6,4 +6,5 @@ precision=3 resolution=NaN rotation=false scale=1.0 +sign_bit=0 unit=mrad diff --git a/devices/gsx.properties b/devices/gsx.properties index af3dd05..e56f294 100644 --- a/devices/gsx.properties +++ b/devices/gsx.properties @@ -1,4 +1,4 @@ -#Tue Jun 13 10:51:13 CEST 2017 +#Fri Jun 29 17:40:53 CEST 2018 maxValue=1.0 minValue=-1.0 offset=0.0 @@ -6,4 +6,5 @@ precision=3 resolution=NaN rotation=false scale=1.0 +sign_bit=0 unit=mm diff --git a/devices/gsy.properties b/devices/gsy.properties index af3dd05..e56f294 100644 --- a/devices/gsy.properties +++ b/devices/gsy.properties @@ -1,4 +1,4 @@ -#Tue Jun 13 10:51:13 CEST 2017 +#Fri Jun 29 17:40:53 CEST 2018 maxValue=1.0 minValue=-1.0 offset=0.0 @@ -6,4 +6,5 @@ precision=3 resolution=NaN rotation=false scale=1.0 +sign_bit=0 unit=mm diff --git a/devices/gun_phase.properties b/devices/gun_phase.properties index 5491644..61cf9d2 100755 --- a/devices/gun_phase.properties +++ b/devices/gun_phase.properties @@ -1,4 +1,4 @@ -#Tue Jun 13 10:51:13 CEST 2017 +#Fri Jun 29 17:40:53 CEST 2018 maxValue=180.0 minValue=-179.99 offset=0.0 @@ -6,4 +6,5 @@ precision=2 resolution=1.0 rotation=false scale=1.0 +sign_bit=0 unit=DEG diff --git a/devices/gun_solenoid.properties b/devices/gun_solenoid.properties index f42bcc8..378a59c 100644 --- a/devices/gun_solenoid.properties +++ b/devices/gun_solenoid.properties @@ -1,4 +1,4 @@ -#Tue Jun 13 10:51:13 CEST 2017 +#Fri Jun 29 17:40:53 CEST 2018 maxValue=210.0 minValue=0.0 offset=0.0 @@ -6,4 +6,5 @@ precision=3 resolution=0.02 rotation=false scale=1.0 +sign_bit=0 unit=A diff --git a/devices/rep_rate.properties b/devices/rep_rate.properties index 86e45d8..dd8297a 100644 --- a/devices/rep_rate.properties +++ b/devices/rep_rate.properties @@ -1,8 +1,9 @@ -#Thu May 03 16:25:49 CEST 2018 +#Fri Jun 29 17:40:53 CEST 2018 maxValue=NaN minValue=NaN offset=0.0 precision=2 resolution=NaN scale=1.0 +sign_bit=0 unit=Hz diff --git a/plugins/Correlation2.form b/plugins/Correlation2.form new file mode 100644 index 0000000..bb22aea --- /dev/null +++ b/plugins/Correlation2.form @@ -0,0 +1,314 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/plugins/Correlation2.java b/plugins/Correlation2.java new file mode 100644 index 0000000..6268bd1 --- /dev/null +++ b/plugins/Correlation2.java @@ -0,0 +1,583 @@ +/* + * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. + */ + +import ch.psi.pshell.plot.Plot; +import ch.psi.pshell.swing.ChannelSelector; +import ch.psi.pshell.ui.App; +import ch.psi.pshell.ui.Panel; +import ch.psi.utils.State; +import ch.psi.utils.Chrono; +import ch.psi.utils.swing.SwingUtils; +import ch.psi.utils.swing.SwingUtils.OptionResult; +import ch.psi.utils.swing.SwingUtils.OptionType; +import java.awt.Component; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.util.HashMap; +import java.util.List; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; + +/** + * + */ +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()); + } + comboTypeXActionPerformed(null); + comboTypeYActionPerformed(null); + } + + @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(""); + } + try{ + String peak = (String)getContext().getInterpreterVariable("pos_peak"); + if (peak!=null){ + textPeak.setText(peak + " (max)"); + } else { + peak = (String)getContext().getInterpreterVariable("neg_peak"); + if (peak!=null){ + textPeak.setText(peak + " (min)"); + } else { + textPeak.setText(""); + } + } + + } catch (Exception ex){ + textPeak.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"); + buttonElog.setEnabled(true); + } + } + 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() { + } + + void elog(String logbook, String title, String message, String[] attachments) throws Exception { + String domain = ""; + String category = "Info"; + String entry = ""; + StringBuffer cmd = new StringBuffer(); + + cmd.append("G_CS_ELOG_add -l \"").append(logbook).append("\" "); + cmd.append("-a \"Author=ScreenPanel\" "); + cmd.append("-a \"Type=pshell\" "); + cmd.append("-a \"Entry=").append(entry).append("\" "); + cmd.append("-a \"Title=").append(title).append("\" "); + cmd.append("-a \"Category=").append(category).append("\" "); + cmd.append("-a \"Domain=").append(domain).append("\" "); + for (String attachment : attachments) { + cmd.append("-f \"").append(attachment).append("\" "); + } + cmd.append("-n 1 "); + cmd.append("\"").append(message).append("\" "); + System.out.println(cmd.toString()); + + final Process process = Runtime.getRuntime().exec(new String[]{"bash", "-c", cmd.toString()}); + new Thread(() -> { + try { + process.waitFor(); + int bytes = process.getInputStream().available(); + byte[] arr = new byte[bytes]; + process.getInputStream().read(arr, 0, bytes); + System.out.println(new String(arr)); + bytes = process.getErrorStream().available(); + arr = new byte[bytes]; + process.getErrorStream().read(arr, 0, bytes); + System.err.println(new String(arr)); + } catch (Exception ex) { + System.err.println(ex); + } + }).start(); + } + + + @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(); + 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(); + textDevX = new ch.psi.pshell.swing.ChannelSelector(); + textDevY = new ch.psi.pshell.swing.ChannelSelector(); + buttonElog = new javax.swing.JButton(); + jLabel8 = new javax.swing.JLabel(); + textPeak = new javax.swing.JTextField(); + + 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" })); + comboTypeX.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + comboTypeXActionPerformed(evt); + } + }); + + comboTypeY.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Channel", "Stream", "Camera" })); + comboTypeY.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + comboTypeYActionPerformed(evt); + } + }); + + textDevX.setHistorySize(20); + textDevX.setName("Correlation_textDevX"); // NOI18N + + textDevY.setHistorySize(20); + textDevY.setName("Correlation_textDevY"); // NOI18N + + buttonElog.setText("ELOG"); + buttonElog.setEnabled(false); + buttonElog.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonElogActionPerformed(evt); + } + }); + + jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); + jLabel8.setText("Peak:"); + + textPeak.setEditable(false); + textPeak.setHorizontalAlignment(javax.swing.JTextField.CENTER); + + 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) + .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(checkQuadratic) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(buttonElog) + .addContainerGap()) + .addComponent(textDevY, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(textDevX, javax.swing.GroupLayout.DEFAULT_SIZE, 318, Short.MAX_VALUE) + .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(checkLinear) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) + .addComponent(textPeak, javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(textQuadratic, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 250, 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, textLinear, textQuadratic}); + + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .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.TRAILING) + .addComponent(jLabel2) + .addComponent(textDevY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(5, 5, 5) + .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) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(checkQuadratic) + .addComponent(buttonElog)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, 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.UNRELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(jLabel8) + .addComponent(textPeak, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, 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, 277, 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(); + //Stooping smootly so displayed variables get updated. + getContext().setInterpreterVariable("stop_exec", true); + Chrono chrono = new Chrono(); + while (!chrono.isTimeout(500)){ + if (!Boolean.TRUE.equals(getContext().getInterpreterVariable("stop_exec"))){ + break; + } + Thread.sleep(1); + } + if (Boolean.TRUE.equals(getContext().getInterpreterVariable("stop_exec"))){ + System.out.println("Timeout stopping script - aborting..."); + abort(); + } + updateResults(); + //buttonStart.setText("Start"); + } else { + textCorrelation.setText(""); + textLinear.setText(""); + textQuadratic.setText(""); + textPeak.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 + + private void comboTypeXActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboTypeXActionPerformed + if (comboTypeX.getSelectedIndex()==0){ + textDevX.configure(ChannelSelector.Type.Epics, "http://epics-boot-info.psi.ch", "swissfel", 5000); + } else if (comboTypeX.getSelectedIndex()==1){ + textDevX.configure(ChannelSelector.Type.DataAPI, "https://data-api.psi.ch/sf", "sf-databuffer", 5000); + } else if (comboTypeX.getSelectedIndex()==2){ + textDevX.configure(ChannelSelector.Type.Camera, "sf-daqsync-01:8889", null, 5000); + } + }//GEN-LAST:event_comboTypeXActionPerformed + + private void comboTypeYActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboTypeYActionPerformed + if (comboTypeY.getSelectedIndex()==0){ + textDevY.configure(ChannelSelector.Type.Epics, "http://epics-boot-info.psi.ch", "swissfel", 5000); + } else if (comboTypeY.getSelectedIndex()==1){ + textDevY.configure(ChannelSelector.Type.DataAPI, "https://data-api.psi.ch/sf", "sf-databuffer", 5000); + } else if (comboTypeY.getSelectedIndex()==2){ + textDevY.configure(ChannelSelector.Type.Camera, "sf-daqsync-01:8889", null, 5000); + } + }//GEN-LAST:event_comboTypeYActionPerformed + + private void buttonElogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonElogActionPerformed + try{ + String snapshotFile = getContext().getSetup().expandPath("{context}/correlation_plot.png"); + plot.saveSnapshot(snapshotFile, "png"); + JPanel panel = new JPanel(); + GridBagLayout layout = new GridBagLayout(); + layout.columnWidths = new int[]{0, 180}; //Minimum width + layout.rowHeights = new int[]{30, 30, 30}; //Minimum height + panel.setLayout(layout); + JComboBox comboLogbook = new JComboBox(new String[]{"SwissFEL commissioning data", "SwissFEL commissioning"}); + JTextField textComment = new JTextField(); + GridBagConstraints c = new GridBagConstraints(); + c.gridx = 0; + c.gridy = 0; + panel.add(new JLabel("Logbook:"), c); + c.gridy = 1; + panel.add(new JLabel("Comment:"), c); + c.fill = GridBagConstraints.HORIZONTAL; + c.gridx = 1; + panel.add(textComment, c); + c.gridy = 0; + panel.add(comboLogbook, c); + + if (SwingUtils.showOption(getTopLevel(), "ELOG", panel, OptionType.OkCancel) == OptionResult.Yes) { + StringBuilder message = new StringBuilder(); + message.append("Device X: ").append(String.valueOf(textDevX.getText())).append("\n"); + message.append("Device Y: ").append(String.valueOf(textDevY.getText())).append("\n"); + message.append("Interval: ").append(String.valueOf(spinnerInterval.getValue())).append("\n"); + message.append("Samples: ").append(String.valueOf(spinnerWindow.getValue())).append("\n"); + message.append("Correlation: ").append(textCorrelation.getText()).append("\n"); + message.append("Linear fit: ").append(textLinear.getText()).append("\n"); + message.append("Quadratic fit: ").append(textQuadratic.getText()).append("\n"); + message.append("Peak: ").append(textPeak.getText()).append("\n"); + message.append("Comment: ").append(textComment.getText()).append("\n"); + elog((String) comboLogbook.getSelectedItem(), "Correlation Panel Snapshot", message.toString(), new String[]{snapshotFile}); + } + }catch (Exception ex){ + showException(ex); + } + }//GEN-LAST:event_buttonElogActionPerformed + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton buttonElog; + 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.JLabel jLabel8; + 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 ch.psi.pshell.swing.ChannelSelector textDevX; + private ch.psi.pshell.swing.ChannelSelector textDevY; + private javax.swing.JTextField textLinear; + private javax.swing.JTextField textPeak; + private javax.swing.JTextField textQuadratic; + // End of variables declaration//GEN-END:variables +} diff --git a/plugins/ScreenPanel3.java b/plugins/ScreenPanel3.java index 03a3caa..4c07fbf 100644 --- a/plugins/ScreenPanel3.java +++ b/plugins/ScreenPanel3.java @@ -2092,7 +2092,7 @@ public class ScreenPanel3 extends Panel { } ArrayList frames = new ArrayList<>(); frames.add(frame); - this.saveFrames("camera_snapshot", frames); + this.saveFrames(cameraName + "_camera_snapshot", frames); //Enforce the same timestamp to data & image files. snapshotFile = getContext().getExecutionPars().getPath() + ".png"; @@ -2140,7 +2140,7 @@ public class ScreenPanel3 extends Panel { void saveStack() throws Exception { synchronized (imageBuffer) { - saveFrames("camera_stack", imageBuffer); + saveFrames(cameraName + "_camera_stack", imageBuffer); } SwingUtils.showMessage(getTopLevel(), "Success", "Generated data file:\n" + getContext().getExecutionPars().getPath()); } diff --git a/plugins/WireScanCalibration.form b/plugins/WireScanCalibration.form new file mode 100644 index 0000000..514d94f --- /dev/null +++ b/plugins/WireScanCalibration.form @@ -0,0 +1,265 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/plugins/WireScanCalibration.java b/plugins/WireScanCalibration.java new file mode 100644 index 0000000..cc9c01f --- /dev/null +++ b/plugins/WireScanCalibration.java @@ -0,0 +1,309 @@ +/* + * Copyright (c) 2014-2017 Paul Scherrer Institute. All rights reserved. + */ + +import ch.psi.pshell.ui.Panel; +import ch.psi.pshell.ui.Plugin; +import ch.psi.utils.State; +import ch.psi.utils.swing.SwingUtils; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.DefaultComboBoxModel; +import javax.swing.JComboBox; + +/** + * + */ +public class WireScanCalibration extends Panel { + + public WireScanCalibration() { + initComponents(); + }c.getSetting( + + //Overridable callbacks + @Override + public void onInitialize(int runCount) { + try { + startTimer(1000, 10); + + DefaultComboBoxModel model = new DefaultComboBoxModel(); + eval("run('Devices/Elements')", true); + model.addElement(""); + List ret = (List) ((Plugin)this).eval("get_wire_scanners()", true); + for (String scan: ret){ + model.addElement(scan); + } + comboWireScanner.setModel(model); + + } catch (Exception ex) { + showException(ex); + } + + } + + +//S20CB01-DWSC440:MOTOR_1_HOME.PROC + @Override + public void onStateChange(State state, State former) { + buttonScan.setEnabled(state==State.Ready) ; + buttonAbort.setEnabled(state==State.Busy); + } + + @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(); + panelLeft = new javax.swing.JPanel(); + buttonScan = new javax.swing.JButton(); + comboWire = new javax.swing.JComboBox(); + jLabel7 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + comboWireScanner = new javax.swing.JComboBox(); + jLabel20 = new javax.swing.JLabel(); + spinnerRangeStart = new javax.swing.JSpinner(); + buttonAbort = new javax.swing.JButton(); + jLabel6 = new javax.swing.JLabel(); + spinnerRangeEnd = new javax.swing.JSpinner(); + spinnerScanPoints = new javax.swing.JSpinner(); + jLabel8 = new javax.swing.JLabel(); + jLabel9 = new javax.swing.JLabel(); + spinnerSaturation = new javax.swing.JSpinner(); + jLabel10 = new javax.swing.JLabel(); + spinnerRangeFactor = new javax.swing.JSpinner(); + jLabel11 = new javax.swing.JLabel(); + spinnerInitialGain = new javax.swing.JSpinner(); + + plot.setTitle(""); + + buttonScan.setText("Start"); + buttonScan.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonScanActionPerformed(evt); + } + }); + + comboWire.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "X1", "Y1", "X2", "Y2" })); + + jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel7.setText("Range End X (µm):"); + + jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel2.setText("Wire:"); + + jLabel20.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel20.setText("Wire Scanner:"); + + spinnerRangeStart.setModel(new javax.swing.SpinnerNumberModel(-2000.0d, -10000.0d, 10000.0d, 1.0d)); + + buttonAbort.setText("Abort"); + buttonAbort.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonAbortActionPerformed(evt); + } + }); + + jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel6.setText("Range Start (µm):"); + + spinnerRangeEnd.setModel(new javax.swing.SpinnerNumberModel(2000.0d, -10000.0d, 10000.0d, 1.0d)); + + spinnerScanPoints.setModel(new javax.swing.SpinnerNumberModel(200.0d, 10.0d, 10000.0d, 1.0d)); + + jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel8.setText("Scan points:"); + + jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel9.setText("Saturation:"); + + spinnerSaturation.setModel(new javax.swing.SpinnerNumberModel(1995.0d, 10.0d, 100000.0d, 1.0d)); + + jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel10.setText("Range factor:"); + + spinnerRangeFactor.setModel(new javax.swing.SpinnerNumberModel(6.0d, 1.0d, 20.0d, 1.0d)); + + jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel11.setText("Initial Gain:"); + + spinnerInitialGain.setModel(new javax.swing.SpinnerNumberModel(0.6d, 0.5d, 1.1d, 0.1d)); + + javax.swing.GroupLayout panelLeftLayout = new javax.swing.GroupLayout(panelLeft); + panelLeft.setLayout(panelLeftLayout); + panelLeftLayout.setHorizontalGroup( + panelLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(panelLeftLayout.createSequentialGroup() + .addContainerGap() + .addGroup(panelLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelLeftLayout.createSequentialGroup() + .addComponent(buttonScan) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(buttonAbort) + .addContainerGap()) + .addGroup(panelLeftLayout.createSequentialGroup() + .addGroup(panelLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel20, javax.swing.GroupLayout.DEFAULT_SIZE, 86, Short.MAX_VALUE) + .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(comboWireScanner, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(comboWire, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(spinnerRangeStart) + .addComponent(spinnerRangeEnd) + .addComponent(spinnerScanPoints) + .addComponent(spinnerSaturation) + .addComponent(spinnerRangeFactor) + .addComponent(spinnerInitialGain))))) + ); + + panelLeftLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel10, jLabel11, jLabel2, jLabel20, jLabel6, jLabel7, jLabel8, jLabel9}); + + panelLeftLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonAbort, buttonScan}); + + panelLeftLayout.setVerticalGroup( + panelLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(panelLeftLayout.createSequentialGroup() + .addGap(0, 0, 0) + .addGroup(panelLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(comboWireScanner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel20)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(comboWire, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel2)) + .addGap(70, 70, 70) + .addGroup(panelLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(jLabel6) + .addComponent(spinnerRangeStart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel7) + .addComponent(spinnerRangeEnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel11) + .addComponent(spinnerInitialGain, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(70, 70, 70) + .addGroup(panelLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel8) + .addComponent(spinnerScanPoints, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel9) + .addComponent(spinnerSaturation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel10) + .addComponent(spinnerRangeFactor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 78, Short.MAX_VALUE) + .addGroup(panelLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(buttonAbort) + .addComponent(buttonScan)) + .addGap(43, 43, 43)) + ); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(panelLeft, 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, 425, Short.MAX_VALUE) + .addGap(11, 11, 11)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(panelLeft, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, 484, Short.MAX_VALUE)) + .addContainerGap()) + ); + }// //GEN-END:initComponents + + private void buttonScanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonScanActionPerformed + try { + ArrayList parameters = new ArrayList(); + parameters.add(comboWireScanner.getSelectedItem().toString()); + parameters.add(plot); + parameters.add(comboWire.getSelectedItem().toString()); + parameters.add(spinnerRangeStart.getValue()); + parameters.add(spinnerRangeEnd.getValue()); + parameters.add(spinnerScanPoints.getValue()); + parameters.add(spinnerSaturation.getValue()); + parameters.add(spinnerRangeFactor.getValue()); + parameters.add(spinnerInitialGain.getValue()); + + runAsync("Diagnostics/WireScanCalibration", parameters).handle((ret, ex) -> { + if (ex != null) { + getLogger().info("Exception executing scan: " + ex); + showException((Exception) ex); + } else { + SwingUtils.showMessage(WireScanCalibration.this, "Success", String.valueOf(ret)); + } + return ret; + }); + + } catch (Exception ex) { + showException(ex); + ex.printStackTrace(); + } + }//GEN-LAST:event_buttonScanActionPerformed + + private void buttonAbortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAbortActionPerformed + try { + abort(); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonAbortActionPerformed + + //String caqtdm = "caqtdm -noMsg -stylefile sfop.qss -attach"; + String caqtdm = "caqtdm -noMsg -stylefile sfop.qss"; + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton buttonAbort; + private javax.swing.JButton buttonScan; + private javax.swing.JComboBox comboWire; + private javax.swing.JComboBox comboWireScanner; + private javax.swing.JLabel jLabel10; + private javax.swing.JLabel jLabel11; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel20; + private javax.swing.JLabel jLabel6; + private javax.swing.JLabel jLabel7; + private javax.swing.JLabel jLabel8; + private javax.swing.JLabel jLabel9; + private javax.swing.JPanel panelLeft; + private ch.psi.pshell.plot.LinePlotJFree plot; + private javax.swing.JSpinner spinnerInitialGain; + private javax.swing.JSpinner spinnerRangeEnd; + private javax.swing.JSpinner spinnerRangeFactor; + private javax.swing.JSpinner spinnerRangeStart; + private javax.swing.JSpinner spinnerSaturation; + private javax.swing.JSpinner spinnerScanPoints; + // End of variables declaration//GEN-END:variables +} diff --git a/script/2Dscan01.py b/script/2Dscan01.py new file mode 100644 index 0000000..694aabe --- /dev/null +++ b/script/2Dscan01.py @@ -0,0 +1,45 @@ +import ch.psi.pshell.epics.ChannelDouble as ChannelDouble +A1 = ChannelDouble("x", "SARUN13-DBPM070:X-REF-FB") +A2 = ChannelDouble("y", "SARUN13-DBPM070:Y-REF-FB") +camera_name = "SARBD01-DSCR110" +cam_server.start(camera_name+"_sp1", True) #True for shared pipeline +wait_cam_server_message() +S1 = cam_server.stream.getChild("intensity") + +A1.initialize() +A2.initialize() +S1.initialize() +A1_init = A1.read() +A2_init = A2.read() +A1i = A1_init-0.1 +A1f = A1_init+0.1 +A2i = A2_init-0.1 +A2f = A2_init+0.1 +nstep = 11 +lat = 5.0 +nav = 10 + + +def data_ok(): + return (mps_beam_ok.read() == 1) + +#def before_sample(record, scan): +# while not data_ok(): +# time.sleep(1.0) + +def after_sample(record, scan): + if not data_ok(): + time.sleep(1.0) + record.invalidate() + print "Invalidating record: " + str(record) +try: + S1_averager = create_averager(S1, nav, 0.1) + r = ascan((A1,A2), (S1_averager), (A1i,A2i), (A1f,A2f), (nstep,nstep), latency=lat, after_read = after_sample) + Act1 = r.getPositions(0) + S1mean = [val.mean for val in r.getReadable(0)] + S1rms = [val.stdev for val in r.getReadable(0)] +finally: + A1.write(A1_init) + A1.close() + S1.close() + #S2.close() \ No newline at end of file diff --git a/script/Correlation/Correlation2.py b/script/Correlation/Correlation2.py index 334f4e6..5182d3d 100644 --- a/script/Correlation/Correlation2.py +++ b/script/Correlation/Correlation2.py @@ -33,7 +33,9 @@ print dy, dytype corr = None pars_lin = None pars_quad = None - +pos_peak = None +neg_peak = None +stop_exec = None bs = TYPE_STREAM in [dxtype, dytype] @@ -134,7 +136,10 @@ try: if get_exec_pars().source == CommandSource.ui: if globals().has_key("marker"): p.removeMarker(marker) + if globals().has_key("peak_marker"): + p.removeMarker(peak_marker) marker=None + peak_marker=None while(True): @@ -190,6 +195,30 @@ try: fitted_quad_function = PolynomialFunction(pars_quad) ax = frange(x1, x2, res, True) plot_function(p, fitted_quad_function, "Fit Quadratic", ax, color=Color.GREEN) + + peak = None + peaks = calculate_peaks(fitted_quad_function, x1, x2, positive=True) + if len(peaks)>0: + peak = peaks[0] + pos_peak = str(round(peak,4)) + peak_str = "Positive peak: " + pos_peak + else: + peaks = calculate_peaks(fitted_quad_function, x1, x2, positive=False) + if len(peaks)>0: + peak = peaks[0] + neg_peak = str(round(peak,4)) + peak_str = "Negative peak: " + neg_peak + else: + pos_peak = neg_peak = None + if get_exec_pars().source == CommandSource.ui: + if peak_marker is not None: + p.removeMarker(peak_marker) + if peak is not None: + peak_marker = p.addMarker(peak, p.AxisId.X, peak_str, Color(0,128,0)) + + if stop_exec == True: + stop_exec = False + break if bs != True: time.sleep(interval) finally: diff --git a/script/Diagnostics/WireScanCalibration.py b/script/Diagnostics/WireScanCalibration.py index 7c0bcdb..1aea591 100644 --- a/script/Diagnostics/WireScanCalibration.py +++ b/script/Diagnostics/WireScanCalibration.py @@ -11,21 +11,23 @@ run("Diagnostics/sig_process_wrapper") # Arguments and constants ################################################################################################### -ws_prefix = args[0] if is_panel else "SINDI01-DWSC090" #"S10DI01-DWSC010" #"S10CB07-DWSC440" #"SINDI01-DWSC090" \\ -plt = args[1] if is_panel else plot(None, title = "Wire Scan Calibration")[0] -ws_wire = args[2] if is_panel else WireScanner.WireX1 -cal_range = args[3] if is_panel else True -cal_gain = args[4] if is_panel else True +ws_prefix = args[0] if is_panel else "SINDI01-DWSC090" #"S10DI01-DWSC010" #"S10CB07-DWSC440" #"SINDI01-DWSC090" \\ +plt = args[1] if is_panel else plot(None, title = "Wire Scan Calibration")[0] +ws_wire = args[2] if is_panel else WireScanner.WireX1 +range_start = args[3] if is_panel else -2000 +range_end = args[4] if is_panel else 2000 +n_shot = args[5] if is_panel else 200 +saturation = args[6] if is_panel else 19950 / 10 #S10DI01-DBLM113:AL1-WS-PMT-GAIN +scan_range_factor = args[7] if is_panel else 6.0 +initial_gain = args[8] if is_panel else 0.6 ws_blm = get_wire_scanners_blms(ws_prefix )[0] -#S10DI01-DBLM113:AL1-WS-PMT-GAIN -SATURATION = 19950 / 10 MIN_GAIN, MAX_GAIN = 0.5, 1.1 OPT_STEP = 0.02 -SCAN_RANGE_FACTOR = 6.0 -DEFAULT_RANGE = [-2000.0, 2000.0] + +print "WireScanCalibration parameters: ", ws_prefix, ws_wire, range_start, range_end, n_shot, saturation, scan_range_factor, initial_gain ################################################################################################### @@ -56,18 +58,15 @@ def set_wire_scan_range(wire, start, end): # Find COM ################################################################################################### print "--------------- Find COM --------------- " +set_status("Performing wire scan to find initial COM...") -#2) Set the number of RF shots (N_shot) to be acquired during a single cycle WSC measurement (e.g.,N_shot=50) -n_shot = 200 +set_gain(initial_gain) +print "Setting gain=", initial_gain -#3) Set a test scanning range (e.g.,Xmin=-1000,Xmax=+1000um) -x_min, x_max = DEFAULT_RANGE[0], DEFAULT_RANGE[1] - -#4) For a given machine repetition-rate (RR), the scan speed is automatically set to WSC_speed=(Xmax- Xmin)*RR/N_shot +#Calculate speed +x_min, x_max = range_start, range_end rr = get_repetition_rate() ws_speed = (x_max- x_min)*rr/n_shot - -#5) Proceed with a test scan (1 cycle) according to the above defined motor settings args = [ ws_prefix , ws_wire, [x_min, x_max, x_min, x_max], 1, ws_speed, [], [ws_blm], 10, plt, False,1] ret = run("Diagnostics/WireScan", args) [rms_com, rms_sigma, com, sigma, pos_path, path] = ret @@ -81,27 +80,18 @@ ret = run("Diagnostics/WireScan", args) print "--------------- Optimize gain --------------- " -#1) Select a BLM to be used in the WSC measurement and enable the WS_START so that it can be extracted out of the MPS and PMT-Gain and attenuation can be adjusted + start_blm_ws(ws_blm, 600.0) - - -#6) Apply a gauss fit to the obtained WSC profile in order to determine X_CoM and standard deviation (sigma_Gauss) - -#7) Move the wire to the X_CoM position and optimize the PMT-Gain so that the time-integral of the BLM voltage reaches a value equal to 90% of the Σsat level - -#offset = caget(ws_prefix + ":W1X_U0_SP") -#motor_pos=offset - com * math.sqrt(2) - ws_info = WireScanInfo("ws_info", ws_prefix ) - -#self.wire_velocity = Channel(self.prefix + ":SCAN_VELO_SP") motor_pos= ws_info.get_motor_pos(com, ws_wire) -caput(ws_prefix+":MOTOR_1.VAL", motor_pos) #DVAL? -#LOPR:0.5 HOPR:1.1 +set_status("Setting motor position to COM...") +caput(ws_prefix+":MOTOR_1.VAL", motor_pos) #DVAL? print "Starting stream..." +set_status("Creating stream for gain search..." ) + st = Stream("blm_stream", dispatcher) ch = ws_blm + ":B1_LOSS" st.addScalar(ch, ch, int(100.0 / get_repetition_rate()), 0) @@ -124,11 +114,12 @@ def get_loss(): start_gain = get_gain() pos = start_val = get_loss() loss = get_loss() -target = SATURATION * 0.8 +target = saturation * 0.8 print "Start Gain = ", start_gain print "Start Loss = ", start_val print "Target = ", target +set_status("Searching gain to match peak losses of " + str(target) + "...") def change_blm_ws_gain(gain): set_gain(gain) @@ -151,35 +142,20 @@ try: finally: stop_blm_ws(ws_blm) -""" -if start_val>target: - for pos in frange(start_gain, MIN_GAIN, -OPT_STEP, True): - change_blm_ws_gain(pos) - loss = get_loss() - print "Pos = ", pos, " Loss = ", loss - if loss<=target: - break - stop_blm_ws(ws_blm) -elif start_val