use of org.eclipse.scanning.api.script.IScriptService in project gda-core by openGDA.
the class TomographySubmitScanSection method submitScan.
@Override
protected void submitScan() {
// Read parameters from file
try (BufferedReader reader = Files.newBufferedReader(CALIBRATION_FILE_PATH)) {
final IScriptService scriptService = getService(IScriptService.class);
final IMarshallerService marshallerService = getService(IMarshallerService.class);
final IMappingExperimentBean mappingBean = getMappingBean();
final TomographyCalibrationData calibrationParams = marshallerService.unmarshal(reader.readLine(), TomographyCalibrationData.class);
final ScanRequest scanRequest = getScanRequest(mappingBean);
final TomographyParams tomoParams = new TomographyParams();
tomoParams.setTomographyCalibration(calibrationParams);
tomoParams.setProcessingFiles(getProcessingFilesAs(mappingBean));
tomoParams.setVisitId(InterfaceProvider.getBatonStateProvider().getBatonHolder().getVisitID());
populateScriptService(scriptService, marshallerService, scanRequest, tomoParams);
} catch (Exception e) {
handleException(getClientMessage(TOMO_CALIBRATE_SUBMIT_ERROR), e);
return;
}
Async.execute(() -> runScript(tomoScanScript, "tomography scanning script"));
}
use of org.eclipse.scanning.api.script.IScriptService in project gda-core by openGDA.
the class XanesSubmitScanSection method submitScan.
@Override
protected void submitScan() {
final IScriptService scriptService = getService(IScriptService.class);
final ScanRequest scanRequest = getScanRequest(getMappingBean());
final XanesEdgeParametersSection paramsSection = getMappingView().getSection(XanesEdgeParametersSection.class);
final XanesEdgeParameters xanesEdgeParameters = paramsSection.getScanParameters();
if (xanesEdgeParameters.isEnforcedShape()) {
final CompoundModel newModel = new CompoundModel(scanRequest.getCompoundModel());
final List<IScanPointGeneratorModel> models = newModel.getModels();
final List<IScanPointGeneratorModel> enforcedShapes = new ArrayList<>(models.size());
for (IScanPointGeneratorModel model : models) {
enforcedShapes.add(enforce(model));
}
newModel.setModels(enforcedShapes);
scanRequest.setCompoundModel(newModel);
}
xanesEdgeParameters.setVisitId(InterfaceProvider.getBatonStateProvider().getBatonHolder().getVisitID());
// Add XANES parameters as metadata to the ScanRequest, so they appear in the Nexus file
final ScanMetadata xanesMetadata = new ScanMetadata(MetadataType.ENTRY);
xanesMetadata.addField("tracking_method", xanesEdgeParameters.getTrackingMethod());
xanesMetadata.addField("visit_id", xanesEdgeParameters.getVisitId());
final LinesToTrackEntry linesToTrackEntry = xanesEdgeParameters.getLinesToTrack();
if (linesToTrackEntry == null || linesToTrackEntry.getLine() == null || linesToTrackEntry.getLine().isEmpty()) {
// The entry for a blank "lines to track" contains an unmodifiable Collection, which causes problems in
// marshalling, so make sure it is set null.
xanesEdgeParameters.setLinesToTrack(null);
xanesMetadata.addField("line", "None");
} else {
xanesMetadata.addField("line", linesToTrackEntry.getLine());
xanesMetadata.addField("file_paths", new ArrayList<String>(linesToTrackEntry.getFilePaths()));
}
final List<ScanMetadata> scanMetadata = new ArrayList<>(scanRequest.getScanMetadata());
scanMetadata.add(xanesMetadata);
scanRequest.setScanMetadata(scanMetadata);
try {
final IMarshallerService marshallerService = getService(IMarshallerService.class);
scriptService.setNamedValue(VAR_NAME_SCAN_REQUEST_JSON, marshallerService.marshal(scanRequest));
scriptService.setNamedValue(VAR_NAME_XANES_EDGE_PARAMS_JSON, marshallerService.marshal(xanesEdgeParameters));
} catch (Exception e) {
logger.error("Scan submission failed", e);
MessageDialog.openError(getShell(), "Error Submitting Scan", "The scan could not be submitted. See the error log for more details.");
return;
}
Async.execute(() -> runScript(scriptFilePath, "XANES scanning script"));
}
use of org.eclipse.scanning.api.script.IScriptService in project gda-core by openGDA.
the class PolarisationSubmitScanSection method submitScan.
@Override
protected void submitScan() {
if (!polarisationCheckbox.getSelection()) {
// Ordinary mapping scan
super.submitScan();
return;
}
final IScriptService scriptService = getService(IScriptService.class);
final ScanRequest scanRequest = getScanRequest(getMappingBean());
try {
// Serialise ScanRequest to JSON and put in the Jython namespace.
final IMarshallerService marshallerService = getService(IMarshallerService.class);
scriptService.setNamedValue(VAR_NAME_SCAN_REQUEST_JSON, marshallerService.marshal(scanRequest));
} catch (Exception e) {
logger.error("Scan submission failed", e);
MessageDialog.openError(getShell(), "Error Submitting Scan", "The scan could not be submitted. See the error log for more details.");
return;
}
Async.execute(() -> runScript(scriptFilePath, "Polarisation scanning script"));
}
use of org.eclipse.scanning.api.script.IScriptService in project gda-core by openGDA.
the class PtychographySubmitScanSection method submitScan.
@Override
protected void submitScan() {
final IScriptService scriptService = getService(IScriptService.class);
final ScanRequest scanRequest = getScanRequest(getMappingBean());
try {
final IMarshallerService marshallerService = getService(IMarshallerService.class);
scriptService.setNamedValue(VAR_NAME_SCAN_REQUEST_JSON, marshallerService.marshal(scanRequest));
final PtychographyParams ptychographyParams = new PtychographyParams();
final PtychographyParams.Resolution resolution = lowResButton.getSelection() ? PtychographyParams.Resolution.LOW : PtychographyParams.Resolution.HIGH;
ptychographyParams.setResolution(resolution);
scriptService.setNamedValue(VAR_NAME_PTYCHO_PARAMS_JSON, marshallerService.marshal(ptychographyParams));
} catch (Exception e) {
logger.error("Scan submission failed", e);
MessageDialog.openError(getShell(), "Error Submitting Scan", "The scan could not be submitted. See the error log for more details.");
return;
}
Async.execute(() -> runScript(scriptFilePath, "Ptychography scanning script"));
}
use of org.eclipse.scanning.api.script.IScriptService in project gda-core by openGDA.
the class StandardsScanView method submitScan.
/**
* Set the parameters of the scan in the Jython namespace and call a script to process them.
*/
private void submitScan() {
final String scanPath = scanPathEditor.getAxisText();
if (scanPath == null || scanPath.isEmpty()) {
displayError("Scan path empty", "No scan path has been defined");
return;
}
try {
final StandardsScanParams scanParams = new StandardsScanParams();
scanParams.setScanPath(scanPathEditor.getAxisText());
scanParams.setExposureTime(Double.parseDouble(exposureTimeText.getText()));
scanParams.setReverseScan(reverseCheckBox.getSelection());
final IScriptService scriptService = injectionContext.get(IScriptService.class);
final IMarshallerService marshallerService = injectionContext.get(IMarshallerService.class);
scriptService.setNamedValue(VAR_NAME_STANDARDS_SCAN_PARAMS_JSON, marshallerService.marshal(scanParams));
} catch (Exception e) {
displayError("Submit error", "Error submitting scan: " + e.getMessage());
return;
}
Async.execute(() -> {
// Run the script, disabling the submit button while it is running
final JythonServerFacade jythonServerFacade = JythonServerFacade.getInstance();
try {
setSubmitButtonEnabled(false);
logger.info("Running standards scan script: {}", SCRIPT_FILE);
jythonServerFacade.runScript(SCRIPT_FILE);
while (jythonServerFacade.getScriptStatus() == RUNNING) {
Thread.sleep(500);
}
logger.info("Finished running standards scan script");
} catch (Exception e) {
logger.error("Error running standards scan script", e);
} finally {
setSubmitButtonEnabled(true);
}
});
}
Aggregations