This commit is contained in:
gobbo_a
2017-06-07 10:59:53 +02:00
parent c9a61d49a7
commit a6733e4cc5
6 changed files with 164 additions and 55 deletions

View File

@@ -1,7 +1,7 @@
#Tue Jun 06 12:40:51 CEST 2017
#Wed Jun 07 10:46:57 CEST 2017
colormap=Flame
colormapAutomatic=true
colormapMax=10600.0
colormapAutomatic=false
colormapMax=1000.0
colormapMin=10.0
flipHorizontally=false
flipVertically=false
@@ -21,9 +21,9 @@ rotation=0.0
rotationCrop=false
scale=1.0
serverURL=localhost\:10000
spatialCalOffsetX=-216.34895100768858
spatialCalOffsetY=-231.41621563133825
spatialCalScaleX=-26.85765457769588
spatialCalScaleY=-27.12477389498874
spatialCalOffsetX=-50.03909304143862
spatialCalOffsetY=-50.048875855327466
spatialCalScaleX=-1.0
spatialCalScaleY=-1.0
spatialCalUnits=mm
transpose=false

View File

@@ -1,12 +1,12 @@
#Fri Jun 02 16:31:12 CEST 2017
defaultSpeed=6000.0
#Wed Jun 07 10:56:09 CEST 2017
defaultSpeed=141.4213562373095
estbilizationDelay=0
hasEnable=false
homingType=None
maxSpeed=8000.0
maxValue=64000.0
minSpeed=50.0
minValue=-48153.0
minValue=-47600.0
offset=0.0
precision=1
resolution=0.1

View File

@@ -1,4 +1,4 @@
#Tue Jun 06 10:04:55 CEST 2017
#Wed Jun 07 10:19:49 CEST 2017
colormap=Flame
colormapAutomatic=true
colormapMax=578.797
@@ -18,9 +18,9 @@ roiY=0
rotation=0.0
rotationCrop=false
scale=1.0
spatialCalOffsetX=0.0
spatialCalOffsetY=0.0
spatialCalScaleX=1.0
spatialCalScaleY=1.0
spatialCalOffsetX=-50.03909304143862
spatialCalOffsetY=-50.048875855327466
spatialCalScaleX=-1.0
spatialCalScaleY=-1.0
spatialCalUnits=mm
transpose=false

View File

