-
-
Notifications
You must be signed in to change notification settings - Fork 425
Search provider - NASA ADS #499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 89bfc00
NASA ADS query : test format RST to open link in new window
vilhelmp 9dc6b7d
NASA ADS query : test format RST to open link in new window
vilhelmp cfa1c4d
NASA ADS query, rst doc : couldn't get link 2 open in new window
vilhelmp 8fa5f78
NASA ADS query - rst doc : new test with links...
vilhelmp 256006c
NASA ADS query - rst doc : new test with links
vilhelmp c776832
NASA ADS query - rst doc : new test with links
vilhelmp 6c99482
initial code dump
vilhelmp e6dc230
fix import
vilhelmp a1af152
NASA ADS simple text search working. Results NOT parsed.
vilhelmp acd282b
Error in documentation for API. query_region_async function should re…
vilhelmp d525a2d
NASA ADS : Started parsing simple query XML results into AstroPy table.
vilhelmp b3652fe
NASA ADS : Initial parsing supported.
vilhelmp bcdb4d0
moved function to extract field from BFS structure to separate file u…
vilhelmp 8c5bed6
moved over to standard Python xml library, started parsing results in…
vilhelmp a5ca7c7
now results are parsed into a Astropy Table table
vilhelmp b42c0e8
Merge remote-tracking branch 'upstream/master'
vilhelmp d74d873
NASA ADS query : initial commit
vilhelmp ee153fb
NASA ADS query : test format RST to open link in new window
vilhelmp 6e383f8
NASA ADS query : test format RST to open link in new window
vilhelmp e3140d5
NASA ADS query, rst doc : couldn't get link 2 open in new window
vilhelmp 69f0753
NASA ADS query - rst doc : new test with links...
vilhelmp 78ede10
NASA ADS query - rst doc : new test with links
vilhelmp 84975b0
NASA ADS query - rst doc : new test with links
vilhelmp b74df42
initial code dump
vilhelmp b90fc84
fix import
vilhelmp 82cd81d
NASA ADS simple text search working. Results NOT parsed.
vilhelmp 5b43fd8
Error in documentation for API. query_region_async function should re…
vilhelmp 207702a
NASA ADS : Started parsing simple query XML results into AstroPy table.
vilhelmp bd51513
NASA ADS : Initial parsing supported.
vilhelmp e86eca5
moved function to extract field from BFS structure to separate file u…
vilhelmp 40daf15
moved over to standard Python xml library, started parsing results in…
vilhelmp cc157a4
now results are parsed into a Astropy Table table
vilhelmp 7ae7587
Merge branch 'master' of https://github.com/vilhelmp/astroquery
vilhelmp ea5e4d9
Merge remote-tracking branch 'upstream/master'
vilhelmp 1a659ec
added nasa_ads to index.rst and cleaned up the docs for nasa_ads.rst …
vilhelmp ec0d89e
Merge remote-tracking branch 'upstream/master'
vilhelmp c4b63c5
added some docs and one test (my first test ever!).
vilhelmp 47cffb0
changed the test, removed patch_post
vilhelmp 9f3e83c
changed the test, added decorator remote_data
vilhelmp bd34224
corrected docs/nasa_ads/nasa_ads.rst code block
vilhelmp ef9412f
cleanup of comments
vilhelmp 2aae04f
cleanup of comments
vilhelmp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
| 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/ | ||
|
|
||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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: