我有一个(1727,1853)大小的数组(图像),其中我已经确定了恒星来模拟点扩散函数。阵列的每个索引对应于图像坐标,然而,每个星的质心由子像素坐标给出。我必须做以下
答案 0 :(得分:3)
您可以在每个切片中表达像素的中心坐标。相对于恒星的质心,然后计算加权的二维直方图。
首先,一些示例数据:
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()
加权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)