diff --git a/config/variables.properties b/config/variables.properties index 0c37e80..32ac6b1 100644 --- a/config/variables.properties +++ b/config/variables.properties @@ -1,4 +1,4 @@ -#Tue Jan 17 17:14:23 CET 2023 -LastRunDate=230117 -FileSequentialNumber=136 -DaySequentialNumber=16 +#Wed Jan 18 15:55:04 CET 2023 +LastRunDate=230118 +FileSequentialNumber=189 +DaySequentialNumber=51 diff --git a/plugins/EnergyScan.java b/plugins/EnergyScan.java index 4231624..b9029f7 100644 --- a/plugins/EnergyScan.java +++ b/plugins/EnergyScan.java @@ -213,6 +213,7 @@ public class EnergyScan extends ScriptProcessor { buttonInsert.setEnabled(editing); buttonClear.setEnabled(editing); buttonOpen.setEnabled(editing); + buttonSave.setEnabled(getState().isInitialized()); table.setEnabled(editing); textName.setEnabled(editing); } diff --git a/plugins/TimeResolved.java b/plugins/TimeResolved.java index 5f08b8e..b39ceb2 100644 --- a/plugins/TimeResolved.java +++ b/plugins/TimeResolved.java @@ -78,6 +78,7 @@ public class TimeResolved extends ScriptProcessor { boolean editing = !isExecuting(); buttonClear.setEnabled(editing); buttonOpen.setEnabled(editing); + buttonSave.setEnabled(getState().isInitialized()); textName.setEnabled(editing); spinnerScans.setEnabled(editing); diff --git a/plugins/XPS.form b/plugins/XPS.form index 4c5198e..b075d67 100644 --- a/plugins/XPS.form +++ b/plugins/XPS.form @@ -29,16 +29,16 @@ - + - + - + - + @@ -49,16 +49,18 @@ - + + + - + - + @@ -66,14 +68,15 @@ - + - - - - - + + + + + + @@ -266,7 +269,7 @@ - + @@ -371,5 +374,10 @@ + + + + + diff --git a/plugins/XPS.java b/plugins/XPS.java index a5d9a8c..c52266b 100644 --- a/plugins/XPS.java +++ b/plugins/XPS.java @@ -69,7 +69,8 @@ public class XPS extends ScriptProcessor { } }); table.getColumnModel().getColumn(0).setMaxWidth(60); - table.getColumnModel().getColumn(0).setResizable(false); + table.getColumnModel().getColumn(0).setResizable(false); + progress.setVisible(false); updateButtons(); } @@ -115,6 +116,7 @@ public class XPS extends ScriptProcessor { //Overridable callbacks @Override public void onInitialize(int runCount) { + progress.setVisible(false); this.startTimer(1000); } @@ -131,6 +133,15 @@ public class XPS extends ScriptProcessor { @Override public void onTimer() { if (isRunning()){ + progress.setVisible(true); + + try { + progress.setValue((Integer) this.eval("int(scienta.getProgress()*1000)", true)); + //this.getView().getStatusBar().setProgress(eval("scienta.getProgress()", true)); + } catch (Exception ex) { + getLogger().log(Level.FINER, null, ex); + } + try{ textCurScan.setText(getGlobalVar("CURRENT_REGION").toString()); } catch(Exception ex){ @@ -154,7 +165,8 @@ public class XPS extends ScriptProcessor { table.clearSelection(); } } else { - textCurScan.setText(""); + textCurScan.setText(""); + progress.setVisible(false); } } @@ -269,6 +281,7 @@ public class XPS extends ScriptProcessor { buttonInsert.setEnabled(editing); buttonClear.setEnabled(editing); buttonOpen.setEnabled(editing); + buttonSave.setEnabled(getState().isInitialized()); table.setEnabled(editing); textName.setEnabled(editing); } @@ -304,6 +317,7 @@ public class XPS extends ScriptProcessor { buttonResetId = new javax.swing.JButton(); jLabel4 = new javax.swing.JLabel(); textCurScan = new javax.swing.JTextField(); + progress = new javax.swing.JProgressBar(); jScrollPane2.setViewportView(jEditorPane1); @@ -461,7 +475,7 @@ public class XPS extends ScriptProcessor { jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 85, Short.MAX_VALUE) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(buttonInsert) @@ -533,20 +547,22 @@ public class XPS extends ScriptProcessor { textCurScan.setEditable(false); textCurScan.setHorizontalAlignment(javax.swing.JTextField.CENTER); + progress.setMaximum(1000); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 421, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addGap(0, 0, Short.MAX_VALUE) + .addGap(0, 34, Short.MAX_VALUE) .addComponent(buttonStart, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(33, 33, 33) .addComponent(buttonAbort) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap(44, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup() @@ -554,9 +570,11 @@ public class XPS extends ScriptProcessor { .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(textCurScan, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(buttonScienta, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGap(18, 18, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(progress, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) + .addGap(18, 18, Short.MAX_VALUE) .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(textFileId, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)) @@ -570,14 +588,15 @@ public class XPS extends ScriptProcessor { layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGroup(layout.createSequentialGroup() .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGap(8, 8, 8) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(jLabel2) - .addComponent(textFileId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) + .addComponent(progress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(textCurScan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel4) - .addComponent(textCurScan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(jLabel2) + .addComponent(textFileId, 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.BASELINE) .addComponent(buttonResetId) @@ -762,6 +781,7 @@ public class XPS extends ScriptProcessor { private javax.swing.JPanel jPanel2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; + private javax.swing.JProgressBar progress; private javax.swing.JSpinner spinnerPasses; private javax.swing.JTable table; private javax.swing.JTextField textCurScan; diff --git a/script/local.py b/script/local.py index 8d4b5f3..73a8beb 100644 --- a/script/local.py +++ b/script/local.py @@ -102,5 +102,8 @@ def dummy_trigger_scienta(): scienta.setIterations(iterations) print "Done" -def clear_output(): - App.getInstance().mainFrame.clearScanDisplays() +def clear_scan_output(): + App.getInstance().mainFrame.clearScanDisplays(None) + +def start_scan_output(scan): + App.getInstance().mainFrame.setScanDisplays(scan, None) diff --git a/script/templates/XPS.py b/script/templates/XPS.py index f76835f..5cc006d 100644 --- a/script/templates/XPS.py +++ b/script/templates/XPS.py @@ -4,7 +4,7 @@ if get_exec_pars().debug: print "Setting debug parameters" NAME = None FILE = None - PASSES = 1 + PASSES = 2 R1 = """{ "scienta.acquisitionMode" : "Swept", "scienta.elementSet" : "HiPPHAXPES", @@ -17,7 +17,7 @@ if get_exec_pars().debug: "scienta.highEnergy" : 407.0, "scienta.slices" : 1.0, "scienta.stepSize" : 0.25, - "scienta.stepTime" : 1.0, + "scienta.stepTime" : 0.08, "scienta.iterations" : 1.0 } """ @@ -30,14 +30,18 @@ if FILE: NAME , REGIONS, PASSES= cfg[0][0][0], cfg[1], cfg[2] print "FILE: ", FILE print "NAME: ", NAME -#print "REGIONS: ", REGIONS +print "REGIONS: ", [name for (name, val) in REGIONS] print "PASSES: ", PASSES -DUMMY_TRIGGER = False CURRENT_REGION = "" CURRENT_INDEX = -1 PLOT_TYPES={"spectrum":1, "energy":1} +SEQUENTIAL=False +DEBUG=False +parallel = not (SEQUENTIAL or (PASSES<=1) or (len(REGIONS)<=1)) + +set_exec_pars(enabled_plots=["spectrum",], plot_types=PLOT_TYPES) for r in REGIONS: name=r[0] @@ -77,34 +81,58 @@ def set_region_index(index): pars = json.loads(r[1]) CURRENT_REGION = name CURRENT_INDEX = CURRENT_INDEX+1 - print "Region: ", name - print "Pars: ", pars + if DEBUG: print "Setting Region: ", name, " ", index apply_pars(pars) def before_read(position, scan): - #set_region_index(scan.getRecordIndexInPass()-1) - #time.sleep(0.5) trigger_scienta() - pass + if parallel: + start_scan_output(scan) -clear_output() + + + + +scanning=False +def scan(region): + if DEBUG: print "Starting scan region ", region + name=REGIONS[region][0] + def before_pass(pass_num): + global scanning + if DEBUG: print "Waiting for pass: " , pass_num, " on region: ", region + while (CURRENT_INDEX != (region-1)) or scanning: + time.sleep(0.1) + scanning = True + if DEBUG: print "Starting pass: " , pass_num, " on region: ", region + set_region_index(region) + + def after_pass(pass_num): + global scanning, CURRENT_INDEX + if DEBUG: print "Finished pass: " , pass_num, " on region: ", region + if CURRENT_INDEX>=(len(REGIONS)-1): + CURRENT_INDEX=-1 + scanning = False + + tscan(sensors, 1, 0.1, tag=name, passes=PASSES, #title=name, \ + before_read=before_read, after_read=after_readout, \ + before_pass = before_pass, after_pass=after_pass, \ + name=NAME, lazy=True) + +clear_scan_output() try: - for i in range(len(REGIONS)): - set_region_index(i) - #tscan(sensors, len(REGIONS), 0.1, \ - #passes=PASSES, split=SPLIT_PASSES, \ - #before_read=before_read, after_read=after_readout, name = NAME) - if DUMMY_TRIGGER: - dummy_trigger_scienta() - - tscan(sensors, PASSES, 0.1, tag=CURRENT_REGION, \ - before_read=before_read, after_read=after_readout, \ - name=NAME, lazy=not DUMMY_TRIGGER, plot_types=PLOT_TYPES) + if not parallel: + for i in range(len(REGIONS)): + set_region_index(i) + tscan(sensors, PASSES, 0.1, tag=CURRENT_REGION, \ + before_read=before_read, after_read=after_readout, \ + name=NAME, lazy=True ) + else: + scans = [[scan,[i,]] for i in range(len(REGIONS))] + parallelize(*scans) finally: - print "Finalizing" scienta.zeroSupplies() - print "Quit script" + if DEBUG: print "Quit script" diff --git a/script/templates/XPS_seq.py b/script/templates/XPS_seq.py new file mode 100644 index 0000000..f76835f --- /dev/null +++ b/script/templates/XPS_seq.py @@ -0,0 +1,110 @@ +import json + +if get_exec_pars().debug: + print "Setting debug parameters" + NAME = None + FILE = None + PASSES = 1 + R1 = """{ + "scienta.acquisitionMode" : "Swept", + "scienta.elementSet" : "HiPPHAXPES", + "scienta.lensMode" : "T_HiPPHAXPES", + "scienta.detectorMode" : "ADC", + "scienta.energyMode" : "Kinetic", + "scienta.passEnergy" : 2, + "scienta.lowEnergy" : 387.0, + "scienta.centerEnergy" : 397.0, + "scienta.highEnergy" : 407.0, + "scienta.slices" : 1.0, + "scienta.stepSize" : 0.25, + "scienta.stepTime" : 1.0, + "scienta.iterations" : 1.0 + } """ + + REGIONS = [["R1", R1]] + +if FILE: + FILE = get_context().setup.expandPath("{home}/parameters/" + FILE) + with open(FILE) as json_file: + cfg = json.load(json_file) + NAME , REGIONS, PASSES= cfg[0][0][0], cfg[1], cfg[2] + print "FILE: ", FILE +print "NAME: ", NAME +#print "REGIONS: ", REGIONS +print "PASSES: ", PASSES + +DUMMY_TRIGGER = False +CURRENT_REGION = "" +CURRENT_INDEX = -1 +PLOT_TYPES={"spectrum":1, "energy":1} + + +for r in REGIONS: + name=r[0] + pars = json.loads(r[1]) + for k,v in pars.items(): + if (v is None) or (v== float("NaN")): + raise Exception ("Invalid value in region: ", r, " parameter: ", k) + +set_device_alias(scienta.getSpectrum(), "spectrum") +set_device_alias(scienta.getSpectrumScale(), "energy") +set_device_alias(scienta.getDataMatrix(), "image") +set_device_alias(scienta.stats[0], "sum") + +sensors=[i0, scienta.stats[0], scienta.getSpectrum(), scienta.getSpectrumScale()] #), scienta.getDataMatrix()] + + +def apply_pars(pars): + scienta.elementSet = scienta.elementSet.valueOf(pars["scienta.elementSet"]) + scienta.lensMode = scienta.lensMode.valueOf(pars["scienta.lensMode"]) + scienta.detectorMode = scienta.detectorMode.valueOf(pars["scienta.detectorMode"]) + scienta.energyMode = scienta.energyMode.valueOf(pars["scienta.energyMode"]) + scienta.acquisitionMode = scienta.acquisitionMode.valueOf(pars["scienta.acquisitionMode"]) + scienta.passEnergy = pars["scienta.passEnergy"] + scienta.getLowEnergy().writeAsync(pars["scienta.lowEnergy"]) + scienta.getCenterEnergy().writeAsync(pars["scienta.centerEnergy"]) + scienta.getHighEnergy().writeAsync(pars["scienta.highEnergy"]) + scienta.getSlices().writeAsync(pars["scienta.slices"]) + scienta.getStepSize().writeAsync(pars["scienta.stepSize"]) + scienta.getStepTime().writeAsync(pars["scienta.stepTime"]) + scienta.setIterations(int(pars["scienta.iterations"])) + + +def set_region_index(index): + global REGIONS, CURRENT_REGION, CURRENT_INDEX + r=REGIONS[index] + name=r[0] + pars = json.loads(r[1]) + CURRENT_REGION = name + CURRENT_INDEX = CURRENT_INDEX+1 + print "Region: ", name + print "Pars: ", pars + apply_pars(pars) + +def before_read(position, scan): + #set_region_index(scan.getRecordIndexInPass()-1) + #time.sleep(0.5) + trigger_scienta() + pass + +clear_output() + +try: + for i in range(len(REGIONS)): + set_region_index(i) + #tscan(sensors, len(REGIONS), 0.1, \ + #passes=PASSES, split=SPLIT_PASSES, \ + #before_read=before_read, after_read=after_readout, name = NAME) + if DUMMY_TRIGGER: + dummy_trigger_scienta() + + tscan(sensors, PASSES, 0.1, tag=CURRENT_REGION, \ + before_read=before_read, after_read=after_readout, \ + name=NAME, lazy=not DUMMY_TRIGGER, plot_types=PLOT_TYPES) + +finally: + print "Finalizing" + scienta.zeroSupplies() + print "Quit script" + +