Healpix将经度、纬度转换为银河系坐标

2024-09-27 09:32:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个Healpix像素协调文件 https://wwwmpa.mpa-garching.mpg.de/~ensslin/research/data/faraday2020.html

这包含我想在skyplot中实现的纬度和经度值。 然而,这些值需要首先转换为银河系坐标(l,b)

我的密码是:

from astropy.io import fits
from astropy import units as u
from astropy.coordinates import Galactic
import matplotlib.pyplot as plt
import h5py
from astropy_healpix import HEALPix

filename='pixel_coords_map_ring_galactic_res9.fits'

hdulist=fits.open(filename) 
nside = hdulist[1].header['NSIDE']
order = hdulist[1].header['ORDERING']
hp = HEALPix(nside=nside, order=order, frame=Galactic())    

print(hdulist[1].header)

ggl = hdulist[1].data['LONGITUDE']           #storing coordinate values in ggl and ggb
ggb = hdulist[1].data['LATITUDE'] 

gl = ggl * u.degree                            #convering to galactic coordinates
gb = ggb * u.degree

c = Galactic(l=gl,b=gb) 

l_rad = c.l.wrap_at(180 * u.deg).radian
b_rad = c.b.radian

有没有更有效的方法来实现从长lat到galactic或Healpix功能的转换?请帮忙


Tags: fromimportdataasorderheaderfitshealpix
1条回答
网友
1楼 · 发布于 2024-09-27 09:32:35

这段代码来自我之前写的一个答案。在银河系坐标系中,它不是把长纬度转换成u度吗?Ref:Plotting mean and standard dev values on skyplot using astropy
注意:这是我用来获取HEALPix文件的链接:('pixel_coords_map_ring_galactic_res9.fits')

from astropy.io import fits                        
from astropy import units as u
from astropy.coordinates import SkyCoord

fits_file = 'pixel_coords_map_ring_galactic_res9.fits'  #healpix

with fits.open(fits_file) as hdulist:
    nside = hdulist[1].header['NSIDE']
    order = hdulist[1].header['ORDERING']
        
    ggl = hdulist[1].data['LONGITUDE']           #storing coordinate values in ggl and ggb
    ggb = hdulist[1].data['LATITUDE'] 
    
    gl = ggl * u.degree                            #convering to galactic coordinates
    gb = ggb * u.degree
    
    c = SkyCoord(l=gl,b=gb, frame='galactic', unit = (u.deg, u.deg))  
    l_rad = c.l.wrap_at(180 * u.deg).radian            #X Axis
    b_rad = c.b.radian
    print(len(l_rad), len(b_rad))

相关问题 更多 >

    热门问题