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);
}
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));
}
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);
}
});
}
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;
}
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);
}
Aggregations