简体   繁体   English

从FITS中提取WCS坐标

[英]Extracting WCS Coordinates from FITS

I am trying to change the coordinate system of a FITS file from its original Equatorial coordinate system to Galactic coordinates (in degrees)in order to manipulate the resulting FITS image using these coordinates. 我试图将FITS文件的坐标系从其原始赤道坐标系更改为银河坐标(以度为单位),以便使用这些坐标操纵生成的FITS图像。

For this, I would need to extract an array which contains the Equatorial positions of each pixel in order to transform them into the desired Galactic Coordinates. 为此,我需要提取一个包含每个像素的赤道位置的数组,以便将它们转换为所需的银河系坐标。 This is where my knowledge is limited, and cannot seem to figure out how to extract that array. 这是我的知识有限的地方,似乎无法弄清楚如何提取该数组。

Ultimately, I want to slice the image based on latitudes in the manner: 最终,我想以下列方式基于纬度切割图像:

import pyfits

f = pyfits.open("im1.fits")
h, data = f[0].header, f[0].data

#Here I would include the transformation from Equatorial to Galactic of
the position array doing something like:
coord = SkyCoord(ra, dec, frame=Galactic, unit='deg')

#This would do the slicing
from astropy.nddata import Cutout2D
from astropy import units as u
from astropy import coordinates

#Given a longitude and latitude
size = [mylon, mylat]
cut = Cutout2D(f, center, size, wcs=wcs)

You most likely want to regrid the data rather than transform all of the positions; 您最有可能想要重新调整数据而不是转换所有位置; if the data are on an equatorial grid, it is not possible to slice them along Galactic coordinates. 如果数据位于赤道网格上,则无法沿星系坐标对其进行切片。 reproject is the best astropy-based tool for this job. reproject是这项工作中最好的基于熵的工具。 You'll need to set up a Galactic header and reproject to that: 你需要设置一个Galactic标题并重新投影到:

import reproject
galheader = fits.Header.fromtextfile('gal.hdr')
myfitsfile = fits.open('im1.fits')
newim, weights = reproject.reproject_interp(myfitsfile, galheader)

You can also use reproject.reproject_exact , which uses a different reprojection algorithm. 您还可以使用reproject.reproject_exact ,它使用不同的重投影算法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM