Search in sources :

Example 1 with MandelbrotModel

use of org.eclipse.scanning.example.detector.MandelbrotModel 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)

Example 2 with MandelbrotModel

use of org.eclipse.scanning.example.detector.MandelbrotModel in project gda-core by openGDA.

the class MappingUISerializationTest method testSerializeDetectorModelWrapper.

@Test
public void testSerializeDetectorModelWrapper() throws Exception {
    MandelbrotModel model = createMandelbrotModel();
    DetectorModelWrapper detectorModelWrapper = new DetectorModelWrapper("Mandelbrot Detector", model, true);
    String json = service.marshal(detectorModelWrapper);
    DetectorModelWrapper newDetectorModelWrapper = service.unmarshal(json, DetectorModelWrapper.class);
    assertEquals(detectorModelWrapper, newDetectorModelWrapper);
}
Also used : DetectorModelWrapper(uk.ac.diamond.daq.mapping.impl.DetectorModelWrapper) MandelbrotModel(org.eclipse.scanning.example.detector.MandelbrotModel) Test(org.junit.Test)

Example 3 with MandelbrotModel

use of org.eclipse.scanning.example.detector.MandelbrotModel in project gda-core by openGDA.

the class MappingUISerializationTest method createMandelbrotModel.

private MandelbrotModel createMandelbrotModel() {
    MandelbrotModel model = new MandelbrotModel();
    model.setName("mandelbrot");
    model.setRealAxisName("xNex");
    model.setImaginaryAxisName("yNex");
    model.setColumns(64);
    model.setRows(64);
    model.setMaxIterations(1);
    model.setExposureTime(0.0);
    return model;
}
Also used : MandelbrotModel(org.eclipse.scanning.example.detector.MandelbrotModel)

Example 4 with MandelbrotModel

use of org.eclipse.scanning.example.detector.MandelbrotModel 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 5 with MandelbrotModel

use of org.eclipse.scanning.example.detector.MandelbrotModel in project gda-core by openGDA.

the class ScannableNexusWrapperScanTest method before.

