为什么 WCS 投影子图上的特征在 matplotlib 中的位置错误?
Why features on WCS projected subplot are in the wrong place in matplotlib?
我有一个关于天体的适合文件。我可以这样画:
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)
这有效,并生成了一张漂亮的照片:
我想为这个情节添加一些额外的功能,但这不起作用。例如,让我们尝试添加一个圆到 119°,-67°30'。我通过以下方式扩展代码:
plt.scatter([119],[-67.5],c='r',s=500)
我得到的是:
这真的不是我们想要的,圆在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 中绘图,您需要指定 transform
,例如:
ax = fig.gca()
ax.scatter([34], [3.2], transform=ax.get_transform('world'))
通常,您可以忽略那些 FITS header 警告,因为 none 的 FITS header 卡与 WCS (afaik) 有关。
我有一个关于天体的适合文件。我可以这样画:
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)
这有效,并生成了一张漂亮的照片:
我想为这个情节添加一些额外的功能,但这不起作用。例如,让我们尝试添加一个圆到 119°,-67°30'。我通过以下方式扩展代码:
plt.scatter([119],[-67.5],c='r',s=500)
我得到的是:
这真的不是我们想要的,圆在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 中绘图,您需要指定 transform
,例如:
ax = fig.gca()
ax.scatter([34], [3.2], transform=ax.get_transform('world'))
通常,您可以忽略那些 FITS header 警告,因为 none 的 FITS header 卡与 WCS (afaik) 有关。