Skip to content

Instantly share code, notes, and snippets.

@juandesant
Last active January 5, 2023 20:52
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 juandesant/d33c8fe57e2f4004df6b5595d670c1ef to your computer and use it in GitHub Desktop.
Save juandesant/d33c8fe57e2f4004df6b5595d670c1ef to your computer and use it in GitHub Desktop.
This Python scripts creates four graphs for the evolution of author counts in astronomy papers from 1980 to 2022. It requires an [ADS Config Token][1] in order to work. [1]: https://ui.adsabs.harvard.edu/user/settings/token
import ads
import pandas as pd
ads.config.token='putYourOwnAdsConfigTokenHere'
bibgroups = [
"ALMA",
"CfA",
"CFHT",
"Chandra",
"ESO/Telescopes",
"Gemini",
"HST",
"NOAO",
"NOIRlab",
"SETI",
]
years = range(1980,2022+1)
# Please note that the query below is not necessary if you are recovering from a pickled file
results = {}
for bibgroup in bibgroups:
results[bibgroup] = {}
print(f"Bibgroup: {bibgroup}")
for year in years:
print(f"Year: {year}")
query_string = f'year:{year} bibgroup:"{bibgroup}"'
paper_query = ads.SearchQuery(
q=query_string,
fl=['id', 'bibcode', 'title', 'author', 'bibgroup', 'author_count'],
rows=2000,
sort="author_count"
)
results[bibgroup][year]=list(paper_query)
# Pickle data for saving and retrieval
# Save Pickled results
import pickle
with open('ads_pubs_results.pkl', 'wb') as rd:
pickle.dump(results, rd)
# Import Pickled results
with open('ads_pubs_results.pkl', 'rb') as rd:
results = pickle.load(rd)
# Create the Data Frame
data_rows = []
for telescope in results.keys():
for year in results[telescope].keys():
for article in results[telescope][year]:
row = {
'id': article.id,
'year': year,
'telescope': telescope,
'bibcode': article.bibcode,
'title': article.title,
'author': article.author,
'author_count': article.author_count,
}
data_rows.append(row)
articles = pd.DataFrame(data_rows)
# Create the graphics
median_all_observatories = articles.pivot_table(
index='year',
columns='telescope',
values='author_count',
aggfunc='median').plot.bar()
median_all_observatories.figure.savefig('All Observatories - Median.png')
mean_all_observatories = articles.pivot_table(
index='year',
columns='telescope',
values='author_count',
aggfunc='mean').plot.bar()
mean_all_observatories.figure.savefig('All Observatories - Mean.png')
mean_alma = articles[articles['telescope']=='ALMA'].pivot_table(
index='year',
columns='telescope',
values='author_count',
aggfunc='mean').plot.bar()
mean_alma.figure.savefig('ALMA - Mean.png')
median_alma = articles[articles['telescope']=='ALMA'].pivot_table(
index='year',
columns='telescope',
values='author_count',
aggfunc='median').plot.bar()
median_alma.figure.savefig('ALMA - Median.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment