<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Getting information from Scopus
Note
Step2:  First, we define a function to access to the information
Step3:  Then, a util function to show the information
A function that return the information of the author.
Obtaining Author info
Step4:  Example, to obtain my h-index
Step6:  Obtaining list of references
Now, we are going to extract the list of published papers.
Step7:  Translate to pandas
Step8:  Ploting results
Step9:  Get complete reference of a paper
Step10:  Get authors from a list
Step11:  List of journals in which I have published
Step13:  Searching by a criterion
Step14:  Get the number of journals with the results
Step15:  Count the references and number for each author
Step16:  For Congress
<ASSISTANT_TASK:>
Python Code:
import requests
import json
from my_scopus import MY_API_KEY, PROXY_URL, MY_AUTHOR_ID
Explanation: Getting information from Scopus
Note: This work is obtained from http://kitchingroup.cheme.cmu.edu/blog/2015/04/03/Getting-data-from-the-Scopus-API/, its author is really the author of that information. I have mainly put in a more useful way.
The access to Scopus API is restricted. First, you need a Elseview-API. You can obtain one from http://dev.elsevier.com/myapikey.html. 
In my case, because I have access by a Proxy (and using a VPN, but it is transparent) I also need a PROXY_URL. That both information are not in the repository because they are personal and private. You should create your own my_scopus.py file to run that code without changes.
End of explanation
def print_json(resp_json):
    print(json.dumps(resp_json,
                 sort_keys=True,
                 indent=4, separators=(',', ': ')))
def scopus_get_info_api(url, proxy=PROXY_URL,*,verbose=False,json=True):
    
    Returns the information obtained by the Elseview API
    
    proxies = {
        "http": PROXY_URL
    }
    resp = requests.get("http://api.elsevier.com/content/" +url,
                    headers={'Accept':'application/json',
                             'X-ELS-APIKey': MY_API_KEY}, proxies=proxies)
    if verbose:
        print_json(resp.json())
    
    if json:
        return resp.json()
    else:
        return resp.text.encode('utf-8')
Explanation: First, we define a function to access to the information
End of explanation
def scopus_get_author(author_id):
    msg = "author?author_id={}&view=metrics".format(author_id)
    resp = scopus_get_info_api(msg)
    return resp['author-retrieval-response'][0]
Explanation: Then, a util function to show the information
A function that return the information of the author.
Obtaining Author info
End of explanation
author_info = scopus_get_author(MY_AUTHOR_ID)
print_json(author_info)
h_index = author_info['h-index']
print("My automatic h_index is {}".format(h_index))
Explanation: Example, to obtain my h-index
End of explanation
def scopus_search_list(query, field, max=100, *, debug=False):
    msg = "search/scopus?query={}&nofield={}&count={}".format(query, field, max)
    
    if debug:
        print_json(scopus_get_info_api(msg))
        
    resp = scopus_get_info_api(msg)['search-results']
    list = []
    
    if resp['entry']:
        list = resp['entry']
        
    return list
def extract_info_papers(list):
    def get_type(code):
        if code in ['ar','re', 'ed', 'ip']:
            return 'article'
        elif code == 'cp':
            return 'congress'
        else:
            return code
        
    return [{'id': info['dc:identifier'], 
             'title': info['dc:title'], 
             'url': info['prism:url'], 
            'citations': int(info['citedby-count']), 
            'type': get_type(info['subtype']), 
             'year': info['prism:coverDate'][:4], 
            'journal': info['prism:publicationName']} for info in list]
def scopus_papers_from_author(author_id, *, max=100):
    
    Return the list of papers from the author
    
    query = "AU-ID({})".format(author_id)
    field = "dc:identifier"
    
    list = scopus_search_list(query, field, max)
    #print_json(list)
    return extract_info_papers(list)
    
