Search in sources :

Example 6 with IDetectorModel

use of org.eclipse.scanning.api.device.models.IDetectorModel in project gda-core by openGDA.

the class ScanRequestFactoryTest method testWrongDetectorModelFile.

/**
 * @throws Exception
 */
@Test(expected = ScanningException.class)
public void testWrongDetectorModelFile() throws Exception {
    IDetectorModel model = Mockito.mock(IDetectorModel.class);
    when(detectorModel.getModel()).thenReturn(model);
    new ScanRequestFactory(loadScanningAcquisition()).createScanRequest(runnableService);
}
Also used : IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) Test(org.junit.Test)

Example 7 with IDetectorModel

use of org.eclipse.scanning.api.device.models.IDetectorModel in project gda-core by openGDA.

the class FocusScanSetupPage method populateDetectorCombo.

private void populateDetectorCombo(ComboViewer comboViewer) {
    final List<IScanModelWrapper<IDetectorModel>> mappingDetectors = mappingBeanProvider.getMappingExperimentBean().getDetectorParameters();
    // Get the detectors that can be chosen for a focus scan
    // These are listed in the focus scan bean
    final List<String> focusScannableDevices = focusScanBean.getFocusScanDevices();
    final List<IScanModelWrapper<IDetectorModel>> availableFocusDetectors = mappingDetectors.stream().filter(wrapper -> focusScannableDevices.contains(wrapper.getName())).sorted(Comparator.comparing(IScanModelWrapper::getName)).collect(Collectors.toCollection(ArrayList::new));
    comboViewer.setInput(availableFocusDetectors);
    // The detector to be selected by default in the combo box
    // If unspecified or invalid, use the first one in the list
    Optional<IScanModelWrapper<IDetectorModel>> selectedDetector = Optional.empty();
    final String defaultFocusScanDevice = focusScanBean.getDefaultFocusScanDevice();
    if (defaultFocusScanDevice != null && !defaultFocusScanDevice.isEmpty()) {
        selectedDetector = availableFocusDetectors.stream().filter(wrapper -> wrapper.getName().equals(defaultFocusScanDevice)).findFirst();
    }
    final IScanModelWrapper<IDetectorModel> selection = selectedDetector.isPresent() ? selectedDetector.get() : availableFocusDetectors.get(0);
    comboViewer.setSelection(new StructuredSelection(selection));
}
Also used : IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) IScanModelWrapper(uk.ac.diamond.daq.mapping.api.IScanModelWrapper) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Example 8 with IDetectorModel

use of org.eclipse.scanning.api.device.models.IDetectorModel in project gda-core by openGDA.

the class ProcessingSelectionWizardPage method createDetectorSelectionControls.

private void createDetectorSelectionControls(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(composite);
    GridDataFactory.fillDefaults().applyTo(composite);
    // Label for select detector combo
    Label label = new Label(composite, SWT.NONE);
    label.setText("Detector:");
    GridDataFactory.swtDefaults().applyTo(label);
    // Combo viewer for detector selection
    detectorsComboViewer = new ComboViewer(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
    GridDataFactory.swtDefaults().applyTo(detectorsComboViewer.getControl());
    detectorsComboViewer.setContentProvider(ArrayContentProvider.getInstance());
    detectorsComboViewer.setLabelProvider(new LabelProvider() {

        @SuppressWarnings("unchecked")
        @Override
        public String getText(Object element) {
            return ((IScanModelWrapper<IDetectorModel>) element).getName();
        }
    });
    detectorsComboViewer.setInput(detectors);
    if (!detectors.isEmpty()) {
        detectorsComboViewer.setSelection(new StructuredSelection(getDefaultDetector()));
    }
    detectorsComboViewer.addSelectionChangedListener(evt -> {
        @SuppressWarnings("unchecked") IScanModelWrapper<IDetectorModel> selectedWrapper = (IScanModelWrapper<IDetectorModel>) ((IStructuredSelection) evt.getSelection()).getFirstElement();
        IDetectorModel detectorModel = selectedWrapper.getModel();
        if (detectorModel instanceof IMalcolmModel && !getDetectorDatasetNameForMalcolm((IMalcolmModel) detectorModel).isPresent()) {
            MessageDialog.openError(getShell(), "Setup Processing", "Could not get primary dataset for malcolm device: " + detectorModel.getName());
            setPageComplete(false);
        } else {
            setPageComplete(true);
        }
    });
}
Also used : Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) IScanModelWrapper(uk.ac.diamond.daq.mapping.api.IScanModelWrapper) ComboViewer(org.eclipse.jface.viewers.ComboViewer) IMalcolmModel(org.eclipse.scanning.api.device.models.IMalcolmModel) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 9 with IDetectorModel

use of org.eclipse.scanning.api.device.models.IDetectorModel 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)

Example 10 with IDetectorModel

use of org.eclipse.scanning.api.device.models.IDetectorModel in project gda-core by openGDA.

the class CalibrationFrameCollector method configureCollection.

@Override
void configureCollection(ScanModel model) throws ScanningException {
    // If no detector is set for the "main" scan, we can't do anything here
    if (model.getDetectors().isEmpty()) {
        throw new ScanningException("No detector selected for scan - cannot collect calibration frame");
    }
    // At this point in the scan, the detector models directly in the ScanModel are not up-to-date, especially as
    // regards their exposure time. However, the models in the ScanRequest are correct, so copy the exposure
    // time from there.
    final IRunnableDevice<? extends IDetectorModel> mainScanDetector = model.getDetectors().get(0);
    final String mainScanDetectorName = mainScanDetector.getName();
    final IDetectorModel modelFromRequest = model.getBean().getScanRequest().getDetectors().get(mainScanDetectorName);
    if (modelFromRequest == null) {
        logger.error("Cannot find detector model for {}", mainScanDetectorName);
        return;
    }
    final double exposureTime = modelFromRequest.getExposureTime();
    // If no detector has been explicitly configured, use the "main scan" detector
    final IRunnableDevice<? extends IDetectorModel> acquisitionDetector = getSnapshotDetector(mainScanDetector);
    logger.debug("Setting exposure time on {} to {}", acquisitionDetector.getName(), exposureTime);
    var frameRequestDocument = new FrameRequestDocument.Builder().withExposure(exposureTime).withName(acquisitionDetector.getName()).withMalcolmDetectorName(getMalcolmDetectorName(acquisitionDetector)).build();
    setFrameRequestDocument(frameRequestDocument);
}
Also used : IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) ScanningException(org.eclipse.scanning.api.scan.ScanningException)

Aggregations

IDetectorModel (org.eclipse.scanning.api.device.models.IDetectorModel)20 IScanModelWrapper (uk.ac.diamond.daq.mapping.api.IScanModelWrapper)9 ScanRequest (org.eclipse.scanning.api.event.scan.ScanRequest)7 Test (org.junit.Test)6 ScanningException (org.eclipse.scanning.api.scan.ScanningException)5 IMalcolmModel (org.eclipse.scanning.api.device.models.IMalcolmModel)4 CompoundModel (org.eclipse.scanning.api.points.models.CompoundModel)4 DetectorModelWrapper (uk.ac.diamond.daq.mapping.impl.DetectorModelWrapper)4 HashMap (java.util.HashMap)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 IScanPointGeneratorModel (org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)3 ScanRegion (org.eclipse.scanning.api.points.models.ScanRegion)3 MandelbrotModel (org.eclipse.scanning.example.detector.MandelbrotModel)3 Composite (org.eclipse.swt.widgets.Composite)3 File (java.io.File)2 ComboViewer (org.eclipse.jface.viewers.ComboViewer)2 LabelProvider (org.eclipse.jface.viewers.LabelProvider)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 AxialStepModel (org.eclipse.scanning.api.points.models.AxialStepModel)2 IMapPathModel (org.eclipse.scanning.api.points.models.IMapPathModel)2