Search in sources :

Example 1 with MappingExperimentBean

use of uk.ac.diamond.daq.mapping.impl.MappingExperimentBean in project gda-core by openGDA.

the class ScanRequestConverterTest method setUp.

@Before
public void setUp() throws Exception {
    // We wire things together without OSGi here
    // DO NOT COPY THIS IN NON-TEST CODE!
    mappingStageInfo = new MappingStageInfo();
    mappingStageInfo.setPlotXAxisName(X_AXIS_NAME);
    mappingStageInfo.setPlotYAxisName(Y_AXIS_NAME);
    mappingStageInfo.setBeamSize(BEAM_SIZE_NAME);
    // Prepare the Finder
    Factory testFactory = mock(Factory.class);
    ScannableMotionUnits xAxis = mock(ScannableMotionUnits.class);
    when(xAxis.getHardwareUnitString()).thenReturn(X_AXIS_UNITS);
    ScannableMotionUnits yAxis = mock(ScannableMotionUnits.class);
    when(yAxis.getHardwareUnitString()).thenReturn(Y_AXIS_UNITS);
    when(testFactory.getFindable(X_AXIS_NAME)).thenReturn(xAxis);
    when(testFactory.getFindable(Y_AXIS_NAME)).thenReturn(yAxis);
    Finder.addFactory(testFactory);
    scanRequestConverter = new ScanRequestConverter();
    scanRequestConverter.setMappingStageInfo(mappingStageInfo);
    // Set up the experiment bean with some sensible defaults
    mappingBean = new MappingExperimentBean();
    scanPath = new TwoAxisGridPointsModel();
    scanPath.setContinuous(true);
    mappingBean.getScanDefinition().getMappingScanRegion().setScanPath(scanPath);
    final RectangularMappingRegion scanRegion = new RectangularMappingRegion();
    scanRegion.setxStart(X_START);
    scanRegion.setxStop(X_START + X_LENGTH);
    scanRegion.setyStart(Y_START);
    scanRegion.setyStop(Y_START + Y_LENGTH);
    mappingBean.getScanDefinition().getMappingScanRegion().setRegion(scanRegion);
    mappingBean.setDetectorParameters(Collections.emptyList());
    mappingBean.setPerScanMonitorNames(new HashSet<>(Arrays.asList("perScan1", "perScan2")));
    mappingBean.setPerPointMonitorNames(new HashSet<>(Arrays.asList("perPoint1", "perPoint2", "perPoint3")));
    newMappingBean = new MappingExperimentBean();
}
Also used : ScannableMotionUnits(gda.device.ScannableMotionUnits) TwoAxisGridPointsModel(org.eclipse.scanning.api.points.models.TwoAxisGridPointsModel) MappingExperimentBean(uk.ac.diamond.daq.mapping.impl.MappingExperimentBean) MappingStageInfo(uk.ac.diamond.daq.mapping.impl.MappingStageInfo) Factory(gda.factory.Factory) RectangularMappingRegion(uk.ac.diamond.daq.mapping.region.RectangularMappingRegion) ScanRequestConverter(uk.ac.diamond.daq.mapping.ui.experiment.ScanRequestConverter) Before(org.junit.Before)

Example 2 with MappingExperimentBean

use of uk.ac.diamond.daq.mapping.impl.MappingExperimentBean in project gda-core by openGDA.

the class MappingUISerializationTest method testSerializeMappingExperimentBean.

@Test
public void testSerializeMappingExperimentBean() throws Exception {
    ScriptFiles scriptFiles = new ScriptFiles();
    scriptFiles.setBeforeScanScript("/path/to/before.py");
    scriptFiles.setAfterScanScript("/path/to/after.py");
    Map<String, Object> beamlineConfiguration = new HashMap<>();
    beamlineConfiguration.put("D7A", "Gap");
    beamlineConfiguration.put("D7B", "gap");
    beamlineConfiguration.put("kb_vfm_x", "7.0");
    MandelbrotModel model = createMandelbrotModel();
    DetectorModelWrapper mandelbrotWrapper = new DetectorModelWrapper("Mandelbrot Detector", model, true);
    SimpleSampleMetadata sampleMetadata = new SimpleSampleMetadata();
    sampleMetadata.setSampleName("SampleName");
    sampleMetadata.setDescription("Description of sample");
    IScanDefinition scanDefinition = createScanDefinition();
    MappingExperimentBean mappingBean = new MappingExperimentBean();
    mappingBean.setScriptFiles(scriptFiles);
    mappingBean.setBeamlineConfiguration(beamlineConfiguration);
    mappingBean.setDetectorParameters(Arrays.asList(mandelbrotWrapper));
    mappingBean.setSampleMetadata(sampleMetadata);
    mappingBean.setScanDefinition(scanDefinition);
    ConfigWrapper w = new ConfigWrapper();
    w.setAppName("dawn");
    w.setPathToConfig("/path/to/config.json");
    mappingBean.addProcessingRequest(w);
    String json = service.marshal(mappingBean);
    MappingExperimentBean newMappingBean = service.unmarshal(json, MappingExperimentBean.class);
    assertEquals(mappingBean, newMappingBean);
}
Also used : MappingExperimentBean(uk.ac.diamond.daq.mapping.impl.MappingExperimentBean) ConfigWrapper(uk.ac.diamond.daq.mapping.api.ConfigWrapper) ScriptFiles(uk.ac.diamond.daq.mapping.impl.ScriptFiles) HashMap(java.util.HashMap) DetectorModelWrapper(uk.ac.diamond.daq.mapping.impl.DetectorModelWrapper) MandelbrotModel(org.eclipse.scanning.example.detector.MandelbrotModel) SimpleSampleMetadata(uk.ac.diamond.daq.mapping.impl.SimpleSampleMetadata) IScanDefinition(uk.ac.diamond.daq.mapping.api.IScanDefinition) Test(org.junit.Test)

