파일 (다운로드 test.fits) 자르기 후 보존되지 않습니다좌표를 맞는이 고려 다음 코드를
from astropy.io import fits
from photutils.utils import cutout_footprint
# Read fits file.
hdulist = fits.open('test.fits')
hdu_data = hdulist[0].data
hdulist.close()
# Some center and box to crop
xc, yc, xbox, ybox = 267., 280., 50., 100.
# Crop image.
hdu_crop = cutout_footprint(hdu_data, (xc, yc), (ybox, xbox))[0]
# Add comment to header
prihdr = hdulist[0].header
prihdr['COMMENT'] = "= Cropped fits file")
# Write cropped frame to new fits file.
fits.writeto('crop.fits', hdu_crop, prihdr)
을 원본 (왼쪽)와 (오른쪽) 이미지는 다음과 같이립니다 :
프레임 중앙의 별에 대한 (ra, dec) equatorial coordinates은 다음과 같습니다.
Original frame: 12:10:32 +39:24:17
Cropped frame: 12:12:07 +39:06:50
자른 프레임에서 좌표가 다른 이유는 무엇입니까?
두 가지 방법을 사용하여이를 해결할 수있는 두 가지 방법이 있습니다.
from astropy.io import fits
from photutils.utils import cutout_footprint
from astropy.wcs import WCS
from astropy.nddata.utils import Cutout2D
import datetime
# Read fits file.
hdulist = fits.open('test.fits')
hdu = hdulist[0].data
# Header
hdr = hdulist[0].header
hdulist.close()
# Some center and box to crop
xc, yc, xbox, ybox = 267., 280., 50., 100.
# First method using cutout_footprint
# Crop image.
hdu_crop = cutout_footprint(hdu, (xc, yc), (ybox, xbox))[0]
# Read original WCS
wcs = WCS(hdr)
# Cropped WCS
wcs_cropped = wcs[yc - ybox // 2:yc + ybox // 2, xc - xbox // 2:xc + xbox // 2]
# Update WCS in header
hdr.update(wcs_cropped.to_header())
# Add comment to header
hdr['COMMENT'] = "= Cropped fits file ({}).".format(datetime.date.today())
# Write cropped frame to new fits file.
fits.writeto('crop.fits', hdu_crop, hdr)
# Second method using Cutout2D
# Crop image
hdu_crop = Cutout2D(hdu, (xc, yc), (xbox, ybox), wcs=WCS(hdr))
# Cropped WCS
wcs_cropped = hdu_crop.wcs
# Update WCS in header
hdr.update(wcs_cropped.to_header())
# Add comment to header
hdr['COMMENT'] = "= Cropped fits file ({}).".format(datetime.date.today())
# Write cropped frame to new fits file.
fits.writeto('crop.fits', hdu_crop.data, hdr)
가브리엘 - 아, 알았어 주셔서 감사합니다. 지금 photutils 태그를 클릭하면 "photutils 태그에는 사용법에 대한 지침이 없습니다. 만들 수 있습니까?" '세부 정보'를 클릭하면 정보가 혼란스럽고 제안한 내용이 표시되지 않습니다. 저는 전원 사용자가 아니기 때문에 어디에서보고해야하는지 알고 계시다면 보내주십시오. 프로세스 나 새로운 제안 태그에서 향상시킬 수있는 것처럼 보입니다. – Christoph
내가 준 태그 설명은 피어 리뷰를 기다리고 있습니다. 나는 당신이 이것을 볼 수 있다고 생각했습니다. 이 문제와 관련하여 질문을 Meta에 게시 할 수 있습니까? http://meta.stackoverflow.com/ – Gabriel
@Gabriel 질문에 솔루션을 편집하는 대신 솔루션 (예 : Cutout2D)이 포함 된 답변을 게시하고 문제의 솔루션 부분을 다시 제거하십시오. 대답으로 받아 들일 수도 있습니다! – MSeifert