Search in sources :

Example 11 with IScanPointGeneratorModel

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

the class PointGeneratorPathInfoCalculator method calculatePathInfo.

@Override
public PathInfo calculatePathInfo(PathInfoRequest request) throws PathInfoCalculationException {
    IScanPointGeneratorModel scanPathModel = request.getScanPathModel();
    try {
        // Invokes ScanPointGenerator to create the points
        IPointGenerator<CompoundModel> pointGenerator = getPointGeneratorService().createGenerator(scanPathModel, request.getScanRegion());
        // Initialise with sensible starting values
        int pointCount = 0;
        double smallestXStep = Double.MAX_VALUE;
        double smallestYStep = Double.MAX_VALUE;
        double smallestAbsStep = Double.MAX_VALUE;
        List<Double> xCoordinates = new ArrayList<>();
        List<Double> yCoordinates = new ArrayList<>();
        double lastX = Double.NaN;
        double lastY = Double.NaN;
        String xAxisName = getXAxisName(scanPathModel);
        String yAxisName = getYAxisName(scanPathModel);
        // - The smallest distance between two consecutive positions in 2D space
        for (IPosition point : pointGenerator) {
            pointCount++;
            if (pointCount > 1) {
                // Updates the smallest distance tracking variables if the distance
                // between this point and the last is smaller than the smallest
                // distance we've seen so far. Do this for x, y and 2D space.
                double thisXStep = Math.abs(point.getValue(xAxisName) - lastX);
                double thisYStep = Math.abs(point.getValue(yAxisName) - lastY);
                double thisAbsStep = Math.sqrt(Math.pow(thisXStep, 2) + Math.pow(thisYStep, 2));
                if (thisXStep > 0) {
                    smallestXStep = Math.min(smallestXStep, thisXStep);
                }
                if (thisYStep > 0) {
                    smallestYStep = Math.min(smallestYStep, thisYStep);
                }
                smallestAbsStep = Math.min(smallestAbsStep, thisAbsStep);
            }
            // Ensures no more than MAX_POINTS_IN_ROI points are inserted into
            // the PathInfo. Still need to iterate through the rest of the points
            // to accurately calculate step sizes and number of points.
            lastX = point.getValue(xAxisName);
            lastY = point.getValue(yAxisName);
            if (xCoordinates.size() < request.getMaxPoints()) {
                xCoordinates.add(Double.valueOf(lastX));
                yCoordinates.add(Double.valueOf(lastY));
            }
        }
        // outerAxisMultiplier is the product of the number of points
        // in each outer axis. It defaults to 1 if there are no outer axes.
        // It is multiplied by the number of points in the mapping scan
        // e.g. if the mapping scan in x and y has 25 points and is
        // also projected back through 10 points in z then there are
        // 250 points in total.
        int outerAxisMultiplier = calculateAllOuterPoints(request.getOuterScannables());
        int totalPoints = outerAxisMultiplier * pointCount;
        return PathInfo.builder().withSourceId(request.getSourceId()).withInnerPointCount(pointCount).withTotalPointCount(totalPoints).withSmallestXStep(smallestXStep).withSmallestYStep(smallestYStep).withSmallestAbsStep(smallestAbsStep).withxCoordinateList(xCoordinates).withyCoordinateList(yCoordinates).build();
    } catch (GeneratorException e) {
        throw new PathInfoCalculationException(e);
    }
}
Also used : IPosition(org.eclipse.scanning.api.points.IPosition) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) PathInfoCalculationException(uk.ac.diamond.daq.mapping.api.PathInfoCalculationException) ArrayList(java.util.ArrayList) GeneratorException(org.eclipse.scanning.api.points.GeneratorException) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)

Example 12 with IScanPointGeneratorModel

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

the class StandardsScanView method createScannableEditor.

/**
 * Create the GUI elements to edit the energy scannable.<br>
 * This consists of
 * <ul>
 * <li>the specification of the energy ranges</li>
 * <li>a drop-down box to choose the edge</li>
 * <li>a text box for the exposure time</li>
 * <li>a check box to specify whether the energy steps should be run in reverse order</li>
 * </ul>
 * In general, the energy ranges should be set by choosing the edge, though they can also be edited directly.
 *
 * @param parent
 *            the parent composite to draw these controls on
 */
