Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
9231a6f
NASA ADS query : initial commit
vilhelmp Dec 19, 2014
89bfc00
NASA ADS query : test format RST to open link in new window
vilhelmp Dec 19, 2014
9dc6b7d
NASA ADS query : test format RST to open link in new window
vilhelmp Dec 19, 2014
cfa1c4d
NASA ADS query, rst doc : couldn't get link 2 open in new window
vilhelmp Dec 19, 2014
8fa5f78
NASA ADS query - rst doc : new test with links...
vilhelmp Dec 19, 2014
256006c
NASA ADS query - rst doc : new test with links
vilhelmp Dec 19, 2014
c776832
NASA ADS query - rst doc : new test with links
vilhelmp Dec 19, 2014
6c99482
initial code dump
vilhelmp Dec 19, 2014
e6dc230
fix import
vilhelmp Dec 19, 2014
a1af152
NASA ADS simple text search working. Results NOT parsed.
vilhelmp Jan 12, 2015
acd282b
Error in documentation for API. query_region_async function should re…
vilhelmp Jan 12, 2015
d525a2d
NASA ADS : Started parsing simple query XML results into AstroPy table.
vilhelmp Jan 12, 2015
b3652fe
NASA ADS : Initial parsing supported.
vilhelmp Jan 13, 2015
bcdb4d0
moved function to extract field from BFS structure to separate file u…
vilhelmp Jan 15, 2015
8c5bed6
moved over to standard Python xml library, started parsing results in…
vilhelmp Feb 15, 2015
a5ca7c7
now results are parsed into a Astropy Table table
vilhelmp Mar 15, 2015
b42c0e8
Merge remote-tracking branch 'upstream/master'
vilhelmp Mar 16, 2015
d74d873
NASA ADS query : initial commit
vilhelmp Dec 19, 2014
ee153fb
NASA ADS query : test format RST to open link in new window
vilhelmp Dec 19, 2014
6e383f8
NASA ADS query : test format RST to open link in new window
vilhelmp Dec 19, 2014
e3140d5
NASA ADS query, rst doc : couldn't get link 2 open in new window
vilhelmp Dec 19, 2014
69f0753
NASA ADS query - rst doc : new test with links...
vilhelmp Dec 19, 2014
78ede10
NASA ADS query - rst doc : new test with links
vilhelmp Dec 19, 2014
84975b0
NASA ADS query - rst doc : new test with links
vilhelmp Dec 19, 2014
b74df42
initial code dump
vilhelmp Dec 19, 2014
b90fc84
fix import
vilhelmp Dec 19, 2014
82cd81d
NASA ADS simple text search working. Results NOT parsed.
vilhelmp Jan 12, 2015
5b43fd8
Error in documentation for API. query_region_async function should re…
vilhelmp Jan 12, 2015
207702a
NASA ADS : Started parsing simple query XML results into AstroPy table.
vilhelmp Jan 12, 2015
bd51513
NASA ADS : Initial parsing supported.
vilhelmp Jan 13, 2015
e86eca5
moved function to extract field from BFS structure to separate file u…
vilhelmp Jan 15, 2015
40daf15
moved over to standard Python xml library, started parsing results in…
vilhelmp Feb 15, 2015
cc157a4
now results are parsed into a Astropy Table table
vilhelmp Mar 15, 2015
7ae7587
Merge branch 'master' of https://github.com/vilhelmp/astroquery
vilhelmp Mar 27, 2015
ea5e4d9
Merge remote-tracking branch 'upstream/master'
vilhelmp Apr 12, 2015
1a659ec
added nasa_ads to index.rst and cleaned up the docs for nasa_ads.rst …
vilhelmp Apr 13, 2015
ec0d89e
Merge remote-tracking branch 'upstream/master'
vilhelmp Apr 21, 2015
c4b63c5
added some docs and one test (my first test ever!).
vilhelmp Apr 21, 2015
47cffb0
changed the test, removed patch_post
vilhelmp Apr 21, 2015
9f3e83c
changed the test, added decorator remote_data
vilhelmp Apr 21, 2015
bd34224
corrected docs/nasa_ads/nasa_ads.rst code block
vilhelmp Apr 23, 2015
ef9412f
cleanup of comments
vilhelmp Apr 23, 2015
2aae04f
cleanup of comments
vilhelmp Apr 23, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions astroquery/nasa_ads/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""
SAO/NASA ADS Query Tool
-----------------------------------

:Author: Magnus Vilhelm Persson (magnusp@vilhelm.nu)

"""

from astropy import config as _config


class Conf(_config.ConfigNamespace):
"""
Configuration parameters for `astroquery.nasa_ads`.
"""

server = _config.ConfigItem(
'http://adswww.harvard.edu',
'SAO/NASA ADS main server.'
)
mirrors = _config.ConfigItem(
['http://cdsads.u-strasbg.fr',
'http://ukads.nottingham.ac.uk',
'http://esoads.eso.org',
'http://ads.ari.uni-heidelberg.de',
'http://ads.inasan.ru',
'http://ads.mao.kiev.ua',
'http://ads.astro.puc.cl',
'http://ads.nao.ac.jp',
'http://ads.bao.ac.cn',
'http://ads.iucaa.ernet.in',
'http://ads.arsip.lipi.go.id',
'http://saaoads.chpc.ac.za',
'http://ads.on.br'],
'SAO/NASA ADS mirrors around the world'
)
advanced_path = _config.ConfigItem(
'/cgi-bin/nph-abs_connect',
'Path for advanced query (unconfirmed)'
)
simple_path = _config.ConfigItem(
'/cgi-bin/basic_connect',
'Path for simple query (return XML)'
)
timeout = _config.ConfigItem(
120,
'Time limit for connecting to ADS server'
)

conf = Conf()


conf.adsfields = ['bibcode', 'title', 'author', 'affiliation',
'journal', 'volume', 'pubdate', 'page', 'lastpage', 'keywords', 'keyword',
'origin', 'copyright', 'link', 'name', 'url', 'count', 'score', 'citations',
'abstract', 'doi', 'eprintid']

from .core import ADSClass, ADS

__all__ = ['ADSClass', 'ADS',
'Conf', 'conf']
102 changes: 102 additions & 0 deletions astroquery/nasa_ads/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""
Module to search the SAO/NASA Astrophysics Data System

:author: Magnus Persson <magnusp@vilhelm.nu>

"""

import warnings
from ..query import BaseQuery
from ..utils import commons, async_to_sync
from . import conf
from astropy.table import Table, Column

from ..utils.class_or_instance import class_or_instance
from ..utils import commons, async_to_sync
from .utils import *

from xml.dom import minidom

__all__ = ['ADS', 'ADSClass']

@async_to_sync
class ADSClass(BaseQuery):

SERVER = conf.server
QUERY_ADVANCED_PATH = conf.advanced_path
QUERY_SIMPLE_PATH = conf.simple_path
TIMEOUT = conf.timeout

QUERY_SIMPLE_URL = SERVER + QUERY_SIMPLE_PATH
QUERY_ADVANCED_URL = SERVER + QUERY_ADVANCED_PATH

def __init__(self, *args):
""" set some parameters """
pass

@class_or_instance
def query_simple(self, query_string, get_query_payload=False, get_raw_response=False):
self.query_string = query_string
request_payload = self._args_to_payload(query_string)

response = commons.send_request(self.QUERY_SIMPLE_URL, request_payload, self.TIMEOUT)

# primarily for debug purposes, but also useful if you want to send
# someone a URL linking directly to the data
if get_query_payload:
return request_payload
if get_raw_response:
return response
# parse the XML response into AstroPy Table
resulttable = self._parse_response(response.encode(results.encoding).decode('utf-8'))

return resulttable

def _parse_response(self, response):
xmlrepr = minidom.parseString(response.text)
# Check if there are any results!

# get the list of hits
hitlist = xmlrepr.childNodes[0].childNodes
hitlist = hitlist[1::2] # every second hit is a "line break"

# Grab the various fields
titles = _get_data_from_xml(hitlist, 'title')
bibcode = _get_data_from_xml(hitlist, 'bibcode')
journal = _get_data_from_xml(hitlist, 'journal')
volume = _get_data_from_xml(hitlist, 'volume')
pubdate = _get_data_from_xml(hitlist, 'pubdate')
page = _get_data_from_xml(hitlist, 'page')
score = _get_data_from_xml(hitlist, 'score')
citations = _get_data_from_xml(hitlist, 'citations')
abstract = _get_data_from_xml(hitlist, 'abstract')
doi = _get_data_from_xml(hitlist, 'DOI')
eprintid = _get_data_from_xml(hitlist, 'eprintid')
authors = _get_data_from_xml(hitlist, 'author')
# put into AstroPy Table
t = Table()
t['title'] = titles
t['bibcode'] = bibcode
t['journal'] = journal
t['volume'] = volume
t['pubdate'] = pubdate
t['page'] = page
t['score'] = score
t['citations'] = citations
t['abstract'] = abstract
t['doi'] = doi
t['eprintid'] = eprintid
t['authors'] = authors

return t

def _args_to_payload(self, query_string):
# convert arguments to a valid requests payload
# i.e. a dictionary
return {'qsearch' : query_string, 'data_type' : 'XML'}



ADS = ADSClass()

Empty file.
7 changes: 7 additions & 0 deletions astroquery/nasa_ads/tests/test_nasaads.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from ... import nasa_ads
from astropy.tests.helper import remote_data

@remote_data
def test_simple():
x = nasa_ads.ADS.query_simple('^Persson Origin of water around deeply embedded low-mass protostars')
assert x[-1]['authors'][0] == 'Persson, M. V.'
18 changes: 18 additions & 0 deletions astroquery/nasa_ads/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@


def _get_data_from_xml(doclist, fieldname, nohitreturn=None):
"""Get the fieldname (i.e. author, title etc)
from minidom.parseString().childNodes[0].childNodes list
"""
result = []
for element in doclist:
fieldlist = element.getElementsByTagName(fieldname)
try:
tmp = fieldlist[0]
except IndexError:
fields = [nohitreturn]
fields = []
for field in fieldlist: # this is useful for e.g. author field
fields.append(field.childNodes[0].data)
result.append(fields)
return result
2 changes: 1 addition & 1 deletion docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ Directory Structure::
if get_query_payload:
return request_payload

return result
return response

@class_or_instance
def get_images_async(self, *args):
Expand Down
2 changes: 2 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ The following modules have been completed using a common API:
atomic/atomic.rst
alma/alma.rst
skyview/skyview.rst
nasa_ads/nasa_ads.rst

These others are functional, but do not follow a common & consistent API:

Expand Down Expand Up @@ -225,6 +226,7 @@ above categories.
lamda/lamda.rst
nist/nist.rst
splatalogue/splatalogue.rst
nasa_ads/nasa_ads.rst


Developer documentation
Expand Down
65 changes: 65 additions & 0 deletions docs/nasa_ads/nasa_ads.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
.. doctest-skip-all

.. _astroquery.nasa_ads:

****************************************
NASA ADS Queries (`astroquery.nasa_ads`)
****************************************

Getting Started
===============

This module provides an interface to the online `SAO/NASA Astrophysics Data System`_.
At the moment only the "simple search", i.e. omni-box search is available, and only
a subset of the results are accessible.

Examples
========

Search works by specific identifier
-----------------------------------
.. code-block:: python

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this stuff should be in an indented code block:

.. code-block:: python

    from astro....

from astroquery import nasa_ads as na
# the "^" makes ADS to return only papers where Persson
# is first author
results = na.ADS.query_simple('^Persson Origin of water\
around deeply embedded low-mass protostars') results[0].title

# to sort after publication date
results.sort(['pubdate'])

# get the title of the last hit
title = results[-1]['title'][0]

# printout the authors of the last hit
print results[-1]['authors']


Get links
---------
Not yet implemented.

Download publisher/ArXiv PDF
----------------------------
Not yet implemented.

Get Bibtex
----------
Not yet implemented.






Reference/API
=============

#.. automodapi:: astroquery.nasa_ads:no-inheritance-diagram:

.. _nasa_ads: http://adsabs.harvard.edu/
.. _SAO/NASA Astrophysics Data System: http://adsabs.harvard.edu/