Search in sources :

Example 1 with ScanRequest

use of org.eclipse.scanning.api.event.scan.ScanRequest in project gda-core by openGDA.

the class FocusScanConverterTest method testConvertFocusScanBean.

@Test
public void testConvertFocusScanBean() {
    final ScanRequest scanRequest = focusScanConverter.convertToScanRequest(focusScanBean);
    // test compound model
    final CompoundModel compoundModel = scanRequest.getCompoundModel();
    assertNotNull(compoundModel);
    final List<IScanPointGeneratorModel> models = compoundModel.getModels();
    assertEquals(2, models.size());
    // test outer model - the focus model
    assertThat(models.get(0), is(instanceOf(AxialStepModel.class)));
    final AxialStepModel focusModel = (AxialStepModel) models.get(0);
    assertEquals(1, focusModel.getScannableNames().size());
    assertEquals(focusScanBean.getFocusScannableName(), focusModel.getScannableNames().get(0));
    assertEquals(focusScanBean.getFocusCentre() - focusScanBean.getFocusRange() + focusModel.getStep() / 2, focusModel.getStart(), 1e-15);
    assertEquals(focusScanBean.getFocusCentre() + focusScanBean.getFocusRange() - focusModel.getStep() / 2 + focusModel.getStep() / 100, focusModel.getStop(), 1e-15);
    assertEquals(focusScanBean.getFocusRange() * 2 / focusScanBean.getNumberOfFocusSteps(), focusModel.getStep(), 1e-15);
    // test inner model - the line model
    assertThat(models.get(1), is(instanceOf(TwoAxisLinePointsModel.class)));
    final TwoAxisLinePointsModel lineModel = (TwoAxisLinePointsModel) models.get(1);
    assertEquals(2, lineModel.getScannableNames().size());
    assertEquals(mappingStageInfo.getPlotYAxisName(), lineModel.getScannableNames().get(1));
    assertEquals(mappingStageInfo.getPlotXAxisName(), lineModel.getScannableNames().get(0));
    assertEquals(focusScanBean.getNumberOfLinePoints(), lineModel.getPoints());
    final BoundingLine boundingLine = lineModel.getBoundingLine();
    assertNotNull(boundingLine);
    final LinearROI expectedRegion = (LinearROI) focusScanBean.getLineRegion().toROI();
    assertEquals(expectedRegion.getPointX(), boundingLine.getxStart(), 1e-15);
    assertEquals(expectedRegion.getPointY(), boundingLine.getyStart(), 1e-15);
    assertEquals(expectedRegion.getAngle(), boundingLine.getAngle(), 1e-15);
    assertEquals(expectedRegion.getLength(), boundingLine.getLength(), 1e-15);
    // test scan regions
    assertEquals(1, compoundModel.getRegions().size());
    final ScanRegion scanRegion = compoundModel.getRegions().iterator().next();
    assertEquals(2, scanRegion.getScannables().size());
    assertEquals(mappingStageInfo.getPlotYAxisName(), scanRegion.getScannables().get(1));
    assertEquals(mappingStageInfo.getPlotXAxisName(), scanRegion.getScannables().get(0));
    assertThat(scanRegion.getRoi(), is(instanceOf(LinearROI.class)));
    assertEquals(expectedRegion, scanRegion.getRoi());
    // test detectors
    final Map<String, IDetectorModel> detectors = scanRequest.getDetectors();
    assertNotNull(detectors);
    assertEquals(1, detectors.size());
    assertTrue(detectors.containsKey("mandelbrot"));
    assertThat(detectors.get("mandelbrot"), is(instanceOf(MandelbrotModel.class)));
    // test that the remaining fields have not been set
    assertThat(scanRequest.getMonitorNamesPerPoint(), is(empty()));
    assertThat(scanRequest.getMonitorNamesPerScan(), is(empty()));
    assertThat(scanRequest.getScanMetadata(), is(nullValue()));
    assertThat(scanRequest.getAfterScript(), is(nullValue()));
    assertThat(scanRequest.getBeforeScript(), is(nullValue()));
    assertThat(scanRequest.isAlwaysRunAfterScript(), is(false));
    assertThat(scanRequest.getStartPosition(), is(nullValue()));
    assertThat(scanRequest.getEndPosition(), is(nullValue()));
    assertThat(scanRequest.getFilePath(), is(nullValue()));
}
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) TwoAxisLinePointsModel(org.eclipse.scanning.api.points.models.TwoAxisLinePointsModel) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) LinearROI(org.eclipse.dawnsci.analysis.dataset.roi.LinearROI) AxialStepModel(org.eclipse.scanning.api.points.models.AxialStepModel) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel) BoundingLine(org.eclipse.scanning.api.points.models.BoundingLine) Test(org.junit.Test)

