Search in sources :

Example 1 with IScriptService

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"));
}
Also used : IMarshallerService(org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService) ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) TomographyCalibrationData(uk.ac.diamond.daq.mapping.api.TomographyCalibrationData) BufferedReader(java.io.BufferedReader) IScriptService(org.eclipse.scanning.api.script.IScriptService) TomographyParams(uk.ac.diamond.daq.mapping.api.TomographyParams) IMappingExperimentBean(uk.ac.diamond.daq.mapping.api.IMappingExperimentBean)

Example 2 with IScriptService

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"));
}
Also used : ScanMetadata(org.eclipse.scanning.api.scan.models.ScanMetadata) IMarshallerService(org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService) ArrayList(java.util.ArrayList) ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) IScriptService(org.eclipse.scanning.api.script.IScriptService) XanesEdgeParameters(uk.ac.diamond.daq.mapping.api.XanesEdgeParameters) LinesToTrackEntry(uk.ac.diamond.daq.mapping.api.XanesEdgeParameters.LinesToTrackEntry) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)

Example 3 with IScriptService

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"));
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) IMarshallerService(org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService) IScriptService(org.eclipse.scanning.api.script.IScriptService)

Example 4 with IScriptService

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"));
}
Also used : PtychographyParams(uk.ac.diamond.daq.mapping.api.PtychographyParams) ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) IMarshallerService(org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService) IScriptService(org.eclipse.scanning.api.script.IScriptService)

Example 5 with IScriptService

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);
        }
    });
}
Also used : IMarshallerService(org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService) StandardsScanParams(uk.ac.diamond.daq.mapping.api.StandardsScanParams) IScriptService(org.eclipse.scanning.api.script.IScriptService) EventException(org.eclipse.scanning.api.event.EventException) JythonServerFacade(gda.jython.JythonServerFacade)

Aggregations

IMarshallerService (org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService)6 IScriptService (org.eclipse.scanning.api.script.IScriptService)6 ScanRequest (org.eclipse.scanning.api.event.scan.ScanRequest)5 JythonServerFacade (gda.jython.JythonServerFacade)2 TomographyCalibrationData (uk.ac.diamond.daq.mapping.api.TomographyCalibrationData)2 TomographyParams (uk.ac.diamond.daq.mapping.api.TomographyParams)2 DeviceException (gda.device.DeviceException)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 EventException (org.eclipse.scanning.api.event.EventException)1 CompoundModel (org.eclipse.scanning.api.points.models.CompoundModel)1 IScanPointGeneratorModel (org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)1 ScanMetadata (org.eclipse.scanning.api.scan.models.ScanMetadata)1 IMappingExperimentBean (uk.ac.diamond.daq.mapping.api.IMappingExperimentBean)1 PtychographyParams (uk.ac.diamond.daq.mapping.api.PtychographyParams)1 StandardsScanParams (uk.ac.diamond.daq.mapping.api.StandardsScanParams)1 XanesEdgeParameters (uk.ac.diamond.daq.mapping.api.XanesEdgeParameters)1 LinesToTrackEntry (uk.ac.diamond.daq.mapping.api.XanesEdgeParameters.LinesToTrackEntry)1