Search in sources :

Example 1 with TwoAxisLinePointsModel

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

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

the class MScanSubmitterTest method setUp.

@Before
public void setUp() throws Exception {
    try (final MockedStatic<JythonServerFacade> facade = mockStatic(JythonServerFacade.class)) {
        facade.when(JythonServerFacade::getInstance).thenReturn(theFacadeInstance);
        builder = new MScanSubmitter(eventService, runnableDeviceService, resolverFactory);
        when(eventService.getEventConnectorService()).thenReturn(connectorService);
        when(connectorService.marshal(any())).thenReturn("");
        when(eventService.createSubmitter(any(), any())).thenReturn(submitter);
        when(eventService.createSubscriber(any(), anyString())).thenReturn(eventSubscriber);
        when(resolverFactory.getResolver(captor.capture())).thenReturn(resolver);
        when(detector.getName()).thenReturn(DETECTOR_NAME);
        when(runnableDeviceService.getRunnableDevice(DETECTOR_NAME)).thenReturn(runnableDevice);
        when(runnableDevice.getModel()).thenReturn(detectorModel);
        when(detectorRunnableDevice.getModel()).thenReturn(detectorModel);
        when(monitor.getName()).thenReturn("monitor");
        when(scannable.getName()).thenReturn("stage_x");
        when(scannable.getUserUnits()).thenReturn("mm");
        when(anotherScannable.getName()).thenReturn("stage_y");
        when(anotherScannable.getUserUnits()).thenReturn("mm");
        point = new TwoAxisPointSingleModel();
        point.setX(2.0);
        point.setY(3.0);
        pointRoi = new PointROI(point.getX(), point.getY());
        axPoints = new AxialPointsModel(scannable.getName(), 2, 3, 20);
        axPoints.setContinuous(false);
        axStep = new AxialStepModel(scannable.getName(), 2, 3, 0.2);
        axStep.setContinuous(false);
        axArray = new AxialArrayModel(scannable.getName(), positions);
        axArray.setContinuous(false);
        liPoints = new TwoAxisLinePointsModel();
        liPoints.setPoints(20);
        liStep = new TwoAxisLineStepModel();
        liStep.setStep(0.2);
        line = new LinearROI(new double[] { 2, 2 }, new double[] { 3, 3 });
        grid = new TwoAxisGridPointsModel(scannable.getName(), anotherScannable.getName(), 20, 10);
        grid.setContinuous(false);
        steppedGrid = new TwoAxisGridStepModel();
        steppedGrid.setxAxisStep(0.1);
        steppedGrid.setyAxisStep(0.2);
        steppedGrid.setContinuous(false);
        rectangle = new RectangularROI(2, 3, 4, 5, 0);
        rectangleX2 = rectangle.getPointX() + rectangle.getLength(X);
        rectangleY2 = rectangle.getPointY() + rectangle.getLength(Y);
        circle = new CircularROI(5.5, 2, 3);
    }
}
Also used : TwoAxisLinePointsModel(org.eclipse.scanning.api.points.models.TwoAxisLinePointsModel) JythonServerFacade(gda.jython.JythonServerFacade) AxialArrayModel(org.eclipse.scanning.api.points.models.AxialArrayModel) TwoAxisGridPointsModel(org.eclipse.scanning.api.points.models.TwoAxisGridPointsModel) TwoAxisLineStepModel(org.eclipse.scanning.api.points.models.TwoAxisLineStepModel) CircularROI(org.eclipse.dawnsci.analysis.dataset.roi.CircularROI) TwoAxisPointSingleModel(org.eclipse.scanning.api.points.models.TwoAxisPointSingleModel) TwoAxisGridStepModel(org.eclipse.scanning.api.points.models.TwoAxisGridStepModel) LinearROI(org.eclipse.dawnsci.analysis.dataset.roi.LinearROI) AxialStepModel(org.eclipse.scanning.api.points.models.AxialStepModel) IRectangularROI(org.eclipse.dawnsci.analysis.api.roi.IRectangularROI) RectangularROI(org.eclipse.dawnsci.analysis.dataset.roi.RectangularROI) AxialPointsModel(org.eclipse.scanning.api.points.models.AxialPointsModel) PointROI(org.eclipse.dawnsci.analysis.dataset.roi.PointROI) Before(org.junit.Before)

Example 3 with TwoAxisLinePointsModel

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

the class FocusScanSetupPage method initializePage.

private void initializePage() {
    ILineMappingRegion lineRegion = focusScanBean.getLineRegion();
    if (lineRegion == null) {
        lineRegion = new LineMappingRegion();
        focusScanBean.setLineRegion(lineRegion);
    }
    // Only trigger path calculation once region limits has been adjusted
    regionBeanPropertyChangeListener = event -> {
        if (event.getPropertyName().equals(CALC_POINTS)) {
            updateLineRegion();
        }
    };
    lineRegion.addPropertyChangeListener(regionBeanPropertyChangeListener);
    linePathModel = new TwoAxisLinePointsModel();
    pathBeanPropertyChangeListener = event -> updatePoints();
    linePathModel.addPropertyChangeListener(pathBeanPropertyChangeListener);
    // Ensure the line boundaries are kept up to date with the model
    linePathModel.addPropertyChangeListener(evt -> mapRegionOntoModel());
    pathCalculationJob = createPathCalculationJob();
    endPointTextUpdateStrategy = new UpdateValueStrategy();
    endPointTextUpdateStrategy.setConverter(new EndPointNumberConverter());
}
Also used : UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) TwoAxisLinePointsModel(org.eclipse.scanning.api.points.models.TwoAxisLinePointsModel) ILineMappingRegion(uk.ac.diamond.daq.mapping.api.ILineMappingRegion) ILineMappingRegion(uk.ac.diamond.daq.mapping.api.ILineMappingRegion) LineMappingRegion(uk.ac.diamond.daq.mapping.region.LineMappingRegion)

Example 4 with TwoAxisLinePointsModel

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

the class FocusScanConverter method createLineModel.

private IBoundingLineModel createLineModel(FocusScanBean focusScanBean) {
    final ILineMappingRegion lineRegion = focusScanBean.getLineRegion();
    final int numPoints = focusScanBean.getNumberOfLinePoints();
    final TwoAxisLinePointsModel lineModel = new TwoAxisLinePointsModel();
    lineModel.setPoints(numPoints);
    // continuous if possible (i.e. malcolm)
    lineModel.setContinuous(true);
    if (mappingStageInfo != null) {
        lineModel.setxAxisName(mappingStageInfo.getPlotXAxisName());
        lineModel.setyAxisName(mappingStageInfo.getPlotYAxisName());
    }
    // DO we need to do this, as we set the region in the scan request?
    final LinearROI lineRoi = (LinearROI) lineRegion.toROI();
    BoundingLine line = lineModel.getBoundingLine();
    if (line == null) {
        line = new BoundingLine();
        lineModel.setBoundingLine(line);
    }
    line.setxStart(lineRoi.getPointX());
    line.setyStart(lineRoi.getPointY());
    line.setAngle(lineRoi.getAngle());
    line.setLength(lineRoi.getLength());
    lineModel.setBoundingLine(line);
    return lineModel;
}
Also used : TwoAxisLinePointsModel(org.eclipse.scanning.api.points.models.TwoAxisLinePointsModel) ILineMappingRegion(uk.ac.diamond.daq.mapping.api.ILineMappingRegion) LinearROI(org.eclipse.dawnsci.analysis.dataset.roi.LinearROI) BoundingLine(org.eclipse.scanning.api.points.models.BoundingLine)

Example 5 with TwoAxisLinePointsModel

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

the class ScanpathTest method createModelCreatesCorrectModelForTwoDEqualSpacing.

@Test
public void createModelCreatesCorrectModelForTwoDEqualSpacing() throws Exception {
    pathParams = Arrays.asList(5);
    mutators.put(Mutator.CONTINUOUS, Arrays.asList(blankArray));
    IScanPathModel model = LINE_POINTS.createModel(scannables, pathParams, bboxParams, mutators);
    assertThat(model, is(instanceOf(TwoAxisLinePointsModel.class)));
    TwoAxisLinePointsModel eModel = (TwoAxisLinePointsModel) model;
    assertThat(eModel.getScannableNames(), contains("name1", "name2"));
    assertThat(eModel.getBoundingLine().getxStart(), is(1.0));
    assertThat(eModel.getBoundingLine().getyStart(), is(2.0));
    assertThat(eModel.getBoundingLine().getLength(), is(5.0));
    assertThat(Math.rint(Math.toDegrees(eModel.getBoundingLine().getAngle())), is(53.0));
    assertThat(eModel.getPoints(), is(5));
    assertThat(eModel.isContinuous(), is(true));
}
Also used : TwoAxisLinePointsModel(org.eclipse.scanning.api.points.models.TwoAxisLinePointsModel) IScanPathModel(org.eclipse.scanning.api.points.models.IScanPathModel) Test(org.junit.Test)

Aggregations

TwoAxisLinePointsModel (org.eclipse.scanning.api.points.models.TwoAxisLinePointsModel)5 LinearROI (org.eclipse.dawnsci.analysis.dataset.roi.LinearROI)3 AxialStepModel (org.eclipse.scanning.api.points.models.AxialStepModel)2 BoundingLine (org.eclipse.scanning.api.points.models.BoundingLine)2 Test (org.junit.Test)2 ILineMappingRegion (uk.ac.diamond.daq.mapping.api.ILineMappingRegion)2 JythonServerFacade (gda.jython.JythonServerFacade)1 UpdateValueStrategy (org.eclipse.core.databinding.UpdateValueStrategy)1 IRectangularROI (org.eclipse.dawnsci.analysis.api.roi.IRectangularROI)1 CircularROI (org.eclipse.dawnsci.analysis.dataset.roi.CircularROI)1 PointROI (org.eclipse.dawnsci.analysis.dataset.roi.PointROI)1 RectangularROI (org.eclipse.dawnsci.analysis.dataset.roi.RectangularROI)1 IDetectorModel (org.eclipse.scanning.api.device.models.IDetectorModel)1 ScanRequest (org.eclipse.scanning.api.event.scan.ScanRequest)1 AxialArrayModel (org.eclipse.scanning.api.points.models.AxialArrayModel)1 AxialPointsModel (org.eclipse.scanning.api.points.models.AxialPointsModel)1 CompoundModel (org.eclipse.scanning.api.points.models.CompoundModel)1 IScanPathModel (org.eclipse.scanning.api.points.models.IScanPathModel)1 IScanPointGeneratorModel (org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)1 ScanRegion (org.eclipse.scanning.api.points.models.ScanRegion)1