You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让photutils仅绘制满足指定条件的孔径

你创建的CircularAperture对象默认包含了所有检测到的星体的位置信息,每次调用plot方法都会绘制全部孔径,才会出现你遇到的重复绘制问题。
修改逻辑很简单:先按条件筛选出符合要求的星体,再仅用这部分星体的坐标创建孔径对象即可,不需要遍历所有星体做判断。
你可以把代码中从positions = np.transpose(...)开始到末尾的部分,替换为以下内容:

# 筛选星等小于-2的星体
# 若列名不确定可以替换为 sources[sources.colnames[-1]] < -2 取最后一列判断
filtered_sources = sources[sources['mag'] < -2]

# 仅使用符合条件的星体坐标创建孔径
positions = np.transpose((filtered_sources['xcentroid'], filtered_sources['ycentroid']))
apertures = CircularAperture(positions, r = 4.)

norm = ImageNormalize(stretch = SqrtStretch())
plt.imshow(data, cmap = 'Greys', origin = 'lower', norm = norm,
           interpolation = 'nearest')

# 批量绘制所有符合条件的孔径
apertures.plot(color = 'r', lw = 1.5, alpha = 0.5)

# 如果需要打印符合条件的星等,单独加这段即可
for source in filtered_sources:
    print(source['mag'])

修改后就只会在符合条件的星体周围绘制红色孔径,不会出现重复绘制全量孔径的问题。另外你原代码最后的apertures.plot行缺少闭合右括号,上面的代码也做了补全。

内容的提问来源于stack exchange,提问作者Jim421616

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 16:54:03