为什么WCS投影子图上的要素在matplotlib中放在错误的位置? [英] Why features on WCS projected subplot are in the wrong place in matplotlib?

查看:39
本文介绍了为什么WCS投影子图上的要素在matplotlib中放在错误的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a fits file about an astronomical object. I can plot it like this:

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)

这有效,并产生了一张漂亮的照片:

This works, and produces a nice pic:

我想为这个图添加一些额外的功能,但这是行不通的.例如,让我们尝试将圆添加到119°,-67°30'.我通过以下方式扩展代码:

I would like to add some additional features to this plot, which doesn't work. For example lets try to add a circle to 119°, -67°30'. I expand the code by:

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

我得到的是:

这实际上不是我们想要的,圆大约在118°5',-67°5',而不是应该在的位置(119°,-67°30').

Which is really not what we wanted, the circle is around 118°5', -67°5', not where it is supposed to be (119°, -67°30').

我哪里出错了,或者有什么好的解决方法可以解决这个问题?

What am I getting wrong, or what is a good fix to this issue?

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

Note: when I run wcs = WCS(hdul.header), I get a warning:

警告:Verify警告:验证报告的错误:[astropy.io.fits.verify]警告:VerifyWarning:卡"A_2_0"不是FITS标准(无效值字符串:'3.29341755408e-05').固定的符合FITS标准的"A_2_0"卡.[astropy.io.fits.verify]警告:VerifyWarning:注意:astropy.io.fits 使用基于零的索引.[astropy.io.fits.verify]警告:Verify警告:卡"A_1_1"不是FITS标准(无效值字符串:'1.51709339878e-05').修复了A_1_1"卡以符合 FITS 标准.[astropy.io.fits.verify]警告:VerifyWarning:卡"A_0_2"不是FITS 标准(无效值字符串:'5.17973753556e-06').固定的符合FITS标准的"A_0_2"卡.[astropy.io.fits.verify]警告:验证警告:卡"B_2_0"不是FITS标准(无效值字符串:"2.97627426087e-06").修复了B_2_0"卡以满足适合标准.[astropy.io.fits.verify]警告:Verify警告:卡'B_1_1' 不是 FITS 标准(无效值字符串:'2.71948126373e-05').修复了B_1_1"卡以符合 FITS 标准.[astropy.io.fits.verify]警告:VerifyWarning:卡"B_0_2"不是FITS标准(无效值字符串:'1.66848449653e-05').固定的符合FITS标准的"B_0_2"卡.[astropy.io.fits.verify]警告:VerifyWarning:卡AP_1_0"不是 FITS 标准(无效值字符串:"1.79541533196e-06").固定了"AP_1_0"卡以满足适合标准.[astropy.io.fits.verify]警告:Verify警告:卡AP_0_1"不是 FITS 标准(无效值字符串:'9.20624843151e-07').修复了AP_0_1"卡以符合 FITS 标准.[astropy.io.fits.verify] 警告:VerifyWarning:卡AP_2_0"不是FITS标准(无效值字符串:'-3.29292923201e-05').固定的符合FITS标准的"AP_2_0"卡.[astropy.io.fits.verify]警告:VerifyWarning:卡"AP_1_1"不是FITS标准(无效值字符串:'-1.51738446887e-05').修复了"AP_1_1"卡可以满足适合标准.[astropy.io.fits.verify] 警告:VerifyWarning:卡"AP_0_2"不是FITS标准(无效值字符串:'-5.18321445978e-06').修复了"AP_0_2"卡符合FITS标准的问题.[astropy.io.fits.verify] 警告:VerifyWarning:卡片BP_1_0"不是FITS 标准(无效值字符串:'8.99029048217e-07').固定的符合FITS标准的"BP_1_0"卡.[astropy.io.fits.verify]警告:VerifyWarning:卡BP_0_1"不是 FITS 标准(无效值字符串:'1.15967736014e-06').修复了"BP_0_1"卡满足适合标准.[astropy.io.fits.verify] 警告:VerifyWarning:卡'BP_2_0' 不是 FITS 标准(无效值字符串:'-2.97837492348e-06').修复了"BP_2_0"卡符合FITS标准的问题.[astropy.io.fits.verify]警告:VerifyWarning:卡"BP_1_1"不是FITS 标准(无效值字符串:'-2.71998518336e-05').固定的符合FITS标准的"BP_1_1"卡.[astropy.io.fits.verify]警告:Verify警告:卡"BP_0_2"不是FITS标准(无效值字符串:-1.66872388359e-05").修复了"BP_0_2"卡满足适合标准.[astropy.io.fits.verify] 警告:VerifyWarning:卡"WCSR_PRJ"不是FITS标准(无效值字符串:"3.6679e-07").修复了"WCSR_PRJ"卡符合FITS标准的问题.[astropy.io.fits.verify] 警告:VerifyWarning:卡片WCSR_PIX"是不是FITS标准(无效值字符串:'8.2565e-05').固定的"WCSR_PIX"卡符合FITS标准.[astropy.io.fits.verify]

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]

所以这可能是相关的;如何解决它的问题仍然存在.

So this might be relevant; question of how to fix it still holds.

推荐答案

To plot in world coordinates, you need to specify the transform, e.g.:

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

通常,您可以忽略那些FITS标头警告,因为那里没有FITS标头卡与WCS(afaik)相关.

Generally, you can ignore those FITS header warnings, since none of the FITS header cards there are related to the WCS (afaik).

这篇关于为什么WCS投影子图上的要素在matplotlib中放在错误的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