Search in sources :

Example 1 with DatasetException

use of org.eclipse.january.DatasetException in project gda-core by openGDA.

the class ZebraRunnableDevice method write.

@Override
public boolean write(IPosition position) throws ScanningException {
    try {
        final double data1 = EPICS_CONTROLLER.cagetDouble(div1LastChannel);
        final double data2 = EPICS_CONTROLLER.cagetDouble(div2LastChannel);
        final double data3 = EPICS_CONTROLLER.cagetDouble(div3LastChannel);
        final double data4 = EPICS_CONTROLLER.cagetDouble(div4LastChannel);
        final IScanSlice scanSlice = IScanRankService.getScanRankService().createScanSlice(position);
        // We assume that all datasets have the same shape
        final SliceND slice = new SliceND(dataset1.getShape(), dataset1.getMaxShape(), scanSlice.getStart(), scanSlice.getStop(), scanSlice.getStep());
        final Dataset ds1 = DatasetFactory.createFromObject(data1);
        final Dataset ds2 = DatasetFactory.createFromObject(data2);
        final Dataset ds3 = DatasetFactory.createFromObject(data3);
        final Dataset ds4 = DatasetFactory.createFromObject(data4);
        dataset1.setSlice(null, ds1, slice);
        dataset2.setSlice(null, ds2, slice);
        dataset3.setSlice(null, ds3, slice);
        dataset4.setSlice(null, ds4, slice);
    } catch (TimeoutException | CAException | InterruptedException | DatasetException e) {
        final String message = "Error writing data";
        logger.error(message, e);
        throw new ScanningException(message, e);
    }
    setDeviceState(DeviceState.ARMED);
    return true;
}
Also used : CAException(gov.aps.jca.CAException) ILazyWriteableDataset(org.eclipse.january.dataset.ILazyWriteableDataset) Dataset(org.eclipse.january.dataset.Dataset) ScanningException(org.eclipse.scanning.api.scan.ScanningException) IScanSlice(org.eclipse.scanning.api.scan.rank.IScanSlice) SliceND(org.eclipse.january.dataset.SliceND) TimeoutException(gov.aps.jca.TimeoutException) DatasetException(org.eclipse.january.DatasetException)

Example 2 with DatasetException

use of org.eclipse.january.DatasetException in project gda-core by openGDA.

the class NexusSlitsWrapper method setPosition.

@Override
public DeviceValueMultiPosition setPosition(DeviceValueMultiPosition value, IPosition position) throws ScanningException {
    logger.debug("setPosition({}, {}) called on {}", value, position, getName());
    if (value != null) {
        logger.warn("non null setPosition() not expected on {}, ignoring...", getName());
    }
    if (position != null) {
        try {
            DeviceValueMultiPosition currentLocation = getPosition();
            write(value, currentLocation, position);
            return currentLocation;
        } catch (DatasetException e) {
            throw new ScanningException("Could not set position of scannable: " + getName(), e);
        }
    }
    return null;
}
Also used : DeviceValueMultiPosition(org.eclipse.scanning.api.event.scan.DeviceValueMultiPosition) ScanningException(org.eclipse.scanning.api.scan.ScanningException) DatasetException(org.eclipse.january.DatasetException)

Example 3 with DatasetException

use of org.eclipse.january.DatasetException in project gda-core by openGDA.

the class MeanProc method processFrame.

@Override
public void processFrame(Dataset data, SliceFromSeriesMetadata metaSlice) {
    logger.debug("Start of processFrame");
    Object mean = data.mean();
    Dataset s = DatasetFactory.createFromObject(mean);
    SliceND sl = new SliceND(meanDataset.getShape(), meanDataset.getMaxShape(), metaSlice.getSliceFromInput());
    try {
        meanDataset.setSlice(null, s, sl);
    } catch (DatasetException e) {
        logger.error("Error setting slice", e);
    }
    logger.debug("End of processFrame");
}
Also used : Dataset(org.eclipse.january.dataset.Dataset) LazyWriteableDataset(org.eclipse.january.dataset.LazyWriteableDataset) SliceND(org.eclipse.january.dataset.SliceND) DatasetException(org.eclipse.january.DatasetException)

Example 4 with DatasetException

use of org.eclipse.january.DatasetException in project gda-core by openGDA.

the class SumProc method processFrame.

@Override
public void processFrame(Dataset data, SliceFromSeriesMetadata metaSlice) {
    logger.debug("Start of processFrame");
    Object sum = data.sum();
    Dataset s = DatasetFactory.createFromObject(sum);
    SliceND sl = new SliceND(sumDataset.getShape(), sumDataset.getMaxShape(), metaSlice.getSliceFromInput());
    try {
        sumDataset.setSlice(null, s, sl);
    } catch (DatasetException e) {
        logger.error("Error setting slice", e);
    }
    logger.debug("End of processFrame");
}
Also used : Dataset(org.eclipse.january.dataset.Dataset) LazyWriteableDataset(org.eclipse.january.dataset.LazyWriteableDataset) SliceND(org.eclipse.january.dataset.SliceND) DatasetException(org.eclipse.january.DatasetException)

Example 5 with DatasetException

use of org.eclipse.january.DatasetException in project gda-core by openGDA.

the class SwmrMalcolmProcessingReader method runOptimisedLoop.

/**
 * Loop to run if there is up to a max of two processors, typically one ROI and one plot.
 * This only updates the plotting periodically rather than every frame which allows for
 * the lazy dataset to be actually read in the ROI processor (for the region only) rather
 * than reading the full frame here every time.
 */
private void runOptimisedLoop(SimpleDynamicSliceViewIterator it) {
    Optional<RoiProc> roi = procs.stream().filter(RoiProc.class::isInstance).map(RoiProc.class::cast).findFirst();
    Optional<PlotProc> plot = procs.stream().filter(PlotProc.class::isInstance).map(PlotProc.class::cast).findFirst();
    // Last time the plot was updated
    long plotLastUpdate = System.currentTimeMillis();
    // Time last of last frame from iterator
    long iterTime;
    while (it.hasNext()) {
        ILazyDataset next = it.next();
        iterTime = System.currentTimeMillis();
        SliceFromSeriesMetadata md = next.getFirstMetadata(SliceFromSeriesMetadata.class);
        logger.debug("Ready for slice {}", Slice.createString(md.getSliceFromInput()));
        next.clearMetadata(null);
        // We read the full dataset and send to plot and roi only once per second
        if (plot.isPresent() && (iterTime - plotLastUpdate > 1000)) {
            try {
                Dataset dataset = DatasetUtils.convertToDataset(next.getSlice());
                plot.get().processFrame(dataset, md);
                plotLastUpdate = iterTime;
                roi.ifPresent(r -> r.processFrame(dataset, md));
                sendUpdateMessage();
            } catch (DatasetException e) {
                logger.error("Error obtaining slice, meta: {}", md, e);
                return;
            }
        } else if (roi.isPresent()) {
            // Otherwise we pass the LazyDataset to the ROI without reading the full frame
            long roiTStart = System.currentTimeMillis();
            roi.get().processFrame(next, md);
            logger.debug("Roi proc took {} millis", System.currentTimeMillis() - roiTStart);
        }
        logger.debug("Complete for slice {}, total time {} millis", Slice.createString(md.getSliceFromInput()), System.currentTimeMillis() - iterTime);
    }
}
Also used : ILazyDataset(org.eclipse.january.dataset.ILazyDataset) SliceFromSeriesMetadata(org.eclipse.dawnsci.analysis.dataset.slicer.SliceFromSeriesMetadata) ILazyDataset(org.eclipse.january.dataset.ILazyDataset) IDynamicDataset(org.eclipse.january.dataset.IDynamicDataset) Dataset(org.eclipse.january.dataset.Dataset) DatasetException(org.eclipse.january.DatasetException)

Aggregations

DatasetException (org.eclipse.january.DatasetException)186 IDataset (org.eclipse.january.dataset.IDataset)126 Dataset (org.eclipse.january.dataset.Dataset)120 ILazyDataset (org.eclipse.january.dataset.ILazyDataset)103 OperationException (org.eclipse.dawnsci.analysis.api.processing.OperationException)75 OperationData (org.eclipse.dawnsci.analysis.api.processing.OperationData)54 DoubleDataset (org.eclipse.january.dataset.DoubleDataset)48 AxesMetadata (org.eclipse.january.metadata.AxesMetadata)45 SliceND (org.eclipse.january.dataset.SliceND)32 SliceFromSeriesMetadata (org.eclipse.dawnsci.analysis.dataset.slicer.SliceFromSeriesMetadata)26 IntegerDataset (org.eclipse.january.dataset.IntegerDataset)26 MetadataException (org.eclipse.january.MetadataException)20 ArrayList (java.util.ArrayList)19 DataNode (org.eclipse.dawnsci.analysis.api.tree.DataNode)19 NexusException (org.eclipse.dawnsci.nexus.NexusException)16 Slice (org.eclipse.january.dataset.Slice)16 IDiffractionMetadata (org.eclipse.dawnsci.analysis.api.metadata.IDiffractionMetadata)15 ILazyWriteableDataset (org.eclipse.january.dataset.ILazyWriteableDataset)15 Test (org.junit.Test)15 GroupNode (org.eclipse.dawnsci.analysis.api.tree.GroupNode)12