Skip to content

Commit

Permalink
first functioning version of vamdc molecule queries with caching
Browse files Browse the repository at this point in the history
enabled, plus some docs
  • Loading branch information
keflavich committed Sep 1, 2016
1 parent 5111612 commit 85e8bb5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
9 changes: 5 additions & 4 deletions astroquery/vamdc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
42 changes: 42 additions & 0 deletions docs/vamdc/vamdc.rst
Original file line number Diff line number Diff line change
@@ -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/

0 comments on commit 85e8bb5

Please sign in to comment.