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=',')
You'll want to use the to_string()
method on altaz
. That will give you a list of strings, each entry of which is has an altitude an azimuth number (they are separated by a space, so you can .split()
them or whatever). Then you can write it out with numpy or your other library of choice.
Alternately, if you want to go straight to a file, you can create an astropy Table
, and have columns 'alt'
and 'az'
that you respectively set equal to altaz.alt
and altaz.az
. Then you can .write(format='ascii')
that table.