Search in sources :

Example 6 with IScanPointGeneratorModel

use of org.eclipse.scanning.api.points.models.IScanPointGeneratorModel in project gda-core by openGDA.

the class TimeSeriesScanView method createScanBean.

private ScanBean createScanBean() {
    final IMalcolmModel malcolmModel = malcolmModelEditor.getModel();
    final String malcolmDeviceName = malcolmModel.getName();
    final ScanRequest scanRequest = new ScanRequest();
    // add the malcolm model to the scan request
    final Map<String, IDetectorModel> detectors = new HashMap<>();
    detectors.put(malcolmDeviceName, malcolmModel);
    scanRequest.setDetectors(detectors);
    // extract the models from the outer scannables
    final List<IScanPointGeneratorModel> pointsModels = outerScannablesBlock.getOuterScannables().stream().filter(IScanModelWrapper<IScanPointGeneratorModel>::isIncludeInScan).map(IScanModelWrapper<IScanPointGeneratorModel>::getModel).collect(toCollection(ArrayList::new));
    final int numSteps = numStepsSpinner.getSelection();
    pointsModels.add(new StaticModel(numSteps));
    scanRequest.setCompoundModel(new CompoundModel(pointsModels));
    final ScanBean scanBean = new ScanBean(scanRequest);
    scanBean.setName(String.format("%s - Time Series", malcolmDeviceName));
    return scanBean;
}
Also used : HashMap(java.util.HashMap) StaticModel(org.eclipse.scanning.api.points.models.StaticModel) ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) ScanBean(org.eclipse.scanning.api.event.scan.ScanBean) IScanModelWrapper(uk.ac.diamond.daq.mapping.api.IScanModelWrapper) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) IMalcolmModel(org.eclipse.scanning.api.device.models.IMalcolmModel) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)

Example 7 with IScanPointGeneratorModel

use of org.eclipse.scanning.api.points.models.IScanPointGeneratorModel in project gda-core by openGDA.

the class XanesEdgeParametersSection method handleEdgeSelectionChanged.

/**
 * Update {@link #energyScannable} when the user selects an edge
 *
 * @param edgeEnergy
 *            Energy of the edge selected by the user
 */
private void handleEdgeSelectionChanged(IStructuredSelection selection) {
    final EdgeToEnergy selectedEdge = (EdgeToEnergy) selection.getFirstElement();
    if (selectedEdge == null) {
        return;
    }
    final IScanPointGeneratorModel scanPathModel = createModelFromEdgeSelection(selectedEdge.getEnergy(), energyScannableName);
    final IScanModelWrapper<IScanPointGeneratorModel> energyScannable = getOuterScannable(getMappingBean(), energyScannableName);
    if (energyScannable != null) {
        energyScannable.setModel(scanPathModel);
    }
    // Refresh outer scannables section to update text box
    getMappingView().getSection(OuterScannablesSection.class).updateControls();
}
Also used : OuterScannablesSection(uk.ac.diamond.daq.mapping.ui.experiment.OuterScannablesSection) EdgeToEnergy(uk.ac.diamond.daq.mapping.api.XanesEdgeParameters.EdgeToEnergy) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)

Example 8 with IScanPointGeneratorModel

use of org.eclipse.scanning.api.points.models.IScanPointGeneratorModel 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 9 with IScanPointGeneratorModel

use of org.eclipse.scanning.api.points.models.IScanPointGeneratorModel in project gda-core by openGDA.

the class ScanRequestConverter method mergeOuterScannables.

