This commit is contained in:
voulot_d
2017-05-30 17:28:37 +02:00
parent a65efe7076
commit 202cf3bb79
7 changed files with 110 additions and 32 deletions

View File

@@ -1,16 +1,16 @@
#Mon May 29 14:54:24 CEST 2017
#Tue May 30 17:05:36 CEST 2017
colormap=Flame
colormapAutomatic=true
colormapMax=2000.0
colormapMin=0.0
colormapMax=35000.0
colormapMin=300.0
flipHorizontally=false
flipVertically=false
grayscale=false
imageHeight=2160
imageWidth=2560
imageHeight=1680
imageWidth=1744
invert=false
regionStartX=1
regionStartY=1
regionStartX=433
regionStartY=241
rescaleFactor=1.0
rescaleOffset=0.0
roiHeight=-1
@@ -21,9 +21,9 @@ rotation=0.0
rotationCrop=false
scale=1.0
serverURL=localhost\:10000
spatialCalOffsetX=-96.58536606067958
spatialCalOffsetY=-67.48201620883489
spatialCalScaleX=-14.46944297232279
spatialCalScaleY=-13.605441964787545
spatialCalOffsetX=-1093.4812581603794
spatialCalOffsetY=-1098.5114274849898
spatialCalScaleX=-7.617446798629459
spatialCalScaleY=-7.774538463917676
spatialCalUnits=mm
transpose=false

View File

@@ -76,10 +76,13 @@
<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"/>
<TitledBorder title="Parameters (beam phase)"/>
</Border>
</Property>
</Properties>
<AccessibilityProperties>
<Property name="AccessibleContext.accessibleDescription" type="java.lang.String" value=""/>
</AccessibilityProperties>
<Layout>
<DimensionLayout dim="0">

View File

@@ -132,7 +132,7 @@ public class SchottkyScan extends Panel {
}
});
panelPars.setBorder(javax.swing.BorderFactory.createTitledBorder("Parameters"));
panelPars.setBorder(javax.swing.BorderFactory.createTitledBorder("Parameters (beam phase)"));
spinnerStep.setModel(new javax.swing.SpinnerNumberModel(5.0d, 1.0d, 90.0d, 1.0d));
@@ -305,6 +305,8 @@ public class SchottkyScan extends Panel {
.addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(17, 17, 17))
);
panelPars.getAccessibleContext().setAccessibleDescription("");
}// </editor-fold>//GEN-END:initComponents
private void buttonStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStartActionPerformed

View File

@@ -13,11 +13,13 @@ def hfitoff(data, xdeg):
xrad = xdeg / 180 * np.pi
optimize_func = lambda x: x[0] * np.sin(xrad + x[1]) + x[2] - data
fit_amplitude, fit_phase, fit_offset = leastsq(optimize_func, [guess_amplitude, guess_phase, guess_offset])[0]
if fit_amplitude < 0:
fit_amplitude = -fit_amplitude
fit_phase = fit_phase - np.pi
fit_xdeg = np.linspace(start, end, 100)
fit_data = fit_amplitude * np.sin(fit_xdeg / 180 * np.pi + fit_phase) + fit_offset
ph_crest = 90 - fit_phase / np.pi * 180
xdeg_max = xdeg[np.argmax(data)]
if start <= ph_crest <= end:
return (fit_amplitude, fit_phase, fit_offset, True, ph_crest, fit_xdeg, fit_data)
else:
return (fit_amplitude, fit_phase, fit_offset, False, xdeg_max, fit_xdeg, fit_data)
fit_phase_deg = fit_phase / np.pi * 180
ph_crest = 90 - fit_phase_deg
if ph_crest > 180:
ph_crest = ph_crest - 360
return (fit_amplitude, fit_phase_deg, fit_offset, ph_crest, fit_xdeg, fit_data)

View File

@@ -3,7 +3,7 @@ from jeputils import *
def hfitoff(data, xdeg):
ret = call_jep("CPython/hfitoff", "hfitoff", [to_npa(data),to_npa(xdeg)])
print ret
return (ret[0], ret[1], ret[2],ret[3], ret[4], ret[5].data,ret[6].data)
return (ret[0], ret[1], ret[2],ret[3], ret[4].data,ret[5].data)
def gfitoff(x, y, off=None, amp=None, com=None, sigma=None):
ret = call_jep("CPython/gfitoff", "gfitoff", [to_npa(x), to_npa(y), off, amp, com, sigma])

View File

