【发布时间】:2016-01-20 16:38:35
【问题描述】:
我已经尝试调试我的代码,并且我意识到当我尝试将 AltAz 坐标保存到 .csv 文件时它最终会崩溃,因为它不是一个 numpy 数组,它是一个 SkyCoord 对象。有人可以建议一种将大赤道坐标表转换为 AltAz 的简单方法,或者如何让我的代码保存到文件中。
# Get time now
time = astropy.time.Time.now()
time.delta_ut1_utc = 0
# Geodetic coordinates of observatory (example here: Munich)
observatory = astropy.coordinates.EarthLocation(
lat=48.21*u.deg, lon=11.18*u.deg, height=532*u.m)
# Alt/az reference frame at observatory, now
frame = astropy.coordinates.AltAz(obstime=time, location=observatory)
# Look up (celestial) spherical polar coordinates of HEALPix grid.
theta, phi = hp.pix2ang(nside, np.arange(npix))
# Convert to Equatorial coordinates
radecs = astropy.coordinates.SkyCoord(
ra=phi*u.rad, dec=(0.5*np.pi - theta)*u.rad)
# Transform grid to alt/az coordinates at observatory, now
altaz = radecs.transform_to(frame)
#Transpose array from rows to columns
altaz_trans=np.transpose(altaz)
np.savetxt('altaz.csv',altaz_trans,fmt='%s', delimiter=',')
【问题讨论】:
-
np.savetxt相当原始,astropy 内置了更好的选项来处理天文学家喜欢制作的各种文本文件。下面的答案讨论了几个不错的选择。
标签: python numpy coordinate-systems astropy healpy