papers = scopus_papers_from_author(MY_AUTHOR_ID)
print('{} papers'.format(len(papers)))
Explanation: Obtaining list of references
Now, we are going to extract the list of published papers.
End of explanation
import pandas as pd
df = pd.DataFrame.from_dict(papers)
print(df.head())
Explanation: Translate to pandas
End of explanation
papers_journal = df[df['type']=='article']
citations = papers_journal.groupby(['year']).sum()
%pylab inline
from matplotlib import pyplot as plt
import seaborn as sns
sns.set()
ax = citations.plot(kind='bar', legend=None)
ax.set_xlabel('Year')
ax.set_ylabel('Citations')
Explanation: Ploting results
End of explanation
def get_scopus_info(SCOPUS_ID):
    url = ("abstract/scopus_id/"
          + SCOPUS_ID
          + "?field=authors,title,publicationName,volume,issueIdentifier,"
          + "prism:pageRange,coverDate,article-number,doi,citedby-count,prism:aggregationType")
    
    resp = scopus_get_info_api(url, json=True)
    results = resp['abstracts-retrieval-response']
    authors_info = results['authors']
    info = results['coredata']
    fstring = '{authors}, {title}, {journal}, {volume}, {articlenum}, ({date}). {doi} (cited {cites} times).\n'
    return fstring.format(authors=', '.join([au['ce:indexed-name'] for au in authors_info['author']]),
                          title=info['dc:title'],
                          journal=info['prism:publicationName'],
                          volume=info.get('prism:volume') or 1,
                          articlenum=info.get('prism:pageRange') or
                            info.get('article-number'),
                          date=info['prism:coverDate'],
                          doi='doi:' +(info.get('prism:doi') or 'NA'),
                        cites=int(info['citedby-count']))
df_lasts = df[df['year']=='2015']
for id in df.sort(['citations'], ascending=[0])['id']:
    #print("id: '{}'".format(id))
    print(get_scopus_info(id))
Explanation: Get complete reference of a paper
End of explanation
def get_author_info(paper_id):
    url = ("abstract/scopus_id/"
          + paper_id
          + "?field=authors,title,publicationName,volume,issueIdentifier,"
          + "prism:pageRange,coverDate,article-number,doi,citedby-count,prism:aggregationType")
    
    resp = scopus_get_info_api(url, json=True)
    results = resp['abstracts-retrieval-response']
    authors_info = results['authors']['author']
    authors_id = [au['ce:indexed-name'] for au in authors_info]
    return authors_id
    
from collections import defaultdict
def get_authors_list(papers_id):
    number = defaultdict(int)
    
    for i, paper_id in enumerate(papers_id):            
        authors = get_author_info(paper_id)
        
        for author in authors:
            number[author] += 1
            
    return number
authors = get_authors_list(df['id'])
print(authors)
    
def show_author_list(authors):
    names = authors.keys()
    names = sorted(names, key=lambda k: authors[k], reverse=True)
    for name in names:
        print("{}: {}".format(name, authors[name]))
show_author_list(authors = get_authors_list(df.id))
Explanation: Get authors from a list
End of explanation
revistas = sorted(set(papers_journal['journal']))
for revista in revistas:
    print(revista)
Explanation: List of journals in which I have published
End of explanation
def scopus_search_papers(words, type='ar'):
    
    Return the list of papers from the author
    
    query = "TITLE-ABS-KEY({}) AND PUBYEAR > 2010 AND DOCTYPE({})".format(words, type)
    field = "dc:identifier"
    
    list = scopus_search_list(query, field, 200)
    return extract_info_papers(list)  
results = scopus_search_papers("large scale optimization evolutionary")
papers_lsgo = pd.DataFrame.from_dict(results)
num_total = len(papers_lsgo)
print(sorted(set(papers_lsgo['year'])))
Explanation: Searching by a criterion
End of explanation
lsgo_journal = papers_lsgo.groupby(['journal']).sum()
lsgo_journal.columns = ['number']
lsgo_journal = lsgo_journal.sort('number', ascending=False)
lsgo_journal = lsgo_journal[lsgo_journal['number']>0]
print(lsgo_journal)
papers_lsgo = papers_lsgo.sort('citations', ascending=False)
papers_lsgo = papers_lsgo[papers_lsgo['citations']>0]
for id in papers_lsgo['id'][:10]:
    print(get_scopus_info(id))
Explanation: Get the number of journals with the results
End of explanation
show_author_list(authors = get_authors_list(papers_lsgo.id))
Explanation: Count the references and number for each author
End of explanation
results_cp = scopus_search_papers("large scale optimization evolutionary", type='cp')
results = pd.DataFrame.from_dict(results_cp)
show_author_list(authors = get_authors_list(results.id))
results_cp = scopus_search_papers("large scale optimization differential evolution", type='cp')
results = pd.DataFrame.from_dict(results_cp)
show_author_list(authors = get_authors_list(results.id))
results = results.sort(['citations'], ascending=False)
for id in results.id[:10]:
    print(get_scopus_info(id))
Explanation: For Congress
End of explanation
<END_TASK>