Astropy Cutout2D,提高ValueError

问题描述 投票:1回答:1

我正在尝试使用Astropy's Cutout2D测试presented procedure。我的目标是使用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
python extraction valueerror astropy fits
1个回答
0
投票

您可以将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) 
© www.soinside.com 2019 - 2024. All rights reserved.