python - Astropy Cutout2D,引发 ValueError
问题描述
我正在尝试使用Astropy 的 Cutout2D测试提出的程序。我的目标是使用 RA 和 DEC 为我在地面实况目录中的每个来源提取 .png 图像。
文件的标题:
SIMPLE = T /
BITPIX = -32 /
NAXIS = 4 /
NAXIS1 = 30000 /
NAXIS2 = 30000 /
NAXIS3 = 1 /
NAXIS4 = 1 /
EXTEND = T /
BSCALE = 1.00000000000E+00 /
BZERO = 0.00000000000E+00 /
BLANK = -1 /
BUNIT = 'JY/BEAM ' /
DATE-OBS= '2000-01-01T12:00:00.0' /
CRPIX1 = 1.63840000000E+04 /
CDELT1 = -6.71387000000E-05 /
CRVAL1 = 0.00000000000E+00 /
CTYPE1 = 'RA---SIN' /
CRPIX2 = 1.63840000000E+04 /
CDELT2 = 6.71387000000E-05 /
CRVAL2 = -3.00000000000E+01 /
CTYPE2 = 'DEC--SIN' /
CRPIX3 = 1.00000000000E+00 /
CDELT3 = 4.20000000000E+08 /
CRVAL3 = 1.40000000000E+09 /
CTYPE3 = 'FREQ ' /
CRPIX4 = 1.00000000000E+00 /
CDELT4 = 1.00000000000E+00 /
CRVAL4 = 1.00000000000E+00 /
CTYPE4 = 'STOKES ' /
...
我使用从文档中复制的这个小脚本:
hdu = fits.open(file)[0]
data=hdu.data
w = WCS(file)
position = SkyCoord(24.17*u.deg, 15.78*u.deg,frame='fk5',equinox='J2000.0'
size = u.Quantity((10,10), u.arcsec)
cutout = Cutout2D(data, posit
ion, size, fill_value=np.nan, wcs=w)
我明白了:
Traceback (most recent call last):
File "###/Cutoff_patches.py", line 113, in <module>
cutout = Cutout2D(data, position, size, wcs=w)
File "##_venv/lib/python3.5/site-packages/astropy/nddata/utils.py", line 686, in __init__
return_position=True)
File "##_venv/lib/python3.5/site-packages/astropy/nddata/utils.py", line 211, in extract_array
shape, position, mode=mode)
File "##_venv/lib/python3.5/site-packages/astropy/nddata/utils.py", line 91, in overlap_slices
raise ValueError('"large_array_shape" and "small_array_shape" must '
ValueError: "large_array_shape" and "small_array_shape" must have the same number of dimensions.
我不知道为什么会发生这种情况以及如何解决它。
如前所述,我还尝试了重塑:
data = data.reshape(data.shape[2:])
并且,
data=np.squeeze(data)
但后来我对他们俩都一样:
Traceback (most recent call last):
File "##/Cutoff_patches.py", line 114, in <module>
cutout = Cutout2D(data, position, size, wcs=w)
File "##venv/lib/python3.5/site-packages/astropy/nddata/utils.py", line 686, in __init__
return_position=True)
File "/##_venv/lib/python3.5/site-packages/astropy/nddata/utils.py", line 211, in extract_array
shape, position, mode=mode)
File "##_venv/lib/python3.5/site-packages/astropy/nddata/utils.py", line 106, in overlap_slices
raise NoOverlapError('Arrays do not overlap.')
astropy.nddata.utils.NoOverlapError: Arrays do not overlap.
Process finished with exit code 1
解决方案
您可以将 FITS 文件缩小为 2D 图像,然后Cutout2D将更容易工作:
hdu = fits.open(file)[0]
data = hdu.data[0,0,:,:] # checkout image data
# modify header keywords
hdu.header['NAXIS'] = 2
hdu.header['WCSAXES']=2
# delete all keywords of additional axis
del hdu.header['NAXIS3']
del hdu.header['NAXIS4']
del hdu.header['CRPIX3']
...
w = WCS(hdu.header)
position = SkyCoord(24.17*u.deg, 15.78*u.deg,frame='fk5',equinox='J2000.0')
size = u.Quantity((10,10), u.arcsec)
cutout = Cutout2D(data, position, size, fill_value=np.nan, wcs=w)
推荐阅读
- c# - C# PerformanceCounter Requests/Sec 未更新
- java - 如何在 java OpenCV 上循环我的网络摄像头流
- javascript - 如何将 JSON 数据从 Node js 路由传递到 html 文件中的脚本?
- php - 如何使用php在邮件发送功能中显示错误
- android - Android Studio 中的 Javadoc View 等效项
- bash - 如何从 PATH 中具有相同名称的脚本调用 bash 函数
- sql - 在未执行的条件内获取 SQL 语法错误
- javascript - 您如何每次计算父 div 高度(当用户多次使用新浏览器时)
- java - Android:用于编译的JDK版本对最低支持的api有影响吗?
- android - 在 Android 中使用自定义 XML 元素时,我收到一条警告,指出不允许使用该元素。我该如何妥善处理?