Example 3 with MappingExperimentBean

use of uk.ac.diamond.daq.mapping.impl.MappingExperimentBean in project gda-core by openGDA.

the class ScanManagementController method loadScanMappingBean.

/**
 * Loads the file specified by the supplied fully quAlified filename into a mapping bean which is then returned
 * within and {@link Optional}. An error dialog is displayed if the file could not be successfully loaded.
 *
 * @param filename
 *            The fully qualified name of the required file
 * @return An {@link Optional} of a mapping bean constructed from the contents of the file
 */
public Optional<IMappingExperimentBean> loadScanMappingBean(final String filename) {
    checkInitialised();
    Optional<IMappingExperimentBean> result = Optional.empty();
    if (filename != null) {
        try {
            byte[] bytes = Files.readAllBytes(Paths.get(filename));
            final String json = new String(bytes, "UTF-8");
            final IMarshallerService marshaller = getService(IMarshallerService.class);
            MappingExperimentBean mappingBean = marshaller.unmarshal(json, MappingExperimentBean.class);
            stage.merge((MappingStageInfo) mappingBean.getStageInfoSnapshot());
            result = Optional.of(mappingBean);
        } catch (Exception e) {
            final String errorMessage = "Could not load a mapping scan from file: " + filename;
            logger.error(errorMessage, e);
            ErrorDialog.openError(Display.getCurrent().getActiveShell(), "Load Scan", errorMessage, new Status(IStatus.ERROR, MappingUIConstants.PLUGIN_ID, errorMessage, e));
        }
    }
    return result;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IMarshallerService(org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService) IMappingExperimentBean(uk.ac.diamond.daq.mapping.api.IMappingExperimentBean) MappingExperimentBean(uk.ac.diamond.daq.mapping.impl.MappingExperimentBean) PersistableMappingExperimentBean(uk.ac.diamond.daq.mapping.api.PersistableMappingExperimentBean) PersistenceException(uk.ac.diamond.daq.application.persistence.service.PersistenceException) IOException(java.io.IOException) IMappingExperimentBean(uk.ac.diamond.daq.mapping.api.IMappingExperimentBean)

Aggregations

MappingExperimentBean (uk.ac.diamond.daq.mapping.impl.MappingExperimentBean)3 ScannableMotionUnits (gda.device.ScannableMotionUnits)1 Factory (gda.factory.Factory)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 IMarshallerService (org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService)1 TwoAxisGridPointsModel (org.eclipse.scanning.api.points.models.TwoAxisGridPointsModel)1 MandelbrotModel (org.eclipse.scanning.example.detector.MandelbrotModel)1 Before (org.junit.Before)1 Test (org.junit.Test)1 PersistenceException (uk.ac.diamond.daq.application.persistence.service.PersistenceException)1 ConfigWrapper (uk.ac.diamond.daq.mapping.api.ConfigWrapper)1 IMappingExperimentBean (uk.ac.diamond.daq.mapping.api.IMappingExperimentBean)1 IScanDefinition (uk.ac.diamond.daq.mapping.api.IScanDefinition)1 PersistableMappingExperimentBean (uk.ac.diamond.daq.mapping.api.PersistableMappingExperimentBean)1 DetectorModelWrapper (uk.ac.diamond.daq.mapping.impl.DetectorModelWrapper)1 MappingStageInfo (uk.ac.diamond.daq.mapping.impl.MappingStageInfo)1 ScriptFiles (uk.ac.diamond.daq.mapping.impl.ScriptFiles)1