Closedown

This commit is contained in:
sfop
2016-09-23 10:00:40 +02:00
parent 80d48a83d1
commit c2e69088f6
7 changed files with 6 additions and 345 deletions

View File

@@ -1,4 +1,5 @@
CamerasSimple.java=disabled
Correlation.java=enabled
Cameras.java=disabled
ScreenPanel.java=disabled
Camtool.java=disabled
LaserGunAlignment.java=enabled

View File

@@ -1,83 +0,0 @@
from startup import *
from ijutils import *
from ch.psi.pshell.imaging.Overlays import *
import ch.psi.pshell.imaging.Pen as Pen
import java.awt.Color as Color
import random
class BpmStats(DeviceBase):
def __init__(self, name, prefix, read_interval = 0.1):
DeviceBase.__init__(self, name)
self.read_interval = read_interval
self.prefix = prefix
self.bpm_x = Channel(prefix + ":X1", type = 'd', alias = name + " x")
self.bpm_y = Channel(prefix + ":Y1", type = 'd', alias = name + " y")
self.com_x_samples, self.com_y_samples = [], []
class ComX(Readable):
def read(self):
if len(self.image_stats.com_x_samples)==0: return None
return mean(self.image_stats.com_x_samples)
self.com_x_mean = ComX(); self.com_x_mean.image_stats = self
class ComY(Readable):
def read(self):
if len(self.image_stats.com_y_samples)==0: return None
return mean(self.image_stats.com_y_samples)
self.com_y_mean = ComY(); self.com_y_mean.image_stats = self
class ComXVar(Readable):
def read(self):
if len(self.image_stats.com_x_samples)==0: return None
return stdev(self.image_stats.com_x_samples)
self.com_x_stdev = ComXVar(); self.com_x_stdev.image_stats = self
class ComXVar(Readable):
def read(self):
if len(self.image_stats.com_y_samples)==0: return None
return stdev(self.image_stats.com_y_samples)
self.com_y_stdev = ComXVar(); self.com_y_stdev.image_stats = self
set_device_alias(self.com_x_mean, name + " x mean")
set_device_alias(self.com_y_mean, name + " y mean")
set_device_alias(self.com_x_stdev, name + " x stdev")
set_device_alias(self.com_y_stdev, name + " y stdev")
self.num_images = 1
self.initialize()
def doUpdate(self):
self.com_x_samples, self.com_y_samples = [], []
for i in range(self.num_images):
time.sleep(self.read_interval)
cx = self.bpm_x.read()
cy = self.bpm_y.read()
print "centroid ",[cx,cy]
self.com_x_samples.append(cx)
self.com_y_samples.append(cy)
def setNumberOfImages(self, value):
self.num_images = value
def enableBackground(self, value):
pass
def captureBackground(self, images):
pass
def doClose(self):
pass
def start(self):
pass
def stop(self):
pass
if __name__ == "__builtin__":
add_device(BpmStats("bpm_com", "SINEG01-DBPM340"), True)
bpm_com.setNumberOfImages(5)
for i in range (10):
bpm_com.update()
print bpm_com.take(), bpm_com.com_x_mean.read(), bpm_com.com_y_mean.read()
time.sleep(1)

View File

