1

I have tried debugging my code and I've realised that ultimately it breaks down when I try to save my AltAz coordinates into a .csv file because its not a numpy array, its a SkyCoord object. Could someone suggest a simple of way of converting a large table of Equatorial coordinates to AltAz or how I can get my code to save to file.

 # 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=',')
4

1 回答 1

1

你会想to_string()altaz. 这将为您提供一个字符串列表,其中的每个条目都有一个高度和方位角数字(它们用空格分隔,因此您可以使用.split()它们或其他)。然后你可以用 numpy 或你选择的其他库写出来。

或者,如果你想直接进入一个文件,你可以创建一个 astropy Table,并有列'alt''az'你分别设置为altaz.altaltaz.az。然后你可以.write(format='ascii')那张桌子。

于 2016-01-20T17:52:24.233 回答