ScreenPanel
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#Tue Jun 13 14:49:25 CEST 2017
|
||||
maxValue=360.0
|
||||
#Wed Jun 14 11:54:37 CEST 2017
|
||||
maxValue=180.0
|
||||
minValue=-180.0
|
||||
offset=0.0
|
||||
precision=3
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
#Wed Jun 14 08:15:46 CEST 2017
|
||||
#Mon Jun 19 11:07:24 CEST 2017
|
||||
colormap=Flame
|
||||
colormapAutomatic=true
|
||||
colormapMax=100.0
|
||||
colormapMax=24.0
|
||||
colormapMin=0.0
|
||||
flipHorizontally=false
|
||||
flipVertically=false
|
||||
grayscale=false
|
||||
imageHeight=1628
|
||||
imageWidth=1280
|
||||
imageHeight=2160
|
||||
imageWidth=2560
|
||||
invert=false
|
||||
regionStartX=865
|
||||
regionStartY=267
|
||||
regionStartX=1
|
||||
regionStartY=1
|
||||
rescaleFactor=1.0
|
||||
rescaleOffset=0.0
|
||||
roiHeight=-1
|
||||
@@ -21,9 +21,9 @@ rotation=0.0
|
||||
rotationCrop=false
|
||||
scale=1.0
|
||||
serverURL=localhost\:10000
|
||||
spatialCalOffsetX=-1057.4895329398094
|
||||
spatialCalOffsetY=-1420.5549062527236
|
||||
spatialCalScaleX=-8.510638153514359
|
||||
spatialCalScaleY=-8.235817137431614
|
||||
spatialCalOffsetX=-307.51337366396956
|
||||
spatialCalOffsetY=-328.50773007539067
|
||||
spatialCalScaleX=-29.549881440739966
|
||||
spatialCalScaleY=-26.711185419891642
|
||||
spatialCalUnits=mm
|
||||
transpose=false
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#Tue Jun 13 14:21:33 CEST 2017
|
||||
maxValue=360.0
|
||||
minValue=0.0
|
||||
#Fri Jun 16 13:36:38 CEST 2017
|
||||
maxValue=180.0
|
||||
minValue=-180.0
|
||||
offset=0.0
|
||||
precision=3
|
||||
resolution=1.0
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#Thu May 11 08:37:38 CEST 2017
|
||||
#Wed Jun 14 11:27:41 CEST 2017
|
||||
alignmentRetries=20
|
||||
disableCompression=false
|
||||
disableCompression=true
|
||||
dropIncomplete=false
|
||||
keepListeningOnStop=false
|
||||
parallelHandlerProcessing=true
|
||||
|
||||
9
devices/rot 1.properties
Normal file
9
devices/rot 1.properties
Normal file
@@ -0,0 +1,9 @@
|
||||
#Fri Jun 16 14:17:16 CEST 2017
|
||||
maxValue=NaN
|
||||
minValue=NaN
|
||||
offset=0.0
|
||||
precision=-1
|
||||
resolution=NaN
|
||||
rotation=false
|
||||
scale=1.0
|
||||
unit=null
|
||||
@@ -76,7 +76,7 @@
|
||||
<Properties>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
|
||||
<TitledBorder title="Parameters (RF phase)"/>
|
||||
<TitledBorder title="Parameters (beam phase)"/>
|
||||
</Border>
|
||||
</Property>
|
||||
</Properties>
|
||||
|
||||
@@ -97,7 +97,7 @@ public class SchottkyScan extends Panel {
|
||||
}
|
||||
});
|
||||
|
||||
panelPars.setBorder(javax.swing.BorderFactory.createTitledBorder("Parameters (RF phase)"));
|
||||
panelPars.setBorder(javax.swing.BorderFactory.createTitledBorder("Parameters (beam phase)"));
|
||||
|
||||
spinnerStep.setModel(new javax.swing.SpinnerNumberModel(5.0d, 1.0d, 90.0d, 1.0d));
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import ch.psi.pshell.device.Device;
|
||||
import ch.psi.pshell.epics.ChannelInteger;
|
||||
import ch.psi.pshell.epics.DiscretePositioner;
|
||||
import ch.psi.pshell.epics.Epics;
|
||||
import ch.psi.pshell.imaging.Calibration;
|
||||
import ch.psi.pshell.imaging.Colormap;
|
||||
import ch.psi.pshell.imaging.ColormapSource;
|
||||
import ch.psi.pshell.imaging.ColormapSource.ColormapSourceConfig;
|
||||
@@ -63,6 +64,7 @@ import java.awt.event.WindowEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.FileInputStream;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.ServerSocket;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@@ -135,18 +137,18 @@ public class ScreenPanel extends Panel {
|
||||
ImageData(){
|
||||
if (camera instanceof Camtool) {
|
||||
String prefix = goodRegion ? "gr_" : "";
|
||||
xMean = getCamtoolDouble(prefix + "x_fit_mean");
|
||||
yMean = getCamtoolDouble(prefix + "y_fit_mean");
|
||||
xSigma = getCamtoolDouble(prefix + "x_fit_standard_deviation");
|
||||
ySigma = getCamtoolDouble(prefix + "y_fit_standard_deviation");
|
||||
x_fit_mean = getCamtoolDouble(prefix + "x_fit_mean");
|
||||
y_fit_mean = getCamtoolDouble(prefix + "y_fit_mean");
|
||||
x_fit_standard_deviation = getCamtoolDouble(prefix + "x_fit_standard_deviation");
|
||||
y_fit_standard_deviation = getCamtoolDouble(prefix + "y_fit_standard_deviation");
|
||||
x_fit_gauss_function = getCamtoolDoubleArray(prefix +"x_fit_gauss_function");
|
||||
y_fit_gauss_function = getCamtoolDoubleArray(prefix +"y_fit_gauss_function");
|
||||
x_profile = getCamtoolDoubleArray("x_profile");
|
||||
y_profile = getCamtoolDoubleArray("y_profile");
|
||||
xCom = getCamtoolDouble("x_center_of_mass");
|
||||
yCom = getCamtoolDouble("y_center_of_mass");
|
||||
xRms = getCamtoolDouble("x_rms");
|
||||
yRms = getCamtoolDouble("y_rms");
|
||||
x_center_of_mass = getCamtoolDouble("x_center_of_mass");
|
||||
y_center_of_mass = getCamtoolDouble("y_center_of_mass");
|
||||
x_rms = getCamtoolDouble("x_rms");
|
||||
y_rms = getCamtoolDouble("y_rms");
|
||||
if (goodRegion){
|
||||
double[] gX2 = new double[x_profile.length];
|
||||
Arrays.fill(gX2, Double.NaN);
|
||||
@@ -167,18 +169,18 @@ public class ScreenPanel extends Panel {
|
||||
}
|
||||
}
|
||||
}
|
||||
Double xMean;
|
||||
Double yMean;
|
||||
Double xCom;
|
||||
Double xRms;
|
||||
Double xSigma;
|
||||
Double ySigma;
|
||||
Double yCom;
|
||||
Double yRms;
|
||||
double[] x_profile;
|
||||
double[] x_fit_gauss_function;
|
||||
double[] y_profile;
|
||||
double[] y_fit_gauss_function;
|
||||
public Double x_fit_mean;
|
||||
public Double y_fit_mean;
|
||||
public Double x_center_of_mass;
|
||||
public Double x_rms;
|
||||
public Double x_fit_standard_deviation;
|
||||
public Double y_fit_standard_deviation;
|
||||
public Double y_center_of_mass;
|
||||
public Double y_rms;
|
||||
public double[] x_profile;
|
||||
public double[] x_fit_gauss_function;
|
||||
public double[] y_profile;
|
||||
public double[] y_fit_gauss_function;
|
||||
}
|
||||
|
||||
class Frame extends ImageData{
|
||||
@@ -993,6 +995,34 @@ public class ScreenPanel extends Panel {
|
||||
|
||||
Pen penFit = new Pen(new Color(192, 105, 0), 1);
|
||||
Pen penCross = new Pen(new Color(192, 105, 0), 1);
|
||||
|
||||
|
||||
ImageData getCurrentImageData(){
|
||||
return getImageData(null);
|
||||
}
|
||||
|
||||
ImageData getImageData(Data data){
|
||||
ImageData id = null;
|
||||
if (renderer.isPaused()) {
|
||||
synchronized (imageBuffer) {
|
||||
if (data == null){
|
||||
int index = ((int) pauseSelection.getValue()) - 1;
|
||||
if (index < imageBuffer.size()) {
|
||||
data = imageBuffer.get(index).data;
|
||||
}
|
||||
}
|
||||
for (Frame f : imageBuffer) {
|
||||
if (f.data == data) {
|
||||
id = f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
id = new ImageData();
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
Overlay[][] getFitOverlays(Data data) {
|
||||
Overlays.Polyline hgaussian = null;
|
||||
@@ -1009,26 +1039,15 @@ public class ScreenPanel extends Panel {
|
||||
int profileSize = renderer.getProfileSize();
|
||||
if ((useCamtoolStats) && (camera instanceof Camtool)) {
|
||||
try {
|
||||
ImageData id = null;
|
||||
if (renderer.isPaused()) {
|
||||
synchronized (imageBuffer) {
|
||||
for (Frame f : imageBuffer) {
|
||||
if (f.data == data) {
|
||||
id = f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
id = new ImageData();
|
||||
}
|
||||
|
||||
ImageData id = getImageData(data);
|
||||
if (id==null){
|
||||
return null;
|
||||
}
|
||||
xMean = id.xMean; xSigma = id.xSigma;yMean = id.yMean;ySigma = id.ySigma;
|
||||
xMean = id.x_fit_mean; xSigma = id.x_fit_standard_deviation;yMean = id.y_fit_mean;ySigma = id.y_fit_standard_deviation;
|
||||
gX = id.x_fit_gauss_function; gY = id.y_fit_gauss_function;
|
||||
pX = id.x_profile; pY = id.y_profile;
|
||||
xCom = id.xCom; xRms = id.xRms; yCom = id.yCom; yRms = id.yRms;
|
||||
xCom = id.x_center_of_mass; xRms = id.x_rms; yCom = id.y_center_of_mass; yRms = id.y_rms;
|
||||
|
||||
profileSize /= 4;
|
||||
if (pX != null) {
|
||||
@@ -1539,18 +1558,49 @@ public class ScreenPanel extends Panel {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void writeFrameMetadata(String path, ImageData id) throws Exception{
|
||||
getContext().getDataManager().setAttribute("/", "Camera", String.valueOf(cameraName));
|
||||
getContext().getDataManager().setAttribute("/", "Screen", String.valueOf(valueScreen.getLabel().getText()));
|
||||
getContext().getDataManager().setAttribute("/", "Filter", String.valueOf(valueFilter.getLabel().getText()));
|
||||
Calibration cal = renderer.getCalibration();
|
||||
getContext().getDataManager().setAttribute("/", "Calibration", cal == null ? new double[]{1,1,0,0} :
|
||||
new double[]{cal.getScaleX(), cal.getScaleY(), cal.getOffsetX(), cal.getOffsetY()});
|
||||
if (camera instanceof Camtool){
|
||||
try{
|
||||
getContext().getDataManager().setAttribute("/", "ROI", ((Camtool) camera).getRoi());
|
||||
} catch (Exception ex){
|
||||
getContext().getDataManager().setAttribute("/", "ROI", new int[]{0,0,-1,-1});
|
||||
}
|
||||
if (id!=null){
|
||||
for (Field f:ImageData.class.getFields()){
|
||||
Object value = f.get(id);
|
||||
getContext().getDataManager().setAttribute(path, f.getName(), (value == null) ? Double.NaN : value);
|
||||
}
|
||||
}
|
||||
for (String name : new String[]{"x_axis", "y_axis", "gr_x_axis", "gr_y_axis"}){
|
||||
double[] val = getCamtoolDoubleArray(name);
|
||||
getContext().getDataManager().setAttribute("/", "GoodRegion", goodRegion);
|
||||
if (val!=null){
|
||||
getContext().getDataManager().setAttribute("/", name, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void saveSnapshot() throws Exception {
|
||||
String snapshotFile = getContext().getSetup().expandPath("{images}/{date}_{time}_snapshot.png");
|
||||
renderer.saveSnapshot(snapshotFile, "png", true);
|
||||
getContext().setExecutionPars("snapshot");
|
||||
String path = "/data";
|
||||
getContext().getDataManager().setDataset(path, renderer.getData().getMatrix(), renderer.getData().isUnsigned());
|
||||
getContext().getDataManager().setAttribute(path, "Camera", String.valueOf(cameraName));
|
||||
getContext().getDataManager().setAttribute(path, "Screen", String.valueOf(valueScreen.getLabel().getText()));
|
||||
getContext().getDataManager().setAttribute(path, "Filter", String.valueOf(valueFilter.getLabel().getText()));
|
||||
getContext().getDataManager().closeOutput();
|
||||
|
||||
String snapshotFile = null;
|
||||
synchronized (imageBuffer) {
|
||||
getContext().getDataManager().setDataset(path, renderer.getData().getMatrix(), renderer.getData().isUnsigned());
|
||||
writeFrameMetadata(path, getCurrentImageData());
|
||||
getContext().getDataManager().closeOutput();
|
||||
//Enforce the same timestamp to data & image files.
|
||||
snapshotFile = getContext().getSetup().expandPath("{images}/{date}_{time}_snapshot.png", getContext().getExecutionPars().getStart());
|
||||
renderer.saveSnapshot(snapshotFile, "png", true);
|
||||
}
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
GridBagLayout layout = new GridBagLayout();
|
||||
layout.columnWidths = new int[]{0, 180}; //Minimum width
|
||||
@@ -1601,21 +1651,14 @@ public class ScreenPanel extends Panel {
|
||||
Frame frame = imageBuffer.get(i);
|
||||
String path = "/data_" + i;
|
||||
getContext().getDataManager().setDataset(path, frame.data.getMatrix(), frame.data.isUnsigned());
|
||||
getContext().getDataManager().setAttribute(path, "x_mean", (frame.xMean == null) ? Double.NaN : frame.xMean);
|
||||
getContext().getDataManager().setAttribute(path, "x_sigma", (frame.xSigma == null) ? Double.NaN : frame.xSigma);
|
||||
getContext().getDataManager().setAttribute(path, "y_mean", (frame.yMean == null) ? Double.NaN : frame.yMean);
|
||||
getContext().getDataManager().setAttribute(path, "y_sigma", (frame.ySigma == null) ? Double.NaN : frame.ySigma);
|
||||
x.add(frame.xMean);
|
||||
y.add(frame.yMean);
|
||||
writeFrameMetadata(path, getImageData(frame.data));
|
||||
x.add(frame.x_fit_mean);
|
||||
y.add(frame.y_fit_mean);
|
||||
}
|
||||
}
|
||||
DescStatsDouble xs = new DescStatsDouble(x.toArray(new Double[0]), -1);
|
||||
DescStatsDouble ys = new DescStatsDouble(y.toArray(new Double[0]), -1);
|
||||
String path = "/";
|
||||
getContext().getDataManager().setAttribute(path, "x_mean", xs.getMean());
|
||||
getContext().getDataManager().setAttribute(path, "x_sigma", xs.getStdev());
|
||||
getContext().getDataManager().setAttribute(path, "y_mean", ys.getMean());
|
||||
getContext().getDataManager().setAttribute(path, "y_sigma", ys.getStdev());
|
||||
|
||||
getContext().getDataManager().closeOutput();
|
||||
SwingUtils.showMessage(getTopLevel(), "Success", "Generated data file:\n" + getContext().getExecutionPars().getPath(), 5000);
|
||||
}
|
||||
|
||||
139
script/Diagnostics/BlmGainScan_1406.py
Normal file
139
script/Diagnostics/BlmGainScan_1406.py
Normal file
@@ -0,0 +1,139 @@
|
||||
#import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
|
||||
import ch.psi.pshell.bs.Scalar as Scalar
|
||||
import ch.psi.pshell.bs.Waveform as Waveform
|
||||
import ch.psi.pshell.epics.DiscretePositioner as DiscretePositioner
|
||||
import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
|
||||
|
||||
|
||||
#Arguments
|
||||
SAMPLES = 100
|
||||
GAINS = ["SINDI02-DBLM084:M06-1-CH03-V-MM","SINDI02-DBLM084:M06-2-CH03-V-MM","S10DI01-DBLM113:M06-1-CH03-V-MM"] #, "SINDI02-DBLM084:M06-0-CH03-V-MM"]
|
||||
BLMS = ["SINDI02-DBLM025", "SINDI02-DBLM085", "S10DI01-DBLM045"]
|
||||
LLM = ["SINDI01-DLLM105"]
|
||||
BPMS = ["SINDI01-DBPM060:Q1", "SINDI02-DBPM010:Q1"]
|
||||
ATTENUATORS = ["SINDI02-DBLM084:M06-1-ATT2-VAL", "SINDI02-DBLM084:M06-2-ATT2-VAL", "S10DI01-DBLM113:M06-1-ATT2-VAL"] #,"SINDI02-DBLM084:M06-0-ATT2-VAL"]
|
||||
ATT_SP = 15.0 #3.0,6.0,9.0,12.0,15.0
|
||||
RANGE = [0.5, 1.1]
|
||||
STEP_SIZE = 0.05
|
||||
SETTLING_TIME = 3
|
||||
SIMULATION = False
|
||||
do_elog = True
|
||||
|
||||
|
||||
gain_positioners = []
|
||||
for i in range(len(GAINS)):
|
||||
gain_positioners.append( DummyPositioner("gain " + str(i+1)) if SIMULATION else Channel(GAINS[i], alias = "gain " + str(i+1)))
|
||||
|
||||
attenuators = []
|
||||
for i in range(len(ATTENUATORS)):
|
||||
att = ChannelDouble("Att"+str(i+1), ATTENUATORS[i])
|
||||
att.initialize()
|
||||
attenuators.append(att)
|
||||
|
||||
#Channel-based
|
||||
#blm1 = ChannelDouble("blm1", "SINDI02-DBLM025:B1_LOSS"); blm1.setMonitored(True); blm1.initialize()
|
||||
#blm2 = ChannelDouble("blm2", "SINDI02-DBLM085:B1_LOSS"); blm2.setMonitored(True); blm2.initialize()
|
||||
|
||||
#Stream creation
|
||||
for att in attenuators:
|
||||
att.write(ATT_SP)
|
||||
|
||||
sensors = []
|
||||
line_plots = []
|
||||
st = Stream("pulse_id", dispatcher)
|
||||
st.setFilter("SIN-CVME-TIFGUN-EVR0:BEAMOK == 1")
|
||||
for i in range(len(BLMS)):
|
||||
blm = Scalar("blm" + str(i+1), st, BLMS[i] + ":B1_LOSS", 1, 0)
|
||||
av = create_averager(blm, SAMPLES, interval = -1)
|
||||
av.setMonitored(i>0)
|
||||
sensors.append(av)
|
||||
sensors.append(av.stdev)
|
||||
sensors.append(av.samples)
|
||||
line_plots.append(av.samples)
|
||||
blmw = Waveform("blmw" + str(i+1), st, BLMS[i] + ":LOSS_SIGNAL_RAW", 1, 0)
|
||||
sensors.append(blmw)
|
||||
|
||||
#for i in range(len(LLMS)):
|
||||
# llm = Scalar("llm" + str(i+1), st, LLMS[i] + ":XX_LOSS", 1, 0)
|
||||
# avl = create_averager(llm, SAMPLES, interval = -1)
|
||||
# avl.setMonitored(i>0)
|
||||
# sensors.append(avl)
|
||||
# sensors.append(avl.stdev)
|
||||
# sensors.append(avl.samples)
|
||||
# line_plots.append(avl.samples)
|
||||
|
||||
|
||||
for i in range(len(BPMS)):
|
||||
bpm = Scalar("bpm" + str(i+1), st, BPMS[i], 1, 0)
|
||||
av1 = create_averager(bpm, SAMPLES, interval = -1)
|
||||
av1.setMonitored((i>0) or (len(BLMS)>0))
|
||||
sensors.append(av1)
|
||||
sensors.append(av1.stdev)
|
||||
sensors.append(av1.samples)
|
||||
line_plots.append(av1.samples)
|
||||
|
||||
#Scalar("beam_ok" , st, "SIN-CVME-TIFGUN-EVR0:BEAMOK" , 1, 0)
|
||||
st.initialize()
|
||||
st.start()
|
||||
st.waitCacheChange(5000) #Wait stream be running before starting scan
|
||||
|
||||
|
||||
"""
|
||||
#Averaging
|
||||
ablm1 = create_averager(blm1, SAMPLES, interval = -1)
|
||||
ablm2 = create_averager(blm2, SAMPLES, interval = -1)
|
||||
ablm3 = create_averager(blm3, SAMPLES, interval = -1)
|
||||
ablm2.setMonitored(True)
|
||||
ablm3.setMonitored(True)
|
||||
"""
|
||||
|
||||
#Plot setup
|
||||
setup_plotting( line_plots = line_plots)
|
||||
|
||||
|
||||
|
||||
#Metadata
|
||||
set_attribute("/", "Samples" , SAMPLES)
|
||||
set_attribute("/", "StepSize" , STEP_SIZE)
|
||||
set_attribute("/", "SamplingTime" , SETTLING_TIME)
|
||||
set_attribute("/", "Range" , RANGE)
|
||||
set_attribute("/", "BLM" , BLMS)
|
||||
#set_attribute("/", "BLMW" , BLMW)
|
||||
set_attribute("/", "Gain" , GAINS)
|
||||
set_attribute("/", "Attenuators" , ATTENUATORS)
|
||||
set_attribute("/", "BPM" , BPMS)
|
||||
for att in attenuators:
|
||||
set_attribute("/", att.channelName, att.read())
|
||||
|
||||
try:
|
||||
r=lscan(gain_positioners, sensors, [RANGE[0],] * len(gain_positioners), [RANGE[1],] * len(gain_positioners), [STEP_SIZE,] * len(gain_positioners), latency = SETTLING_TIME)
|
||||
#r=bscan(st, 10)
|
||||
finally:
|
||||
st.close()
|
||||
|
||||
|
||||
# save the entry in the logbook
|
||||
if do_elog:
|
||||
if get_option("Generated data file:\n" + get_exec_pars().path + "\n\n" + "Save to ELOG?", "YesNo") == "Yes":
|
||||
gsa_log_msg = "Data file: " + get_exec_pars().path
|
||||
gsa_log_msg = gsa_log_msg + "\nSamples = " + str(SAMPLES)
|
||||
gsa_log_msg = gsa_log_msg + "\nStepSize = " + str(STEP_SIZE)
|
||||
gsa_log_msg = gsa_log_msg + "\nSamplingTime = " + str(SETTLING_TIME)
|
||||
gsa_log_msg = gsa_log_msg + "\nRange = " + str(RANGE)
|
||||
gsa_log_msg = gsa_log_msg + "\nBLM = " + str(BLMS)
|
||||
#gsa_log_msg = gsa_log_msg + "\nBLMW = " + str(BLMW)
|
||||
gsa_log_msg = gsa_log_msg + "\nBPM = " + str(BPMS)
|
||||
gsa_log_msg = gsa_log_msg + "\nGain = " + str(GAINS)
|
||||
gsa_log_msg = gsa_log_msg + "\nAttenuators:" # " + str(ATTENUATORS)
|
||||
for att in attenuators:
|
||||
gsa_log_msg = gsa_log_msg + "\n " + att.setpoint.channelName + " = " + str(att.read())
|
||||
|
||||
plots = get_plot_snapshots()
|
||||
save=[]
|
||||
for i in range(len(BLMS)):
|
||||
save.append(plots[3*i])
|
||||
for i in range(len(BPMS)):
|
||||
save.append(plots[3*i])
|
||||
elog("BLM Gain scan", gsa_log_msg, save)
|
||||
|
||||
|
||||
124
script/Diagnostics/ICTScan_1406.py
Normal file
124
script/Diagnostics/ICTScan_1406.py
Normal file
@@ -0,0 +1,124 @@
|
||||
#import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
|
||||
import ch.psi.pshell.bs.Scalar as Scalar
|
||||
import ch.psi.pshell.epics.DiscretePositioner as DiscretePositioner
|
||||
import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
|
||||
|
||||
|
||||
#Arguments
|
||||
SAMPLES = 100
|
||||
ICTS = ["SINEG01-DICT215", "S10DI01-DICT025", "SARMA01-DICT090", "SARBD01-DICT030"]
|
||||
ICTV = ["SINEG01-DICT009:AL1-ICT-VOLTAGE", "S10DI01-DICT113:AL0-ICT-VOLTAGE", "SARMA01-DICT482:AL0-ICT-VOLTAGE","SARBD01-DICT599:AL0-ICT-VOLTAGE"]
|
||||
BPMS = ["SINEG01-DBPM340:Q1", "S10DI01-DBPM110:Q1", "SARMA01-DBPM100:Q1", "SARBD01-DBPM040:Q1", "SARUN20-DBPM070:Q1"]
|
||||
#ROT = ["SLGJG-LMRM-M031:MOT.VAL"] # Polarizer
|
||||
ROT = ["SLGTV-LAPP:SIZE-SET"] # IRIS
|
||||
#RANGE = [50.0, 15.0]
|
||||
#STEP_SIZE = 5.0
|
||||
RANGE = [4.4, 2.0] # IRIS range
|
||||
STEP_SIZE = 0.1 # IRIS Step size
|
||||
SETTLING_TIME = 3
|
||||
SIMULATION = False
|
||||
do_elog = True
|
||||
|
||||
|
||||
rot_positioners = []
|
||||
for i in range(len(ROT)):
|
||||
rot_positioners.append( DummyPositioner("rot " + str(i+1)) if SIMULATION else Channel(ROT[i], alias = "rot" + str(i+1)))
|
||||
|
||||
#Stream creation
|
||||
sensors = []
|
||||
line_plots = []
|
||||
st = Stream("pulse_id", dispatcher)
|
||||
st.setFilter("SIN-CVME-TIFGUN-EVR0:BEAMOK == 1")
|
||||
for i in range(len(ICTS)):
|
||||
ict = Scalar("ict" + str(i+1), st, ICTS[i] + ":B1_CHARGE", 1, 0)
|
||||
av = create_averager(ict, SAMPLES, interval = -1)
|
||||
av.setMonitored(i>0)
|
||||
sensors.append(av)
|
||||
sensors.append(av.stdev)
|
||||
sensors.append(av.samples)
|
||||
line_plots.append(av.samples)
|
||||
|
||||
for i in range(len(BPMS)):
|
||||
bpm = Scalar("bpm" + str(i+1), st, BPMS[i], 1, 0)
|
||||
av1 = create_averager(bpm, SAMPLES, interval = -1)
|
||||
av1.setMonitored((i>0) or (len(ICTS)>0))
|
||||
sensors.append(av1)
|
||||
sensors.append(av1.stdev)
|
||||
sensors.append(av1.samples)
|
||||
line_plots.append(av1.samples)
|
||||
|
||||
for i in range(len(ICTV)):
|
||||
"""
|
||||
ictv = Scalar("ictv" + str(i+1), st, ICTV[i], 1, 0)
|
||||
av2 = create_averager(ictv, SAMPLES, interval = -1)
|
||||
av2.setMonitored((i>0) or (len(ICTS)>0))
|
||||
sensors.append(av2)
|
||||
sensors.append(av2.stdev)
|
||||
sensors.append(av2.samples)
|
||||
"""
|
||||
ictv = ChannelDouble("ictv" + str(i+1), ICTV[i])
|
||||
add_device(ictv, True)
|
||||
ictv.monitored = True
|
||||
ictv.initialize()
|
||||
av2 = create_averager(ictv, SAMPLES/2 , interval = -1)
|
||||
av2.setMonitored(True)
|
||||
sensors.append(av2)
|
||||
add_device(av2, True)
|
||||
#sensors.append(ictv)
|
||||
|
||||
#Scalar("beam_ok" , st, "SIN-CVME-TIFGUN-EVR0:BEAMOK" , 1, 0)
|
||||
st.initialize()
|
||||
st.start()
|
||||
st.waitCacheChange(5000) #Wait stream be running before starting scan
|
||||
|
||||
|
||||
"""
|
||||
#Averaging
|
||||
aict1 = create_averager(ict1, SAMPLES, interval = -1)
|
||||
aict2 = create_averager(ict2, SAMPLES, interval = -1)
|
||||
aict3 = create_averager(ict3, SAMPLES, interval = -1)
|
||||
aict2.setMonitored(True)
|
||||
aict3.setMonitored(True)
|
||||
"""
|
||||
|
||||
#Plot setup
|
||||
setup_plotting( line_plots = line_plots)
|
||||
|
||||
|
||||
#Metadata
|
||||
set_attribute("/", "Samples" , SAMPLES)
|
||||
set_attribute("/", "StepSize" , STEP_SIZE)
|
||||
set_attribute("/", "SamplingTime" , SETTLING_TIME)
|
||||
set_attribute("/", "Range" , RANGE)
|
||||
set_attribute("/", "ICTS" , ICTS)
|
||||
set_attribute("/", "ICTV" , ICTV)
|
||||
set_attribute("/", "Rot" , ROT)
|
||||
set_attribute("/", "BPM" , BPMS)
|
||||
|
||||
try:
|
||||
r=lscan(rot_positioners, sensors, [RANGE[0],] * len(rot_positioners), [RANGE[1],] * len(rot_positioners), [STEP_SIZE,] * len(rot_positioners), latency = SETTLING_TIME)
|
||||
#r=bscan(st, 10)
|
||||
finally:
|
||||
st.close()
|
||||
|
||||
|
||||
# save the entry in the logbook
|
||||
if do_elog:
|
||||
if get_option("Generated data file:\n" + get_exec_pars().path + "\n\n" + "Save to ELOG?", "YesNo") == "Yes":
|
||||
gsa_log_msg = "Data file: " + get_exec_pars().path
|
||||
gsa_log_msg = gsa_log_msg + "\nSamples = " + str(SAMPLES)
|
||||
gsa_log_msg = gsa_log_msg + "\nStepSize = " + str(STEP_SIZE)
|
||||
gsa_log_msg = gsa_log_msg + "\nSamplingTime = " + str(SETTLING_TIME)
|
||||
gsa_log_msg = gsa_log_msg + "\nRange = " + str(RANGE)
|
||||
gsa_log_msg = gsa_log_msg + "\nICTS = " + str(ICTS)
|
||||
gsa_log_msg = gsa_log_msg + "\nBPM = " + str(BPMS)
|
||||
|
||||
plots = get_plot_snapshots()
|
||||
save=[]
|
||||
for i in range(len(ICTS)):
|
||||
save.append(plots[3*i])
|
||||
for i in range(len(BPMS)):
|
||||
save.append(plots[3*i])
|
||||
elog("Charge scan", gsa_log_msg, save)
|
||||
|
||||
|
||||
@@ -2,9 +2,8 @@ import ch.psi.pshell.epics.Positioner as Positioner
|
||||
import ch.psi.pshell.epics.Camtool as Camtool
|
||||
|
||||
#Parameters
|
||||
dry_run = False
|
||||
dry_run = True
|
||||
do_elog = True
|
||||
camera_name = "SINBD01-DSCR010"
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
start = 45.0
|
||||
stop = 55.0
|
||||
@@ -24,26 +23,27 @@ else:
|
||||
energy0 = args[6]
|
||||
plt = args[7]
|
||||
|
||||
A = energy0 / disp / 1e6
|
||||
B = energy0
|
||||
|
||||
#Plot setup
|
||||
plt.clear()
|
||||
plt.setStyle(plt.Style.ErrorY)
|
||||
plt.addSeries(LinePlotErrorSeries("Energy"))
|
||||
plt.addSeries(LinePlotErrorSeries("Energy Spread", None, 2))
|
||||
plt.getAxis(plt.AxisId.X).setLabel("Gun Phase")
|
||||
plt.getAxis(plt.AxisId.X).setLabel("Gun Beam Phase (deg)")
|
||||
plt.getAxis(plt.AxisId.Y).setLabel("Energy (MeV)")
|
||||
plt.getAxis(plt.AxisId.Y2).setLabel("Energy Spread (MeV)")
|
||||
plt.setLegendVisible(True)
|
||||
|
||||
|
||||
#Creating Phase positioner
|
||||
if dry_run:
|
||||
phase = Positioner("Phase", "SINEG01-RSYS:SET-BEAM-PHASE-SIM", "SINEG01-RSYS:SET-BEAM-PHASE-SIM")
|
||||
#phase = DummyPositioner("Phase")
|
||||
camera_name = "SLG-LCAM-C041"
|
||||
do_elog = False
|
||||
else:
|
||||
phase = Positioner("Phase", "SINEG01-RSYS:SET-BEAM-PHASE", "SINEG01-RSYS:GET-BEAM-PHASE")
|
||||
phase = Positioner("Phase", "SINEG01-RSYS:SET-BEAM-PHASE", "SINEG01-RSYS:GET-BEAM-PHASE")
|
||||
camera_name = "SINBD01-DSCR010"
|
||||
|
||||
phase.config.minValue = -180.0
|
||||
phase.config.maxValue = 180.0
|
||||
phase.config.precision = 3
|
||||
@@ -58,47 +58,41 @@ phase0 = phase.read()
|
||||
check_camtool()
|
||||
camtool.start(camera_name)
|
||||
wait_camtool_message()
|
||||
x = camtool.stream.getChild("x_fit_mean")
|
||||
dx = camtool.stream.getChild("x_fit_standard_deviation")
|
||||
|
||||
x = camtool.stream.getChild("x_center_of_mass")
|
||||
dx = camtool.stream.getChild("x_rms")
|
||||
|
||||
#Creating averagers
|
||||
xb = create_averager(x, nb, -1) # -1 event based, waits for the next value
|
||||
dxb = create_averager(dx, nb, -1)
|
||||
dxb.monitored=True # not blocking, will return last nb values
|
||||
|
||||
x_averager = create_averager(x, nb, -1) # -1 event based, waits for the next value
|
||||
dx_averager = create_averager(dx, nb, -1)
|
||||
dx_averager.monitored=True # not blocking, will return last nb values
|
||||
|
||||
#Record callback: uptate of output plot
|
||||
def after_sample(record, scan):
|
||||
global energy0, disp
|
||||
x_fit_mean, x_fit_mean_sigma, = record.values[0].mean, record.values[0].stdev
|
||||
x_fit_std, x_fit_std_sigma = record.values[1].mean, record.values[1].stdev
|
||||
E_mean, E_std = energy0 * (1 + x_fit_mean / 1e6 / disp), abs(energy0 * (x_fit_mean_sigma / 1e6 / disp))
|
||||
dE_mean, dE_std = abs(energy0 * (x_fit_std / 1e6 / disp)), abs(energy0 * (x_fit_std_sigma / 1e6 / disp))
|
||||
plt.getSeries(0).appendData(record.positions[0], E_mean, E_std)
|
||||
plt.getSeries(1).appendData(record.positions[0], dE_mean, dE_std)
|
||||
|
||||
global A, B
|
||||
x_pos_mean, x_pos_stdev = record.values[0].mean, record.values[0].stdev
|
||||
x_width_mean, x_width_stdev = record.values[1].mean, record.values[1].stdev
|
||||
E_mean, E_stdev = A * x_pos_mean + B, abs(A) * x_pos_stdev
|
||||
dE_mean, dE_stdev = abs(A) * x_width_mean, abs(A) * x_width_stdev
|
||||
plt.getSeries(0).appendData(record.positions[0], E_mean, E_stdev)
|
||||
plt.getSeries(1).appendData(record.positions[0], dE_mean, dE_stdev)
|
||||
|
||||
#The scan loop
|
||||
try:
|
||||
r = lscan(phase, [xb, dxb], start, stop, step , latency=lat, after_read = after_sample)
|
||||
r = lscan(phase, [x_averager, dx_averager], start, stop, step , latency=lat, after_read = after_sample)
|
||||
finally:
|
||||
phase.write(phase0)
|
||||
phase.close()
|
||||
camtool.stop() # stops camtool but does not close it camtool is a global object
|
||||
|
||||
|
||||
#Saving metadata
|
||||
E = [energy0 * (1 + val.mean / 1e6 / disp) for val in r.getReadable(0)]
|
||||
dE = [abs(energy0 * (val.mean / 1e6 / disp)) for val in r.getReadable(1)]
|
||||
E = [A * val.mean + B for val in r.getReadable(0)]
|
||||
dE = [abs(A) * val.mean for val in r.getReadable(1)]
|
||||
save_dataset(get_exec_pars().group + "/E", E)
|
||||
save_dataset(get_exec_pars().group + "/dE", dE)
|
||||
|
||||
if do_elog:
|
||||
if get_option("Generated data file:\n" + get_exec_pars().path +"\n\n" + "Save to ELOG?", "YesNo") == "Yes":
|
||||
log_msg = "Data file: " + get_exec_pars().path
|
||||
#log_msg = log_msg + "\n\n" + r.print()
|
||||
|
||||
log_msg = "Data file: " + get_exec_pars().path
|
||||
sleep(0.1) #Give some time to plot to be finished - it is not sync with acquisition
|
||||
file_name = os.path.abspath(get_context().setup.getContextPath() + "/GunScanPlot.png")
|
||||
plt.saveSnapshot(file_name , "png")
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import ch.psi.pshell.epics.Positioner as Positioner
|
||||
import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
|
||||
|
||||
dry_run = True
|
||||
do_elog = False
|
||||
dry_run = False
|
||||
do_elog = True
|
||||
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
start = -30.0
|
||||
stop = 30.0
|
||||
start = -180.0
|
||||
stop = 180.0
|
||||
step = 5.0
|
||||
nb = 1
|
||||
lat = 0.100
|
||||
plt = None
|
||||
plt = None
|
||||
else:
|
||||
start = args[0]
|
||||
stop = args[1]
|
||||
@@ -21,43 +22,42 @@ else:
|
||||
if plt is not None:
|
||||
plt.setStyle(plt.Style.ErrorY)
|
||||
plt.addSeries(LinePlotErrorSeries("Values"))
|
||||
plt.getAxis(plt.AxisId.X).setLabel("RF Gun Phase")
|
||||
plt.getAxis(plt.AxisId.X).setLabel("Gun Beam Phase (deg)")
|
||||
plt.getAxis(plt.AxisId.Y).setLabel("SINEG01-DICT215:B1_CHARGE")
|
||||
|
||||
|
||||
if dry_run:
|
||||
bph = Positioner("Beam phase", "SINEG01-RSYS:SET-BEAM-PHASE-SIM", "SINEG01-RSYS:SET-BEAM-PHASE-SIM")
|
||||
q = ChannelDouble('ICT-Q', "SINEG01-DICT215:B1_CHARGE-SIM")
|
||||
rph = ChannelDouble('RF phase', "SINEG01-RSYS:SET-VSUM-PHASE-SIM")
|
||||
q = ChannelDouble('ICT-Q', "SINEG01-DICT215:B1_CHARGE-SIM")
|
||||
q.initialize()
|
||||
q.monitored=True
|
||||
else:
|
||||
bph = Positioner("Beam phase", "SINEG01-RSYS:SET-BEAM-PHASE", "SINEG01-RSYS:SET-BEAM-PHASE")
|
||||
bph = Positioner("Beam phase", "SINEG01-RSYS:SET-BEAM-PHASE", "SINEG01-RSYS:GET-BEAM-PHASE")
|
||||
rph = ChannelDouble('RF phase', "SINEG01-RSYS:SET-VSUM-PHASE")
|
||||
st = Stream("ICTstream", dispatcher)
|
||||
q = st.addScalar("Charge", "SINEG01-DICT215:B1_CHARGE", 1, 0)
|
||||
st.initialize()
|
||||
st.start()
|
||||
st.waitValueChange(10000)
|
||||
|
||||
|
||||
bph.config.minValue =-180.0
|
||||
bph.config.maxValue = 360.0
|
||||
bph.config.maxValue = 180.0
|
||||
bph.config.precision = 3
|
||||
bph.config.rotation = True
|
||||
bph.config.rotation = True
|
||||
bph.config.resolution = 1.0
|
||||
bph.config.save()
|
||||
bph.initialize()
|
||||
rph = ChannelDouble('RF phase', "SINEG01-RSYS:SET-VSUM-PHASE-SIM")
|
||||
rph.initialize()
|
||||
rph.monitored=True
|
||||
|
||||
rph0 = rph.read()
|
||||
|
||||
|
||||
#Record callback: uptate of output plot
|
||||
def after_sample(record, scan):
|
||||
if plt is not None:
|
||||
plt.getSeries(0).appendData(record.positions[0], record.values[1].mean, record.values[1].stdev)
|
||||
|
||||
try:
|
||||
try:
|
||||
rph_averager = create_averager(rph, nb, 0.1) # Set polling time to -1 for BS data to get all messages
|
||||
q_averager = create_averager(q, nb, 0.1)
|
||||
q_averager.monitored=True
|
||||
@@ -75,25 +75,20 @@ finally:
|
||||
|
||||
#Setting the return value
|
||||
index_max = charge.index(max(charge))
|
||||
bph_ref = beamphase[index_max] - 80
|
||||
rph_ref = rfphase[index_max] - 80
|
||||
|
||||
print "Beam phase reference = ", bph_ref
|
||||
print "RF phase reference = ", rph_ref
|
||||
bph_ref_guess = beamphase[index_max] - 80
|
||||
rph_ref_guess = rfphase[index_max] - 80
|
||||
|
||||
if do_elog:
|
||||
if get_option("Generated data file:\n" + get_exec_pars().path +"\n\n" + "Save to ELOG?", "YesNo") == "Yes":
|
||||
log_msg = "Data file: " + get_exec_pars().path + "\n"
|
||||
log_msg = log_msg + "Beam phase reference: %0.1f" % bph_ref + "\n"
|
||||
log_msg = log_msg + "RF phase reference: %0.1f" % rph_ref + "\n"
|
||||
log_msg = "Data file: " + get_exec_pars().path + "\n"
|
||||
log_msg = log_msg + "Beam phase reference: %0.1f" % bph_ref_guess + "deg \n"
|
||||
log_msg = log_msg + "RF phase reference: %0.1f" % rph_ref_guess + "deg \n"
|
||||
attachments = []
|
||||
if plt is not None:
|
||||
sleep(0.1) #Give some time to plot to be finished - it is not sync with acquisition
|
||||
file_name = os.path.abspath(get_context().setup.getContextPath() + "/SchottkyScanPlot.png")
|
||||
plt.saveSnapshot(file_name , "png")
|
||||
plt.saveSnapshot(file_name, "png")
|
||||
attachments = [file_name,]
|
||||
elog("Gun scan", log_msg, attachments)
|
||||
|
||||
set_return([bph_ref, rph_ref])
|
||||
|
||||
elog("Schottky scan", log_msg, attachments)
|
||||
|
||||
set_return([bph_ref_guess, rph_ref_guess])
|
||||
|
||||
@@ -1,32 +1,31 @@
|
||||
dry_run = True
|
||||
dry_run = False
|
||||
do_elog = True
|
||||
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
phaseOffset = rph_ref
|
||||
plt = None
|
||||
do_elog = False
|
||||
bph_ref_user = 0.0
|
||||
plt = None
|
||||
else:
|
||||
phaseOffset = args[0]
|
||||
plt = args[1]
|
||||
bph_ref_user = args[0]
|
||||
plt = args[1]
|
||||
|
||||
rph_ref_new = rph_ref_guess + (bph_ref_guess - bph_ref_user)
|
||||
phaseOffset = -rph_ref_new
|
||||
bph_ref_new = rph_ref_new + phaseOffset
|
||||
print "Setting phase offset: ", phaseOffset
|
||||
|
||||
phaseOffset = -phaseOffset
|
||||
|
||||
if not dry_run:
|
||||
caput('SINEG01-RSYS:SET-VSUM-PHASE-OFFSET-BASE', phaseOffset)
|
||||
caput('SINEG01-RSYS:CMD-LOAD-CALIB-BEAM', 1)
|
||||
|
||||
|
||||
|
||||
if do_elog:
|
||||
log_msg = "Phase offset: %0.1f" % bph_ref + "\n"
|
||||
log_msg = "RF phase reference: %0.1f" % rph_ref_new + "deg \n"
|
||||
log_msg = log_msg + "Phase offset: %0.1f" % phaseOffset + "deg \n"
|
||||
log_msg = log_msg + "Beam phase reference: %0.1f" % bph_ref_new + "deg \n"
|
||||
attachments = []
|
||||
if plt is not None:
|
||||
sleep(0.1) #Give some time to plot to be finished - it is not sync with acquisition
|
||||
file_name = os.path.abspath(get_context().setup.getContextPath() + "/SchottkyScanSetPlot.png")
|
||||
plt.saveSnapshot(file_name , "png")
|
||||
attachments = [file_name,]
|
||||
plt.saveSnapshot(file_name , "png")
|
||||
attachments = [file_name]
|
||||
elog("SchottkyScanSet", log_msg, attachments)
|
||||
|
||||
show_message("Success setting phase reference")
|
||||
|
||||
show_message("Success setting phase reference")
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import ch.psi.pshell.epics.ControlledVariable as ControlledVariable
|
||||
import ch.psi.pshell.epics.Positioner as Positioner
|
||||
import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
|
||||
|
||||
dry_run = True
|
||||
do_elog = False
|
||||
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
station = "STEST01"
|
||||
@@ -15,15 +19,25 @@ nb = caget(station + "-RSYS:SET-NUM-AVERAGE")
|
||||
disp = caget(bpm_ch + ":DISPERSION")
|
||||
energy0 = caget(bpm_ch + ":ENERGY")
|
||||
|
||||
phase = ControlledVariable("Phase", station + "-RSYS:SET-VSUM-PHASE", station + "-RSYS:GET-VSUM-PHASE")
|
||||
A = energy0 / disp / 1e3
|
||||
B = energy0
|
||||
|
||||
phase = Positioner("Phase", station + "-RSYS:SET-VSUM-PHASE", station + "-RSYS:GET-VSUM-PHASE")
|
||||
phase.config.minValue =-180.0
|
||||
phase.config.maxValue = 360.0
|
||||
phase.config.maxValue = 180.0
|
||||
phase.config.precision = 4
|
||||
phase.config.rotation = True
|
||||
phase.config.resolution = 0.5
|
||||
phase.initialize()
|
||||
|
||||
V = Channel(station + "-RSYS:GET-VSUM-AMPLT", type = 'd', alias='Amplitude Readback')
|
||||
P = Channel(station + "-RSYS:GET-KLY-POWER", type = 'd', alias='Power Readback')
|
||||
x = Channel(bpm_ch + ":X1", type = 'd', alias='BPM-X')
|
||||
V = ChannelDouble("Amplitude Readback", station + "-RSYS:GET-VSUM-AMPLT")
|
||||
P = ChannelDouble("Power Readback", station + "-RSYS:GET-KLY-POWER")
|
||||
if dry_run:
|
||||
x = ChannelDouble("BPM-X", bpm_ch + ":X1-SIMU")
|
||||
else:
|
||||
x = ChannelDouble("BPM-X", bpm_ch + ":X1")
|
||||
V.initialize()
|
||||
P.initialize()
|
||||
x.initialize()
|
||||
|
||||
phase0 = phase.read()
|
||||
|
||||
@@ -37,9 +51,9 @@ caput(station + "-RSYS:GET-ONCREST-KLY-POWER", float('nan'))
|
||||
#update the plot dynamically
|
||||
arr_phase,arr_energy = [],[]
|
||||
def after(rec):
|
||||
global disp, energy0
|
||||
global A, B
|
||||
arr_phase.append(rec.positions[0])
|
||||
arr_energy.append(energy0 * (1 + rec.values[0].mean / 1000.0 / disp))
|
||||
arr_energy.append(A * rec.values[0].mean + B)
|
||||
caput(station + "-RSYS:GET-PHASE-ARRAY", to_array(arr_phase, 'd'))
|
||||
caput(station + "-RSYS:GET-ENERGY-ARRAY", to_array(arr_energy,'d'))
|
||||
|
||||
@@ -47,7 +61,7 @@ try:
|
||||
x_averager = create_averager(x, nb, 0.100)
|
||||
r = lscan(phase, x_averager, start, stop, step, latency=lat, after_read = after)
|
||||
rf_phase = r.getPositions(0)
|
||||
energy = [energy0 * (1 + val.mean / 1000.0 / disp) for val in r.getReadable(0)]
|
||||
energy = [A * val.mean + B for val in r.getReadable(0)]
|
||||
caput(station + "-RSYS:GET-ENERGY-ARRAY", to_array(energy, 'd'))
|
||||
caput(station + "-RSYS:GET-PHASE-ARRAY", to_array(rf_phase,'d'))
|
||||
try:
|
||||
@@ -78,15 +92,19 @@ finally:
|
||||
|
||||
phase_offset = 90 - ph_crest
|
||||
amplitude_scale = fit_amplitude / Ampl
|
||||
power_scale = Power / math.pow(Ampl,2)
|
||||
power_scale = Power / math.pow(fit_amplitude,2)
|
||||
|
||||
caput(station + "-RSYS:SET-VSUM-PHASE-OFFSET-BASE", phase_offset)
|
||||
#caput(station + "-RSYS:SET-VSUM-AMPLT-SCALE", amplitude_scale)
|
||||
#caput(station + "-RSYS:SET-VOLT-POWER-SCALE", power_scale)
|
||||
caput(station + "-RSYS:SET-VSUM-AMPLT-SCALE", amplitude_scale)
|
||||
caput(station + "-RSYS:SET-VOLT-POWER-SCALE", power_scale)
|
||||
|
||||
#title="Phase scan "+str(station)
|
||||
#message=("Energy Gain: %0.3f" % energy_gain + "MeV\n" +
|
||||
# "Phase Offset: %0.2f" % phase_offset + "deg\n" +
|
||||
# "Amplitude Scale: %0.3f" % amplitude_scale + "MV\n" +
|
||||
# "Power Scale: %0.3f" % power_scale) + "1/ohm"
|
||||
#elog(title, message)
|
||||
if do_elog:
|
||||
if get_option("Generated data file:\n" + get_exec_pars().path +"\n\n" + "Save to ELOG?", "YesNo") == "Yes":
|
||||
title = "Phase scan" + station
|
||||
log_msg = "Data file: " + get_exec_pars().path + "\n"
|
||||
log_msg = log_msg + "Energy Gain: %0.3f" % energy_gain + "MeV\n"
|
||||
log_msg = log_msg + "Phase Offset: %0.2f" % phase_offset + "deg\n"
|
||||
log_msg = log_msg + "Amplitude Scale: %0.3f" % amplitude_scale + "MV\n"
|
||||
log_msg = log_msg + "Power Scale: %0.3f" % power_scale + "MW/MV^2"
|
||||
attachments = []
|
||||
elog(title, log_msg, attachments)
|
||||
|
||||
14
script/test/CamtoolCheckProfile.py
Normal file
14
script/test/CamtoolCheckProfile.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import ch.psi.pshell.imaging.Data as Data
|
||||
|
||||
d = load_data("2017/06/16/20170616_122305_snapshot.h5|/data")
|
||||
atts = get_attributes("2017/06/16/20170616_122305_snapshot.h5|/data")
|
||||
data = Data(d)
|
||||
iv = data.integrateVertically(False)
|
||||
ih = data.integrateHorizontally(False)
|
||||
xp = atts["x_profile"]
|
||||
yp = atts["y_profile"]
|
||||
p1, p2 = plot([xp, yp], ["X profile", "Y profile"])
|
||||
p1.addSeries(LinePlotSeries("d"))
|
||||
p2.addSeries(LinePlotSeries("d"))
|
||||
p1.getSeries(1).setData(iv)
|
||||
p2.getSeries(1).setData(ih)
|
||||
33
script/test/CompressionBug.py
Normal file
33
script/test/CompressionBug.py
Normal file
@@ -0,0 +1,33 @@
|
||||
#import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
|
||||
import ch.psi.pshell.bs.Scalar as Scalar
|
||||
import ch.psi.pshell.bs.Waveform as Waveform
|
||||
|
||||
|
||||
dispatcher.config.disableCompression = False
|
||||
set_exec_pars(persist = False)
|
||||
|
||||
#Arguments
|
||||
SAMPLES = 5
|
||||
BLMS = ["SINDI02-DBLM025", ] #"SINDI02-DBLM085", "S10DI01-DBLM045"]
|
||||
|
||||
|
||||
sensors = []
|
||||
st = Stream("pulse_id", dispatcher)
|
||||
#st.setFilter("SIN-CVME-TIFGUN-EVR0:BEAMOK == 1")
|
||||
for i in range(len(BLMS)):
|
||||
blm = Scalar("blm" + str(i+1), st, BLMS[i] + ":B1_LOSS", 1, 0)
|
||||
av = create_averager(blm, SAMPLES, interval = -1)
|
||||
av.setMonitored(i>0)
|
||||
sensors.append(av)
|
||||
sensors.append(av.stdev)
|
||||
sensors.append(av.samples)
|
||||
bpmw = Waveform("blmw" + str(i+1), st, BLMS[i] + ":LOSS_SIGNAL_RAW", 1, 0)
|
||||
sensors.append(bpmw)
|
||||
|
||||
|
||||
st.initialize()
|
||||
st.start()
|
||||
if not st.waitCacheChange(3000): #Wait stream be running before starting scan
|
||||
raise Exception("Stream timeout")
|
||||
|
||||
bscan(st, 10)
|
||||
100
script/test/TestWaveformListener.py
Normal file
100
script/test/TestWaveformListener.py
Normal file
@@ -0,0 +1,100 @@
|
||||
#import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
|
||||
import ch.psi.pshell.bs.Scalar as Scalar
|
||||
import ch.psi.pshell.bs.Waveform as Waveform
|
||||
import ch.psi.pshell.epics.DiscretePositioner as DiscretePositioner
|
||||
|
||||
|
||||
dispatcher.config.disableCompression = True
|
||||
#set_exec_pars(persist = False)
|
||||
|
||||
#Arguments
|
||||
SAMPLES = 2
|
||||
GAINS = ["SINDI02-DBLM084:M06-1-CH03-V-MM","SINDI02-DBLM084:M06-2-CH03-V-MM","S10DI01-DBLM113:M06-1-CH03-V-MM"]
|
||||
BLMS = ["SINDI02-DBLM025", "SINDI02-DBLM085", "S10DI01-DBLM045"]
|
||||
BLMW = ["SINDI02-DBLM025:LOSS_SIGNAL_RAW", "SINDI02-DBLM085:LOSS_SIGNAL_RAW", "S10DI01-DBLM045:LOSS_SIGNAL_RAW"]
|
||||
BPMS = ["SINDI01-DBPM060:Q1", "SINDI02-DBPM010:Q1"]
|
||||
ATTENUATORS = ["SINDI02-DBLM084:M06-1-ATT2-VAL", "SINDI02-DBLM084:M06-2-ATT2-VAL", "S10DI01-DBLM113:M06-1-ATT2-VAL"]
|
||||
ATT_SP = 0 #3,6,9,12,15
|
||||
RANGE = [0.5, 1.1]
|
||||
STEP_SIZE = 0.1
|
||||
SETTLING_TIME = 0.5
|
||||
SIMULATION = False
|
||||
do_elog = True
|
||||
|
||||
|
||||
gain_positioners = []
|
||||
for i in range(len(GAINS)):
|
||||
gain_positioners.append( DummyPositioner("gain " + str(i+1)) if SIMULATION else Channel(GAINS[i], alias = "gain " + str(i+1)))
|
||||
|
||||
attenuators = []
|
||||
for i in range(len(ATTENUATORS)):
|
||||
att = DiscretePositioner("Att"+str(i+1), ATTENUATORS[i])
|
||||
att.initialize()
|
||||
attenuators.append(att)
|
||||
|
||||
#Channel-based
|
||||
#blm1 = ChannelDouble("blm1", "SINDI02-DBLM025:B1_LOSS"); blm1.setMonitored(True); blm1.initialize()
|
||||
#blm2 = ChannelDouble("blm2", "SINDI02-DBLM085:B1_LOSS"); blm2.setMonitored(True); blm2.initialize()
|
||||
|
||||
#Stream creation
|
||||
class ListenerBpmw (DeviceListener):
|
||||
def onValueChanged(self, device, value, former):
|
||||
if sampling and (get_exec_pars().scan is not None):
|
||||
path = get_exec_pars().group + "rec " + str(get_exec_pars().scan.recordIndex) + "/" + device.name
|
||||
if "Exception" in get_attributes(path).keys(): #If file does not exist
|
||||
create_dataset(path, 'd', False, (0, len(value)))
|
||||
append_dataset(path,value)
|
||||
|
||||
sampling = False
|
||||
|
||||
def before():
|
||||
global sampling
|
||||
sampling = True
|
||||
|
||||
def after():
|
||||
global sampling
|
||||
sampling = False
|
||||
|
||||
|
||||
sensors = []
|
||||
line_plots = []
|
||||
st = Stream("pulse_id", dispatcher)
|
||||
st.setFilter("SIN-CVME-TIFGUN-EVR0:BEAMOK == 1")
|
||||
for i in range(len(BLMS)):
|
||||
blm = Scalar("blm" + str(i+1), st, BLMS[i] + ":B1_LOSS", 1, 0)
|
||||
av = create_averager(blm, SAMPLES, interval = -1)
|
||||
av.setMonitored(i>0)
|
||||
sensors.append(av)
|
||||
sensors.append(av.stdev)
|
||||
sensors.append(av.samples)
|
||||
line_plots.append(av.samples)
|
||||
bpmw = Waveform("blmw" + str(i+1), st, BLMS[i] + ":LOSS_SIGNAL_RAW", 1, 0)
|
||||
#sensors.append(bpmw)
|
||||
bpmw.addListener(ListenerBpmw())
|
||||
|
||||
|
||||
#st.initialize()
|
||||
#st.start()
|
||||
#st.waitCacheChange(10000) #Wait stream be running before starting scan
|
||||
|
||||
|
||||
for i in range(len(BPMS)):
|
||||
bpm = Scalar("bpm" + str(i+1), st, BPMS[i], 1, 0)
|
||||
av1 = create_averager(bpm, SAMPLES, interval = -1)
|
||||
av1.setMonitored(i>0 or (len(BLMS) > 0))
|
||||
sensors.append(av1)
|
||||
sensors.append(av1.stdev)
|
||||
sensors.append(av1.samples)
|
||||
line_plots.append(av1.samples)
|
||||
|
||||
#Scalar("beam_ok" , st, "SIN-CVME-TIFGUN-EVR0:BEAMOK" , 1, 0)
|
||||
try:
|
||||
st.initialize()
|
||||
st.start()
|
||||
if not st.waitCacheChange(10000): #Wait stream be running before starting scan
|
||||
raise Exception("Stream timeout")
|
||||
|
||||
tscan(sensors, 5, 0.5, before_read=before, after_read=after)
|
||||
finally:
|
||||
st.close()
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import ch.psi.pshell.epics.ControlledVariable as ControlledVariable
|
||||
import ch.psi.pshell.epics.Positioner as Positioner
|
||||
import ch.psi.pshell.epics.ChannelDouble as ChannelDouble
|
||||
|
||||
dry_run = True
|
||||
do_elog = False
|
||||
|
||||
if get_exec_pars().source == CommandSource.ui:
|
||||
station = "STEST01"
|
||||
@@ -15,15 +19,22 @@ nb = caget(station + "-RSYS:SET-NUM-AVERAGE")
|
||||
disp = caget(bpm_ch + ":DISPERSION")
|
||||
energy0 = caget(bpm_ch + ":ENERGY")
|
||||
|
||||
phase = ControlledVariable("Phase", station + "-RSYS:SET-VSUM-PHASE", station + "-RSYS:GET-VSUM-PHASE")
|
||||
phase = Positioner("Phase", station + "-RSYS:SET-VSUM-PHASE", station + "-RSYS:GET-VSUM-PHASE")
|
||||
phase.config.minValue =-180.0
|
||||
phase.config.maxValue = 360.0
|
||||
phase.config.maxValue = 180.0
|
||||
phase.config.precision = 3
|
||||
phase.config.rotation = True
|
||||
phase.config.resolution = 0.5
|
||||
phase.initialize()
|
||||
|
||||
V = Channel(station + "-RSYS:GET-VSUM-AMPLT", type = 'd', alias='Amplitude Readback')
|
||||
P = Channel(station + "-RSYS:GET-KLY-POWER", type = 'd', alias='Power Readback')
|
||||
x = Channel(bpm_ch + ":X1-SIMU", type = 'd', alias='BPM-X')
|
||||
V = ChannelDouble("Amplitude Readback", station + "-RSYS:GET-VSUM-AMPLT")
|
||||
P = ChannelDouble("Power Readback", station + "-RSYS:GET-KLY-POWER")
|
||||
if dry_run:
|
||||
x = ChannelDouble("BPM-X", bpm_ch + ":X1-SIMU")
|
||||
else:
|
||||
x = ChannelDouble("BPM-X", bpm_ch + ":X1")
|
||||
V.initialize()
|
||||
P.initialize()
|
||||
x.initialize()
|
||||
|
||||
phase0 = phase.read()
|
||||
|
||||
@@ -84,9 +95,18 @@ caput(station + "-RSYS:SET-VSUM-PHASE-OFFSET-BASE", phase_offset)
|
||||
caput(station + "-RSYS:SET-VSUM-AMPLT-SCALE", amplitude_scale)
|
||||
caput(station + "-RSYS:SET-VOLT-POWER-SCALE", power_scale)
|
||||
|
||||
#title="Phase scan "+str(station)
|
||||
#message=("Energy Gain: %0.3f" % energy_gain + "MeV\n" +
|
||||
# "Phase Offset: %0.2f" % phase_offset + "deg\n" +
|
||||
# "Amplitude Scale: %0.3f" % amplitude_scale + "MV\n" +
|
||||
# "Power Scale: %0.3f" % power_scale) + "1/ohm"
|
||||
#elog(title, message)
|
||||
if do_elog:
|
||||
if get_option("Generated data file:\n" + get_exec_pars().path +"\n\n" + "Save to ELOG?", "YesNo") == "Yes":
|
||||
title = "Phase scan" + station
|
||||
log_msg = "Data file: " + get_exec_pars().path + "\n"
|
||||
log_msg = log_msg + "Energy Gain: %0.3f" % energy_gain + "MeV\n"
|
||||
log_msg = log_msg + "Phase Offset: %0.2f" % phase_offset + "deg\n"
|
||||
log_msg = log_msg + "Amplitude Scale: %0.3f" % amplitude_scale + "MV\n"
|
||||
log_msg = log_msg + "Power Scale: %0.3f" % power_scale + "MW/MV^2"
|
||||
attachments = []
|
||||
if plt is not None:
|
||||
sleep(0.1) #Give some time to plot to be finished - it is not sync with acquisition
|
||||
file_name = os.path.abspath(get_context().setup.getContextPath() + "/SchottkyScanPlot.png")
|
||||
plt.saveSnapshot(file_name, "png")
|
||||
attachments = [file_name,]
|
||||
elog(title, log_msg, attachments)
|
||||
Reference in New Issue
Block a user