@@ -1,62 +0,0 @@
import math
from mathutils import fit_polynomial, PolynomialFunction
from plotutils import plot_line, plot_function
import org.apache.commons.math3.stat.correlation.PearsonsCorrelation as PearsonsCorrelation
if get_context().source == CommandSource.ui:
dx = "SINEG01-MSOL130:X"
dy = "SINEG01-MSOL130:Y"
interval = 0.20
window = 40
p = plot(None, "Data")[0]
if isinstance(dx, basestring):
dx = Channel(dx) if get_device(dx) is None else get_device(dx)
if isinstance(dy, basestring):
dy = Channel(dy) if get_device(dy) is None else get_device(dy)
sd=p.getSeries(0)
sd.setLinesVisible(False)
sd.setPointSize(4)
marker=None
while(True):
#Sample and plot data
x=dx.read()
y=dy.read()
sd.appendData(x, y)
if len(sd.x) > window:
#Remove First Element
sd.token.remove(0)
ax = sd.x
ay = sd.y
if len(ax)>2:
x1, x2 = min(ax), max(ax)
res = (x2-x1)/100
if x1!=x2:
#Display correlation
corr= PearsonsCorrelation().correlation(to_array(ax,'d'), to_array(ay,'d'))
s = "Correlation=" + str(round(corr,4))
#print s
if marker is not None:
p.removeMarker(marker)
marker = p.addMarker(x2+res, p.AxisId.X, s, p.getBackground())
marker.setLabelPaint(Color.BLACK)
#Calculate, print and plot linear fit
pars_lin = (a0,a1) = fit_polynomial(ay, ax, 1)
#print "Fit lin a1:" , a1, " a0:",a0
y1 = poly(x1, pars_lin)
y2 = poly(x2, pars_lin)
plot_line(p, x1, y1, x2, y2, width = 2, color = Color.BLUE, name = "Fit Linear")
#Calculate, print and plot quadratic fit
pars_quad = (a0,a1,a2) = fit_polynomial(ay, ax, 2)
#print "Fit quad a2:" , a2, "a1:" , a1, " a0:",a0
fitted_quad_function = PolynomialFunction(pars_quad)
ax = frange(x1, x2, res, True)
plot_function(p, fitted_quad_function, "Fit Quadratic", ax, color=Color.GREEN)
time.sleep(interval)

View File

@@ -9,7 +9,10 @@ if get_context().source == CommandSource.ui:
dy = "SINEG01-MSOL130:Y"
interval = 0.20
window = 40
p = plot(None, "Data")[0]
p = plot(None)[0]
p.removeSeries(p.getSeries(0))
p.addSeries(LinePlotSeries("Data"))
if isinstance(dx, basestring):
dx = Channel(dx) if get_device(dx) is None else get_device(dx)

View File

@@ -1,52 +0,0 @@
import math
from mathutils import fit_polynomial, PolynomialFunction
from plotutils import plot_line
if get_context().source == CommandSource.ui:
dx = "SINEG01-DICT215:B1_CHARGE"
dy = "SINEG01-DICT210:GUN_CHARGE"
interval = 0.10
window = 20
p = plot(None, "Data")[0]
if isinstance(dx, basestring): dx = Channel(dx)
if isinstance(dy, basestring): dy = Channel(dy)
sd=p.getSeries(0)
#d.setLinesVisible(False)
sd.setPointSize(4)
p.addSeries(LinePlotSeries("Fit Quadratic"))
sfq=p.getSeries(1)
while(True):
#Sample and plot data
x=dx.read()
y=dy.read()
sd.appendData(x, y)
if len(sd.x) > window:
#Remove First Element
sd.token.remove(0)
ax = sd.x
ay = sd.y
if len(ax)>2:
#Calculate, print and plot linear fit
pars_lin = (a0,a1) = fit_polynomial(ay, ax, 1)
print "Fit lin a1:" , a1, " a0:",a0
x1 = min(ax); y1 = poly(x1, pars_lin)
x2 = max(ax); y2 = poly(x2, pars_lin)
plot_line(p, x1, y1, x2, y2, width = 2, color = Color.GREEN, name = "Fit Linear")
#Calculate, print and plot quadratic fit
pars_quad = (a0,a1,a2) = fit_polynomial(ay, ax, 2)
print "Fit quad a2:" , a2, "a1:" , a1, " a0:",a0
fitted_quad_function = PolynomialFunction(pars_quad)
ay=[]
ax = frange(x1, x2, 1 if (x2==x1) else (x2-x1)/100, True)
for x in ax:
ay.append(fitted_quad_function.value(x))
plot_function(plot, fitted_quad_function, "Fit Quadratic", ax, color=Color.BLUE)
#sfq.setData(ax, ay)
time.sleep(interval)

View File

