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

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

>制作每个星星的2D切片.我已经使用numpy的数组切片完成了此操作.但是,它按索引切片,并且我具有亚像素质心坐标,因此,我进行的任何切片都会使星形偏离中心.

>在对每颗恒星进行2D切片后,必须将这些阵列彼此堆叠,以建立点扩散函数模型.只要每个星形的子像素中心对齐,这都是简单的.

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

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

rvpHq.png

解决方法:

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

NxZ23.png

加权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)

6pztn.png

标签:astronomy,arrays,python,numpy

来源: https://codeday.me/bug/20191119/2040077.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值