imdata.py 文件源码

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

项目:sparselab 作者: eht-jp 项目源码 文件源码
def rotate(self, angle=0, deg=True, save_totalflux=False):
        '''
        Rotate the input image

        Arguments:
          self: input imagefite.imagefits object
          angle (float): Rotational Angle. Anti-clockwise direction will be positive (same to the Position Angle).
          deg (boolean): It true, then the unit of angle will be degree. Otherwise, it will be radian.
          save_totalflux (boolean): If true, the total flux of the image will be conserved.
        '''
        # create output fits
        outfits = copy.deepcopy(self)
        if deg:
            degangle = -angle
            radangle = -np.deg2rad(angle)
        else:
            degangle = -np.rad2deg(angle)
            radangle = -angle
        #cosa = np.cos(radangle)
        #sina = np.sin(radangle)
        Nx = outfits.header["nx"]
        Ny = outfits.header["ny"]
        for istokes in np.arange(self.header["ns"]):
            for ifreq in np.arange(self.header["nf"]):
                image = outfits.data[istokes, ifreq]
                # rotate data
                newimage = sn.rotate(image, degangle)
                # get the size of new data
                My = newimage.shape[0]
                Mx = newimage.shape[1]
                # take the center of the rotated image
                outfits.data[istokes, ifreq] = newimage[np.around(My / 2 - Ny / 2):np.around(My / 2 - Ny / 2) + Ny,
                                                        np.around(Mx / 2 - Nx / 2):np.around(Mx / 2 - Nx / 2) + Nx]
                # Flux Scaling
                if save_totalflux:
                    totalflux = self.totalflux(istokes=istokes, ifreq=ifreq)
                    outfits.data[istokes, ifreq] *= totalflux / \
                        outfits.totalflux(istokes=istokes, ifreq=ifreq)
        outfits.update_fits()
        return outfits
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号