Example 2 with ScanRequest

use of org.eclipse.scanning.api.event.scan.ScanRequest in project gda-core by openGDA.

the class ScanRequestConverterTest method testMonitorsIncluded.

@Test
public void testMonitorsIncluded() throws Exception {
    // Act
    final ScanRequest scanRequest = scanRequestConverter.convertToScanRequest(mappingBean);
    // Assert - these are the monitors that are set as active in MockScannableConnector
    String[] expectedMonitorNamesPerPoint = new String[] { "perPoint1", "perPoint2", "perPoint3" };
    assertThat(scanRequest.getMonitorNamesPerPoint(), hasItems(expectedMonitorNamesPerPoint));
    assertThat(scanRequest.getMonitorNamesPerPoint().size(), CoreMatchers.is(expectedMonitorNamesPerPoint.length));
    String[] expectedMonitorNamesPerScan = new String[] { "perScan1", "perScan2", BEAM_SIZE_NAME };
    assertThat(scanRequest.getMonitorNamesPerScan(), hasItems(expectedMonitorNamesPerScan));
    assertThat(scanRequest.getMonitorNamesPerScan().size(), CoreMatchers.is(expectedMonitorNamesPerScan.length));
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) Test(org.junit.Test)

Example 3 with ScanRequest

use of org.eclipse.scanning.api.event.scan.ScanRequest in project gda-core by openGDA.

the class ScanRequestConverterTest method testRoiAxisNamesAreSet.

@Test
public void testRoiAxisNamesAreSet() throws Exception {
    IPointGeneratorService pointGeneratorService = new PointGeneratorService();
    // Act - convert mapping bean to scan request
    final ScanRequest scanRequest = scanRequestConverter.convertToScanRequest(mappingBean);
    final Collection<ScanRegion> regions = scanRequest.getCompoundModel().getRegions();
    // Assert - ensure only one region
    assertThat(regions.size(), is(equalTo(1)));
    for (final ScanRegion scanRegion : regions) {
        final List<String> scannables = scanRegion.getScannables();
        final RectangularROI roi = (RectangularROI) scanRegion.getRoi();
        /* Post DAQ-2739, this ensures if x-y axes of regions are flipped again it will be noticed either here or in the num of point
			 * [n.b. shortly before 2739, Regions were not passed to CompoundModels, then they were but reflected, which broke scanning]
			 */
        assertThat(scannables.get(0), is(equalTo(X_AXIS_NAME)));
        assertThat(scannables.get(1), is(equalTo(Y_AXIS_NAME)));
        assertEquals(X_START, roi.getPoint()[0], DIFF_LIMIT);
        assertEquals(Y_START, roi.getPoint()[1], DIFF_LIMIT);
        assertEquals(X_LENGTH, roi.getLengths()[0], DIFF_LIMIT);
        assertEquals(Y_LENGTH, roi.getLengths()[1], DIFF_LIMIT);
    }
    // Act again - convert scan request back to mapping bean
    scanRequestConverter.mergeIntoMappingBean(scanRequest, newMappingBean);
    assertEquals(mappingBean.getScanDefinition().getMappingScanRegion().getRegion(), newMappingBean.getScanDefinition().getMappingScanRegion().getRegion());
    List<IPosition> allPositions = pointGeneratorService.createCompoundGenerator(scanRequest.getCompoundModel()).createPoints();
    assertEquals(25, allPositions.size());
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) ScanRegion(org.eclipse.scanning.api.points.models.ScanRegion) IMappingScanRegion(uk.ac.diamond.daq.mapping.api.IMappingScanRegion) IPosition(org.eclipse.scanning.api.points.IPosition) IPointGeneratorService(org.eclipse.scanning.api.points.IPointGeneratorService) RectangularROI(org.eclipse.dawnsci.analysis.dataset.roi.RectangularROI) PointGeneratorService(org.eclipse.scanning.points.PointGeneratorService) IPointGeneratorService(org.eclipse.scanning.api.points.IPointGeneratorService) Test(org.junit.Test)

Example 4 with ScanRequest

use of org.eclipse.scanning.api.event.scan.ScanRequest in project gda-core by openGDA.

the class ScanRequestConverterTest method testStageNamesChanged.

