def cpimage(self, fitsdata, save_totalflux=False, order=3):
'''
Copy the first image into the image grid specified in the secondaly input image.
Arguments:
fitsdata: input imagefite.imagefits object. This image will be copied into self.
self: input imagefite.imagefits object specifying the image grid where the orgfits data will be copied.
save_totalflux (boolean): If true, the total flux of the image will be conserved.
'''
# generate output imfits object
outfits = copy.deepcopy(self)
dx0 = fitsdata.header["dx"]
dy0 = fitsdata.header["dy"]
Nx0 = fitsdata.header["nx"]
Ny0 = fitsdata.header["ny"]
Nxr0 = fitsdata.header["nxref"]
Nyr0 = fitsdata.header["nyref"]
dx1 = outfits.header["dx"]
dy1 = outfits.header["dy"]
Nx1 = outfits.header["nx"]
Ny1 = outfits.header["ny"]
Nxr1 = outfits.header["nxref"]
Nyr1 = outfits.header["nyref"]
coord = np.zeros([2, Nx1 * Ny1])
xgrid = (np.arange(Nx1) + 1 - Nxr1) * dx1 / dx0 + Nxr0 - 1
ygrid = (np.arange(Ny1) + 1 - Nyr1) * dy1 / dy0 + Nyr0 - 1
x, y = np.meshgrid(xgrid, ygrid)
coord[0, :] = y.reshape(Nx1 * Ny1)
coord[1, :] = x.reshape(Nx1 * Ny1)
for idxs in np.arange(outfits.header["ns"]):
for idxf in np.arange(outfits.header["nf"]):
outfits.data[idxs, idxf] = sn.map_coordinates(
fitsdata.data[idxs, idxf], coord, order=order,
mode='constant', cval=0.0, prefilter=True).reshape([Ny1, Nx1]
) * dx1 * dy1 / dx0 / dy0
# Flux Scaling
if save_totalflux:
totalflux = fitsdata.totalflux(istokes=idxs, ifreq=idxf)
outfits.data[idxs, idxf] *= totalflux / \
outfits.totalflux(istokes=idxs, ifreq=idxf)
outfits.update_fits()
return outfits
评论列表
文章目录