Search in sources :

Example 1 with IScanSlice

use of org.eclipse.scanning.api.scan.rank.IScanSlice 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 IScanSlice

use of org.eclipse.scanning.api.scan.rank.IScanSlice in project gda-core by openGDA.

the class AbstractScannableNexusDevice method getSliceForPosition.

/**
 * Return the slice to set. The same slice works for all
 * lazy writable datasets as they all have the same shape, i.e. the scan shape
 * @param pos
 * @return
 */
private SliceND getSliceForPosition(IPosition pos) {
    // just use the first dataset as they all have the same shape
    final ILazyWriteableDataset dataset = fieldDataNodes.values().iterator().next().getWriteableDataset();
    final IScanSlice scanSlice = IScanRankService.getScanRankService().createScanSlice(pos);
    return new SliceND(dataset.getShape(), dataset.getMaxShape(), scanSlice.getStart(), scanSlice.getStop(), scanSlice.getStep());
}
Also used : IScanSlice(org.eclipse.scanning.api.scan.rank.IScanSlice) ILazyWriteableDataset(org.eclipse.january.dataset.ILazyWriteableDataset) SliceND(org.eclipse.january.dataset.SliceND)

Example 3 with IScanSlice

use of org.eclipse.scanning.api.scan.rank.IScanSlice in project gda-core by openGDA.

the class AreaDetectorRunnableDevice method write.

@Override
public boolean write(IPosition pos) throws ScanningException {
    if (firstPointInScan) {
        firstFrame();
        firstPointInScan = false;
    }
    try {
        // Get the data from the detector array plugin
        final Object image = adDetector.getNdArray().getImageData(imageDimensions[0] * imageDimensions[1]);
        // Create a dataset from the data
        final Dataset dataset = DatasetFactory.createFromObject(image);
        // Write the image data
        IScanSlice scanSlice = IScanRankService.getScanRankService().createScanSlice(pos, imageDimensions);
        SliceND sliceND = new SliceND(data.getShape(), data.getMaxShape(), scanSlice.getStart(), scanSlice.getStop(), scanSlice.getStep());
        data.setSlice(null, dataset, sliceND);
        // Write the total data
        scanSlice = IScanRankService.getScanRankService().createScanSlice(pos);
        sliceND = new SliceND(total.getShape(), total.getMaxShape(), scanSlice.getStart(), scanSlice.getStop(), scanSlice.getStep());
        total.setSlice(null, DatasetFactory.createFromObject(dataset.sum()), sliceND);
    } catch (Exception e) {
        setDeviceState(DeviceState.FAULT);
        throw new ScanningException("Getting the data from the detector failed", e);
    }
    setDeviceState(DeviceState.ARMED);
    // saying I failed?
    return true;
}
Also used : 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) DeviceException(gda.device.DeviceException) NexusException(org.eclipse.dawnsci.nexus.NexusException) ScanningException(org.eclipse.scanning.api.scan.ScanningException)

Example 4 with IScanSlice

use of org.eclipse.scanning.api.scan.rank.IScanSlice in project gda-core by openGDA.

the class NexusSlitsWrapper method write.

private void write(DeviceValueMultiPosition demand, DeviceValueMultiPosition actual, IPosition loc) throws ScanningException, DatasetException {
    // there are no actual values.
    if (xLzValue == null || yLzValue == null) {
        return;
    }
    if (actual != null) {
        // write actual position
        final Dataset newXPositionData = DatasetFactory.createFromObject(actual.get(NXslit.NX_X_GAP));
        final Dataset newYPositionData = DatasetFactory.createFromObject(actual.get(NXslit.NX_Y_GAP));
        IScanSlice rslice = IScanRankService.getScanRankService().createScanSlice(loc);
        SliceND xSliceND = new SliceND(xLzValue.getShape(), xLzValue.getMaxShape(), rslice.getStart(), rslice.getStop(), rslice.getStep());
        SliceND ySliceND = new SliceND(yLzValue.getShape(), yLzValue.getMaxShape(), rslice.getStart(), rslice.getStop(), rslice.getStep());
        if (isWritingOn()) {
            xLzValue.setSlice(null, newXPositionData, xSliceND);
            yLzValue.setSlice(null, newYPositionData, ySliceND);
        }
    }
    if (xLzSet == null || yLzSet == null) {
        return;
    }
    if (demand != null) {
        int index = loc.getIndex(getName());
        if (index < 0) {
            throw new ScanningException("Incorrect data index for scan for value of '" + getName() + "'. The index is " + index);
        }
        final int[] startPos = new int[] { index };
        final int[] stopPos = new int[] { index + 1 };
        // write demand position
        final Dataset newDemandPositionData = DatasetFactory.createFromObject(demand);
        if (isWritingOn()) {
            xLzSet.setSlice(null, newDemandPositionData, startPos, stopPos, null);
            yLzSet.setSlice(null, newDemandPositionData, startPos, stopPos, null);
        }
    }
}
Also used : 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)

Aggregations

ILazyWriteableDataset (org.eclipse.january.dataset.ILazyWriteableDataset)4 SliceND (org.eclipse.january.dataset.SliceND)4 IScanSlice (org.eclipse.scanning.api.scan.rank.IScanSlice)4 Dataset (org.eclipse.january.dataset.Dataset)3 ScanningException (org.eclipse.scanning.api.scan.ScanningException)3 DeviceException (gda.device.DeviceException)1 CAException (gov.aps.jca.CAException)1 TimeoutException (gov.aps.jca.TimeoutException)1 NexusException (org.eclipse.dawnsci.nexus.NexusException)1 DatasetException (org.eclipse.january.DatasetException)1