从图像中堆叠星形 PSF;对齐子像素中心

mae*_*ist 4 python arrays numpy astronomy

我有一个 (1727,1853) 大小的数组(图像),其中我已经确定了星星来模拟点扩散函数。数组的每个索引对应一个图像坐标,然而,每个恒星的质心由一个子像素坐标给出。我必须做以下事情

  1. 制作每颗星星的二维切片。我已经使用 numpy 的数组切片做到了这一点。但是,它按索引切片,并且我有亚像素质心坐标,因此我制作的任何类型的切片都会使恒星偏离中心。

  2. 在我制作了每颗恒星的 2D 切片之后,我必须将这些阵列堆叠在一起以制作点扩散函数的模型。只要每颗恒星的子像素中心对齐,这很简单。

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

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

在此处输入图片说明

ali*_*i_m 5

您可以相对于恒星的质心表示每个“切片”中像素的中心坐标,然后计算加权的 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()
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

加权二维直方图:

# (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)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明