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,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()