private void mergeOuterScannables(CompoundModel compoundModel, IMappingExperimentBean mappingBean) {
    final List<IScanModelWrapper<IScanPointGeneratorModel>> outerScannables = mappingBean.getScanDefinition().getOuterScannables();
    final List<IScanPointGeneratorModel> models = compoundModel.getModels();
    final List<IScanPointGeneratorModel> outerScannableModels = new ArrayList<>(models.subList(0, models.size() - 1));
    // We assume that models have the same name as the wrapper
    final Iterator<IScanPointGeneratorModel> modelIter = outerScannableModels.iterator();
    IScanPointGeneratorModel currentModel = modelIter.hasNext() ? modelIter.next() : null;
    // current model. If we find a match, then we move on to the next model
    for (IScanModelWrapper<IScanPointGeneratorModel> outerScannable : outerScannables) {
        if (currentModel == null || !outerScannable.getName().equals(currentModel.getName())) {
            // this outer scannable wrapper isn't in the scan request
            ((ScanPathModelWrapper) outerScannable).setIncludeInScan(false);
        } else {
            // this is the wrapper for this model, set it enabled and overwrite its model
            // with the outer scannable model
            ((ScanPathModelWrapper) outerScannable).setIncludeInScan(true);
            ((ScanPathModelWrapper) outerScannable).setModel(currentModel);
            currentModel = modelIter.hasNext() ? modelIter.next() : null;
        }
    }
    // We didn't find a wrapper for this model; let's create one
    if (currentModel != null) {
        IScanModelWrapper<IScanPointGeneratorModel> wrapper = new ScanPathModelWrapper(currentModel.getName(), currentModel, true);
        List<IScanModelWrapper<IScanPointGeneratorModel>> updatedOuterScannables = new ArrayList<>(outerScannables);
        updatedOuterScannables.add(wrapper);
        mappingBean.getScanDefinition().setOuterScannables(updatedOuterScannables);
    }
}
Also used : ScanPathModelWrapper(uk.ac.diamond.daq.mapping.impl.ScanPathModelWrapper) IScanModelWrapper(uk.ac.diamond.daq.mapping.api.IScanModelWrapper) ArrayList(java.util.ArrayList) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)

Example 10 with IScanPointGeneratorModel

use of org.eclipse.scanning.api.points.models.IScanPointGeneratorModel in project gda-core by openGDA.

the class ScanRequestConverter method convertToScanRequest.

/**
 * Convert an IMappingExperimentBean to a ScanRequest so that it can be run by the
 * GDA9 scanning framework.
 * <p>
 * This will include setting the mapping scan axes with the names from the mapping axis manager.
 * <p>
 * This method is made <code>public</code> to allow testing.
 *
 * @param mappingBean
 *            the IMappingExperimentBean to be converted
 * @return the ScanRequest
 */
