astropy / astroquery
1
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2 1
from astropy import log
3 1
import os
4 1
import json
5 1
from ..splatalogue.load_species_table import SpeciesLookuptable
6 1
from . import Conf
7

8

9 1
def species_lookuptable(cache=True):
10
    """
11
    Get a lookuptable from chemical name + OrdinaryStructuralFormula to VAMDC
12
    id
13
    """
14

15 0
    if not os.path.exists(Conf.cache_location):
16 0
        os.makedirs(Conf.cache_location)
17

18 0
    lut_path = os.path.join(Conf.cache_location,
19
                            'species_lookuptable.json')
20 0
    if os.path.exists(lut_path) and cache:
21 0
        log.info("Loading cached molecular line ID database")
22 0
        with open(lut_path, 'r') as fh:
23 0
            lutdict = json.load(fh)
24 0
        lookuptable = SpeciesLookuptable(lutdict)
25
    else:
26 0
        log.info("Loading molecular line ID database")
27

28 0
        from vamdclib import nodes as vnodes
29 0
        from vamdclib import request as vrequest
30

31 0
        nl = vnodes.Nodelist()
32 0
        nl.findnode('cdms')
33 0
        cdms = nl.findnode('cdms')
34

35 0
        request = vrequest.Request(node=cdms)
36

37
        # Retrieve all species from CDMS
38 0
        result = request.getspecies()
39 0
        molecules = result.data['Molecules']
40

41 0
        lutdict = {"{0} {1}".format(molecules[key].ChemicalName,
42
                                    molecules[key].OrdinaryStructuralFormula):
43
                   molecules[key].VAMDCSpeciesID
44
                   for key in molecules}
45 0
        lookuptable = SpeciesLookuptable(lutdict)
46 0
        if cache:
47 0
            with open(lut_path, 'w') as fh:
48 0
                json.dump(lookuptable, fh)
49

50 0
    return lookuptable

Read our documentation on viewing source code .

Loading