绘制天文散点图 - 平均值与经度(银河系)

Plotting astronomical scatter plot - mean vs longitude (galactic)

我想在healpix文件中创建一个以X轴为经度坐标的散点图 https://wwwmpa.mpa-garching.mpg.de/~ensslin/research/data/faraday2020.html (Healpix)

和 Y 轴作为 hdf5 文件中的平均值 https://wwwmpa.mpa-garching.mpg.de/~ensslin/research/data/faraday2020.html(法拉第天空 2020)

到目前为止的代码:

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

filename='pixel_coords_map_ring_galactic_res9.fits'                       #healpix

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)
print(nside)
print(order)

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

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

c = Galactic(l=gl,b=gb) 
l_rad = c.l.wrap_at(180 * u.deg).radian            #X Axis
b_rad = c.b.radian

with h5py.File('faraday2020.hdf5','r') as hdf:            #importing raw data from hdf5 file
    print(hdf.keys())
    faraday_sky_mean = hdf['faraday_sky_mean'][:]           #Y Axis
    faraday_sky_std = hdf['faraday_sky_std'][:]

鉴于经度和均值采用不同的格式,我完全不知道如何绘制二维方形散点图。另外,我需要经度在银河系坐标中。请帮忙。

我认为你很接近。恕我直言,此散点图比使用两个天空图坐标 (projection="aitoff") 绘制更容易。该过程类似于我在您之前的问题中发布的答案:。您只需要对函数参数进行一些小调整。

我修改了您的代码以创建二维散点图。以下是差异的简要总结:

  • 已更改 from astropy.coordinates import SkyCoord(而不是 HEALPix
  • 更改了 matplot 类型(删除projection=
  • 在散点图上将 y 变量从 b_rad 更改为 faraday_sky_mean
  • 已从 plt.scatter() 中删除 c=faraday_sky_mean,因此数据点没有颜色编码。

请参阅下面的代码。

from astropy import units as u
from astropy.coordinates import SkyCoord
import matplotlib.pyplot as plt
import h5py
#from astropy_healpix import HEALPix
import numpy as np

fits_file = 'pixel_coords_map_ring_galactic_res9.fits'                       #healpix
faraday_file = 'faraday2020.hdf5'

with fits.open(fits_file) as hdulist:
    nside = hdulist[1].header['NSIDE']
    order = hdulist[1].header['ORDERING']
    #hp = HEALPix(nside=nside, order=order, frame=Galactic())    
    
    #print(hdulist[1].header)
    #print(nside)
    #print(order)
    
    ggl = hdulist[1].data['LONGITUDE']           #storing coordinate values in ggl and ggb
    ggb = hdulist[1].data['LATITUDE'] 
    #print(ggl)
    
    gl = ggl * u.degree                            #convering to galactic coordinates
    gb = ggb * u.degree
    #print(gl)
    
    #c = Galactic(l=gl,b=gb) 
    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))

with h5py.File(faraday_file,'r') as hdf:            #importing raw data from hdf5 file
    #print(hdf.keys())
    faraday_sky_mean = hdf['faraday_sky_mean'][:]           #Y Axis
    print(len(faraday_sky_mean))
    faraday_sky_std = hdf['faraday_sky_std'][:]
    
plt.figure(figsize=(8,4.2))
plt.subplot(111)

plt.title("Mean", y=1.08, fontsize=20)
plt.grid(True)
P2 = plt.scatter(l_rad, faraday_sky_mean, s=20, cmap='hsv')

plt.subplots_adjust(top=0.95, bottom=0.0)
plt.xlabel('l (deg)', fontsize=20)
plt.ylabel('Mean', fontsize=20)

plt.subplots_adjust(top=0.95, bottom=0.0)
plt.show()
print('DONE')