@Test
public void testStageNamesChanged() throws Exception {
    // Initially the scan path doesn't have the correct axis names
    assertThat(scanPath.getxAxisName(), is(not(equalTo(X_AXIS_NAME))));
    assertThat(scanPath.getyAxisName(), is(not(equalTo(Y_AXIS_NAME))));
    // Act - they're set according to the MappingStageInfo when the mapping bean is
    // converted to a scan request
    ScanRequest scanRequest = scanRequestConverter.convertToScanRequest(mappingBean);
    // Assert - the axis names are now set to the names of the stage
    assertThat(scanPath.getxAxisName(), is(equalTo(X_AXIS_NAME)));
    assertThat(scanPath.getyAxisName(), is(equalTo(Y_AXIS_NAME)));
    // change the mapping stage axis names
    mappingStageInfo.setPlotXAxisName("new_x_axis");
    mappingStageInfo.setPlotYAxisName("new_y_axis");
    // the new mapping bean hasn't been set up with a scan path at this stage
    IMappingScanRegion newRegion = newMappingBean.getScanDefinition().getMappingScanRegion();
    assertThat(newRegion.getScanPath(), is(nullValue()));
    // merging the scan request back into a mapping bean
    scanRequestConverter.mergeIntoMappingBean(scanRequest, newMappingBean);
    // check that the new mapping bean has the correct stage names
    assertThat(newRegion.getScanPath(), is(instanceOf(TwoAxisGridPointsModel.class)));
    TwoAxisGridPointsModel newScanPath = (TwoAxisGridPointsModel) newRegion.getScanPath();
    assertThat(newScanPath.getxAxisName(), is(equalTo(X_AXIS_NAME)));
    assertThat(newScanPath.getyAxisName(), is(equalTo(Y_AXIS_NAME)));
    // check that the mapping stage info has been updated with the stage names from the scan request
    assertThat(mappingStageInfo.getPlotXAxisName(), is(equalTo(X_AXIS_NAME)));
    assertThat(mappingStageInfo.getPlotYAxisName(), is(equalTo(Y_AXIS_NAME)));
}
Also used : IMappingScanRegion(uk.ac.diamond.daq.mapping.api.IMappingScanRegion) TwoAxisGridPointsModel(org.eclipse.scanning.api.points.models.TwoAxisGridPointsModel) ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) Test(org.junit.Test)

Example 5 with ScanRequest

use of org.eclipse.scanning.api.event.scan.ScanRequest in project gda-core by openGDA.

the class ScanRequestConverterTest method testUnknownDetector.

@Test(expected = IllegalArgumentException.class)
public void testUnknownDetector() throws Exception {
    final String detName = "mandelbrot";
    final String displayName = "Mandelbrot Detector";
    final IDetectorModel detModel = new MandelbrotModel();
    detModel.setName(detName);
    mappingBean.setDetectorParameters(Arrays.asList(new DetectorModelWrapper(displayName, detModel, true)));
    // Act - convert mapping bean to scan request
    final ScanRequest scanRequest = scanRequestConverter.convertToScanRequest(mappingBean);
    // Assert
    assertEquals(detModel, scanRequest.getDetectors().get(detName));
    // Act again - convert scan request back to mapping bean, throws exception
    scanRequestConverter.mergeIntoMappingBean(scanRequest, newMappingBean);
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) DetectorModelWrapper(uk.ac.diamond.daq.mapping.impl.DetectorModelWrapper) MandelbrotModel(org.eclipse.scanning.example.detector.MandelbrotModel) Test(org.junit.Test)

Aggregations

ScanRequest (org.eclipse.scanning.api.event.scan.ScanRequest)42 Test (org.junit.Test)25 IDetectorModel (org.eclipse.scanning.api.device.models.IDetectorModel)8 ScanBean (org.eclipse.scanning.api.event.scan.ScanBean)8 CompoundModel (org.eclipse.scanning.api.points.models.CompoundModel)8 IScanPointGeneratorModel (org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)8 ArrayList (java.util.ArrayList)7 ProcessingRequest (org.eclipse.scanning.api.event.scan.ProcessingRequest)7 IScanModelWrapper (uk.ac.diamond.daq.mapping.api.IScanModelWrapper)7 IMarshallerService (org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService)5 ScanRegion (org.eclipse.scanning.api.points.models.ScanRegion)5 IScriptService (org.eclipse.scanning.api.script.IScriptService)5 IMappingExperimentBean (uk.ac.diamond.daq.mapping.api.IMappingExperimentBean)5 HashMap (java.util.HashMap)4 AxialStepModel (org.eclipse.scanning.api.points.models.AxialStepModel)4 IMappingScanRegion (uk.ac.diamond.daq.mapping.api.IMappingScanRegion)4 TemplateFileWrapper (uk.ac.diamond.daq.mapping.api.TemplateFileWrapper)4 DetectorModelWrapper (uk.ac.diamond.daq.mapping.impl.DetectorModelWrapper)4 IMalcolmModel (org.eclipse.scanning.api.device.models.IMalcolmModel)3 IMapPathModel (org.eclipse.scanning.api.points.models.IMapPathModel)3