Skip to content

Instantly share code, notes, and snippets.

@barentsen
Created September 15, 2016 17:32
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 barentsen/1190add9fe22cf867d5802f8d3034209 to your computer and use it in GitHub Desktop.
Save barentsen/1190add9fe22cf867d5802f8d3034209 to your computer and use it in GitHub Desktop.
Obtain discovery dates for all confirmed exoplanets in the NASA Exoplanet Archive
"""Obtain discovery dates for all confirmed exoplanets.
This script combines the NASA Exoplanet Archive and ADS API to obtain the
publication date for the discovery paper of all the confirmed exoplanets.
Author: Geert Barentsen
"""
import requests
import pandas as pd
# Configure your personal ADS API key below
ADS_TOKEN = open('/home/gb/.ads/dev_key', 'r').readlines()[0].strip()
# Extract the discovery bibcode for all confirmed exoplanets in the archive
planets = pd.read_csv('nexsci-confirmed-planets-20160913.csv')
bibcodes = []
for ref in planets.pl_disc_reflink:
if 'bibcode' in ref:
bibcode = ref.split('bibcode=')[1].split(' ')[0]
elif '/abs/' in ref:
bibcode = ref.split('/abs/')[1].split(' ')[0]
bibcodes.append(bibcode)
planets['discovery_bibcode'] = bibcodes
# Fetch the publication date for these bibcodes from the ADS API
query_data = "bibcode\n"+"\n".join(planets['discovery_bibcode'].unique())
r = requests.post('https://api.adsabs.harvard.edu/v1/search/bigquery',
params={'q': '*:*', 'wt': 'json', 'fq': '{!bitset}',
'fl': 'bibcode,pubdate', 'rows': 2*len(bibcodes)},
headers={'Authorization': 'Bearer ' + ADS_TOKEN},
data=query_data)
ads_response = pd.DataFrame(r.json()['response']['docs'])
# Merge the discovery dates with the original exoplanet archive table
planets_with_discovery_dates = planets.merge(ads_response,
left_on='discovery_bibcode',
right_on='bibcode')
planets_with_discovery_dates.to_csv('planets-with-discovery_dates.csv')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment