Skip to content

Instantly share code, notes, and snippets.

@dfm
Last active July 16, 2020 12:37
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 dfm/b5a21357dc2d3191ffd30e3ebd219cee to your computer and use it in GitHub Desktop.
Save dfm/b5a21357dc2d3191ffd30e3ebd219cee to your computer and use it in GitHub Desktop.
from astropy.io import ascii
import astropy.units as u
from astropy.coordinates import SkyCoord
from astroquery.gaia import Gaia
def find_one(ra, dec, mag):
coord = SkyCoord(ra=ra, dec=dec, unit=(u.deg, u.deg))
radius = 5 * u.arcsec
j = Gaia.cone_search_async(coord, radius)
r = j.get_results()
# Restrict the magnitude
r = r[abs(r["phot_g_mean_mag"] - mag) < 1.0]
if not len(r):
return float("nan")
# Select the closest target
r = r[0]
return float(r["lum_val"])
data = ascii.read("https://arxiv.org/src/1501.01635v3/anc/Tables5_6_7.txt")
with open("lbol.csv", "w") as f:
for row in data:
f.write(
f'{row["Name"]},{find_one(row["RAdeg"], row["DEdeg"], row["Gaiamag"])}\n'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment