Search in sources :

Example 16 with CompoundModel

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

the class MScanSubmitterTest method willAllowStaticScanWithDefaultSize.

@Test
public void willAllowStaticScanWithDefaultSize() throws Exception {
    // > 1 exposure time to ensure number not stolen by previous clause
    Object[] arr = { Scanpath.STATIC, detectorRunnableDevice, 2.7 };
    when(resolver.resolveScanClauses()).thenReturn(Arrays.asList(Arrays.asList(new ScanpathElementProcessor(Scanpath.STATIC)), Arrays.asList(new IRunnableDeviceDetectorElementProcessor(detectorRunnableDevice), new NumberElementProcessor(1.7))));
    builder.buildAndSubmitBlockingScanRequest(arr);
    verify(submitter).blockingSubmit(beanCaptor.capture());
    verify(eventSubscriber).addListener(any(IScanListener.class));
    ScanBean bean = beanCaptor.getValue();
    assertThat(bean.getScanRequest().getCompoundModel(), is(equalTo(new CompoundModel(new StaticModel()))));
    assertThat(bean.getScanRequest().getDetectors().values(), contains(detectorRunnableDevice.getModel()));
}
Also used : IScanListener(org.eclipse.scanning.api.event.scan.IScanListener) ScanBean(org.eclipse.scanning.api.event.scan.ScanBean) NumberElementProcessor(gda.mscan.processor.NumberElementProcessor) ScanpathElementProcessor(gda.mscan.processor.ScanpathElementProcessor) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) IRunnableDeviceDetectorElementProcessor(gda.mscan.processor.IRunnableDeviceDetectorElementProcessor) StaticModel(org.eclipse.scanning.api.points.models.StaticModel) Test(org.junit.Test)

Example 17 with CompoundModel

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

the class ScanRequestFactory method createInterpolatedCompoundModel.

/**
 * Implementation based on {@code org.eclipse.scanning.test.scan.nexus.MalcolmMultiScanTest}
 *
 * @param acquisitionTemplate
 * @return
 */
private CompoundModel createInterpolatedCompoundModel(AcquisitionTemplate acquisitionTemplate) {
    final var multiScanModel = new InterpolatedMultiScanModel();
    // --- Preparation ---
    // Each new multiscanModel must set this start position and image type
    // --- Positions List ---
    final List<IPosition> interpolationPositions = new ArrayList<>();
    // --- Images Type ---
    final List<ImageType> imageTypes = new ArrayList<>();
    // --- Flat Positions ---
    // Note - The shutter "close" position is added by the ScanningAcquisitionController
    final IPosition flatPos = createPositionMap(getFlatCalibration().getPosition());
    // --- Dark Positions ---
    // Note - The shutter "close" position is added by the ScanningAcquisitionController
    final IPosition darkPos = createPositionMap(getDarkCalibration().getPosition());
    // --- Steps estimation
    ScannableTrackDocument trackDocument = getScanpathDocument().getScannableTrackDocuments().get(0);
    // darks and flats should be (step / 2) before the start of the main scan, and the same after
    final double posBeforeMainScan = trackDocument.getStart() - trackDocument.calculatedStep() / 2;
    final double posAfterMainScan = trackDocument.getStop() + trackDocument.calculatedStep() / 2;
    // Flat Before Acquisition
    if (getFlatCalibration().isBeforeAcquisition() && getFlatCalibration().getNumberExposures() > 0) {
        var preScanFlats = getCalibrationModel(trackDocument.getScannable(), posBeforeMainScan, getFlatCalibration().getNumberExposures());
        multiScanModel.addModel(preScanFlats);
        addPosition(flatPos, interpolationPositions::add);
        imageTypes.add(ImageType.FLAT);
    }
    // Dark Before Acquisition
    if (getDarkCalibration().isBeforeAcquisition() && getDarkCalibration().getNumberExposures() > 0) {
        var preScanDarks = getCalibrationModel(trackDocument.getScannable(), posBeforeMainScan, getDarkCalibration().getNumberExposures());
        multiScanModel.addModel(preScanDarks);
        addPosition(darkPos, interpolationPositions::add);
        imageTypes.add(ImageType.DARK);
    }
    // Acquisition
    addPosition(createStartPosition(), interpolationPositions::add);
    multiScanModel.addModel(acquisitionTemplate.getIScanPointGeneratorModel());
    imageTypes.add(ImageType.NORMAL);
    // Flat After Acquisition
    if (getFlatCalibration().isAfterAcquisition() && getFlatCalibration().getNumberExposures() > 0) {
        var postScanFlats = getCalibrationModel(trackDocument.getScannable(), posAfterMainScan, getFlatCalibration().getNumberExposures());
        multiScanModel.addModel(postScanFlats);
        addPosition(flatPos, interpolationPositions::add);
        imageTypes.add(ImageType.FLAT);
    }
    // Dark After Acquisition
    if (getDarkCalibration().isAfterAcquisition() && getDarkCalibration().getNumberExposures() > 0) {
        var posScanDarks = getCalibrationModel(trackDocument.getScannable(), posAfterMainScan, getDarkCalibration().getNumberExposures());
        multiScanModel.addModel(posScanDarks);
        addPosition(darkPos, interpolationPositions::add);
        imageTypes.add(ImageType.DARK);
    }
    multiScanModel.setContinuous(Optional.ofNullable(getScanpathDocument().getMutators().containsKey(Mutator.CONTINUOUS)).orElse(false));
    multiScanModel.setInterpolatedPositions(interpolationPositions);
    multiScanModel.setImageTypes(imageTypes);
    return new CompoundModel(multiScanModel);
}
Also used : InterpolatedMultiScanModel(org.eclipse.scanning.api.points.models.InterpolatedMultiScanModel) IPosition(org.eclipse.scanning.api.points.IPosition) ScannableTrackDocument(uk.ac.diamond.daq.mapping.api.document.scanpath.ScannableTrackDocument) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) ArrayList(java.util.ArrayList) ImageType(org.eclipse.scanning.api.points.models.InterpolatedMultiScanModel.ImageType)