@@ -13,6 +13,7 @@ import ch.psi.utils.Chrono;
import ch.psi.utils.swing.SwingUtils;
import ch.psi.utils.swing.TextEditor;
import ch.psi.pshell.bs.Camtool;
import ch.psi.pshell.bs.StreamValue;
import ch.psi.pshell.device.DescStatsDouble;
import ch.psi.pshell.device.Device;
import ch.psi.pshell.epics.ChannelInteger;
@@ -44,6 +45,7 @@ import ch.psi.utils.Convert;
import ch.psi.utils.TcpClient;
import ch.psi.utils.swing.Editor.EditorDialog;
import ch.psi.utils.swing.MainFrame;
import ch.psi.utils.swing.StandardDialog;
import ch.psi.utils.swing.SwingUtils.OptionResult;
import ch.psi.utils.swing.SwingUtils.OptionType;
import java.awt.BorderLayout;
@@ -56,6 +58,7 @@ import java.awt.GridBagLayout;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
@@ -77,10 +80,14 @@ import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import javax.swing.table.DefaultTableModel;
import org.apache.commons.math3.analysis.function.Gaussian;
import org.apache.commons.math3.fitting.GaussianCurveFitter;
import org.apache.commons.math3.fitting.WeightedObservedPoint;
@@ -230,10 +237,10 @@ public class ScreenPanel extends Panel {
}
});
JMenuItem menuShowIdentifiers = new JMenuItem("Show Identifiers...");
menuShowIdentifiers.addActionListener((ActionEvent e) -> {
JMenuItem menuShowImageData = new JMenuItem("Show Image Data");
menuShowImageData.addActionListener((ActionEvent e) -> {
try {
showIdentifiers();
showImageData();
} catch (Exception ex) {
showException(ex);
}
@@ -295,7 +302,7 @@ public class ScreenPanel extends Panel {
}
});
renderer.getPopupMenu().add(menuShowIdentifiers);
renderer.getPopupMenu().add(menuShowImageData);
renderer.getPopupMenu().add(menuCalibrate);
renderer.getPopupMenu().add(menuSaveStack);
renderer.getPopupMenu().addSeparator();
@@ -306,7 +313,7 @@ public class ScreenPanel extends Panel {
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
menuResetROI.setEnabled(camera instanceof Camtool);
menuSetROI.setEnabled(camera instanceof Camtool);
menuShowIdentifiers.setVisible(camera instanceof Camtool);
menuShowImageData.setVisible(camera instanceof Camtool);
menuCalibrate.setVisible(camera instanceof Camtool);
menuCalibrate.setEnabled(calibrationOverlays==null);
}
@@ -563,9 +570,14 @@ public class ScreenPanel extends Panel {
buttonGrabBackground.setEnabled(false);
checkBackground.setEnabled(false);
spinnerThreshold.setEnabled(false);
checkThreshold.setEnabled(false);
if (dataTableDialog!=null){
dataTableDialog.dispose();
dataTableDialog = null;
}
dataTableModel = null;
if (calibrationDialolg!=null){
calibrationDialolg.dispose();
calibrationDialolg = null;
@@ -689,7 +701,7 @@ public class ScreenPanel extends Panel {
manageFit(bi, data);
manageUserOverlays(bi, data);
}
//updateImageData();
}
@Override
@@ -928,6 +940,9 @@ public class ScreenPanel extends Panel {
if ((renderer.getMarker() == null) && buttonMarker.isSelected()) {
buttonMarker.setSelected(false);
}
if (!renderer.isPaused() && (dataTableDialog!=null) && (dataTableDialog.isShowing())){
updateImageData();
}
updateZoom();
updateColormap();
updateStop();
@@ -1045,7 +1060,9 @@ public class ScreenPanel extends Panel {
double[] saux = new double[sum.length];
int[] p = new int[sum.length];
double[] x_egu = renderer.getCalibration().getAxisX(sum.length);
xCom = getCom(sum, x_egu);
double[] comRms = getComRms(sum, x_egu);
xCom = comRms[0];
xRms = comRms[1];
int[] x = Arr.indexesInt(sum.length);
DescriptiveStatistics stats = new DescriptiveStatistics(sum);
double min = stats.getMin();
@@ -1064,14 +1081,16 @@ public class ScreenPanel extends Panel {
double[] fit = getFitFunction(gaussian, x);
int[] y = new int[x.length];
for (int i = 0; i < x.length; i++) {
y[i] = (int) (height - 1 - ((((fit[i] + min) / height - minPlot) / rangePlot) * profileSize));
p[i] = (int) (height - 1 - (((sum[i] / height- minPlot) / rangePlot) * profileSize));
y[i] = (int) (height - 1 - ((((fit[i] + min) / height - minPlot) / rangePlot) * profileSize));
}
vgaussian = new Overlays.Polyline(penFit, x, y);
}
}
}
if (showProfile){
for (int i = 0; i < x.length; i++) {
p[i] = (int) (height - 1 - (((sum[i] / height- minPlot) / rangePlot) * profileSize));
}
vprofile = new Overlays.Polyline(renderer.getPenProfile(), x, p);
}
} catch (Exception ex) {
@@ -1083,7 +1102,9 @@ public class ScreenPanel extends Panel {
double[] saux = new double[sum.length];
int[] p = new int[sum.length];
double[] y_egu = renderer.getCalibration().getAxisY(sum.length);
yCom = getCom(sum, y_egu);
double[] comRms = getComRms(sum, y_egu);
yCom = comRms[0];
yRms = comRms[1];
int[] x = Arr.indexesInt(sum.length);
DescriptiveStatistics stats = new DescriptiveStatistics(sum);
double min = stats.getMin();
@@ -1105,14 +1126,16 @@ public class ScreenPanel extends Panel {
int[] y = new int[x.length];
for (int i = 0; i < x.length; i++) {
y[i] = (int) ((((fit[i] + min) / width - minPlot) / rangePlot) * profileSize);
p[i] = (int) (((sum[i] / width - minPlot) / rangePlot) * profileSize);
y[i] = (int) ((((fit[i] + min) / width - minPlot) / rangePlot) * profileSize);
}
hgaussian = new Overlays.Polyline(penFit, y, x);
}
}
}
if (showProfile){
for (int i = 0; i < x.length; i++) {
p[i] = (int) (((sum[i] / width - minPlot) / rangePlot) * profileSize);
}
hprofile = new Overlays.Polyline(renderer.getPenProfile(), p, x);
}
@@ -1141,9 +1164,7 @@ public class ScreenPanel extends Panel {
Point textPosition = new Point(12, 20);
if (showProfile){
if ((xCom != null) && (yCom != null)) {
String text = ((xRms != null) && (yRms != null)) ?
String.format("com x: m=" + fmt + " \u03C3=" + fmt + "\ncom y: m=" + fmt + " \u03C3=" + fmt,xCom, xRms,yCom, yRms) :
String.format("com x: m=" + fmt + "\ncom y: m=" + fmt ,xCom, yCom);
String text = String.format("com x: m=" + fmt + " \u03C3=" + fmt + "\ncom y: m=" + fmt + " \u03C3=" + fmt,xCom, xRms,yCom, yRms);
textCom = new Overlays.Text(renderer.getPenProfile(), text, new Font(Font.MONOSPACED, 0, 14), textPosition);
textCom.setFixed(true);
textCom.setAnchor(Overlay.ANCHOR_VIEWPORT_TOP_LEFT);
@@ -1288,22 +1309,26 @@ public class ScreenPanel extends Panel {
return ret.toArray(new Overlay[0]);
}
double getCom(double[] arr, double[] x) {
if (arr == null) {
return Double.NaN;
double[] getComRms(double[] arr, double[] x) {
if (arr != null) {
double xmd = 0;
double xmd2 = 0;
double total = 0;
for (int i=0; i< arr.length; i++) {
double v = (arr[i] * x[i]);
xmd += v;
xmd2 += (v * x[i]);
total += arr[i];
}
if (total > 0) {
double com = xmd / total;
double com2 = xmd2 / total;
double rms = Math.sqrt(Math.abs(com2 - com * com));
return new double[] {com, rms};
}
}
int index = 0;
double ret = 0;
double total = 0;
for (double v : arr) {
ret += (v * x[index++]);
total += v;
}
if (total == 0) {
return Double.NaN;
}
return ret / total;
}
return new double[]{Double.NaN, Double.NaN};
}
double[] fitGaussianScript(int[] y, int[] x) {
ScriptManager sm = Context.getInstance().getScriptManager();
@@ -1633,12 +1658,74 @@ public class ScreenPanel extends Panel {
}
}
void showIdentifiers(){
StandardDialog dataTableDialog;
DefaultTableModel dataTableModel;
void showImageData(){
dataTableModel = null;
if (camera instanceof Camtool){
List<String> ids = ((Camtool)camera).getValue().getIdentifiers();
if ((dataTableDialog!=null) && (dataTableDialog.isShowing())){
SwingUtils.centerComponent(getTopLevel(), dataTableDialog);
dataTableDialog.requestFocus();
return;
}
List<String> ids = new ArrayList(((Camtool)camera).getValue().getIdentifiers());
Collections.sort(ids);
String msg = String.join("\n", ids);
SwingUtils.showMessage(getTopLevel(), "Camtool Identifiers", msg);
//String msg = String.join("\n", ids);
//SwingUtils.showMessage(getTopLevel(), "Image Data", msg);
dataTableModel = new DefaultTableModel(new Object[0][2], new String[]{"Name", "Value"}) {
public Class getColumnClass(int columnIndex) {
return String.class;
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
};
for (String id : ids){
dataTableModel.addRow(new Object[]{id, ""});
}
updateImageData();
StreamValue val = ((Camtool)camera).getStream().take();
JTable dataTable = new JTable(dataTableModel);
dataTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
dataTable.getTableHeader().setReorderingAllowed(false);
dataTable.getTableHeader().setResizingAllowed(true);
dataTableDialog = new StandardDialog(getTopLevel(), "Image Data", false);
dataTableDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE );
JScrollPane scrollPane = new JScrollPane();
scrollPane.setViewportView(dataTable);
scrollPane.setPreferredSize(new Dimension(300, 400));
dataTableDialog.setContentPane(scrollPane);
dataTableDialog.pack();
SwingUtils.centerComponent(getTopLevel(), dataTableDialog);
dataTableDialog.setVisible(true);
dataTableDialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
dataTableModel = null;
}
});
}
}
void updateImageData(){
if (dataTableModel!=null){
if (camera instanceof Camtool){
for (int i = 0 ; i< dataTableModel.getRowCount(); i++){
String id = String.valueOf(dataTableModel.getValueAt(i, 0));
Object obj = ((Camtool)camera).getValue(id);
if (obj!=null){
if (obj.getClass().isArray()){
obj = obj.getClass().getName();
} else if (obj instanceof Double){
obj = Convert.roundDouble((Double) obj, 1);
} else if (obj instanceof Float){
obj = Convert.roundDouble((Float) obj, 1);
}
}
dataTableModel.setValueAt(String.valueOf(obj), i, 1);
}
}
}
}
@@ -2467,6 +2554,7 @@ public class ScreenPanel extends Panel {
pauseSelection.setValue(imageBuffer.size());;
}
}
updateImageData();
}
} catch (Exception ex) {
ex.printStackTrace();

View File

@@ -5,12 +5,13 @@ import ch.psi.pshell.epics.ControlledVariable as ControlledVariable
#CAMERA = "S10DI01-DSCR020" #"simulation"
#CAMERA = "SINDI02-DLAC055" #"simulation"
#CAMERA = "S10BD01-DSCR030" #"simulation"
CAMERA = "S10BD01-DSCR030" #"simulation"
#CAMERA = "SINDI01-DSCR080" #"simulation"
CAMERA = "SINEG01-DSCR190" #"simulation"
#CAMERA = "SINEG01-DSCR190" #"simulation"
#QUADRUPOLE = "S10CB02-MQUA230" # quadrupole for the scan with S10DI01-DSCR020: S10CB02-MQUA230
CHARGE_BPM = "SINDI01-DBPM060:Q1"
CHARGE_ICT = "S10DI01-DICT025:B1_CHARGE-OP"
WirePos = "SINDI01-DWSC090:MOTOR_1.RBV"
#RANGE = (-3.0, 0.0)
#STEPS = 100
#SETTLING_TIME = 1
@@ -51,7 +52,7 @@ set_device_alias(m,"image")
bpm = Channel(CHARGE_BPM, 'd', alias = "Charge BPM")
ict = Channel(CHARGE_ICT, 'd', alias = "Charge ICT")
wcs = Channel(WirePos, 'd', alias = "Wire position")
#Metadata
try:
@@ -79,8 +80,8 @@ try:
#readables.remove(camtool.stream.getChild("image"))
#readables.insert(0,m)
# lscan(quad, readables, RANGE[0], RANGE[1], STEPS, latency=SETTLING_TIME)
mscan(camtool.stream, (m, x_profile, y_profile, x_axis, y_axis), 1)
#tscan((m, x_profile, y_profile, x_axis, y_axis, bpm, wcs), 10, 1.0) #Saves 10 samples waiting 1.0 s between them
tscan((m, x_profile, y_profile, x_axis, y_axis, bpm, wcs), 20, 0.11)
finally:
# quad.close()
camtool.stop()

View File

@@ -0,0 +1,20 @@
camtool.start("SLG-LCAM-C041")
v=camtool.stream.take()
ids = v.getIdentifiers()
vals = v.getValues()
for i in range(len(ids)):
if "__len__" in dir(vals[i]):
print ids[i] + " = " + str(type(vals[i]))
else:
print ids[i] + " = " + str(vals[i])
for id in ids:
obj = camtool.getValue(id)
if (obj is None):
obj="null"
elif "__len__" in dir(obj):
obj = type(obj)
print str(id) + " = " + str(obj)