@Before
public void before() throws Exception {
    final MandelbrotModel model = new MandelbrotModel();
    model.setName("mandelbrot");
    model.setRealAxisName(SCANNABLE_NAME_SALONG);
    model.setImaginaryAxisName(SCANNABLE_NAME_SAPERP);
    detector = TestDetectorHelpers.createAndConfigureMandelbrotDetector(model);
    assertThat(detector, is(notNullValue()));
    detector.addRunListener(IRunListener.createRunPerformedListener(event -> System.out.println("Ran mandelbrot detector @ " + event.getPosition())));
    readLegacySpringConfig(TEST_CONFIG_FILE_PATH);
    ServiceHolder.getNexusDataWriterConfiguration().setLocationMap(locationMap);
    ServiceHolder.getNexusDataWriterConfiguration().setMetadataScannables(legacyMetadataScannables);
    final Factory factory = TestHelpers.createTestFactory();
    factory.addFindable(jythonServer);
    factory.addFindable(new SampleAngleScannable(SCANNABLE_NAME_SALONG, false));
    factory.addFindable(new SampleAngleScannable(SCANNABLE_NAME_SAPERP, true));
    factory.addFindable(new DummyScannable("sax", 5.0, "BL00P-MO-SAMPLE-01:SAX"));
    factory.addFindable(new DummyScannable("say", 23.4, "BL00P-MO-SAMPLE-01:SAY"));
    factory.addFindable(new DummyScannable("satilt", 127.4));
    factory.addFindable(new DummyScannable("saazimuth", 24.32));
    factory.addFindable(new DummyScannable("s6_xsize", 2.92));
    factory.addFindable(new DummyScannable("s2_ysize", 8.34));
    factory.addFindable(new DummyScannable("s2_xsize", 1.66));
    factory.addFindable(new DummyScannable("exit_slit", 0.0683, "BL00P-MO-SLIT-01:EXIT"));
    factory.addFindable(new DummyEnergyScannable("pgm_cff", 123.45));
    factory.addFindable(new DummyScannable("energy", 9.357e8));
    factory.addFindable(new DummyScannable("pgm_linedensity", 28));
    factory.addFindable(new DummyScannable("ring_current", 15.2, "SR-DI-DCCT-01:SIGNAL"));
    factory.addFindable(new DummyScannable("ring_energy", 47.53, "CS-CS-MSTAT-01:BEAMENERGY"));
    factory.addFindable(new DummyScannable("lc_pressure", 73.012));
    factory.addFindable(new DummyStringScannable("sample_name", "name", "test sample"));
    final DummyMultiFieldUnitsScannable<Temperature> cryostat = new DummyMultiFieldUnitsScannable<>("cryostat", "K");
    cryostat.setInputNames(new String[] { "temperature_demand" });
    cryostat.setExtraNames(new String[] { "cryostat_temperature", "temperature", "shield_temperature", "heater_percent", "heater_setting" });
    cryostat.setCurrentPosition(20.0);
    cryostat.setExtraFieldsPosition(19.9, 19.9, 26.5, 64.3, 15.3);
    factory.addFindable(cryostat);
    final DummyMultiFieldUnitsScannable<Length> id = new DummyMultiFieldUnitsScannable<>("id");
    id.setScanMetadataAttribute(Scannable.ATTR_NX_CLASS, "NXinsertion_device");
    // no input names
    id.setInputNames(new String[0]);
    id.setExtraNames(new String[] { "gap", "final_polarisation_label", "phase" });
    id.setExtraFieldsPosition(20, "label", 60);
    factory.addFindable(id);
    final DummyMultiFieldUnitsScannable<Angle> sapolar = new DummyMultiFieldUnitsScannable<>("sapolar");
    sapolar.setInputNames(new String[] { "alpha", "delta", "omicron" });
    sapolar.setExtraNames(new String[0]);
    sapolar.setCurrentPosition(0.5, 1.25, -0.75);
    factory.addFindable(sapolar);
    final DummyScannable attr = new DummyScannable("attributes", 2.5);
    attr.setInputNames(new String[] { NXpositioner.NX_VALUE });
    attr.setScanMetadataAttribute("stringAttr", "foo");
    attr.setScanMetadataAttribute("doubleAttr", 123.456);
    factory.addFindable(attr);
    final DummyScannable beam = new DummyScannable("beam", 3.25);
    beam.setInputNames(new String[] { "extent" });
    beam.setScanMetadataAttribute(Scannable.ATTR_NX_CLASS, "NXbeam");
    beam.setScanMetadataAttribute(Scannable.ATTR_NEXUS_CATEGORY, "NXsample");
    factory.addFindable(beam);
    Finder.addFactory(factory);
}
Also used : Attribute(org.eclipse.dawnsci.analysis.api.tree.Attribute) IDataset(org.eclipse.january.dataset.IDataset) Arrays(java.util.Arrays) NXinstrument(org.eclipse.dawnsci.nexus.NXinstrument) NXroot(org.eclipse.dawnsci.nexus.NXroot) MandelbrotModel(org.eclipse.scanning.example.detector.MandelbrotModel) ATTR_NAME_LOCAL_NAME(gda.data.scan.nexus.device.AbstractScannableNexusDevice.ATTR_NAME_LOCAL_NAME) ScanRole(org.eclipse.dawnsci.nexus.NexusScanInfo.ScanRole) ValidatorService(org.eclipse.scanning.points.validation.ValidatorService) ATTR_NAME_UNITS(gda.data.scan.nexus.device.AbstractScannableNexusDevice.ATTR_NAME_UNITS) Matchers.not(org.hamcrest.Matchers.not) DefaultNexusBuilderFactory(org.eclipse.dawnsci.nexus.builder.impl.DefaultNexusBuilderFactory) ATTR_NAME_GDA_FIELD_NAME(gda.data.scan.nexus.device.AbstractScannableNexusDevice.ATTR_NAME_GDA_FIELD_NAME) StringUtils(org.apache.commons.lang3.StringUtils) TestDetectorHelpers(org.eclipse.scanning.test.util.TestDetectorHelpers) DataNode(org.eclipse.dawnsci.analysis.api.tree.DataNode) Matchers.closeTo(org.hamcrest.Matchers.closeTo) Temperature(javax.measure.quantity.Temperature) Detector(gda.device.Detector) COLLECTION_NAME_SCANNABLES(gda.data.scan.nexus.device.AbstractScannableNexusDevice.COLLECTION_NAME_SCANNABLES) Document(org.w3c.dom.Document) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) NexusFile(org.eclipse.dawnsci.nexus.NexusFile) ScannableMotionUnits(gda.device.ScannableMotionUnits) Finder(gda.factory.Finder) RunnableDeviceServiceImpl(org.eclipse.scanning.sequencer.RunnableDeviceServiceImpl) MockFilePathService(org.eclipse.scanning.example.file.MockFilePathService) ATTR_NAME_TARGET(org.eclipse.dawnsci.nexus.builder.data.NexusDataBuilder.ATTR_NAME_TARGET) IScannableDeviceService(org.eclipse.scanning.api.device.IScannableDeviceService) Set(java.util.Set) ScanningException(org.eclipse.scanning.api.scan.ScanningException) TestHelpers(gda.TestHelpers) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ServiceHolder(gda.data.ServiceHolder) Stream(java.util.stream.Stream) Matchers.contains(org.hamcrest.Matchers.contains) NXCLASS(org.eclipse.dawnsci.nexus.NexusConstants.NXCLASS) NexusDataWriterConfiguration(gda.data.scan.datawriter.NexusDataWriterConfiguration) NXobject(org.eclipse.dawnsci.nexus.NXobject) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Mockito.mock(org.mockito.Mockito.mock) ScanModel(org.eclipse.scanning.api.scan.models.ScanModel) IRunnableEventDevice(org.eclipse.scanning.api.device.IRunnableEventDevice) ScannableWriter(gda.data.scan.datawriter.scannablewriter.ScannableWriter) DummyScannable(gda.device.scannable.DummyScannable) ActivemqConnectorService(org.eclipse.scanning.connector.activemq.ActivemqConnectorService) NXdata(org.eclipse.dawnsci.nexus.NXdata) ArrayList(java.util.ArrayList) IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) Length(javax.measure.quantity.Length) ATTR_NAME_GDA_SCANNABLE_NAME(gda.data.scan.nexus.device.AbstractScannableNexusDevice.ATTR_NAME_GDA_SCANNABLE_NAME) DeviceException(gda.device.DeviceException) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) AbstractRunnableDevice(org.eclipse.scanning.api.device.AbstractRunnableDevice) Before(org.junit.Before) NexusAssert.assertDiamondScanGroup(org.eclipse.dawnsci.nexus.test.utilities.NexusAssert.assertDiamondScanGroup) NexusDeviceService(org.eclipse.dawnsci.nexus.device.impl.NexusDeviceService) IOException(java.io.IOException) Test(org.junit.Test) NXbeam(org.eclipse.dawnsci.nexus.NXbeam) ScannableMotion(gda.device.ScannableMotion) File(java.io.File) InterfaceUtils(org.eclipse.january.dataset.InterfaceUtils) INameable(org.eclipse.scanning.api.INameable) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) IPosition(org.eclipse.scanning.api.points.IPosition) DocumentBuilder(javax.xml.parsers.DocumentBuilder) IPointGeneratorService(org.eclipse.scanning.api.points.IPointGeneratorService) FIELD_NAME_VALUE_SET(gda.data.scan.nexus.device.AbstractScannableNexusDevice.FIELD_NAME_VALUE_SET) BoundingBox(org.eclipse.scanning.api.points.models.BoundingBox) CoreMatchers.is(org.hamcrest.CoreMatchers.is) TreeFile(org.eclipse.dawnsci.analysis.api.tree.TreeFile) Array(java.lang.reflect.Array) Findable(gda.factory.Findable) IRunListener(org.eclipse.scanning.api.scan.event.IRunListener) NXtransformations(org.eclipse.dawnsci.nexus.NXtransformations) InterfaceProvider(gda.jython.InterfaceProvider) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) NexusAssert.assertTarget(org.eclipse.dawnsci.nexus.test.utilities.NexusAssert.assertTarget) EventServiceImpl(org.eclipse.scanning.event.EventServiceImpl) NXentry(org.eclipse.dawnsci.nexus.NXentry) After(org.junit.After) PointsModelMarshaller(org.eclipse.scanning.points.serialization.PointsModelMarshaller) ScannableBase(gda.device.scannable.ScannableBase) Collection(java.util.Collection) INexusFileFactory(org.eclipse.dawnsci.nexus.INexusFileFactory) IWritableDetector(org.eclipse.scanning.api.device.IWritableDetector) Collectors(java.util.stream.Collectors) NexusAssert.assertAxes(org.eclipse.dawnsci.nexus.test.utilities.NexusAssert.assertAxes) Scannable(gda.device.Scannable) AxialStepModel(org.eclipse.scanning.api.points.models.AxialStepModel) Factory(gda.factory.Factory) List(java.util.List) IScanService(org.eclipse.scanning.api.scan.IScanService) IPointGenerator(org.eclipse.scanning.api.points.IPointGenerator) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) NexusAssert.assertIndices(org.eclipse.dawnsci.nexus.test.utilities.NexusAssert.assertIndices) Matchers.equalTo(org.hamcrest.Matchers.equalTo) RunEvent(org.eclipse.scanning.api.scan.event.RunEvent) Optional(java.util.Optional) DeviceState(org.eclipse.scanning.api.event.scan.DeviceState) IntStream(java.util.stream.IntStream) INexusDeviceService(org.eclipse.dawnsci.nexus.device.INexusDeviceService) IEventService(org.eclipse.scanning.api.event.IEventService) MockOperationService(org.eclipse.scanning.test.utilities.scan.mock.MockOperationService) Energy(javax.measure.quantity.Energy) BeforeClass(org.junit.BeforeClass) ATTR_NAME_GDA_SCAN_ROLE(gda.data.scan.nexus.device.AbstractScannableNexusDevice.ATTR_NAME_GDA_SCAN_ROLE) JythonServer(gda.jython.JythonServer) HashMap(java.util.HashMap) ArrayUtils(org.apache.commons.lang3.ArrayUtils) NexusUtils(org.eclipse.dawnsci.nexus.NexusUtils) DatasetFactory(org.eclipse.january.dataset.DatasetFactory) ControllerRecord(gda.device.ControllerRecord) MarshallerService(org.eclipse.dawnsci.json.MarshallerService) IScannable(org.eclipse.scanning.api.IScannable) HashSet(java.util.HashSet) Angle(javax.measure.quantity.Angle) NexusBaseClass(org.eclipse.dawnsci.nexus.NexusBaseClass) NexusConstants(org.eclipse.dawnsci.nexus.NexusConstants) NexusScanFileServiceImpl(org.eclipse.dawnsci.nexus.scan.impl.NexusScanFileServiceImpl) NXsample(org.eclipse.dawnsci.nexus.NXsample) Node(org.w3c.dom.Node) DummyMultiFieldUnitsScannable(gda.device.scannable.DummyMultiFieldUnitsScannable) IRunnableDevice(org.eclipse.scanning.api.device.IRunnableDevice) NexusFileFactoryHDF5(org.eclipse.dawnsci.hdf5.nexus.NexusFileFactoryHDF5) Services(org.eclipse.scanning.server.servlet.Services) SingleScannableWriter(gda.data.scan.datawriter.scannablewriter.SingleScannableWriter) PointGeneratorService(org.eclipse.scanning.points.PointGeneratorService) Matchers.empty(org.hamcrest.Matchers.empty) TransformationWriter(gda.data.scan.datawriter.scannablewriter.TransformationWriter) NXcollection(org.eclipse.dawnsci.nexus.NXcollection) TwoAxisGridPointsModel(org.eclipse.scanning.api.points.models.TwoAxisGridPointsModel) Element(org.w3c.dom.Element) NXpositioner(org.eclipse.dawnsci.nexus.NXpositioner) Collections(java.util.Collections) AbstractPosition(org.eclipse.scanning.api.points.AbstractPosition) DummyUnitsScannable(gda.device.scannable.DummyUnitsScannable) Temperature(javax.measure.quantity.Temperature) DefaultNexusBuilderFactory(org.eclipse.dawnsci.nexus.builder.impl.DefaultNexusBuilderFactory) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) INexusFileFactory(org.eclipse.dawnsci.nexus.INexusFileFactory) Factory(gda.factory.Factory) DatasetFactory(org.eclipse.january.dataset.DatasetFactory) DummyMultiFieldUnitsScannable(gda.device.scannable.DummyMultiFieldUnitsScannable) DummyScannable(gda.device.scannable.DummyScannable) Angle(javax.measure.quantity.Angle) Length(javax.measure.quantity.Length) MandelbrotModel(org.eclipse.scanning.example.detector.MandelbrotModel) Before(org.junit.Before)