@@ -1,137 +0,0 @@
from startup import *
from ijutils import *
from ch.psi.pshell.imaging.Overlays import *
import ch.psi.pshell.imaging.Pen as Pen
import java.awt.Color as Color
import random
def get_centroid(source):
bi = source.getImage()
if bi is None:
return None
op = show_panel(bi, "Original")
ip = load_image(bi)
plot(get_histogram(ip), title = "Histogram")
grayscale(ip)
invert(ip)
gaussian_blur(ip)
auto_threshold(ip)
#binary_erode(ip)
show_panel(ip.getBufferedImage(), "Image")
(results,output_img)=analyse_particles(ip, 2000,20000, exclude_edges=False, print_table=True)
op.clearOverlays()
show_panel(output_img.getBufferedImage(), "Outlines")
if results.size()>0:
centroid = (results.getValue("XM",0), results.getValue("YM",0))
ov = Crosshairs(Pen(Color.ORANGE), java.awt.Point(int(centroid[0]),int(centroid[1])), java.awt.Dimension(15,15))
op.addOverlay(ov)
return centroid
import ch.psi.pshell.imaging.Filter as Filter
class SimulatedSource(Filter):
def process(self, img, data):
self.img=img
if img is None:
return None
ip = load_image(img)
pad_h = int((random.random()-0.5) * 500)
pad_v = int((random.random()-0.5) * 500)
#print "Pad = " , (pad_h, pad_v)
ip = pad_image(ip, -pad_h, pad_h, pad_v, -pad_v, fill_color = Color.BLACK)
return ip.getBufferedImage()
#return img
def waitNext(self, timeout):
self.pushImage(self.process(self.img, None))
class ImageStats(DeviceBase):
def __init__(self, name, source):
DeviceBase.__init__(self, name)
self.source = source
self.com_x_samples, self.com_y_samples = [], []
class ComX(Readable):
def read(self):
if len(self.image_stats.com_x_samples)==0: return None
return mean(self.image_stats.com_x_samples)
self.com_x_mean = ComX(); self.com_x_mean.image_stats = self
class ComY(Readable):
def read(self):
if len(self.image_stats.com_y_samples)==0: return None
return mean(self.image_stats.com_y_samples)
self.com_y_mean = ComY(); self.com_y_mean.image_stats = self
class ComXVar(Readable):
def read(self):
if len(self.image_stats.com_x_samples)==0: return None
return stdev(self.image_stats.com_x_samples)
self.com_x_stdev = ComXVar(); self.com_x_stdev.image_stats = self
class ComXVar(Readable):
def read(self):
if len(self.image_stats.com_y_samples)==0: return None
return stdev(self.image_stats.com_y_samples)
self.com_y_stdev = ComXVar(); self.com_y_stdev.image_stats = self
set_device_alias(self.com_x_mean, name + " com x mean")
set_device_alias(self.com_y_mean, name + " com y mean")
set_device_alias(self.com_x_stdev, name + " com x stdev")
set_device_alias(self.com_y_stdev, name + " com y stdev")
self.bg_en = False
self.num_images = 1
self.initialize()
def doUpdate(self):
self.com_x_samples, self.com_y_samples = [], []
for i in range(self.num_images):
if type(self.source) is not ch.psi.pshell.imaging.FileSource:
self.source.waitNext(3000)
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])
def setNumberOfImages(self, value):
self.num_images = value
def enableBackground(self, value):
self.bg_en = value
def captureBackground(self, images):
self.doInitialize()
def doClose(self):
pass
def start(self):
pass
def stop(self):
pass
def get_simulated_source(img):
simulated_source = SimulatedSource()
simulated_source.img=None
simulated_source.initialize()
img.addListener(simulated_source)
show_panel(simulated_source)
return simulated_source
if __name__ == "__builtin__":
simulated_source = get_simulated_source(image)
print get_centroid(simulated_source)
add_device(ImageStats("image_stats", simulated_source), True)
image_stats.enableBackground(False)
for i in range (10):
image_stats.update()
print image_stats.take(), image_stats.com_x_mean.read(), image_stats.com_y_mean.read()
time.sleep(1)

View File

@@ -1,9 +0,0 @@
import datetime
knob = Channel("SINEG01-RSYS:SET-BEAM-PHASE", 'd', alias = "RF phase")
instrument = Channel("SINEG01-DICT215:CHARGE", 'd', alias = "Bunch Charge (ICT)")
r = lscan(knob, [instrument], -120., 60., 10.,2.0)
elog("SchottkyICT", "Data file: " + get_context().path + "\n\n" + r.print() , get_plot_snapshots())