kernel.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:CAAPR 作者: Stargrazer82301 项目源码 文件源码
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))

    # -----------------------------------------------------------------
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号