Search in sources :

Example 1 with ScriptFiles

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

the class MappingUISerializationTest method testSerializeScriptFiles.

@Test
public void testSerializeScriptFiles() throws Exception {
    ScriptFiles scriptFiles = new ScriptFiles();
    scriptFiles.setBeforeScanScript("/path/to/before.py");
    scriptFiles.setAfterScanScript("/path/to/after.py");
    scriptFiles.setAlwaysRunAfterScript(true);
    String json = service.marshal(scriptFiles);
    ScriptFiles newScriptFiles = service.unmarshal(json, ScriptFiles.class);
    assertEquals(scriptFiles, newScriptFiles);
}
Also used : ScriptFiles(uk.ac.diamond.daq.mapping.impl.ScriptFiles) Test(org.junit.Test)

Example 2 with ScriptFiles

use of uk.ac.diamond.daq.mapping.impl.ScriptFiles 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 ScriptFiles

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

the class ScanRequestConverterTest method testScriptFilesIncludedCorrectly.

@Test
public void testScriptFilesIncludedCorrectly() throws Exception {
    // Arrange
    final String beforeScanScript = "/path/to/before.py";
    final String afterScanScript = "/path/to/after.py";
    final IScriptFiles scriptFiles = new ScriptFiles();
    mappingBean.setScriptFiles(scriptFiles);
    scriptFiles.setBeforeScanScript(beforeScanScript);
    scriptFiles.setAfterScanScript(afterScanScript);
    scriptFiles.setAlwaysRunAfterScript(true);
    // Act - covert mapping bean to scan request
    final ScanRequest scanRequest = scanRequestConverter.convertToScanRequest(mappingBean);
    // Assert
    final ScriptRequest beforeScriptReq = scanRequest.getBeforeScript();
    assertThat(beforeScriptReq, is(notNullValue()));
    assertThat(beforeScriptReq.getLanguage(), is(SPEC_PASTICHE));
    assertThat(beforeScriptReq.getFile(), is(equalTo(beforeScanScript)));
    final ScriptRequest afterScriptReq = scanRequest.getAfterScript();
    assertThat(afterScriptReq, is(notNullValue()));
    assertThat(afterScriptReq.getLanguage(), is(SPEC_PASTICHE));
    assertThat(afterScriptReq.getFile(), is(equalTo(afterScanScript)));
    assertThat(scanRequest.isAlwaysRunAfterScript(), is(true));
    // Act again - convert the scan request back to a mapping bean
    scanRequestConverter.mergeIntoMappingBean(scanRequest, newMappingBean);
    // Assert again
    final IScriptFiles newScriptFiles = newMappingBean.getScriptFiles();
    assertThat(newScriptFiles, is(notNullValue()));
    assertThat(newScriptFiles.getBeforeScanScript(), is(equalTo(beforeScanScript)));
    assertThat(newScriptFiles.getAfterScanScript(), is(equalTo(afterScanScript)));
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) ScriptRequest(org.eclipse.scanning.api.script.ScriptRequest) IScriptFiles(uk.ac.diamond.daq.mapping.api.IScriptFiles) ScriptFiles(uk.ac.diamond.daq.mapping.impl.ScriptFiles) IScriptFiles(uk.ac.diamond.daq.mapping.api.IScriptFiles) Test(org.junit.Test)

Example 4 with ScriptFiles

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

the class ScanRequestConverter method mergeIntoMappingBean.

/**
 * Merge a scan request into an existing mapping bean so that it can be viewed
 * and possibly modified in the Mapping Experiment Setup view.
 * The reason for merging into an existing mapping bean is so that we don't remove
 * detectors and processing steps that we not selected when this scan was run -
 * when creating the scan request from the mapping bean a detector is only added if
 * {@link IScanModelWrapper#isIncludeInScan()} is true. The mapping bean reconstructed
 * from the scan request still needs to include this detector.
 *
 * @param scanRequest the {@link ScanRequest}
 * @param mappingBean the {@link IMappingExperimentBean} to merge into
 */
public void mergeIntoMappingBean(ScanRequest scanRequest, IMappingExperimentBean mappingBean) {
    final CompoundModel compoundModel = scanRequest.getCompoundModel();
    final Collection<ScanRegion> regions = compoundModel.getRegions();
    if (regions.size() != 1) {
        throw new IllegalArgumentException("The scan request must have exactly one region, has " + regions.size());
    }
    // Check that the scannable names in the scan region are the same as in the mapping stage
    final IMapPathModel mapPath = checkMapModelAndUpdateMappingStage(compoundModel);
    // recreate the outer scannable wrappers from the scan request
    mergeOuterScannables(compoundModel, mappingBean);
    // set the scan path to the last child model of the compound model
    final IScanDefinition scanDefinition = mappingBean.getScanDefinition();
    final IMappingScanRegion scanRegion = scanDefinition.getMappingScanRegion();
    scanRegion.setScanPath(mapPath);
    // convert the ROI to a mapping scan region shape
    final ScanRegion region = regions.iterator().next();
    final IMappingScanRegionShape shape = convertROItoRegionShape(region.getRoi());
    scanRegion.setRegion(shape);
    // recreate the beamline configuration from the scan start position
    if (scanRequest.getStartPosition() != null) {
        mappingBean.setBeamlineConfiguration(new LinkedHashMap<>(scanRequest.getStartPosition().getValues()));
    }
    // recreate the detector models and processing steps (included in the same map of detectors in the scan request)
    mergeDetectorAndProcessing(scanRequest, mappingBean);
    // recreate the scripts to run before and after the scan, if any
    if (scanRequest.getBeforeScript() != null || scanRequest.getAfterScript() != null) {
        ScriptFiles scriptFiles = new ScriptFiles();
        if (scanRequest.getBeforeScript() != null) {
            scriptFiles.setBeforeScanScript(scanRequest.getBeforeScript().getFile());
        }
        if (scanRequest.getAfterScript() != null) {
            scriptFiles.setAfterScanScript(scanRequest.getAfterScript().getFile());
        }
        scriptFiles.setAlwaysRunAfterScript(scanRequest.isAlwaysRunAfterScript());
        mappingBean.setScriptFiles(scriptFiles);
    }
    // recreate the sample metadata from the metadata in the scan request
    mergeSampleMetadata(scanRequest, mappingBean);
    mergeTemplateFiles(scanRequest, mappingBean);
    mergeProcessingRequest(scanRequest, mappingBean);
}
Also used : IMappingScanRegion(uk.ac.diamond.daq.mapping.api.IMappingScanRegion) IMappingScanRegionShape(uk.ac.diamond.daq.mapping.api.IMappingScanRegionShape) ScanRegion(org.eclipse.scanning.api.points.models.ScanRegion) IMappingScanRegion(uk.ac.diamond.daq.mapping.api.IMappingScanRegion) IMapPathModel(org.eclipse.scanning.api.points.models.IMapPathModel) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) ScriptFiles(uk.ac.diamond.daq.mapping.impl.ScriptFiles) IScriptFiles(uk.ac.diamond.daq.mapping.api.IScriptFiles) IScanDefinition(uk.ac.diamond.daq.mapping.api.IScanDefinition)

Aggregations

ScriptFiles (uk.ac.diamond.daq.mapping.impl.ScriptFiles)4 Test (org.junit.Test)3 IScanDefinition (uk.ac.diamond.daq.mapping.api.IScanDefinition)2 IScriptFiles (uk.ac.diamond.daq.mapping.api.IScriptFiles)2 HashMap (java.util.HashMap)1 ScanRequest (org.eclipse.scanning.api.event.scan.ScanRequest)1 CompoundModel (org.eclipse.scanning.api.points.models.CompoundModel)1 IMapPathModel (org.eclipse.scanning.api.points.models.IMapPathModel)1 ScanRegion (org.eclipse.scanning.api.points.models.ScanRegion)1 ScriptRequest (org.eclipse.scanning.api.script.ScriptRequest)1 MandelbrotModel (org.eclipse.scanning.example.detector.MandelbrotModel)1 ConfigWrapper (uk.ac.diamond.daq.mapping.api.ConfigWrapper)1 IMappingScanRegion (uk.ac.diamond.daq.mapping.api.IMappingScanRegion)1 IMappingScanRegionShape (uk.ac.diamond.daq.mapping.api.IMappingScanRegionShape)1 DetectorModelWrapper (uk.ac.diamond.daq.mapping.impl.DetectorModelWrapper)1 MappingExperimentBean (uk.ac.diamond.daq.mapping.impl.MappingExperimentBean)1 SimpleSampleMetadata (uk.ac.diamond.daq.mapping.impl.SimpleSampleMetadata)1