WCS 未出现在生成的 FITS 文件中

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

我正在尝试生成带有随机星星的 FITS 文件。由于某种原因,当我在 SAO DS9 中打开文件时,鼠标悬停不显示天空坐标,而是仅显示我鼠标悬停的像素位置。下面我展示了我在 Python 中使用的脚本来生成 FITS 文件,以及我在 DS9 中看到的内容:

import numpy as np
from pathlib import Path
import matplotlib.pyplot as plt
import pandas as pd
import os
from astropy.wcs import WCS
from astropy import units as u
from astropy.io import fits
from astropy.visualization import AsinhStretch, LogStretch
from astropy.visualization.mpl_normalize import ImageNormalize
from convenience_functions import show_image
from photutils.datasets import make_gaussian_sources_image, make_random_gaussians_table
from astropy.nddata import Cutout2D



def add_wcs(cntrpix,cntrval,cdelt,ctype, radesys):
    #zhdrbb.remove('ZODIL')
    #CREATE WCS KEYWORDS
    w = WCS(naxis=2)
    w.wcs.crpix = cntrpix
    w.wcs.crval = cntrval
    w.wcs.cdelt = cdelt
    w.wcs.ctype = ctype
    w.wcs.radesys = radesys
    w.wcs.equinox = 2000
    w.wcs.set_pv([(2, 1, 45.0)])
    w.wcs.cunit = [u.deg, u.deg]

    header = w.to_header()
    return header

def stars(image, number, mag_min, mag_max):
    """
    Add some stars to the image.
    """

    # Most of the code below is a direct copy/paste from
    # https://photutils.readthedocs.io/en/stable/_modules/photutils/datasets/make.html#make_100gaussians_image

    flux_min = 10**mag_min
    flux_max = 10**mag_max
    flux_range = [flux_min, flux_max]

    y_max, x_max = image.shape
    xmean_range = [0.01 * x_max, 0.99 * x_max]
    ymean_range = [0.01 * y_max, 0.99 * y_max]
    xstddev_range = [4, 4]
    ystddev_range = [4, 4]
    params = dict([('flux', flux_range),
                  ('x_mean', xmean_range),
                  ('y_mean', ymean_range),
                  ('x_stddev', xstddev_range),
                  ('y_stddev', ystddev_range),
                  ('theta', [0, 2*np.pi])])
    
    sources = make_random_gaussians_table(number, params, seed=int(random.random()*1e4))

    star_im = make_gaussian_sources_image(image.shape, sources)

    return sources, star_im

RA_0, RA_F = 30, 70
DEC_0, DEC_F = -20,20
MAG_0, MAG_F = 3, 8
N_STARS = 250

D_RA = np.abs(RA_0 - RA_F)
D_DEC = np.abs(DEC_0 - DEC_F)


GRID_LENGTH = int(2e3) # N PIXELS PER SIDE

# WCS STUFF
CRPIX = (int(GRID_LENGTH / 2), int(GRID_LENGTH / 2))
CRVAL = (RA_0 + D_RA / 2., DEC_0 + D_DEC / 2.)

cdelt_x = D_RA / GRID_LENGTH
cdelt_y = D_DEC / GRID_LENGTH
CDELT = (cdelt_x, cdelt_y)
CTYPE = ["RA-TAN", "DEC-TAN"]
RADESYS = 'ICRS'
base_pix_full_image = np.zeros((GRID_LENGTH,GRID_LENGTH))
star_data, star_cat_img = stars(base_pix_full_image, N_STARS, MAG_0, MAG_F)
# WCS
wcs_header = add_wcs(CRPIX, CRVAL, CDELT, CTYPE, RADESYS)

hdr = fits.Header()
hdu_cat = fits.PrimaryHDU(header=wcs_header,data=star_cat_img)

# WRITE FITS PIXEL FILE
hdu_cat.writeto(fits_pixel_file, overwrite=True)

从图像中,鼠标悬停在图像上会显示 x 和 y 指向像素坐标,即使标题中包含 WCS 信息。

我觉得我错过了一些非常简单的东西,只需要一双新的眼睛来解决问题。

python astropy astronomy fits ds9
1个回答
0
投票

看来需要将

CTYPE
设置为
CTYPE = ["RA---TAN", "DEC--TAN"]

这里引用了FITS 标准

CTYPEi – [字符串;索引;默认值:'␣'(即线性、未定义的轴)]。输入中间坐标轴 i。本标准或官方认可的 FITS 公约未涵盖的任何坐标类型均应视为线性。所有非线性坐标系名称必须以“4-3”形式表示:前四个字符指定坐标类型,第五个字符是连字符(“-”),其余三个字符指定用于计算的算法代码世界坐标值。名称少于四个字符的坐标类型在右侧用连字符填充,少于三个字符的算法代码在右侧用空格填充11。算法代码应该是三个字符。

© www.soinside.com 2019 - 2024. All rights reserved.