public ScanRequest convertToScanRequest(IMappingExperimentBean mappingBean) {
    final ScanRequest scanRequest = new ScanRequest();
    final IMappingScanRegion scanRegion = mappingBean.getScanDefinition().getMappingScanRegion();
    final IMapPathModel mapPath = getMapPathAndConfigureScanAxes(scanRegion);
    // Build the list of models for the scan
    // first get the models for any outer scannables to be included
    final List<IScanPointGeneratorModel> models = mappingBean.getScanDefinition().getOuterScannables().stream().filter(IScanModelWrapper<IScanPointGeneratorModel>::isIncludeInScan).map(IScanModelWrapper<IScanPointGeneratorModel>::getModel).filter(Objects::nonNull).collect(// use array list as we're going to add an element
    toCollection(ArrayList::new));
    // then add the actual map path model last, it's the inner most model
    models.add(mapPath);
    // Convert the list of models into a compound model
    final CompoundModel compoundModel = new CompoundModel(models);
    // Add the ROI for the mapping region
    final ScanRegion region = new ScanRegion(scanRegion.getRegion().toROI(), mapPath.getxAxisName(), mapPath.getyAxisName());
    // Convert to a List of ScanRegion<IROI> containing one item to avoid unsafe varargs warning
    compoundModel.setRegions(Arrays.asList(region));
    // Set the model on the scan request
    scanRequest.setCompoundModel(compoundModel);
    // set the scan start position (scannables not in the scan that are set to a certain value before the scan starts)
    final Map<String, Object> beamlineConfiguration = mappingBean.getBeamlineConfiguration();
    if (beamlineConfiguration != null) {
        scanRequest.setStartPosition(new MapPosition(beamlineConfiguration));
    }
    // add the required detectors to the scan
    for (IScanModelWrapper<IDetectorModel> detectorWrapper : mappingBean.getDetectorParameters()) {
        if (detectorWrapper.isIncludeInScan()) {
            IDetectorModel detectorModel = detectorWrapper.getModel();
            scanRequest.putDetector(detectorModel.getName(), detectorModel);
        }
    }
    // set the per-scan and per-point monitors according to the mapping bean
    configureMonitors(mappingBean, scanRequest);
    // set the scripts to run before and after the scan, if any
    if (mappingBean.getScriptFiles() != null) {
        final IScriptFiles scriptFiles = mappingBean.getScriptFiles();
        scanRequest.setBeforeScript(createScriptRequest(scriptFiles.getBeforeScanScript()));
        scanRequest.setAfterScript(createScriptRequest(scriptFiles.getAfterScanScript()));
        scanRequest.setAlwaysRunAfterScript(scriptFiles.isAlwaysRunAfterScript());
    }
    // add the sample metadata
    if (mappingBean.getSampleMetadata() != null) {
        setSampleMetadata(mappingBean, scanRequest);
    }
    // Add required processing
    Map<String, Collection<Object>> processingRequest = mappingBean.getProcessingRequest();
    ProcessingRequest r = new ProcessingRequest();
    r.setRequest(processingRequest);
    scanRequest.setProcessingRequest(r);
    // Add template files
    final List<TemplateFileWrapper> templateFiles = mappingBean.getTemplateFiles();
    if (templateFiles != null && !templateFiles.isEmpty()) {
        final Set<String> existingTemplateFilePaths = scanRequest.getTemplateFilePaths();
        final Set<String> allTemplateFilePaths = new TreeSet<>();
        Optional.ofNullable(existingTemplateFilePaths).ifPresent(allTemplateFilePaths::addAll);
        templateFiles.stream().filter(TemplateFileWrapper::isActive).forEach(fp -> allTemplateFilePaths.add(fp.getFilePath()));
        scanRequest.setTemplateFilePaths(allTemplateFilePaths);
    }
    // Add alternative output directory if selected and valid
    if (mappingBean.isUseAlternativeDirectory()) {
        final String outputDirString = mappingBean.getAlternativeDirectory();
        final File outputDir = new File(outputDirString);
        if (outputDir.isDirectory()) {
            scanRequest.setFilePath(outputDirString);
        } else {
            logger.warn("Cannot write output to {}: it is not a directory", outputDirString);
        }
    }
    return scanRequest;
}
Also used : ScanRegion(org.eclipse.scanning.api.points.models.ScanRegion) IMappingScanRegion(uk.ac.diamond.daq.mapping.api.IMappingScanRegion) IScriptFiles(uk.ac.diamond.daq.mapping.api.IScriptFiles) TemplateFileWrapper(uk.ac.diamond.daq.mapping.api.TemplateFileWrapper) ProcessingRequest(org.eclipse.scanning.api.event.scan.ProcessingRequest) IMappingScanRegion(uk.ac.diamond.daq.mapping.api.IMappingScanRegion) ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) IMapPathModel(org.eclipse.scanning.api.points.models.IMapPathModel) IScanModelWrapper(uk.ac.diamond.daq.mapping.api.IScanModelWrapper) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) TreeSet(java.util.TreeSet) Collection(java.util.Collection) Collectors.toCollection(java.util.stream.Collectors.toCollection) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel) File(java.io.File) MapPosition(org.eclipse.scanning.api.points.MapPosition)

Aggregations

IScanPointGeneratorModel (org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)17 ScanRequest (org.eclipse.scanning.api.event.scan.ScanRequest)7 CompoundModel (org.eclipse.scanning.api.points.models.CompoundModel)6 IScanModelWrapper (uk.ac.diamond.daq.mapping.api.IScanModelWrapper)5 IDetectorModel (org.eclipse.scanning.api.device.models.IDetectorModel)4 Composite (org.eclipse.swt.widgets.Composite)4 ScanPathModelWrapper (uk.ac.diamond.daq.mapping.impl.ScanPathModelWrapper)4 ArrayList (java.util.ArrayList)3 ScanBean (org.eclipse.scanning.api.event.scan.ScanBean)3 AxialStepModel (org.eclipse.scanning.api.points.models.AxialStepModel)3 IMapPathModel (org.eclipse.scanning.api.points.models.IMapPathModel)3 Label (org.eclipse.swt.widgets.Label)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 IMarshallerService (org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService)2 GridDataFactory (org.eclipse.jface.layout.GridDataFactory)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 IScanPathModel (org.eclipse.scanning.api.points.models.IScanPathModel)2 ScanRegion (org.eclipse.scanning.api.points.models.ScanRegion)2 Button (org.eclipse.swt.widgets.Button)2