diff --git a/script/EnergyScanOld.py b/script/EnergyScanOld.py new file mode 100644 index 0000000..87e9db9 --- /dev/null +++ b/script/EnergyScanOld.py @@ -0,0 +1,923 @@ +/* + * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. + */ + +import java.awt.Component; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.logging.Level; +import javax.swing.DefaultComboBoxModel; +import javax.swing.JLabel; +import ch.psi.utils.State; +import ch.psi.utils.swing.DsvEditor; +import ch.psi.utils.swing.Editor.EditorDialog; +import ch.psi.pshell.data.PlotDescriptor; +import ch.psi.pshell.device.Device; +import ch.psi.pshell.device.DeviceAdapter; +import ch.psi.pshell.epics.ChannelDoubleArray; +import ch.psi.pshell.epics.ChannelInteger; +import ch.psi.pshell.plot.LinePlot; +import ch.psi.pshell.plot.LinePlotBase; +import ch.psi.pshell.plot.LinePlotSeries; +import ch.psi.pshell.plot.Plot; +import ch.psi.pshell.ui.Panel; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.io.File; + +/** + * + */ +public class EnergyScan extends Panel { + + public EnergyScan() { + initComponents(); + buttonDefaultsActionPerformed(null); + setBackgroundUpdate(true); + } + + ChannelDoubleArray data; + ChannelDoubleArray edata; + ChannelDoubleArray idata; + ChannelDoubleArray fdata; + ChannelInteger count; + + double[] offsets = new double[4]; + /* + //Overridable callbacks + @Override + public void onStart() { + super.onStart(); + loadConfig(); + } + */ + + @Override + public void onInitialize(int runCount) { + super.onInitialize(runCount); + + loadConfig(); + + count = (ChannelInteger) getController().getDevicePool().getByName("count"); + data = (ChannelDoubleArray) getController().getDevicePool().getByName("data"); + edata = (ChannelDoubleArray) getController().getDevicePool().getByName("edata"); + idata = (ChannelDoubleArray) getController().getDevicePool().getByName("idata"); + fdata = (ChannelDoubleArray) getController().getDevicePool().getByName("fdata"); + + + count.addListener(new DeviceAdapter() { + @Override + public void onValueChanged(Device device, Object value, Object former) { + update(); + } + }); + update(); + //loadConfig(); + } + + @Override + public void onStateChange(State state, State former) { + setEnabled(state == State.Ready); + } + + @Override + public void onExecutedFile(String fileName, Object result) { + } + + @Override + protected void doUpdate() { + plot(); + } + + void stopScan() { + try{ + getLogger().info("Stopping scan"); + evalAsync("caput('START', 'STOP')"); + } catch (Exception ex){ + getLogger().log(Level.WARNING, null, ex); + } + } + + Path getConfigFile() { + return Paths.get(getController().getSetup().getConfigPath(), "energy_scan.properties"); + } + + enum Mode { + + plus, + minus, + lh, + lv + } + + Mode[] batch; + int batchIndex; + + LinePlotBase scanPlot; + LinePlotSeries scanSeries; + + @Override + public void setEnabled(boolean value) { + super.setEnabled(value); + buttonExecute.setEnabled(value); + comboSetup.setEnabled(value); + comboRunType.setEnabled(value); + buttonConfigure.setEnabled(value); + textFile.setEnabled(value); + buttonDefaults.setEnabled(value); + buttonPlot.setEnabled(value); + checkParameterControls(); + } + + void checkParameterControls() { + boolean enabled = isEnabled() && (comboRunType.getSelectedIndex() == 0); + for (Component c : panelParameters.getComponents()) { + if (!(c instanceof JLabel)) { + c.setEnabled(enabled); + } + } + spinnerAlpha.setEnabled(enabled && comboMode.getSelectedItem().equals("LINEAR")); + } + + void plot() { + try { + if ((scanPlot != null) && (scanSeries != null) && scanPlot.isShowing() && (count != null)) { + //buttonGroupPlot.getSelection(). + Integer c = count.take(); + if (c == null) { + scanSeries.clear(); + } else { + double[] ydata = null; + if (radioE.isSelected()) { + data.setSize(c); + ydata = data.read(); + } else if (radioF.isSelected()) { + fdata.setSize(c); + ydata = fdata.read(); + } else if (radioI0.isSelected()) { + idata.setSize(c); + ydata = idata.read(); + } else if (radioTEY.isSelected()) { + data.setSize(c); + idata.setSize(c); + ydata = data.read(); + double[] i0 = idata.read(); + for (int i = 0; i < c; i++) { + ydata[i] = (i0[i] == 0.0) ? Double.NaN : ydata[i] / i0[i]; + } + } else if (radioTFY.isSelected()) { + fdata.setSize(c); + idata.setSize(c); + ydata = fdata.read(); + double[] i0 = idata.read(); + for (int i = 0; i < c; i++) { + ydata[i] = (i0[i] == 0.0) ? Double.NaN : ydata[i] / i0[i]; + } + } + if (ydata == null) { + scanSeries.clear(); + } else { + edata.setSize(c); + double[] xdata = edata.read(); + scanSeries.setData(xdata, ydata); + } + } + } + } catch (Exception ex) { + showException(ex); + ex.printStackTrace(); + } + } + + void loadConfig() { + DefaultComboBoxModel model = (DefaultComboBoxModel) comboSetup.getModel(); + model.removeAllElements(); + try { + for (String line : Files.readAllLines(getConfigFile())) { + if ((line != null) && (!line.trim().isEmpty())) { + String[] tokens = line.split("="); + if (tokens.length > 0) { + model.addElement(tokens[0].trim()); + } + } + } + } catch (Exception ex) { + } + } + + String expandPath(String path) { + long time = System.currentTimeMillis(); + String mode; + if (comboMode.getSelectedIndex() == 0) { + mode = "plus"; + } else if (comboMode.getSelectedIndex() == 1) { + mode = "minus"; + } else { + mode = "lin_" + String.format("%1.0f", (Double) spinnerAlpha.getValue()); + } + path = getController().getSetup().expandPath(path); + path = path.replaceAll("\\{el\\}", String.valueOf(comboSetup.getSelectedItem())); + path = path.replaceAll("\\{mode\\}", mode); + return path; + } + + void setMode(Mode mode) { + switch (mode) { + case plus: + comboMode.setSelectedIndex(0); + spinnerOffset.setValue(offsets[0]); + return; + case minus: + comboMode.setSelectedIndex(1); + spinnerOffset.setValue(offsets[1]); + return; + case lh: + comboMode.setSelectedIndex(2); + spinnerOffset.setValue(offsets[2]); + spinnerAlpha.setValue(0.0); + return; + case lv: + comboMode.setSelectedIndex(2); + spinnerOffset.setValue(offsets[3]); + spinnerAlpha.setValue(90.0); + return; + } + } + + boolean isManualRun() { + return (comboRunType.getSelectedIndex() == 0); + } + + void setElement() throws Exception { + String selection = comboSetup.getSelectedItem().toString(); + for (String line : Files.readAllLines(getConfigFile())) { + if ((line != null) && (!line.trim().isEmpty())) { + String[] tokens = line.split("="); + if (tokens.length < 2) { + throw new Exception("Invalid file format"); + } + if (tokens[0].equals(selection)) { + tokens = tokens[1].trim().split(";"); + if (tokens.length != 8) { + throw new Exception("Invalid file format"); + } + spinnerE1.setValue(Double.valueOf(tokens[0].trim())); + spinnerE2.setValue(Double.valueOf(tokens[1].trim())); + spinnerTime.setValue(Double.valueOf(tokens[2].trim())); + spinnerDelay.setValue(Double.valueOf(tokens[3].trim())); + + offsets[0] = Double.valueOf(tokens[4].trim()); + offsets[1] = Double.valueOf(tokens[5].trim()); + offsets[2] = Double.valueOf(tokens[6].trim()); + offsets[3] = Double.valueOf(tokens[7].trim()); + break; + } + } + } + } + + void setRunType() throws Exception { + switch (comboRunType.getSelectedIndex()) { + case 0: //Manual + break; + case 1: //+ + setMode(Mode.plus); + break; + case 2: //- + setMode(Mode.minus); + break; + case 3: //LH + setMode(Mode.lh); + break; + case 4: //LV + setMode(Mode.lv); + break; + case 5: //+/- + setMode(Mode.plus); + break; + case 6: //+/-/-/+ + setMode(Mode.plus); + break; + case 7: //LH/LV + setMode(Mode.lh); + break; + case 8: //LH/LV/LV/LH + setMode(Mode.lh); + break; + } + checkParameterControls(); + } + + void run() throws Exception { + HashMap args = new HashMap(); + Double e1 = (Double) spinnerE1.getValue(); + Double e2 = (Double) spinnerE2.getValue(); + args.put("E1", e1); + args.put("E2", e2); + args.put("TIME", (Double) spinnerTime.getValue()); + args.put("DELAY", (Double) spinnerDelay.getValue()); + args.put("MODE", comboMode.getSelectedItem().toString()); + args.put("OFFSET", (Double) spinnerOffset.getValue()); + args.put("ALPHA", (Double) spinnerAlpha.getValue()); + + String file = expandPath(textFile.getText()); + args.put("FILE", file); + String folder = expandPath("{year}_{month}/{date}"); + args.put("FOLDER", folder); + buttonAbort.setEnabled(true); + + runAsync("EnergyScan", args).handle((ok, ex) -> { + try{ + buttonAbort.setEnabled(false); + if (ex != null) { + stopScan(); + throw ex; + } else { + if (batch != null) { + batchIndex++; + if (batchIndex >= batch.length) { + batch = null; + } else { + setMode(batch[batchIndex]); + run(); + } + } + } + } catch (Throwable t){ + batch = null; + getLogger().log(Level.WARNING, null, ex); + //showException((Exception)ex); + } + return ok; + }); + + if (scanPlot != null) { + scanPlot.getAxis(Plot.AxisId.X).setRange(Math.min(e1, e2), Math.max(e1, e2)); + } + } + + void startPlot() throws Exception { + PlotDescriptor descriptors = new PlotDescriptor("Energy Scan"); + ArrayList plots = getController().plot(new PlotDescriptor[]{descriptors}, null); + scanPlot = (LinePlotBase) plots.get(0); + scanSeries = scanPlot.getSeries(0); + } + + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + buttonGroupPlot = new javax.swing.ButtonGroup(); + panelParameters = new javax.swing.JPanel(); + jLabel1 = new javax.swing.JLabel(); + spinnerE1 = new javax.swing.JSpinner(); + jLabel2 = new javax.swing.JLabel(); + spinnerE2 = new javax.swing.JSpinner(); + jLabel3 = new javax.swing.JLabel(); + spinnerTime = new javax.swing.JSpinner(); + jLabel4 = new javax.swing.JLabel(); + spinnerDelay = new javax.swing.JSpinner(); + jLabel5 = new javax.swing.JLabel(); + comboMode = new javax.swing.JComboBox(); + jLabel8 = new javax.swing.JLabel(); + spinnerOffset = new javax.swing.JSpinner(); + jLabel9 = new javax.swing.JLabel(); + spinnerAlpha = new javax.swing.JSpinner(); + jPanel1 = new javax.swing.JPanel(); + comboSetup = new javax.swing.JComboBox(); + buttonConfigure = new javax.swing.JButton(); + jLabel10 = new javax.swing.JLabel(); + jLabel11 = new javax.swing.JLabel(); + comboRunType = new javax.swing.JComboBox(); + jPanel2 = new javax.swing.JPanel(); + radioTEY = new javax.swing.JRadioButton(); + radioTFY = new javax.swing.JRadioButton(); + radioE = new javax.swing.JRadioButton(); + radioF = new javax.swing.JRadioButton(); + radioI0 = new javax.swing.JRadioButton(); + buttonPlot = new javax.swing.JButton(); + panelData = new javax.swing.JPanel(); + buttonDefaults = new javax.swing.JButton(); + jLabel6 = new javax.swing.JLabel(); + textFile = new javax.swing.JTextField(); + jPanel3 = new javax.swing.JPanel(); + buttonExecute = new javax.swing.JButton(); + buttonAbort = new javax.swing.JButton(); + + panelParameters.setBorder(javax.swing.BorderFactory.createTitledBorder("Parameters")); + + jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel1.setText("E1:"); + + spinnerE1.setModel(new javax.swing.SpinnerNumberModel(690.0d, 0.0d, 9999.0d, 1.0d)); + + jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel2.setText("E2:"); + + spinnerE2.setModel(new javax.swing.SpinnerNumberModel(755.0d, 0.0d, 9999.0d, 1.0d)); + + jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel3.setText("Time(min):"); + + spinnerTime.setModel(new javax.swing.SpinnerNumberModel(3.0d, 0.0d, 60.0d, 1.0d)); + + jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel4.setText("Delay(s):"); + + spinnerDelay.setModel(new javax.swing.SpinnerNumberModel(10.0d, 0.0d, 600.0d, 1.0d)); + + jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel5.setText("Mode:"); + + comboMode.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "CIRC +", "CIRC -", "LINEAR" })); + comboMode.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + comboModeActionPerformed(evt); + } + }); + + jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel8.setText("Offset:"); + + spinnerOffset.setModel(new javax.swing.SpinnerNumberModel(0.0d, -20.0d, 20.0d, 1.0d)); + + jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel9.setText("Alpha:"); + + spinnerAlpha.setModel(new javax.swing.SpinnerNumberModel(0.0d, 0.0d, 90.0d, 1.0d)); + + javax.swing.GroupLayout panelParametersLayout = new javax.swing.GroupLayout(panelParameters); + panelParameters.setLayout(panelParametersLayout); + panelParametersLayout.setHorizontalGroup( + panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(panelParametersLayout.createSequentialGroup() + .addContainerGap() + .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(spinnerE1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(spinnerTime, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(comboMode, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(spinnerE2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(spinnerDelay, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(spinnerOffset, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(spinnerAlpha, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + panelParametersLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {comboMode, spinnerE1, spinnerTime}); + + panelParametersLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel2, jLabel4, jLabel8, jLabel9}); + + panelParametersLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerAlpha, spinnerDelay, spinnerE2, spinnerOffset}); + + panelParametersLayout.setVerticalGroup( + panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(panelParametersLayout.createSequentialGroup() + .addGap(0, 0, 0) + .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel1) + .addComponent(spinnerE1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel2) + .addComponent(spinnerE2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel3) + .addComponent(spinnerTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel4) + .addComponent(spinnerDelay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel5) + .addComponent(comboMode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel8) + .addComponent(spinnerOffset, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGap(5, 5, 5) + .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(spinnerAlpha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel9)) + .addContainerGap()) + ); + + jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Setup")); + + comboSetup.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + comboSetupActionPerformed(evt); + } + }); + + buttonConfigure.setText("Configure"); + buttonConfigure.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonConfigureActionPerformed(evt); + } + }); + + jLabel10.setText("Element:"); + + jLabel11.setText("Run Type:"); + + comboRunType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Manual", "+", "-", "LH", "LV", "+/-", "+/-/-/+", "LH/LV", "LH/LV/LV/LH" })); + comboRunType.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + comboRunTypeActionPerformed(evt); + } + }); + + 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) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.TRAILING)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(comboRunType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(comboSetup, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(buttonConfigure))) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {comboRunType, comboSetup}); + + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addGap(4, 4, 4) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(comboSetup, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel10) + .addComponent(buttonConfigure)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel11) + .addComponent(comboRunType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap()) + ); + + jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Plot Options")); + + buttonGroupPlot.add(radioTEY); + radioTEY.setSelected(true); + radioTEY.setText("TEY"); + radioTEY.setMinimumSize(new java.awt.Dimension(100, 22)); + radioTEY.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + radioPlotActionPerformed(evt); + } + }); + + buttonGroupPlot.add(radioTFY); + radioTFY.setText("TFY"); + radioTFY.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + radioPlotActionPerformed(evt); + } + }); + + buttonGroupPlot.add(radioE); + radioE.setText("TEYraw"); + radioE.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + radioPlotActionPerformed(evt); + } + }); + + buttonGroupPlot.add(radioF); + radioF.setText("TFYraw"); + radioF.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + radioPlotActionPerformed(evt); + } + }); + + buttonGroupPlot.add(radioI0); + radioI0.setText("I0"); + radioI0.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + radioPlotActionPerformed(evt); + } + }); + + buttonPlot.setText("Plot"); + buttonPlot.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonPlotActionPerformed(evt); + } + }); + + javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); + jPanel2.setLayout(jPanel2Layout); + jPanel2Layout.setHorizontalGroup( + jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel2Layout.createSequentialGroup() + .addContainerGap() + .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(radioTEY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(radioTFY) + .addComponent(radioE) + .addComponent(radioF) + .addComponent(radioI0)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(buttonPlot, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {radioE, radioF, radioI0, radioTEY, radioTFY}); + + jPanel2Layout.setVerticalGroup( + jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel2Layout.createSequentialGroup() + .addContainerGap() + .addComponent(radioTEY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(radioTFY) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(radioE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(radioF) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(radioI0) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonPlot) + .addContainerGap()) + ); + + panelData.setBorder(javax.swing.BorderFactory.createTitledBorder("File")); + + buttonDefaults.setText("Default"); + buttonDefaults.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonDefaultsActionPerformed(evt); + } + }); + + jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel6.setText("File:"); + + javax.swing.GroupLayout panelDataLayout = new javax.swing.GroupLayout(panelData); + panelData.setLayout(panelDataLayout); + panelDataLayout.setHorizontalGroup( + panelDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(panelDataLayout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel6) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(textFile) + .addGap(18, 18, 18) + .addComponent(buttonDefaults) + .addContainerGap()) + ); + panelDataLayout.setVerticalGroup( + panelDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(panelDataLayout.createSequentialGroup() + .addGroup(panelDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel6) + .addComponent(textFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(buttonDefaults, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap()) + ); + + jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Scan Control")); + + buttonExecute.setText("Start"); + buttonExecute.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonExecuteActionPerformed(evt); + } + }); + + buttonAbort.setText("Abort"); + buttonAbort.setEnabled(false); + buttonAbort.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonAbortActionPerformed(evt); + } + }); + + javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); + jPanel3.setLayout(jPanel3Layout); + jPanel3Layout.setHorizontalGroup( + jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup() + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(buttonAbort, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(buttonExecute, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + jPanel3Layout.setVerticalGroup( + jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup() + .addGap(4, 4, 4) + .addComponent(buttonExecute) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonAbort) + .addContainerGap()) + ); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(0, 0, 0) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(panelData, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(panelParameters, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) + .addGap(0, 0, 0)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(16, 16, 16) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(panelParameters, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(panelData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jPanel1, jPanel3}); + + layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jPanel2, panelParameters}); + + }// //GEN-END:initComponents + + private void buttonExecuteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonExecuteActionPerformed + try { + startPlot(); + batchIndex = 0; + switch (comboRunType.getSelectedIndex()) { + case 5: + batch = new Mode[]{Mode.plus, Mode.minus}; + break; + case 6: + batch = new Mode[]{Mode.plus, Mode.minus, Mode.minus, Mode.plus}; + break; + case 7: + batch = new Mode[]{Mode.lh, Mode.lv}; + break; + case 8: + batch = new Mode[]{Mode.lh, Mode.lv, Mode.lv, Mode.lh}; + break; + default: + batch = null; + } + run(); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonExecuteActionPerformed + + private void buttonAbortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAbortActionPerformed + batch = null; + abort(); + }//GEN-LAST:event_buttonAbortActionPerformed + + private void comboSetupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboSetupActionPerformed + try { + if (comboSetup.getSelectedItem() != null) { + setElement(); + if (!isManualRun()) { + setRunType(); + } + } + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_comboSetupActionPerformed + + EditorDialog dlgConfig; + private void buttonConfigureActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonConfigureActionPerformed + try { + //Desktop.getDesktop().open(getConfigFile().toFile()); + if ((dlgConfig == null) || (!dlgConfig.isShowing())) { + String[] columns = new String[]{"Element", "E1", "E2", "Time", "Delay", "OffPlus", "OffMinus", "OffLH", "OffLV"}; + Class[] types = new Class[]{String.class, Double.class, Double.class, Double.class, Double.class, Double.class, Double.class, Double.class, Double.class}; + DsvEditor editor = new DsvEditor(columns, types, ";"); + dlgConfig = editor.getDialog(getView(), false); + editor.load(getConfigFile().toString()); + editor.setTitle("Energy Scan Configuration"); + dlgConfig.addWindowListener(new WindowAdapter() { + @Override + public void windowClosed(WindowEvent e) { + if (System.currentTimeMillis() - new File(dlgConfig.getEditor().getFileName()).lastModified() < 5000) { + loadConfig(); + } + } + }); + } + dlgConfig.setSize(680, 320); + showWindow(dlgConfig); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonConfigureActionPerformed + + private void comboModeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboModeActionPerformed + checkParameterControls(); + }//GEN-LAST:event_comboModeActionPerformed + + private void radioPlotActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioPlotActionPerformed + plot(); + }//GEN-LAST:event_radioPlotActionPerformed + + private void comboRunTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboRunTypeActionPerformed + try { + if (!isManualRun()) { + setElement(); + } + setRunType(); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_comboRunTypeActionPerformed + + private void buttonDefaultsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDefaultsActionPerformed + textFile.setText("{el}_{mode}"); + }//GEN-LAST:event_buttonDefaultsActionPerformed + + private void buttonPlotActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPlotActionPerformed + try { + startPlot(); + plot(); + } catch (Exception ex) { + showException(ex); + } + + }//GEN-LAST:event_buttonPlotActionPerformed + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton buttonAbort; + private javax.swing.JButton buttonConfigure; + private javax.swing.JButton buttonDefaults; + private javax.swing.JButton buttonExecute; + private javax.swing.ButtonGroup buttonGroupPlot; + private javax.swing.JButton buttonPlot; + private javax.swing.JComboBox comboMode; + private javax.swing.JComboBox comboRunType; + private javax.swing.JComboBox comboSetup; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel10; + private javax.swing.JLabel jLabel11; + 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 jLabel8; + private javax.swing.JLabel jLabel9; + private javax.swing.JPanel jPanel1; + private javax.swing.JPanel jPanel2; + private javax.swing.JPanel jPanel3; + private javax.swing.JPanel panelData; + private javax.swing.JPanel panelParameters; + private javax.swing.JRadioButton radioE; + private javax.swing.JRadioButton radioF; + private javax.swing.JRadioButton radioI0; + private javax.swing.JRadioButton radioTEY; + private javax.swing.JRadioButton radioTFY; + private javax.swing.JSpinner spinnerAlpha; + private javax.swing.JSpinner spinnerDelay; + private javax.swing.JSpinner spinnerE1; + private javax.swing.JSpinner spinnerE2; + private javax.swing.JSpinner spinnerOffset; + private javax.swing.JSpinner spinnerTime; + private javax.swing.JTextField textFile; + // End of variables declaration//GEN-END:variables +} diff --git a/script/HystScanMult.py b/script/HystScanMult.py new file mode 100644 index 0000000..843e215 --- /dev/null +++ b/script/HystScanMult.py @@ -0,0 +1,96 @@ +#Parameters +""" +FIELD = "Hx" +RANGES = [(-0.1, 0.1, 0,2),] +ENERGIES = (707.90, 703.90) +ENERGY_CHANGE_SLEEP = 0.5 +MODE = 'CIRC +' +OFFSET = -1.0 +""" + + +FIELD_PRECISION = 0.01 +field = field_z if FIELD == "Hz" else field_x +field_done = field_z_done if FIELD == "Hz" else field_x_done +ramp_rate = ramp_rate_z if FIELD == "Hz" else ramp_rate_x + +#Pre-actions +#cawait('ACOAU-ACCU:OP-MODE', 'Light Available', type = 's') +wait_beam() +if MODE is not None: + pol_mode.write(MODE) +if OFFSET is not None: + pol_offset.write(OFFSET) #caput('X07MA-ID:ENERGY-OFFS', OFFSET) +caputq('X07MA-PC:CSCALER.INPB', '1') + +if len(ENERGIES) ==2: + dif_series = plot([],"Dif", context="Dif")[0].getSeries(0) +else: + dif_series = None + +set_preference(Preference.ENABLED_PLOTS, ['field', 'tey_norm', 'trans_norm']) +set_preference(Preference.PLOT_TYPES, {'tey_norm':1, 'trans_norm':1}) + +scan = ManualScan(['field', 'Energy'], ['TEY', 'I0', 'trans', 'polarization', 'polAngle', 'temperature', 'RingCurrent', 'fieldAnalogX', 'tey_norm','trans_norm'], [0.0, ENERGIES[0]], [0.0, ENERGIES[-1]], [0, len(ENERGIES)-1]) +scan.start() + + + +print "SKIPPED Waiting for start field" + + +for (START_FIELD, END_FIELD, RAMP_RATE) in RANGES: + ramp_rate.write(RAMP_RATE) + if abs(field.readback.read() - START_FIELD) > FIELD_PRECISION: + field.write(START_FIELD) + + + field_done.waitValue(1) #ramp_done.wait_for_value(1.0) + pol_done.waitValue("DONE") + + open(2.0) + + print "Set end field" + field.write(END_FIELD) #caputq('X07MA-PC-PS2:M:GO.A', END_FIELD) + + index = 0 + while(True): + for setpoint2 in ENERGIES: + #Energy.put(setpoint2, timeout=None) # TODO: Set appropriate timeout + energy.write(setpoint2) + sleep( ENERGY_CHANGE_SLEEP ) # Settling time + + #TODO: change to Controlled variable? + readback2 = energy_readback.read() #EnergyReadback.get() + if abs(readback2 - setpoint2) > 0.1 : # TODO: Check accuracy + raise Exception('Energy could not be set to the value ' + str(setpoint2)) + + #Detector field readback + field_readback = field.readback.read() #fieldReadback.get() + + detector1 = signal_tey.read() #TEY.get() + detector2 = signal_i0.read() #I0.get() + detector3 = signal_trans.read() #trans.get() + detector4 = float(pol_mode.getPositions().index(pol_mode.readback.read())) #polarization.get() + detector5 = pol_angle.read() #polAngle.get() + detector6 = temperature.read() #temperature.get() + detector7 = current.read() + detector8 = signal_field_analog_x.read() # fieldAnalogX.get() + + tey_norm = detector1/detector2 + trans_norm = detector3/detector2 + + if dif_series is not None: + if setpoint2 == ENERGIES[0]: + first = tey_norm + else: + dif = tey_norm-first + dif_series.appendData(field_readback,dif) + scan.append ([field_readback, setpoint2], [field_readback, readback2], [detector1, detector2, detector3, detector4, detector5, detector6, detector7, detector8, tey_norm, trans_norm]) + + if field_done.read() == 1: #If not ramping #ramp_done.get() == 1: + print "Not ramping, breaking execution" + break + index = index+1 + + scan.end() diff --git a/script/HystScanOld.py b/script/HystScanOld.py new file mode 100644 index 0000000..8c373b1 --- /dev/null +++ b/script/HystScanOld.py @@ -0,0 +1,171 @@ +#Script imported from: Fe_hyst_plus.xml + +#Parameters +""" +START_FIELD = -0.1 +END_FIELD = 0.1 +ENERGIES = (707.90, 703.90) +RAMP_RATE = 0.2 +ENERGY_CHANGE_SLEEP = 0.5 +MODE = 'CIRC +' +OFFSET = -1.0 +""" + + +FIELD_PRECISION = 0.01 + +#Pre-actions +cawait('ACOAU-ACCU:OP-MODE', 'Light Available', type = 's') +caput('X07MA-ID:MODE', MODE) +caput('X07MA-ID:ENERGY-OFFS', OFFSET) +caputq('X07MA-PC:CSCALER.INPB', '1') +caputq('X07MA-PC-PS2:SET:DMD:RAMPRATE:TPM', RAMP_RATE) +#sleep(15.0) + +if len(ENERGIES) ==2: + dif_series = plot([],"Dif", context="Dif")[0].getSeries(0) +else: + dif_series = None + +set_preference(Preference.ENABLED_PLOTS, ['field', 'tey_norm', 'trans_norm']) +set_preference(Preference.PLOT_TYPES, {'tey_norm':1, 'trans_norm':1}) + +#scan = ManualScan(['field', 'Energy'], ['TEY', 'I0', 'trans', 'polarization', 'polAngle', 'temperature', 'RingCurrent', 'fieldAnalogX', 'tey_norm','trans_norm']) +scan = ManualScan(['field', 'Energy'], ['TEY', 'I0', 'trans', 'polarization', 'polAngle', 'temperature', 'RingCurrent', 'fieldAnalogX', 'tey_norm','trans_norm'], [0.0, ENERGIES[0]], [0.0, ENERGIES[-1]], [0, len(ENERGIES)-1]) +scan.start() + +#Stop condition +ramp_done = Channel('X07MA-PC-MAG:X:RAMP:DONE', type = 'i') + +#Creating channels: dimension 1 +#RegionPositioner field +#field = Channel('X07MA-PC:GO', type = 'd') +fieldReadback = Channel('X07MA-PC-PS2:STS:PMCURRENT', type = 'd') +#Creating channels: dimension 2 +#ArrayPositioner Energy +Energy = Channel('X07MA-PHS-E:GO.A', type = 'd') +EnergyReadback = Channel('X07MA-PGM:CERBK', type = 'd') +#ScalarDetector TEY +TEY = Channel('X07MA-ES1-AI:SIGNAL0', type = 'd') +#ScalarDetector I0 +I0 = Channel('X07MA-ES1-AI:SIGNAL1', type = 'd') +#ScalarDetector trans +trans = Channel('X07MA-ES1-AI:SIGNAL2', type = 'd') +#ScalarDetector polarization +polarization = Channel('X07MA-ID:MODE', type = 'd') +#ScalarDetector polAngle +polAngle = Channel('X07MA-ID:ALPHA', type = 'd') +#ScalarDetector temperature +temperature = Channel('X07MA-PC-TC:STS:T1', type = 'd') +#ScalarDetector RingCurrent +RingCurrent = Channel('ARIDI-PCT:CURRENT', type = 'd') +#ScalarDetector fieldAnalogX +fieldAnalogX = Channel('X07MA-ES1-AI:SIGNAL4', type = 'd') + + +print "SKIPPED Waiting for start field" + + +#if abs(fieldReadback.get() - START_FIELD) > FIELD_PRECISION: +# caput('X07MA-PC-PS2:M:GO.A', START_FIELD) + + + +#caput("X07MA-PC-MAG:X:DMD", START_FIELD) +#caput("X07MA-PC-MAG:STARTRAMP.PROC", 1) + +ramp_done.wait_for_value(1.0) + +cawait('X07MA-ID:DONE', 'DONE', type = 's') + +caput('X07MA-OP-VG13:WT_SET', 'Try open') +time.sleep(2.0) + +print "Set end field" +#caput("X07MA-PC-MAG:X:DMD", END_FIELD) +#caputq("X07MA-PC-MAG:STARTRAMP.PROC", 1) +caputq('X07MA-PC-PS2:M:GO.A', END_FIELD) + + + + +index = 0 +while(True): + #Dimension 2START_FIELD = -0.2 + #ArrayPositioner Energy + for setpoint2 in ENERGIES: + Energy.put(setpoint2, timeout=None) # TODO: Set appropriate timeout + sleep( ENERGY_CHANGE_SLEEP ) # Settling time + + readback2 = EnergyReadback.get() + if abs(readback2 - setpoint2) > 0.1 : # TODO: Check accuracy + raise Exception('Actor Energy could not be set to the value ' + str(setpoint2)) + + #Detector field readback + field_readback = fieldReadback.get() + + #Detector TEY + detector1 = TEY.get() + #Detector I0 + detector2 = I0.get() + #Detector trans + detector3 = trans.get() + #Detector polarization + detector4 = polarization.get() + #Detector polAngle + detector5 = polAngle.get() + #Detector temperature + detector6 = temperature.get() + #Detector RingCurrent + detector7 = RingCurrent.get() + #Detector fieldAnalogX + detector8 = fieldAnalogX.get() + + + #Manipulation tey_norm + #Variable Mappings + + #TODO: Move, if needed, this import to the file header: import math + tey_norm = detector1/detector2 + + #Manipulation trans_norm + #Variable Mappings + + #TODO: Move, if needed, this import to the file header: import math + trans_norm = detector3/detector2 + + + if dif_series is not None: + if setpoint2 == ENERGIES[0]: + first = tey_norm + else: + dif = tey_norm-first + dif_series.appendData(field_readback,dif) + #print [field_readback, setpoint2] + #print [field_readback, readback2] + #print [detector1, detector2, detector3, detector4, detector5, detector6, detector7, detector8, tey_norm, trans_norm] + scan.append ([field_readback, setpoint2], [field_readback, readback2], [detector1, detector2, detector3, detector4, detector5, detector6, detector7, detector8, tey_norm, trans_norm]) + + + #print "Field = " + str(fieldReadback.get()) + if ramp_done.get() == 1: #If not ramping + print "Not ramping, breaking execution" + break + index = index+1 + +#Closing channels +Energy.close() +EnergyReadback.close() +TEY.close() +I0.close() +trans.close() +polarization.close() +polAngle.close() +temperature.close() +RingCurrent.close() +fieldAnalogX.close() +#field.close() +fieldReadback.close() +ramp_done.close() + +scan.end()