private void createScannableEditor(Composite parent) {
    // Energy scannable
    final Composite editorComposite = new Composite(parent, SWT.NONE);
    GridDataFactory.swtDefaults().applyTo(editorComposite);
    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(editorComposite);
    final StandardsScanConfig standardsScanConfig = PlatformUI.getWorkbench().getService(StandardsScanConfig.class);
    if (standardsScanConfig == null) {
        logger.error("Missing configuration for standards scan");
        return;
    }
    // Scannable name
    final String energyScannableName = standardsScanConfig.getScannableName();
    final Label nameLabel = new Label(editorComposite, SWT.NONE);
    nameLabel.setText(energyScannableName);
    // Scan path editor to display & edit energy values
    final IScanModelWrapper<IScanPointGeneratorModel> scannableWrapper = new ScanPathModelWrapper(energyScannableName, null, false);
    scanPathEditor = new ScanPathEditor(editorComposite, SWT.NONE, scannableWrapper);
    // Edge, exposure, reverse check box
    final Composite edgeAndExposureComposite = new Composite(parent, SWT.NONE);
    GridDataFactory.swtDefaults().applyTo(edgeAndExposureComposite);
    GridLayoutFactory.swtDefaults().numColumns(4).applyTo(edgeAndExposureComposite);
    // List of energy/edge combinations
    final XanesEdgeCombo edgeCombo = new XanesEdgeCombo(edgeAndExposureComposite);
    edgeCombo.addSelectionChangedListener(e -> {
        final IScanPointGeneratorModel scanPathModel = createModelFromEdgeSelection(edgeCombo.getSelectedEnergy(), energyScannableName);
        scanPathEditor.setScanPathModel(scanPathModel);
    });
    // Exposure time
    final Label exposureTimeLabel = new Label(edgeAndExposureComposite, SWT.NONE);
    GridDataFactory.swtDefaults().applyTo(exposureTimeLabel);
    exposureTimeLabel.setText("Exposure time");
    exposureTimeText = new Text(edgeAndExposureComposite, SWT.BORDER);
    GridDataFactory.swtDefaults().hint(80, SWT.DEFAULT).applyTo(exposureTimeText);
    // Reverse check box
    reverseCheckBox = new Button(edgeAndExposureComposite, SWT.CHECK);
    GridDataFactory.swtDefaults().applyTo(reverseCheckBox);
    reverseCheckBox.setText("Reverse scan");
}
Also used : ScanPathModelWrapper(uk.ac.diamond.daq.mapping.impl.ScanPathModelWrapper) Composite(org.eclipse.swt.widgets.Composite) ScanPathEditor(uk.ac.diamond.daq.mapping.ui.experiment.ScanPathEditor) Button(org.eclipse.swt.widgets.Button) Label(org.eclipse.swt.widgets.Label) XanesEdgeCombo(uk.ac.diamond.daq.mapping.ui.xanes.XanesEdgeCombo) Text(org.eclipse.swt.widgets.Text) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)

Example 13 with IScanPointGeneratorModel

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

the class MappingExperimentView method loadPreviousState.

private void loadPreviousState(MPart part) {
    // Restore mapping bean unless it has been set by another view
    if (!mappingBeanProvider.isSetByView()) {
        final String json = part.getPersistedState().get(STATE_KEY_MAPPING_BEAN_JSON);
        if (json != null) {
            logger.trace("Restoring the previous state of the mapping view.");
            final IMarshallerService marshaller = injectionContext.get(IMarshallerService.class);
            try {
                setMappingBean(marshaller.unmarshal(json, MappingExperimentBean.class));
            } catch (Exception e) {
                logger.error("Failed to restore the previous state of the mapping view", e);
            }
        } else {
            // If there is no state to restore, ensure that any default outer scannables are set
            final IScanDefinition scanDefinition = mappingBeanProvider.getMappingExperimentBean().getScanDefinition();
            if (scanDefinition == null) {
                return;
            }
            final List<String> defaultOuterScannables = scanDefinition.getDefaultOuterScannables();
            if (defaultOuterScannables.isEmpty()) {
                return;
            }
            final List<IScanModelWrapper<IScanPointGeneratorModel>> scanModels = defaultOuterScannables.stream().map(scannable -> new ScanPathModelWrapper(scannable, null, false)).collect(Collectors.toList());
            scanDefinition.setOuterScannables(scanModels);
        }
    }
}
Also used : IMappingExperimentBean(uk.ac.diamond.daq.mapping.api.IMappingExperimentBean) IServiceConstants(org.eclipse.e4.ui.services.IServiceConstants) IMarshallerService(org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService) LoggerFactory(org.slf4j.LoggerFactory) ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) PreDestroy(javax.annotation.PreDestroy) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) URI(java.net.URI) Focus(org.eclipse.e4.ui.di.Focus) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) IAdaptable(org.eclipse.core.runtime.IAdaptable) LocalProperties(gda.configuration.properties.LocalProperties) IScannableDeviceService(org.eclipse.scanning.api.device.IScannableDeviceService) PlatformUI(org.eclipse.ui.PlatformUI) Optional(org.eclipse.e4.core.di.annotations.Optional) Display(org.eclipse.swt.widgets.Display) Collectors(java.util.stream.Collectors) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) MappingExperimentBean(uk.ac.diamond.daq.mapping.impl.MappingExperimentBean) Objects(java.util.Objects) List(java.util.List) IScanModelWrapper(uk.ac.diamond.daq.mapping.api.IScanModelWrapper) SWT(org.eclipse.swt.SWT) PostConstruct(javax.annotation.PostConstruct) ScanBean(org.eclipse.scanning.api.event.scan.ScanBean) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Label(org.eclipse.swt.widgets.Label) PersistState(org.eclipse.e4.ui.di.PersistState) IMappingExperimentBeanProvider(uk.ac.diamond.daq.mapping.api.IMappingExperimentBeanProvider) IEventService(org.eclipse.scanning.api.event.IEventService) UIEventTopic(org.eclipse.e4.ui.di.UIEventTopic) MessageFormat(java.text.MessageFormat) IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) Inject(javax.inject.Inject) ClassToInstanceMap(com.google.common.collect.ClassToInstanceMap) MPart(org.eclipse.e4.ui.model.application.ui.basic.MPart) IScanDefinition(uk.ac.diamond.daq.mapping.api.IScanDefinition) IScanPathModel(org.eclipse.scanning.api.points.models.IScanPathModel) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Named(javax.inject.Named) StatusBean(org.eclipse.scanning.api.event.status.StatusBean) Shell(org.eclipse.swt.widgets.Shell) Logger(org.slf4j.Logger) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) IMapPathModel(org.eclipse.scanning.api.points.models.IMapPathModel) MutableClassToInstanceMap(com.google.common.collect.MutableClassToInstanceMap) PathInfo(uk.ac.diamond.daq.mapping.api.document.scanpath.PathInfo) IRunnableDeviceService(org.eclipse.scanning.api.device.IRunnableDeviceService) OpenRequest(org.eclipse.scanning.api.event.status.OpenRequest) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ScanPathModelWrapper(uk.ac.diamond.daq.mapping.impl.ScanPathModelWrapper) Control(org.eclipse.swt.widgets.Control) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel) ScanPathModelWrapper(uk.ac.diamond.daq.mapping.impl.ScanPathModelWrapper) IMarshallerService(org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService) IMappingExperimentBean(uk.ac.diamond.daq.mapping.api.IMappingExperimentBean) MappingExperimentBean(uk.ac.diamond.daq.mapping.impl.MappingExperimentBean) IScanModelWrapper(uk.ac.diamond.daq.mapping.api.IScanModelWrapper) IScanDefinition(uk.ac.diamond.daq.mapping.api.IScanDefinition)

Example 14 with IScanPointGeneratorModel

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

the class ScanRequestConverter method checkMapModelAndUpdateMappingStage.

private IMapPathModel checkMapModelAndUpdateMappingStage(final CompoundModel compoundModel) {
    final List<IScanPointGeneratorModel> models = compoundModel.getModels();
    // check that the inner most model is an IMapPathModel, i.e. for a mapping scan
    final IScanPointGeneratorModel innerModelObj = models.get(models.size() - 1);
    if (!(innerModelObj instanceof IMapPathModel)) {
        throw new IllegalArgumentException("The inner most model is not a map model. This is not mapping scan");
    }
    final IMapPathModel mapPath = (IMapPathModel) innerModelObj;
    // update the mapping bean with axes in the mapping path
    if (mappingStageInfo != null) {
        mappingStageInfo.setPlotXAxisName(mapPath.getxAxisName());
        mappingStageInfo.setPlotYAxisName(mapPath.getyAxisName());
    }
    return mapPath;
}
Also used : IMapPathModel(org.eclipse.scanning.api.points.models.IMapPathModel) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)

Example 15 with IScanPointGeneratorModel

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

the class RegionAndPathSection method handleRegionAndPathEvent.

private void handleRegionAndPathEvent(String value) {
    try {
        final Gson gson = new Gson();
        @SuppressWarnings("unchecked") final Map<String, Object> regionAndPathMap = gson.fromJson(value, HashMap.class);
        // Change to region
        final String region = (String) regionAndPathMap.get("region");
        if (!StringUtils.isEmpty(region)) {
            final IMappingScanRegionShape scanRegion = scanRegionMap.get(region);
            if (scanRegion == null) {
                throw new IllegalArgumentException("Invalid region " + region);
            }
            uiSync.syncExec(() -> controller.getRegionSelectorListener().handleRegionChange(scanRegion));
        }
        // Change to path
        final String path = (String) regionAndPathMap.get("path");
        if (!StringUtils.isEmpty(path)) {
            // Get the available scan paths for the current region
            final Map<String, IScanPointGeneratorModel> scanPathMap = controller.getScanPathListAndLinkPath().stream().collect(toMap(IScanPointGeneratorModel::getName, identity()));
            final IScanPointGeneratorModel scanPath = scanPathMap.get(path);
            if (scanPath == null) {
                throw new IllegalArgumentException("No scan path corresponding to " + path);
            }
            uiSync.syncExec(() -> {
                final IMappingScanRegionShape scanRegion = controller.getScanRegionShape();
                controller.updateMappingBeanScanRegion(scanRegion, scanPath);
                controller.getRegionSelectorListener().handleRegionChange(scanRegion);
            });
        }
        // Changes to scan region properties
        controller.getScanRegionShape().updateFromPropertiesMap(regionAndPathMap);
        // Changes to scan path properties
        controller.getScanPathModel().updateFromPropertiesMap(regionAndPathMap);
        // Update GUI
        uiSync.asyncExec(this::rebuildMappingSection);
    } catch (Exception e) {
        logger.error("Invalid region/path parameter: {}", value, e);
    }
}
Also used : IMappingScanRegionShape(uk.ac.diamond.daq.mapping.api.IMappingScanRegionShape) Gson(com.google.gson.Gson) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)

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