Example 18 with CompoundModel

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

the class ScannableNexusWrapperScanTest method createGridScan.

private IRunnableDevice<ScanModel> createGridScan(final IRunnableDevice<? extends IDetectorModel> detector, String outerScannableName, int... size) throws Exception {
    // Create scan points for a grid and make a generator
    final TwoAxisGridPointsModel gridModel = new TwoAxisGridPointsModel();
    gridModel.setxAxisName("salong");
    gridModel.setxAxisPoints(size[size.length - 1]);
    gridModel.setyAxisName("saperp");
    gridModel.setyAxisPoints(size[size.length - 2]);
    gridModel.setBoundingBox(new BoundingBox(0, 0, 3, 3));
    final CompoundModel compoundModel = new CompoundModel();
    // We add the outer scans, if any
    if (outerScannableName != null) {
        for (int dim = 0; dim < size.length - 2; dim++) {
            if (size[dim] > 1) {
                // TODO outer scannable name(s)? could use cryostat temperature as an outer scan
                compoundModel.addModel(new AxialStepModel(outerScannableName, 10000, 20000, 9999.99d / (size[dim] - 1)));
            } else {
                // Will generate one value at 10
                compoundModel.addModel(new AxialStepModel(outerScannableName + (dim + 1), 10, 20, 30));
            }
        }
    }
    compoundModel.addModel(gridModel);
    final IPointGenerator<CompoundModel> pointGen = pointGenService.createCompoundGenerator(compoundModel);
    // Create the model for a scan
    final ScanModel scanModel = new ScanModel();
    scanModel.setPointGenerator(pointGen);
    scanModel.setScanPathModel(compoundModel);
    scanModel.setDetector(detector);
    final IScannable<?> attributeScannable = scannableDeviceService.getScannable("attributes");
    final IScannable<?> beamSizeScannable = scannableDeviceService.getScannable("beam");
    scanModel.setMonitorsPerScan(attributeScannable, beamSizeScannable);
    // Create a file to scan into
    final File output = File.createTempFile("test_legacy_nexus", ".nxs");
    output.deleteOnExit();
    scanModel.setFilePath(output.getAbsolutePath());
    System.out.println("File writing to " + scanModel.getFilePath());
    // Create a scan and run it without publishing events
    final IRunnableDevice<ScanModel> scanner = scanService.createScanDevice(scanModel);
    final IPointGenerator<?> fgen = pointGen;
    ((IRunnableEventDevice<ScanModel>) scanner).addRunListener(new IRunListener() {

        @Override
        public void runWillPerform(RunEvent evt) throws ScanningException {
            System.out.println("Running acquisition scan of size " + fgen.size());
        }
    });
    return scanner;
}
Also used : ScanModel(org.eclipse.scanning.api.scan.models.ScanModel) IRunListener(org.eclipse.scanning.api.scan.event.IRunListener) TwoAxisGridPointsModel(org.eclipse.scanning.api.points.models.TwoAxisGridPointsModel) IRunnableEventDevice(org.eclipse.scanning.api.device.IRunnableEventDevice) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) ScanningException(org.eclipse.scanning.api.scan.ScanningException) BoundingBox(org.eclipse.scanning.api.points.models.BoundingBox) AxialStepModel(org.eclipse.scanning.api.points.models.AxialStepModel) NexusFile(org.eclipse.dawnsci.nexus.NexusFile) File(java.io.File) TreeFile(org.eclipse.dawnsci.analysis.api.tree.TreeFile) RunEvent(org.eclipse.scanning.api.scan.event.RunEvent)

Example 19 with CompoundModel

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

the class ScanRequestConverter method mergeIntoMappingBean.

/**
 * Merge a scan request into an existing mapping bean so that it can be viewed
 * and possibly modified in the Mapping Experiment Setup view.
 * The reason for merging into an existing mapping bean is so that we don't remove
 * detectors and processing steps that we not selected when this scan was run -
 * when creating the scan request from the mapping bean a detector is only added if
 * {@link IScanModelWrapper#isIncludeInScan()} is true. The mapping bean reconstructed
 * from the scan request still needs to include this detector.
 *
 * @param scanRequest the {@link ScanRequest}
 * @param mappingBean the {@link IMappingExperimentBean} to merge into
 */
public void mergeIntoMappingBean(ScanRequest scanRequest, IMappingExperimentBean mappingBean) {
    final CompoundModel compoundModel = scanRequest.getCompoundModel();
    final Collection<ScanRegion> regions = compoundModel.getRegions();
    if (regions.size() != 1) {
        throw new IllegalArgumentException("The scan request must have exactly one region, has " + regions.size());
    }
    // Check that the scannable names in the scan region are the same as in the mapping stage
    final IMapPathModel mapPath = checkMapModelAndUpdateMappingStage(compoundModel);
    // recreate the outer scannable wrappers from the scan request
    mergeOuterScannables(compoundModel, mappingBean);
    // set the scan path to the last child model of the compound model
    final IScanDefinition scanDefinition = mappingBean.getScanDefinition();
    final IMappingScanRegion scanRegion = scanDefinition.getMappingScanRegion();
    scanRegion.setScanPath(mapPath);
    // convert the ROI to a mapping scan region shape
    final ScanRegion region = regions.iterator().next();
    final IMappingScanRegionShape shape = convertROItoRegionShape(region.getRoi());
    scanRegion.setRegion(shape);
    // recreate the beamline configuration from the scan start position
    if (scanRequest.getStartPosition() != null) {
        mappingBean.setBeamlineConfiguration(new LinkedHashMap<>(scanRequest.getStartPosition().getValues()));
    }
    // recreate the detector models and processing steps (included in the same map of detectors in the scan request)
    mergeDetectorAndProcessing(scanRequest, mappingBean);
    // recreate the scripts to run before and after the scan, if any
    if (scanRequest.getBeforeScript() != null || scanRequest.getAfterScript() != null) {
        ScriptFiles scriptFiles = new ScriptFiles();
        if (scanRequest.getBeforeScript() != null) {
            scriptFiles.setBeforeScanScript(scanRequest.getBeforeScript().getFile());
        }
        if (scanRequest.getAfterScript() != null) {
            scriptFiles.setAfterScanScript(scanRequest.getAfterScript().getFile());
        }
        scriptFiles.setAlwaysRunAfterScript(scanRequest.isAlwaysRunAfterScript());
        mappingBean.setScriptFiles(scriptFiles);
    }
    // recreate the sample metadata from the metadata in the scan request
    mergeSampleMetadata(scanRequest, mappingBean);
    mergeTemplateFiles(scanRequest, mappingBean);
    mergeProcessingRequest(scanRequest, mappingBean);
}
Also used : IMappingScanRegion(uk.ac.diamond.daq.mapping.api.IMappingScanRegion) IMappingScanRegionShape(uk.ac.diamond.daq.mapping.api.IMappingScanRegionShape) ScanRegion(org.eclipse.scanning.api.points.models.ScanRegion) IMappingScanRegion(uk.ac.diamond.daq.mapping.api.IMappingScanRegion) IMapPathModel(org.eclipse.scanning.api.points.models.IMapPathModel) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) ScriptFiles(uk.ac.diamond.daq.mapping.impl.ScriptFiles) IScriptFiles(uk.ac.diamond.daq.mapping.api.IScriptFiles) IScanDefinition(uk.ac.diamond.daq.mapping.api.IScanDefinition)

