Search in sources :

Example 1 with ScanMetadata

use of org.eclipse.scanning.api.scan.models.ScanMetadata in project gda-core by openGDA.

the class XanesSubmitScanSection method submitScan.

@Override
protected void submitScan() {
    final IScriptService scriptService = getService(IScriptService.class);
    final ScanRequest scanRequest = getScanRequest(getMappingBean());
    final XanesEdgeParametersSection paramsSection = getMappingView().getSection(XanesEdgeParametersSection.class);
    final XanesEdgeParameters xanesEdgeParameters = paramsSection.getScanParameters();
    if (xanesEdgeParameters.isEnforcedShape()) {
        final CompoundModel newModel = new CompoundModel(scanRequest.getCompoundModel());
        final List<IScanPointGeneratorModel> models = newModel.getModels();
        final List<IScanPointGeneratorModel> enforcedShapes = new ArrayList<>(models.size());
        for (IScanPointGeneratorModel model : models) {
            enforcedShapes.add(enforce(model));
        }
        newModel.setModels(enforcedShapes);
        scanRequest.setCompoundModel(newModel);
    }
    xanesEdgeParameters.setVisitId(InterfaceProvider.getBatonStateProvider().getBatonHolder().getVisitID());
    // Add XANES parameters as metadata to the ScanRequest, so they appear in the Nexus file
    final ScanMetadata xanesMetadata = new ScanMetadata(MetadataType.ENTRY);
    xanesMetadata.addField("tracking_method", xanesEdgeParameters.getTrackingMethod());
    xanesMetadata.addField("visit_id", xanesEdgeParameters.getVisitId());
    final LinesToTrackEntry linesToTrackEntry = xanesEdgeParameters.getLinesToTrack();
    if (linesToTrackEntry == null || linesToTrackEntry.getLine() == null || linesToTrackEntry.getLine().isEmpty()) {
        // The entry for a blank "lines to track" contains an unmodifiable Collection, which causes problems in
        // marshalling, so make sure it is set null.
        xanesEdgeParameters.setLinesToTrack(null);
        xanesMetadata.addField("line", "None");
    } else {
        xanesMetadata.addField("line", linesToTrackEntry.getLine());
        xanesMetadata.addField("file_paths", new ArrayList<String>(linesToTrackEntry.getFilePaths()));
    }
    final List<ScanMetadata> scanMetadata = new ArrayList<>(scanRequest.getScanMetadata());
    scanMetadata.add(xanesMetadata);
    scanRequest.setScanMetadata(scanMetadata);
    try {
        final IMarshallerService marshallerService = getService(IMarshallerService.class);
        scriptService.setNamedValue(VAR_NAME_SCAN_REQUEST_JSON, marshallerService.marshal(scanRequest));
        scriptService.setNamedValue(VAR_NAME_XANES_EDGE_PARAMS_JSON, marshallerService.marshal(xanesEdgeParameters));
    } catch (Exception e) {
        logger.error("Scan submission failed", e);
        MessageDialog.openError(getShell(), "Error Submitting Scan", "The scan could not be submitted. See the error log for more details.");
        return;
    }
    Async.execute(() -> runScript(scriptFilePath, "XANES scanning script"));
}
Also used : ScanMetadata(org.eclipse.scanning.api.scan.models.ScanMetadata) IMarshallerService(org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService) ArrayList(java.util.ArrayList) ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) IScriptService(org.eclipse.scanning.api.script.IScriptService) XanesEdgeParameters(uk.ac.diamond.daq.mapping.api.XanesEdgeParameters) LinesToTrackEntry(uk.ac.diamond.daq.mapping.api.XanesEdgeParameters.LinesToTrackEntry) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)

Example 2 with ScanMetadata

use of org.eclipse.scanning.api.scan.models.ScanMetadata in project gda-core by openGDA.

the class ScanRequestConverter method mergeSampleMetadata.

