编程语言
首页 > 编程语言> > python-从图像堆叠星型PSF;对齐亚像素中心

python-从图像堆叠星型PSF;对齐亚像素中心

作者:互联网

我有一个(1727,1853)大小数组(图像),在其中确定了恒星以模拟点扩散函数.数组的每个索引对应于一个图像坐标,但是,每个星星的质心由一个子像素坐标给出.我必须执行以下操作

>制作每个星星的2D切片.我已经使用numpy的数组切片完成了此操作.但是,它按索引切片,并且我具有亚像素质心坐标,因此,我进行的任何切片都会使星形偏离中心.
>在对每颗恒星进行2D切片后,必须将这些阵列彼此堆叠,以建立点扩散函数模型.只要每个星形的子像素中心对齐,这都是简单的.

我的问题是对齐这些子像素坐标并将每个2D切片堆叠在一起的最有效(最正确)方法是什么?

我希望这是清楚的.任何帮助将非常感激.以下是其中一颗恒星的2D切片(不是很好),但由于偏离索引的numpy切片和星星的质心具有亚像素坐标,因此它偏离中心.

enter image description here

解决方法:

您可以表达每个“切片”中像素相对于恒星质心的中心坐标,然后计算加权2D直方图.

首先,一些示例数据:

import numpy as np
from matplotlib import pyplot as plt

# pixel coordinates (integer)
x, y = np.mgrid[:100, :100]
# centroids (float)
cx, cy = np.random.rand(2, 9) * 100

# a Gaussian kernel to represent the PSF
def gausskern(x, y, cx, cy, sigma):
    return np.exp(-((x - cx) ** 2 + (y - cy) ** 2) / (2 * sigma ** 2))

# (nstars, ny, nx)
stars = gausskern(x[None, ...], y[None, ...],
                  cx[:, None, None], cy[:, None, None], 10)

# add some noise for extra realism
stars += np.random.randn(*stars.shape) * 0.5

fig, ax = plt.subplots(3, 3, figsize=(5, 5))
for ii in xrange(9):
    ax.flat[ii].imshow(stars[ii], cmap=plt.cm.hot)
    ax.flat[ii].set_axis_off()
fig.tight_layout()

enter image description here

加权2D直方图:

# (nstars, ny, nx) pixel coordinates relative to each centroid
dx = cx[:, None, None] - x[None, ...]
dy = cy[:, None, None] - y[None, ...]

# 2D weighted histogram
bins = np.linspace(-50, 50, 100)
h, xe, ye = np.histogram2d(dx.ravel(), dy.ravel(), bins=bins,
                           weights=stars.ravel())

fig, ax = plt.subplots(1, 1, subplot_kw={'aspect':'equal'})
ax.hold(True)
ax.pcolormesh(xe, ye, h, cmap=plt.cm.hot)
ax.axhline(0, ls='--', lw=2, c='w')
ax.axvline(0, ls='--', lw=2, c='w')
ax.margins(x=0, y=0)

enter image description here

标签:astronomy,arrays,python,numpy
来源: https://codeday.me/bug/20191119/2040077.html