Python Astropy Cutout2D,提升值错误
我正在尝试使用Astropy的Cutout2D测试。我的目标是使用RA和DEC,为我在地面真相目录中的每个来源提取一个.png图像 文件的标题:Python Astropy Cutout2D,提升值错误,python,extraction,valueerror,astropy,fits,Python,Extraction,Valueerror,Astropy,Fits,我正在尝试使用Astropy的Cutout2D测试。我的目标是使用RA和DEC,为我在地面真相目录中的每个来源提取一个.png图像 文件的标题: SIMPLE = T / BITPIX = -32 / NAXIS =
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=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
回溯(最近一次呼叫最后一次):
文件“##/Cutoff_patches.py”,第114行,在
切口=切口2D(数据、位置、尺寸、wcs=w)
文件“##venv/lib/python3.5/site packages/astropy/nddata/utils.py”,第686行,在u init中__
返回(位置=真)
文件“/####venv/lib/python3.5/site packages/astropy/nddata/utils.py”,第211行,摘录数组
形状、位置、模式=模式)
文件“###venv/lib/python3.5/site packages/astropy/nddata/utils.py”,第106行,重叠切片
raise NoOverlapError('数组不重叠')
astropy.nddata.utils.NoOverlapError:数组不重叠。
进程已完成,退出代码为1
您可以将FITS文件缩小为2D图像,然后剪切2D将更容易工作:
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)
您可以将FITS文件缩小为二维图像,然后剪切2D将更容易工作:
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)
错误在哪里产生?你需要发表完整的文章。你可以通过点击文章底部的“编辑”链接来编辑你的问题。请将完整的回溯放在帖子中,确保格式正确,以便更清晰。我现在看到您的FITS标题,它是一个4-D数组,但其中两个维度的大小为1。尝试一下
data=data.resforme(data.shape[2:])
错误发生在哪里?你需要发表完整的文章。你可以通过点击文章底部的“编辑”链接来编辑你的问题。请将完整的回溯放在帖子中,确保格式正确,以便更清晰。我现在看到您的FITS标题,它是一个4-D数组,但其中两个维度的大小为1。尝试一下data=data.resforme(data.shape[2:])