Example 20 with CompoundModel

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

the class FocusScanConverter method convertToScanRequest.

public ScanRequest convertToScanRequest(FocusScanBean focusScanBean) {
    logger.debug("Converting focusScanBean to scan request");
    final ScanRequest scanRequest = new ScanRequest();
    final IMapPathModel lineModel = createLineModel(focusScanBean);
    final ILineMappingRegion lineRegion = focusScanBean.getLineRegion();
    final ScanRegion scanRegion = new ScanRegion(lineRegion.toROI(), lineModel.getxAxisName(), lineModel.getyAxisName());
    final AxialStepModel focusModel = createFocusPathModel(focusScanBean);
    final CompoundModel compoundModel = new CompoundModel(Arrays.asList(focusModel, lineModel));
    compoundModel.setRegions(Arrays.asList(scanRegion));
    scanRequest.setCompoundModel(compoundModel);
    // add detectors
    final IDetectorModel detectorModel = focusScanBean.getDetector();
    final Map<String, IDetectorModel> detectorsMap = new HashMap<>();
    detectorsMap.put(detectorModel.getName(), detectorModel);
    scanRequest.setDetectors(detectorsMap);
    return scanRequest;
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) ScanRegion(org.eclipse.scanning.api.points.models.ScanRegion) IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) IMapPathModel(org.eclipse.scanning.api.points.models.IMapPathModel) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) HashMap(java.util.HashMap) ILineMappingRegion(uk.ac.diamond.daq.mapping.api.ILineMappingRegion) AxialStepModel(org.eclipse.scanning.api.points.models.AxialStepModel)

Aggregations

CompoundModel (org.eclipse.scanning.api.points.models.CompoundModel)21 Test (org.junit.Test)10 ScanpathElementProcessor (gda.mscan.processor.ScanpathElementProcessor)8 IScanListener (org.eclipse.scanning.api.event.scan.IScanListener)8 ScanBean (org.eclipse.scanning.api.event.scan.ScanBean)8 ScanRequest (org.eclipse.scanning.api.event.scan.ScanRequest)7 StaticModel (org.eclipse.scanning.api.points.models.StaticModel)7 IRunnableDeviceDetectorElementProcessor (gda.mscan.processor.IRunnableDeviceDetectorElementProcessor)6 ArrayList (java.util.ArrayList)6 IScanPointGeneratorModel (org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)6 NumberElementProcessor (gda.mscan.processor.NumberElementProcessor)5 AxialStepModel (org.eclipse.scanning.api.points.models.AxialStepModel)5 IDetectorModel (org.eclipse.scanning.api.device.models.IDetectorModel)4 ScanRegion (org.eclipse.scanning.api.points.models.ScanRegion)4 ScannableElementProcessor (gda.mscan.processor.ScannableElementProcessor)3 IMapPathModel (org.eclipse.scanning.api.points.models.IMapPathModel)3 RegionShapeElementProcessor (gda.mscan.processor.RegionShapeElementProcessor)2 File (java.io.File)2 HashMap (java.util.HashMap)2 IPosition (org.eclipse.scanning.api.points.IPosition)2