def recenter(self, centroid_method="2dg"):
"""
This function ...
:return:
"""
center_x = 0.5 * (self.xsize - 1)
center_y = 0.5 * (self.ysize - 1)
if centroid_method == "com": x_centroid, y_centroid = self.centroid_com()
elif centroid_method == "fit": x_centroid, y_centroid = self.centroid_fit()
elif centroid_method == "2dg": x_centroid, y_centroid = self.centroid_2dg()
elif centroid_method == "aniano": x_centroid, y_centroid = self.get_maximum_aniano()
else: raise ValueError("Invalid centroid method")
# Debugging
log.debug("The centroid coordinate of the kernel was found to be " + str(x_centroid) + ", " + str(y_centroid))
log.debug("The center of the kernel image is " + str(center_x) + ", " + str(center_y))
# Calculate shift
shift_x = center_x - x_centroid
shift_y = center_y - y_centroid
# If the shift is less than 0.2 pixel, don't shift
if shift_x < 0.2 and shift_y <= 0.2:
log.debug("Kernel is already perfectly aligned with the center: skipping recentering ...")
return
# Debugging
log.debug("Shifting the kernel center by (" + str(shift_x) + ", " + str(shift_y) + " pixels ...")
# Shift
self._data = shift(self._data, [shift_x, shift_y])
# CHECK AGAIN
if centroid_method == "com": x_centroid, y_centroid = self.centroid_com()
elif centroid_method == "fit": x_centroid, y_centroid = self.centroid_fit()
elif centroid_method == "2dg": x_centroid, y_centroid = self.centroid_2dg()
elif centroid_method == "aniano": x_centroid, y_centroid = self.get_maximum_aniano()
else: raise ValueError("Invalid centroid method")
new_shift_x = center_x - x_centroid
new_shift_y = center_y - y_centroid
new_shift_x_relative = abs(new_shift_x) / abs(shift_x)
new_shift_y_relative = abs(new_shift_y) / abs(shift_y)
#print("new shift x relative " + str(new_shift_x_relative))
#print("new shift y relative " + str(new_shift_y_relative))
if new_shift_x_relative >= 0.1: raise RuntimeError("The recentering of the kernel failed: new x shift = " + str(new_shift_x) + ", previous x shift = " + str(shift_x))
if new_shift_y_relative >= 0.1: raise RuntimeError("The recentering of the kernel failed: new y shift = " + str(new_shift_y) + ", previous y shift = " + str(shift_y))
# -----------------------------------------------------------------
评论列表
文章目录