Skip to content

Instantly share code, notes, and snippets.

@StuartLittlefair
Created May 31, 2018 13:52
Show Gist options
  • Save StuartLittlefair/18a5c5271b099945a00a03454d9c34c2 to your computer and use it in GitHub Desktop.
Save StuartLittlefair/18a5c5271b099945a00a03454d9c34c2 to your computer and use it in GitHub Desktop.
Use broadcasting to transform many SkyCoords into frames with vector properties
from astropy.coordinates import SkyCoord, EarthLocation
from astropy.coordinates.tests.utils import randomly_sample_sphere
from astropy.time import Time
import numpy as np
# 1000 random locations on the sky
ra, dec, _ = randomly_sample_sphere(1000)
coos = SkyCoord(ra, dec)
# 300 times over the space of 10 hours
times = Time.now() + np.linspace(-5, 5, 300)*u.hour
# note the use of broadcasting so that 300 times broadcast against 1000 positions
aa_frame = coord.AltAz(obstime=times[:, np.newaxis],
location=EarthLocation.of_site('lapalma'))
# calculate alt-az of each object at each time.
aa_coos = coos.transform_to(aa_frame)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment