207 lines
6.3 KiB
Java
207 lines
6.3 KiB
Java
//package ch.psi.pshell.epics;
|
|
import ch.psi.pshell.epics.*;
|
|
import ch.psi.pshell.device.AccessType;
|
|
import ch.psi.pshell.device.ArrayCalibration;
|
|
import ch.psi.pshell.device.CameraImageDescriptor;
|
|
import ch.psi.pshell.device.MatrixCalibration;
|
|
import ch.psi.pshell.device.Device;
|
|
import ch.psi.pshell.device.DeviceAdapter;
|
|
import ch.psi.pshell.device.Readable.ReadableCalibratedArray;
|
|
import ch.psi.utils.Arr;
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.logging.Level;
|
|
|
|
/**
|
|
* Implementation of Scienta spectrometer analyser.
|
|
*/
|
|
public class Scienta extends ch.psi.pshell.epics.Scienta {
|
|
final String channelCtrl;
|
|
final ChannelDoubleArray spectrum, spectrumX;
|
|
|
|
public Scienta(final String name, final String channelPrefix) {
|
|
this(name, channelPrefix + ":cam1", channelPrefix + ":image1");
|
|
}
|
|
|
|
public Scienta(String name, String channelCtrl, String channelData) {
|
|
super(name, channelCtrl, channelData);
|
|
this.channelCtrl=channelCtrl;
|
|
|
|
//Device[] children = getChildren();
|
|
//Arr.remove(children, getSpectrum());
|
|
//setChildren(children);
|
|
super.getSpectrum().close();
|
|
|
|
spectrum = new ScientaSpectrum();
|
|
getNumChannels().removeAllListeners();
|
|
/*
|
|
getNumChannels().addListener(new DeviceAdapter() {
|
|
@Override
|
|
public void onValueChanged(Device device, Object value, Object former) {
|
|
try {
|
|
if (value != null) {
|
|
spectrum.setSize((Integer) value);
|
|
}
|
|
} catch (IOException ex) {
|
|
getLogger().log(Level.WARNING, null, ex);
|
|
}
|
|
}
|
|
});
|
|
*/
|
|
addChild(spectrum);
|
|
|
|
spectrumX = new ChannelDoubleArray("Spectrum X", "X03DA-SCIENTA:cam1:CHANNEL_SCALE_RBV");
|
|
addChild(spectrumX);
|
|
}
|
|
|
|
|
|
@Override
|
|
protected void doInitialize() throws IOException, InterruptedException {
|
|
super.doInitialize();
|
|
spectrum.setSize(KEEP_TO_VALID);
|
|
spectrumX.setSize(KEEP_TO_VALID);
|
|
}
|
|
|
|
|
|
@Override
|
|
protected void doSetSimulated() {
|
|
super.doSetSimulated();
|
|
setCache(spectrum, new double[100]);
|
|
}
|
|
|
|
@Override
|
|
protected void doUpdate() throws IOException, InterruptedException {
|
|
super.doUpdate();
|
|
}
|
|
|
|
@Override
|
|
protected void doSetMonitored(boolean value) {
|
|
super.doSetMonitored(value);
|
|
}
|
|
|
|
@Override
|
|
protected CameraImageDescriptor doReadImageDescriptor() throws IOException, InterruptedException {
|
|
CameraImageDescriptor ret = super.doReadImageDescriptor();
|
|
return ret;
|
|
}
|
|
|
|
//Progress
|
|
//Disconnected operations
|
|
@Override
|
|
public double getProgress() {
|
|
return super.getProgress();
|
|
}
|
|
|
|
|
|
public class ScientaSpectrum extends ChannelDoubleArray implements ReadableCalibratedArray<double[]> {
|
|
|
|
ScientaSpectrum() {
|
|
super(Scienta.this.getName() + " spectrum", channelCtrl + ":INT_SPECTRUM", 8, 200, false);
|
|
setAccessType(AccessType.Read);
|
|
}
|
|
|
|
/*
|
|
@Override
|
|
protected double[] doRead() throws IOException, InterruptedException {
|
|
getNumChannels().getValue();
|
|
return super.doRead();
|
|
}
|
|
*/
|
|
|
|
@Override
|
|
public ArrayCalibration getCalibration() {
|
|
double scale = 1.0;
|
|
double offset = 0.0;
|
|
try {
|
|
List<Double> channelRange = getChannelRange();
|
|
Double cb = channelRange.get(0);
|
|
Double ce = channelRange.get(1);
|
|
scale = (ce - cb) / Math.max(getNumChannels().getValue()- 1, 1);
|
|
offset = cb;
|
|
} catch (Exception ex) {
|
|
}
|
|
return new ArrayCalibration(scale, offset);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public double[] getSpectrumX() throws IOException, InterruptedException {
|
|
/*
|
|
List<Double> range = getChannelRange();
|
|
Double begin = range.get(0);
|
|
Double end = range.get(1);
|
|
double[] spectrum = getSpectrum().take();
|
|
if ((begin == null) || (end == null) || (spectrum == null)) {
|
|
return null;
|
|
}
|
|
int spectrumSize = spectrum.length;
|
|
double step = (end - begin) / (spectrumSize - 1);
|
|
double[] x = new double[spectrumSize];
|
|
for (int i = 0; i < spectrumSize; i++) {
|
|
x[i] = begin + step * i;
|
|
}
|
|
return x;
|
|
*/
|
|
return spectrumX.read();
|
|
}
|
|
|
|
@Override
|
|
public List<Double> getChannelRange() throws IOException, InterruptedException {
|
|
ArrayList<Double> ret = new ArrayList<>();
|
|
//ret.add(getChannelBegin().getValue());
|
|
//ret.add(getChannelEnd().getValue());
|
|
switch (getAcquisitionMode()) {
|
|
case Swept:
|
|
ret.add(getLowEnergy().getValue());
|
|
ret.add(getHighEnergy().getValue());
|
|
break;
|
|
case Fixed:
|
|
default:
|
|
double eCenter = getCenterEnergy().getValue();
|
|
int ePass = getPassEnergy();
|
|
double xe = 0.04464;
|
|
double xn = 0.04464;
|
|
ret.add(eCenter - xe * ePass);
|
|
ret.add(eCenter + xn * ePass);
|
|
break;
|
|
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
@Override
|
|
public List<Double> getSliceRange() throws IOException, InterruptedException {
|
|
ArrayList<Double> ret = new ArrayList<>();
|
|
//ret.add(sliceBegin.getValue());
|
|
//ret.add(sliceEnd.getValue());
|
|
try{
|
|
switch (getLensMode()) {
|
|
case Angular45:
|
|
ret.add(-28.148);
|
|
ret.add(27.649);
|
|
break;
|
|
case Angular60:
|
|
ret.add(-34.736);
|
|
ret.add(34.119);
|
|
break;
|
|
case Transmission:
|
|
default:
|
|
ret.add(-2.332);
|
|
ret.add(2.291);
|
|
break;
|
|
|
|
}
|
|
} catch (Exception ex){
|
|
ret.add(Double.NaN);
|
|
ret.add(Double.NaN);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
@Override
|
|
public ChannelDoubleArray getSpectrum() {
|
|
return spectrum;
|
|
}
|
|
}
|