Search in sources :

Example 1 with CompoundModel

use of org.eclipse.scanning.api.points.models.CompoundModel 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 CompoundModel

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

the class MScanSubmitterTest method willAllowStaticScanWithDefaultSizeAndNoDetectorParams.

@Test
public void willAllowStaticScanWithDefaultSizeAndNoDetectorParams() throws Exception {
    Object[] arr = { Scanpath.STATIC, detectorRunnableDevice };
    when(resolver.resolveScanClauses()).thenReturn(Arrays.asList(Arrays.asList(new ScanpathElementProcessor(Scanpath.STATIC)), Arrays.asList(new IRunnableDeviceDetectorElementProcessor(detectorRunnableDevice))));
    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) 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 3 with CompoundModel

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

the class MScanSubmitterTest method trimIfStepTooLongForRegionOccursOnGenerator.

@Test
public // Behaviour combined with {@link StepTest#testTooLargeStep} shows expected behaviour
void trimIfStepTooLongForRegionOccursOnGenerator() throws Exception {
    final AxialStepModel expectedModel = new AxialStepModel(scannable.getName(), -1, 1, 5);
    expectedModel.setContinuous(false);
    Object[] arr = { scannable, RegionShape.AXIAL, -1, 1, Scanpath.AXIS_STEP, 5, detectorRunnableDevice };
    when(resolver.resolveScanClauses()).thenReturn(Arrays.asList(Arrays.asList(new ScannableElementProcessor(scannable), new RegionShapeElementProcessor(RegionShape.AXIAL), new NumberElementProcessor(-1), new NumberElementProcessor(1), new ScanpathElementProcessor(Scanpath.AXIS_STEP), new NumberElementProcessor(5)), Arrays.asList(new IRunnableDeviceDetectorElementProcessor(detectorRunnableDevice))));
    builder.buildAndSubmitBlockingScanRequest(arr);
    verify(submitter).blockingSubmit(beanCaptor.capture());
    verify(eventSubscriber).addListener(any(IScanListener.class));
    CompoundModel model = beanCaptor.getValue().getScanRequest().getCompoundModel();
    assertThat(model.getModels().get(0), is(equalTo(expectedModel)));
}
Also used : IScanListener(org.eclipse.scanning.api.event.scan.IScanListener) NumberElementProcessor(gda.mscan.processor.NumberElementProcessor) ScanpathElementProcessor(gda.mscan.processor.ScanpathElementProcessor) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) ScannableElementProcessor(gda.mscan.processor.ScannableElementProcessor) IRunnableDeviceDetectorElementProcessor(gda.mscan.processor.IRunnableDeviceDetectorElementProcessor) AxialStepModel(org.eclipse.scanning.api.points.models.AxialStepModel) RegionShapeElementProcessor(gda.mscan.processor.RegionShapeElementProcessor) Test(org.junit.Test)

Example 4 with CompoundModel

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

the class MScanSubmitterTest method willAllowStaticScanWithOnlyDetectorAndParams.

@Test
public void willAllowStaticScanWithOnlyDetectorAndParams() throws Exception {
    Object[] arr = { Scanpath.STATIC, detectorRunnableDevice, 2.5 };
    when(resolver.resolveScanClauses()).thenReturn(Arrays.asList(Arrays.asList(new ScanpathElementProcessor(Scanpath.STATIC)), Arrays.asList(new IRunnableDeviceDetectorElementProcessor(detectorRunnableDevice), new NumberElementProcessor(2.5))));
    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 5 with CompoundModel

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

the class MScanSubmitterTest method willAllowStaticScanWithOnlyDetector.

@Test
public void willAllowStaticScanWithOnlyDetector() throws Exception {
    Object[] arr = { detector };
    when(resolver.resolveScanClauses()).thenReturn(Arrays.asList(Arrays.asList(new ScanpathElementProcessor(Scanpath.STATIC)), Arrays.asList(new ScannableDetectorElementProcessor(detector))));
    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()))));
}
Also used : IScanListener(org.eclipse.scanning.api.event.scan.IScanListener) ScanBean(org.eclipse.scanning.api.event.scan.ScanBean) ScanpathElementProcessor(gda.mscan.processor.ScanpathElementProcessor) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) StaticModel(org.eclipse.scanning.api.points.models.StaticModel) ScannableDetectorElementProcessor(gda.mscan.processor.ScannableDetectorElementProcessor) Test(org.junit.Test)

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