Aggregations

MandelbrotModel (org.eclipse.scanning.example.detector.MandelbrotModel)8 Test (org.junit.Test)6 DetectorModelWrapper (uk.ac.diamond.daq.mapping.impl.DetectorModelWrapper)5 IDetectorModel (org.eclipse.scanning.api.device.models.IDetectorModel)4 HashMap (java.util.HashMap)2 ScanRequest (org.eclipse.scanning.api.event.scan.ScanRequest)2 IScanModelWrapper (uk.ac.diamond.daq.mapping.api.IScanModelWrapper)2 TestHelpers (gda.TestHelpers)1 ServiceHolder (gda.data.ServiceHolder)1 NexusDataWriterConfiguration (gda.data.scan.datawriter.NexusDataWriterConfiguration)1 ScannableWriter (gda.data.scan.datawriter.scannablewriter.ScannableWriter)1 SingleScannableWriter (gda.data.scan.datawriter.scannablewriter.SingleScannableWriter)1 TransformationWriter (gda.data.scan.datawriter.scannablewriter.TransformationWriter)1 ATTR_NAME_GDA_FIELD_NAME (gda.data.scan.nexus.device.AbstractScannableNexusDevice.ATTR_NAME_GDA_FIELD_NAME)1 ATTR_NAME_GDA_SCANNABLE_NAME (gda.data.scan.nexus.device.AbstractScannableNexusDevice.ATTR_NAME_GDA_SCANNABLE_NAME)1 ATTR_NAME_GDA_SCAN_ROLE (gda.data.scan.nexus.device.AbstractScannableNexusDevice.ATTR_NAME_GDA_SCAN_ROLE)1 ATTR_NAME_LOCAL_NAME (gda.data.scan.nexus.device.AbstractScannableNexusDevice.ATTR_NAME_LOCAL_NAME)1 ATTR_NAME_UNITS (gda.data.scan.nexus.device.AbstractScannableNexusDevice.ATTR_NAME_UNITS)1 COLLECTION_NAME_SCANNABLES (gda.data.scan.nexus.device.AbstractScannableNexusDevice.COLLECTION_NAME_SCANNABLES)1 FIELD_NAME_VALUE_SET (gda.data.scan.nexus.device.AbstractScannableNexusDevice.FIELD_NAME_VALUE_SET)1