private void mergeSampleMetadata(ScanRequest scanRequest, IMappingExperimentBean mappingBean) {
    List<ScanMetadata> scanMetadata = scanRequest.getScanMetadata();
    if (scanMetadata == null)
        return;
    Optional<ScanMetadata> sampleScanMetadataOpt = scanMetadata.stream().filter(metadata -> metadata.getType() == MetadataType.SAMPLE).findFirst();
    if (!sampleScanMetadataOpt.isPresent())
        return;
    ScanMetadata sampleScanMetadata = sampleScanMetadataOpt.get();
    SimpleSampleMetadata sampleMetadata = (SimpleSampleMetadata) mappingBean.getSampleMetadata();
    if (sampleMetadata == null) {
        sampleMetadata = new SimpleSampleMetadata();
        mappingBean.setSampleMetadata(sampleMetadata);
    }
    sampleMetadata.setSampleName((String) sampleScanMetadata.getFieldValue(FIELD_NAME_SAMPLE_NAME));
    sampleMetadata.setDescription((String) sampleScanMetadata.getFieldValue(FIELD_NAME_SAMPLE_DESCRIPTION));
}
Also used : Arrays(java.util.Arrays) IMappingExperimentBean(uk.ac.diamond.daq.mapping.api.IMappingExperimentBean) ScanRegion(org.eclipse.scanning.api.points.models.ScanRegion) LoggerFactory(org.slf4j.LoggerFactory) ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) TemplateFileWrapper(uk.ac.diamond.daq.mapping.api.TemplateFileWrapper) ScriptFiles(uk.ac.diamond.daq.mapping.impl.ScriptFiles) Map(java.util.Map) ScannableMotionUnits(gda.device.ScannableMotionUnits) Finder(gda.factory.Finder) PolygonMappingRegion(uk.ac.diamond.daq.mapping.region.PolygonMappingRegion) ConfigWrapper(uk.ac.diamond.daq.mapping.api.ConfigWrapper) Collection(java.util.Collection) Set(java.util.Set) ISampleMetadata(uk.ac.diamond.daq.mapping.api.ISampleMetadata) RectangularROI(org.eclipse.dawnsci.analysis.dataset.roi.RectangularROI) MapPosition(org.eclipse.scanning.api.points.MapPosition) Objects(java.util.Objects) List(java.util.List) IROI(org.eclipse.dawnsci.analysis.api.roi.IROI) IScanModelWrapper(uk.ac.diamond.daq.mapping.api.IScanModelWrapper) ProcessingRequest(org.eclipse.scanning.api.event.scan.ProcessingRequest) ScanMetadata(org.eclipse.scanning.api.scan.models.ScanMetadata) SimpleSampleMetadata(uk.ac.diamond.daq.mapping.impl.SimpleSampleMetadata) Optional(java.util.Optional) ScanBean(org.eclipse.scanning.api.event.scan.ScanBean) CircularMappingRegion(uk.ac.diamond.daq.mapping.region.CircularMappingRegion) IMappingScanRegion(uk.ac.diamond.daq.mapping.api.IMappingScanRegion) LinearROI(org.eclipse.dawnsci.analysis.dataset.roi.LinearROI) IScriptFiles(uk.ac.diamond.daq.mapping.api.IScriptFiles) HashMap(java.util.HashMap) RectangularMappingRegion(uk.ac.diamond.daq.mapping.region.RectangularMappingRegion) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Collectors.toCollection(java.util.stream.Collectors.toCollection) LineMappingRegion(uk.ac.diamond.daq.mapping.region.LineMappingRegion) IScanDefinition(uk.ac.diamond.daq.mapping.api.IScanDefinition) PointROI(org.eclipse.dawnsci.analysis.dataset.roi.PointROI) IGuiGeneratorService(org.eclipse.richbeans.api.generator.IGuiGeneratorService) CircularROI(org.eclipse.dawnsci.analysis.dataset.roi.CircularROI) DetectorModelWrapper(uk.ac.diamond.daq.mapping.impl.DetectorModelWrapper) PointMappingRegion(uk.ac.diamond.daq.mapping.region.PointMappingRegion) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) MetadataType(org.eclipse.scanning.api.scan.models.ScanMetadata.MetadataType) ScriptRequest(org.eclipse.scanning.api.script.ScriptRequest) File(java.io.File) IMapPathModel(org.eclipse.scanning.api.points.models.IMapPathModel) ScriptLanguage(org.eclipse.scanning.api.script.ScriptLanguage) PolygonalROI(org.eclipse.dawnsci.analysis.dataset.roi.PolygonalROI) Collections(java.util.Collections) MappingStageInfo(uk.ac.diamond.daq.mapping.impl.MappingStageInfo) ScanPathModelWrapper(uk.ac.diamond.daq.mapping.impl.ScanPathModelWrapper) IMappingScanRegionShape(uk.ac.diamond.daq.mapping.api.IMappingScanRegionShape) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel) ScanMetadata(org.eclipse.scanning.api.scan.models.ScanMetadata) SimpleSampleMetadata(uk.ac.diamond.daq.mapping.impl.SimpleSampleMetadata)

Example 3 with ScanMetadata

use of org.eclipse.scanning.api.scan.models.ScanMetadata in project gda-core by openGDA.

the class ScanManagementController method setSampleMetadata.

/**
 * This method clones a similar one present in {@link ScanRequestConverter#convertToScanRequest}.
 * The reason is to mitigate the replacement of the {@link MetadataController} properties so that
 * can be again written as {@link ScanMetadata}
 *
 * @param scanRequest
 * @param sampleName
 */
private void setSampleMetadata(ScanRequest scanRequest, String sampleName) {
    final ScanMetadata scanMetadata = new ScanMetadata(MetadataType.SAMPLE);
    scanMetadata.addField(ScanRequestConverter.FIELD_NAME_SAMPLE_NAME, sampleName);
    scanRequest.setScanMetadata(Arrays.asList(scanMetadata));
}
Also used : ScanMetadata(org.eclipse.scanning.api.scan.models.ScanMetadata)

Example 4 with ScanMetadata

use of org.eclipse.scanning.api.scan.models.ScanMetadata in project gda-core by openGDA.

the class ScanRequestConverterTest method testSampleMetadataSet.

@Test
public void testSampleMetadataSet() throws Exception {
    // Arrange
    final String sampleName = "testSample";
    final String sampleDescription = "This is a description of the test sample.";
    mappingBean.getSampleMetadata().setSampleName(sampleName);
    mappingBean.getSampleMetadata().setDescription(sampleDescription);
    // Act - convert mapping bean to scan request
    ScanRequest scanRequest = scanRequestConverter.convertToScanRequest(mappingBean);
    // Assert
    List<ScanMetadata> scanMetadataList = scanRequest.getScanMetadata();
    assertEquals(1, scanMetadataList.size());
    ScanMetadata scanMetadata = scanMetadataList.get(0);
    assertEquals(MetadataType.SAMPLE, scanMetadata.getType());
    assertEquals(sampleName, scanMetadata.getFieldValue("name"));
    assertEquals(sampleDescription, scanMetadata.getFieldValue("description"));
    // Act again - merge scan request back into new mapping bean
    scanRequestConverter.mergeIntoMappingBean(scanRequest, newMappingBean);
    // Assert again - check the new mapping bean is the same as the old one
    SimpleSampleMetadata sampleMetadata = newMappingBean.getSampleMetadata();
    assertEquals(sampleName, sampleMetadata.getSampleName());
    assertEquals(sampleDescription, sampleMetadata.getDescription());
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) ScanMetadata(org.eclipse.scanning.api.scan.models.ScanMetadata) SimpleSampleMetadata(uk.ac.diamond.daq.mapping.impl.SimpleSampleMetadata) Test(org.junit.Test)

Example 5 with ScanMetadata

use of org.eclipse.scanning.api.scan.models.ScanMetadata in project gda-core by openGDA.

the class ScanRequestConverter method setSampleMetadata.

private void setSampleMetadata(IMappingExperimentBean mappingBean, ScanRequest scanRequest) {
    final ISampleMetadata sampleMetadata = mappingBean.getSampleMetadata();
    String sampleName = sampleMetadata.getSampleName();
    if (sampleName == null || sampleName.trim().isEmpty()) {
        sampleName = "Unnamed Sample";
    }
    final ScanMetadata scanMetadata = new ScanMetadata(MetadataType.SAMPLE);
    scanMetadata.addField(FIELD_NAME_SAMPLE_NAME, sampleName);
    if (sampleMetadata instanceof SimpleSampleMetadata) {
        String description = ((SimpleSampleMetadata) sampleMetadata).getDescription();
        if (description == null || description.trim().isEmpty()) {
            description = "No description provided.";
        }
        scanMetadata.addField(FIELD_NAME_SAMPLE_DESCRIPTION, description);
    }
    scanRequest.setScanMetadata(Arrays.asList(scanMetadata));
}
Also used : ScanMetadata(org.eclipse.scanning.api.scan.models.ScanMetadata) ISampleMetadata(uk.ac.diamond.daq.mapping.api.ISampleMetadata) SimpleSampleMetadata(uk.ac.diamond.daq.mapping.impl.SimpleSampleMetadata)

Aggregations

ScanMetadata (org.eclipse.scanning.api.scan.models.ScanMetadata)6 ScanRequest (org.eclipse.scanning.api.event.scan.ScanRequest)4 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 CompoundModel (org.eclipse.scanning.api.points.models.CompoundModel)2 IScanPointGeneratorModel (org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)2 SimpleSampleMetadata (uk.ac.diamond.daq.mapping.impl.SimpleSampleMetadata)2 Detector (gda.device.Detector)1 Monitor (gda.device.Monitor)1 Scannable (gda.device.Scannable)1 ScannableMotionUnits (gda.device.ScannableMotionUnits)1 Finder (gda.factory.Finder)1 IMScanDimensionalElementEnum (gda.mscan.element.IMScanDimensionalElementEnum)1 Mutator (gda.mscan.element.Mutator)1 RegionShape (gda.mscan.element.RegionShape)1 AXIAL (gda.mscan.element.RegionShape.AXIAL)1