python - 为什么 WCS 投影子图上的特征在 matplotlib 中位于错误的位置?

标签 python python-3.x matplotlib projection astropy

我有一个关于天文物体的拟合文件。我可以这样绘制:

from astropy.io import fits
from astropy.wcs import WCS

hdul = fits.open(fitsfilename)[0]

wcs = WCS(hdul.header)
fig = plt.figure(figsize=(12,12))
fig.add_subplot(111, projection=wcs)
plt.imshow(hdul.data)

这有效,并产生了漂亮的图片:

enter image description here

我想向该图中添加一些附加功能,但这不起作用。例如,让我们尝试将一个圆添加到 119°, -67°30'。我通过以下方式扩展代码:

plt.scatter([119],[-67.5],c='r',s=500)

我得到的是:

enter image description here

这确实不是我们想要的,圆在 118°5', -67°5' 附近,而不是它应该在的位置 (119°, -67°30')。

我做错了什么,或者这个问题有什么好的解决办法?

<小时/>

注意:当我运行 wcs = WCS(hdul.header) 时,我收到警告:

WARNING: VerifyWarning: Verification reported errors: [astropy.io.fits.verify] WARNING: VerifyWarning: Card 'A_2_0' is not FITS standard (invalid value string: '3.29341755408e-05'). Fixed 'A_2_0' card to meet the FITS standard. [astropy.io.fits.verify] WARNING: VerifyWarning: Note: astropy.io.fits uses zero-based indexing. [astropy.io.fits.verify] WARNING: VerifyWarning: Card 'A_1_1' is not FITS standard (invalid value string: '1.51709339878e-05'). Fixed 'A_1_1' card to meet the FITS standard. [astropy.io.fits.verify] WARNING: VerifyWarning: Card 'A_0_2' is not FITS standard (invalid value string: '5.17973753556e-06'). Fixed 'A_0_2' card to meet the FITS standard. [astropy.io.fits.verify] WARNING: VerifyWarning: Card 'B_2_0' is not FITS standard (invalid value string: '2.97627426087e-06'). Fixed 'B_2_0' card to meet the FITS standard. [astropy.io.fits.verify] WARNING: VerifyWarning: Card 'B_1_1' is not FITS standard (invalid value string: '2.71948126373e-05'). Fixed 'B_1_1' card to meet the FITS standard. [astropy.io.fits.verify] WARNING: VerifyWarning: Card 'B_0_2' is not FITS standard (invalid value string: '1.66848449653e-05'). Fixed 'B_0_2' card to meet the FITS standard. [astropy.io.fits.verify] WARNING: VerifyWarning: Card 'AP_1_0' is not FITS standard (invalid value string: '1.79541533196e-06'). Fixed 'AP_1_0' card to meet the FITS standard. [astropy.io.fits.verify] WARNING: VerifyWarning: Card 'AP_0_1' is not FITS standard (invalid value string: '9.20624843151e-07'). Fixed 'AP_0_1' card to meet the FITS standard. [astropy.io.fits.verify] WARNING: VerifyWarning: Card 'AP_2_0' is not FITS standard (invalid value string: '-3.29292923201e-05'). Fixed 'AP_2_0' card to meet the FITS standard. [astropy.io.fits.verify] WARNING: VerifyWarning: Card 'AP_1_1' is not FITS standard (invalid value string: '-1.51738446887e-05'). Fixed 'AP_1_1' card to meet the FITS standard. [astropy.io.fits.verify] WARNING: VerifyWarning: Card 'AP_0_2' is not FITS standard (invalid value string: '-5.18321445978e-06'). Fixed 'AP_0_2' card to meet the FITS standard. [astropy.io.fits.verify] WARNING: VerifyWarning: Card 'BP_1_0' is not FITS standard (invalid value string: '8.99029048217e-07'). Fixed 'BP_1_0' card to meet the FITS standard. [astropy.io.fits.verify] WARNING: VerifyWarning: Card 'BP_0_1' is not FITS standard (invalid value string: '1.15967736014e-06'). Fixed 'BP_0_1' card to meet the FITS standard. [astropy.io.fits.verify] WARNING: VerifyWarning: Card 'BP_2_0' is not FITS standard (invalid value string: '-2.97837492348e-06'). Fixed 'BP_2_0' card to meet the FITS standard. [astropy.io.fits.verify] WARNING: VerifyWarning: Card 'BP_1_1' is not FITS standard (invalid value string: '-2.71998518336e-05'). Fixed 'BP_1_1' card to meet the FITS standard. [astropy.io.fits.verify] WARNING: VerifyWarning: Card 'BP_0_2' is not FITS standard (invalid value string: '-1.66872388359e-05'). Fixed 'BP_0_2' card to meet the FITS standard. [astropy.io.fits.verify] WARNING: VerifyWarning: Card 'WCSR_PRJ' is not FITS standard (invalid value string: '3.6679e-07'). Fixed 'WCSR_PRJ' card to meet the FITS standard. [astropy.io.fits.verify] WARNING: VerifyWarning: Card 'WCSR_PIX' is not FITS standard (invalid value string: '8.2565e-05'). Fixed 'WCSR_PIX' card to meet the FITS standard. [astropy.io.fits.verify]

所以这可能是相关的;如何修复它的问题仍然存在。

最佳答案

world coordinates 中绘制,您需要指定转换,例如:

ax = fig.gca()
ax.scatter([34], [3.2], transform=ax.get_transform('world'))

通常,您可以忽略这些 FITS header 警告,因为没有任何 FITS header 卡与 WCS 相关(据我所知)。

关于python - 为什么 WCS 投影子图上的特征在 matplotlib 中位于错误的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54109929/

相关文章:

python - 计算字母出现次数 Python

python - python中函数的自适应绘图

python - Doc2vec:如何手动修改 Doc2Vec gensim 模型中的训练向量?

python - 如果我需要跳过列表之间的某些字符,如何转换列表列表中的列表?

python - 如何减小 Python 创建的 txt 文件的大小?

python - 在python中提取定界符[]之间的单词

python - 如何访问具有特定 Class 属性值的 Class 实例?

python - 与 sys.getsizeof() 的结果相比,整数的大内存占用

3d - 如何使用任意法线将 matplotlib 2D 补丁转换为 3D?

python - 分析 pandas 中多个 .txt 文件的数据