@@ -1,5 +1,6 @@
from startup import *
from ijutils import *
from mathutils import *
from ch.psi.pshell.imaging.Overlays import *
import ch.psi.pshell.imaging.Pen as Pen
import java.awt.Color as Color
@@ -8,6 +9,9 @@ import ch.psi.pshell.imaging.ImageListener as ImageListener
from operator import add, mul, sub, truediv
from ch.psi.pshell.imaging.Utils import sub
REMOVE_BACKGROUND = True
PLOT_PROFILE = True
def get_centroid(source):
bi = source.getImage()
if bi is None:
@@ -33,6 +37,39 @@ def get_centroid(source):
def arroff(a, value = "mean"):
"""Subtract offset to all elemets in series.
Args:
a(list, tuple, array ...): subscriptable object containing numbers
type(int or str, optional): value to subtract from the array, or "mean" or "min".
Returns:
List
"""
if value=="mean":
value = mean(a)
elif value=="min":
value = min(a)
return [x-value for x in a]
def arrsubback(data, a, b):
"""Subtract offset to all elemets in series.
Args:
a(list, tuple, array ...): subscriptable object containing numbers
type(int or str, optional): value to subtract from the array, or "mean" or "min".
Returns:
List
"""
return [y-(a*y+b) for y in a]
import ch.psi.pshell.imaging.Filter as Filter
@@ -117,23 +154,47 @@ class ImageStats(DeviceBase):
self.rms_x_samples, self.rms_y_samples = [], []
for i in range(self.num_images):
if type(self.source) is not ch.psi.pshell.imaging.FileSource:
#print "A"
self.source.waitNext(5000)
#print "B"
#time.sleep(0.2)
#print "Ok"
#centroid = get_centroid(self.source)
#print "cent ", centroid
#if centroid is not None:
# self.com_x_samples.append(centroid[0])
# self.com_y_samples.append(centroid[1])
x_profile = self.source.data.integrateVertically(True)
# self.com_y_samples.append(centroid[1])
x_profile = self.source.data.integrateVertically(True)
x_profile_x = self.source.data.getRowSelectionX(True)
y_profile = self.source.data.integrateHorizontally(True)
com_x,rms_x = center_of_mass(x_profile, self.source.data.getRowSelectionX(True))
com_y,rms_y = center_of_mass(y_profile, self.source.data.getColSelectionX(True))
y_profile_x = self.source.data.getColSelectionX(True)
#Remove background
if (self.bg_en == False) and REMOVE_BACKGROUND:
(a, b, amp, com, sigma) = fit_gaussian_linear(x_profile, x_profile_x)
x_profile = [x_profile[i]-(a*x_profile_x[i]+b) for i in range(len(x_profile))]
(a, b, amp, com, sigma) = fit_gaussian_linear(y_profile, y_profile_x)
y_profile = [y_profile[i]-(a*y_profile_x[i]+b) for i in range(len(y_profile))]
com_x,rms_x = center_of_mass(x_profile, x_profile_x)
com_y,rms_y = center_of_mass(y_profile, y_profile_x)
self.com_x_samples.append(com_x)
self.com_y_samples.append(com_y)
self.rms_x_samples.append(rms_x)
self.rms_y_samples.append(rms_y)
if PLOT_PROFILE:
p = get_plots("Profile")
if (p is None) or (len(p)==0):
p = plot([x_profile, y_profile], ["x_profile", "yprofile"], [x_profile_x,y_profile_x], title ="Profile")
else:
p[0].removeMarker(None)
p[1].removeMarker(None)
p[0].getSeries(0).setData(x_profile_x, x_profile)
p[1].getSeries(0).setData(y_profile_x, y_profile)
p[0].addMarker(com_x, None, "COM = " + str(com_x), Color.GREEN)
p[1].addMarker(com_y, None, "COM = " + str(com_y), Color.GREEN)
def setNumberOfImages(self, value):
self.num_images = value
@@ -182,7 +243,7 @@ if __name__ == "__builtin__":
#print get_centroid(simulated_source)
add_device(ImageStats("image_stats", cam3), True)
#cam3.waitNext(5000)
cam3.waitNext(2000)
image_stats.enableBackground(False)
#for i in range (10):
# image_stats.update()

View File

@@ -1,11 +1,11 @@
import ch.psi.pshell.epics.ControlledVariable as ControlledVariable
if get_exec_pars().source == CommandSource.ui:
start = -30.0
stop = 30.0
start = -10.0
stop = 10.0
step = 5.0
nb = 1
lat = 0.100
nb = 3
lat = 0.300
else:
start = args[0]
stop = args[1]
@@ -13,8 +13,8 @@ else:
nb = int(args[3])
lat = args[4]
phase = ControlledVariable("Phase", "SINEG01-RSYS:SET-VSUM-PHASE", "SINEG01-RSYS:GET-VSUM-PHASE")
#phase = ControlledVariable("Phase", "S10CB09-RSYS:SET-VSUM-PHASE", "S10CB09-RSYS:SET-VSUM-PHASE")
phase = ControlledVariable("Phase", "SINEG01-RSYS:SET-BEAM-PHASE", "SINEG01-RSYS:GET-BEAM-PHASE")
#phase = ControlledVariable("Phase", "S10CB09-RSYS:SET-BEAM-PHASE", "S10CB09-RSYS:SET-BEAM-PHASE")
phase.config.minValue =-180.0
phase.config.maxValue = 360.0
phase.config.precision = 3
@@ -50,3 +50,13 @@ index_max = y.index(max(y))
phase_ref = x[index_max] - 80
set_return(phase_ref)
# save the entry in the logbook
#if get_option("Generated data file:\n" + get_exec_pars().path +"\n\n" + "Save to ELOG?", "YesNo") == "Yes":
# log_msg = "Start: %0.1f" % start + "deg\n"
# log_msg = log_msg + "Stop: %0.1f" % stop + "deg\n"
# log_msg = log_msg + "Step: %0.1f" % nb + "deg\n"
# log_msg = log_msg + "Nb samples: %0.0f" % nb + "\n"
# log_msg = log_msg + "Latency: %0.3f" % lat + "s\n"
# log_msg = log_msg + "Data file: " + get_exec_pars().path
# elog("Schottky Scan", log_msg, get_plot_snapshots())