from IPython.display import Image
i = Image(filename='images/8320552323_13cfe4b081_b.jpg')
f = Image(url='http://b.z19r.com/upload/did-you-just-tell-me-to-go-fuck-myself.jpg')
happy = Image(filename='images/5365366130_4ecf6c025f_b.jpg')
tools = Image(filename='images/ScienceToolbox_-_Open_science_software.png')
i
f
happy
# lets test embedding a html page into the presentation
from IPython.display import HTML
HTML('')
# http://gitready.com
HTML('')
# https://mac.github.com
HTML('')
# https://guides.github.com/activities/citable-code/
tools
HTML('')
# get recent DOIs deposited by PLOS using the CrosRef API
import requests
url = "http://api.crossref.org/members/340/works?filter=from-update-date:2014-07-21,until-update-date:2014-07-24&rows=1000"
r = requests.get(url)
def get_dois_from_response(r):
dois = []
crossref_json = r.json()
pub_items = crossref_json["message"]["items"]
for item in pub_items:
dois.append(item["DOI"])
return dois
# extract the dois from the API response
dois = get_dois_from_response(r)
print (dois[0:3])
def return_parent_doi(doi):
# if the doi is a child doi, strip the tail, and return the parent
doi_parts = doi.split(".")
main_doi = ".".join(doi_parts[0:4])
return main_doi
# chop off the child parts of our of our dois
def get_parent_dois(dois):
parent_dois = []
for doi in dois:
parent_dois.append(return_parent_doi(doi))
return parent_dois
# just get the top level DOIS
parent_dois = get_parent_dois(dois)
print (parent_dois[0:3])
# get a set of unique set of dois
def get_unique_dois(dois):
unique_dois = []
for doi in dois:
if doi in unique_dois:
continue
else:
unique_dois.append(doi)
return unique_dois
unique_dois = get_unique_dois(parent_dois)
print (unique_dois[0:3])
# now we import an interface to the PLOS ALM app
import pyalm.pyalm as alm
test_article = alm.get_alm(str(unique_dois[12]), info="event", source="mendeley")
print test_article[0].sources["mendeley"].metrics.total
article_data = {}
for doi in unique_dois:
try:
article = alm.get_alm(str(doi), info="summary")
article_mendeley = alm.get_alm(str(doi), info="event", source="mendeley")
mendeley_metrics = article_mendeley[0].sources["mendeley"].metrics.total
article_data[doi] = {"views":article[0].views, "citations":article[0].citations, "mendeley": mendeley_metrics}
except:
print "no data for ", doi
%matplotlib inline
values = article_data.values()
def get_views(x): return x["views"]
def get_cites(x): return x["citations"]
def get_mendeley(x): return x["mendeley"]
all_views = map(get_views, values)
all_cites = map(get_cites, values)
all_mendeley = map(get_mendeley, values)
print values[0:3]
print all_views[0:3]
print all_cites[0:3]
print all_mendeley[0:3]
import matplotlib.pyplot as plt
import numpy as np
n = array([23,34,56,78])
pos = array([1,2,3,4])
pos = array(range(len(all_views)))
fig, ax = plt.subplots(1, 1)
sorted_views = all_views.sort()
ax.bar(pos,all_views)
fig, ax = plt.subplots(1, 1)
ax.scatter(all_cites,all_views)
fig, ax = plt.subplots(1, 1)
ax.scatter(all_mendeley,all_views)
# The code behind this presentation can be viewed on nb viewer
HTML('')
HTML('')
# http://londonopendrinks.org