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;
}
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());
}
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;
}
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);
}
}
}
Aggregations