use of org.eclipse.scanning.api.points.MapPosition 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.points.MapPosition in project gda-core by openGDA.
the class StageMoveHandler method moveTo.
private void moveTo(final double xLocation, final double yLocation, final Double associatedLocation) {
Map<String, Object> position = getPositionMap(xLocation, yLocation, associatedLocation);
String moveSummary = summarise(position);
// request confirmation to move
boolean userConfirmedMove = confirmMove("Go here?", moveSummary);
if (!userConfirmedMove)
return;
// Do the move
try {
getPositioner().setPosition(new MapPosition(position));
} catch (ScanningException e) {
logger.error("Could not perform stage move", e);
} catch (InterruptedException interrupted) {
logger.error("Stage move interrupted!", interrupted);
Thread.currentThread().interrupt();
}
}
Aggregations