Created
October 12, 2022 18:02
-
-
Save jorgepiloto/847ee0e594b243cc7abc24d6771331b9 to your computer and use it in GitHub Desktop.
Use Astropy to manipulate HYG database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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