From 85e8bb5f3fe65dfec7f009f2f6bf423d854625bc Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Mon, 16 May 2016 11:58:11 +0200 Subject: [PATCH] first functioning version of vamdc molecule queries with caching enabled, plus some docs --- astroquery/vamdc/core.py | 9 +++++---- docs/vamdc/vamdc.rst | 42 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 docs/vamdc/vamdc.rst diff --git a/astroquery/vamdc/core.py b/astroquery/vamdc/core.py index c97e1ff201..64d2e33f6a 100644 --- a/astroquery/vamdc/core.py +++ b/astroquery/vamdc/core.py @@ -44,10 +44,12 @@ def __init__(self): from vamdclib import nodes as vnodes from vamdclib import request as vrequest + from vamdclib import results as vresults from vamdclib import specmodel self._vnodes = vnodes self._vrequest = vrequest + self._vresults = vresults self._nl = vnodes.Nodelist() self._cdms = self._nl.findnode('cdms') @@ -91,10 +93,9 @@ def query_molecule(self, molecule_name, chem_re_flags=0, cache=True): myhashpath = os.path.join(self.CACHE_LOCATION, myhash) if os.path.exists(myhashpath) and cache: - with open(myhashpath, 'r') as fh: + with open(myhashpath, 'rb') as fh: xml = fh.read() - result = self._vrequest.Result() - result.Xml = xml + result = self._vresults.Result(xml=xml) result.populate_model() else: species_id_dict = self.species_lookuptable.find(molecule_name, @@ -111,7 +112,7 @@ def query_molecule(self, molecule_name, chem_re_flags=0, cache=True): result = request.dorequest() if cache: - with open(myhashpath, 'w') as fh: + with open(myhashpath, 'wb') as fh: xml = fh.write(result.Xml) return result diff --git a/docs/vamdc/vamdc.rst b/docs/vamdc/vamdc.rst new file mode 100644 index 0000000000..819f4e749a --- /dev/null +++ b/docs/vamdc/vamdc.rst @@ -0,0 +1,42 @@ +.. doctest-skip-all + +.. _astroquery.vamdc: + +********************************** +Vamdc Queries (`astroquery.vamdc`) +********************************** + +Getting Started +=============== + +The astroquery vamdc interface requires vamdclib_. The documentation is sparse +to nonexistant, but installation is straightforward:: + + pip install https://github.com/keflavich/vamdclib/archive/master.zip + +This is the personal fork of the astroquery maintainer that includes astropy's +setup helpers on top of the vamdclib infrastructure. + +Examples +======== + +If you want to compute the partition function, you can do so using a combination +of astroquery and the vamdclib tools:: + +.. code-block:: python + + >>> from astroquery.vamdc import Vamdc + >>> ch3oh = Vamdc.query_molecule('CH3OH') + >>> from vamdclib import specmodel + >>> partition_func = specmodel.calculate_partitionfunction(ch3oh.data['States'], + temperature=100) + >>> print(partition_func) + {'XCDMS-149': 1185.5304044622881} + +Reference/API +============= + +.. automodapi:: astroquery.vamdc + :no-inheritance-diagram: + +.. _vamdclib: http://vamdclib.readthedocs.io/en/latest/