Skip to content

Instantly share code, notes, and snippets.

@jorgepiloto
Created October 12, 2022 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgepiloto/847ee0e594b243cc7abc24d6771331b9 to your computer and use it in GitHub Desktop.
Save jorgepiloto/847ee0e594b243cc7abc24d6771331b9 to your computer and use it in GitHub Desktop.
Use Astropy to manipulate HYG database
from astropy.coordinates import SkyCoord, Angle, Distance
from astropy.table import Table
from astropy import units as u
def main():
# Read stars data into an astropy table
# https://www.astronexus.com/downloads/catalogs/hygdata_v3.csv.gz
stars_table = Table.read("hygdata_v3.csv")
# Get positions in ICRS
stars_positions_icrs = SkyCoord(
ra=Angle(stars_table["ra"], unit=u.deg),
dec=Angle(stars_table["dec"], unit=u.deg),
distance=Distance(stars_table["dist"], unit=u.parsec),
frame="icrs",
copy=False,
)
# Convert to galactocentric positions and retrieve the XYZ coordinates
stars_positions_galactocentric = stars_positions_icrs.galactocentric
x, y, z = [getattr(stars_positions_galactocentric, axis) for axis in "xyz"]
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment