From d4103a5e810e58febaf665d4096a51185aff28cc Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Sun, 22 Nov 2015 19:12:25 +0100 Subject: [PATCH 01/12] add HITRAN reader and related README. This is incomplete --- astroquery/hitran/data/readme.txt | 208 ++++++++++++++++++++++++++++++ astroquery/hitran/reader.py | 152 ++++++++++++++++++++++ 2 files changed, 360 insertions(+) create mode 100644 astroquery/hitran/data/readme.txt create mode 100644 astroquery/hitran/reader.py diff --git a/astroquery/hitran/data/readme.txt b/astroquery/hitran/data/readme.txt new file mode 100644 index 0000000000..5726a268a0 --- /dev/null +++ b/astroquery/hitran/data/readme.txt @@ -0,0 +1,208 @@ +HITRAN2004 +---------- + +The fields output for this profile are listed in order below with format strings, units and description the following information: : + +molec_id +-------- +C-style format specifier: %2d +Fortran-style format specifier: I2 +Units: None +Description: The HITRAN integer ID for this molecule in all its isotopologue forms + +local_iso_id +------------ +C-style format specifier: %1d +Fortran-style format specifier: I1 +Units: +Description: Integer ID of a particular Isotopologue, unique only to a given molecule, in order or abundance (1 = most abundant) + +nu +-- +C-style format specifier: %12.6f +Fortran-style format specifier: F12.6 +Units: cm-1 +Description: Transition wavenumber + +sw +-- +C-style format specifier: %10.3e +Fortran-style format specifier: E10.3 +Units: cm-1/(molec.cm-2) +Description: Line intensity, multiplied by isotopologue abundance, at T = 296 K + +a +- +C-style format specifier: %10.3e +Fortran-style format specifier: E10.3 +Units: s-1 +Description: Einstein A-coefficient in s-1 + +gamma_air +--------- +C-style format specifier: %5.4f +Fortran-style format specifier: F5.4 +Units: cm-1.atm-1 +Description: Air-broadened Lorentzian half-width at half-maximum at p = 1 atm and T = 296 K + +gamma_self +---------- +C-style format specifier: %5.3f +Fortran-style format specifier: F5.3 +Units: cm-1.atm-1 +Description: Self-broadened HWHM at 1 atm pressure and 296 K + +elower +------ +C-style format specifier: %10.4f +Fortran-style format specifier: F10.4 +Units: cm-1 +Description: Lower-state energy + +n_air +----- +C-style format specifier: %4.2f +Fortran-style format specifier: F4.2 +Units: +Description: Temperature exponent for the air-broadened HWHM + +delta_air +--------- +C-style format specifier: %8.6f +Fortran-style format specifier: F8.6 +Units: cm-1.atm-1 +Description: Pressure shift induced by air, referred to p=1 atm + +global_upper_quanta +------------------- +C-style format specifier: %15s +Fortran-style format specifier: A15 +Units: None +Description: Electronic and vibrational quantum numbers and labels for the upper state of a transition + +global_lower_quanta +------------------- +C-style format specifier: %15s +Fortran-style format specifier: A15 +Units: None +Description: Electronic and vibrational quantum numbers and labels for the lower state of a transition + +local_upper_quanta +------------------ +C-style format specifier: %15s +Fortran-style format specifier: A15 +Units: None +Description: Rotational, hyperfine and other quantum numbers and labels for the upper state of a transition + +local_lower_quanta +------------------ +C-style format specifier: %15s +Fortran-style format specifier: A15 +Units: None +Description: Rotational, hyperfine and other quantum numbers and labels for the lower state of a transition + +ierr1 +----- +C-style format specifier: %1d +Fortran-style format specifier: I1 +Units: +Description: Ordered list of indices corresponding to uncertainty estimates of transition parameters + +ierr2 +----- +C-style format specifier: %1d +Fortran-style format specifier: I1 +Units: +Description: Ordered list of indices corresponding to uncertainty estimates of transition parameters + +ierr3 +----- +C-style format specifier: %1d +Fortran-style format specifier: I1 +Units: +Description: Ordered list of indices corresponding to uncertainty estimates of transition parameters + +ierr4 +----- +C-style format specifier: %1d +Fortran-style format specifier: I1 +Units: +Description: Ordered list of indices corresponding to uncertainty estimates of transition parameters + +ierr5 +----- +C-style format specifier: %1d +Fortran-style format specifier: I1 +Units: +Description: Ordered list of indices corresponding to uncertainty estimates of transition parameters + +ierr6 +----- +C-style format specifier: %1d +Fortran-style format specifier: I1 +Units: +Description: Ordered list of indices corresponding to uncertainty estimates of transition parameters + +iref1 +----- +C-style format specifier: %2d +Fortran-style format specifier: I2 +Units: None +Description: Ordered list of reference identifiers for transition parameters + +iref2 +----- +C-style format specifier: %2d +Fortran-style format specifier: I2 +Units: None +Description: Ordered list of reference identifiers for transition parameters + +iref3 +----- +C-style format specifier: %2d +Fortran-style format specifier: I2 +Units: None +Description: Ordered list of reference identifiers for transition parameters + +iref4 +----- +C-style format specifier: %2d +Fortran-style format specifier: I2 +Units: None +Description: Ordered list of reference identifiers for transition parameters + +iref5 +----- +C-style format specifier: %2d +Fortran-style format specifier: I2 +Units: None +Description: Ordered list of reference identifiers for transition parameters + +iref6 +----- +C-style format specifier: %2d +Fortran-style format specifier: I2 +Units: None +Description: Ordered list of reference identifiers for transition parameters + +line_mixing_flag +---------------- +C-style format specifier: %1s +Fortran-style format specifier: A1 +Units: +Description: A flag indicating the presence of additional data and code relating to line-mixing + +gp +-- +C-style format specifier: %7.1f +Fortran-style format specifier: F7.1 +Units: None +Description: Upper state degeneracy + +gpp +--- +C-style format specifier: %7.1f +Fortran-style format specifier: F7.1 +Units: None +Description: Lower state degeneracy + diff --git a/astroquery/hitran/reader.py b/astroquery/hitran/reader.py new file mode 100644 index 0000000000..cce9459307 --- /dev/null +++ b/astroquery/hitran/reader.py @@ -0,0 +1,152 @@ +from collections import OrderedDict +import numpy as np +from astropy.table import Table +import os + +DATA_DIR = os.path.join(os.path.dirname(__file__), 'data') + +dtype_dict = {'f': 'f', 's':'s', 'd':'i', 'e':'f', 'F':'f', 'A':'s', 'I':'i'} +fmt_dict = {'f': float, 's':str, 'd':int, 'e':float, 'A': str, 'I':int, + 'F': float} + + +def parse_readme(filename, group_global=None, group_local=None): + with open(filename,'r') as f: + lines = f.readlines() + + formats = OrderedDict() + + if group_local is not None and group_local is not None: + qfl,qfg = quanta_formatter(group_local=group_local, group_global=group_global) + use_qf = True + else: + use_qf = False + + for ii, line in enumerate(lines): + if line[0] == '-': + row_name = lines[ii-1].strip() + if 'C-style format specifier:' in line: + fmt = line[len('C-style format specifier:'):].strip() + if '.' in fmt: + length = int(fmt[1:fmt.find('.')]) + else: + length = int(fmt[1:-1]) + dtype = dtype_dict[fmt[-1]] if fmt[-1] != 's' else 'S'+fmt[1:-1] + + if 'quanta' in row_name and use_qf: + g = ('global' in row_name) + ul = 'u' if 'upper' in row_name else 'l' + gl = 'g' if g else 'l' + qf = qfg if g else qfl + + assert sum([x['length'] for x in qf.values()]) == length + + for rn in qf: + formats[rn+"_"+ul] = qf[rn] + else: + formats[row_name] = {'format_str': fmt, + 'length': length, + 'dtype': dtype, + 'formatter': fmt_dict[fmt[-1]]} + + assert sum([x['length'] for x in formats.values()]) == 160 + return formats + +def quanta_formatter(group_global='class1', group_local='group1'): + """ + Format based on the global/local formatters from the HITRAN04 paper + """ + + local_dict = {'group1': # asymmetric + OrderedDict([('J','I3'), + ('Ka','I3'), + ('Kc','I3'), + ('F','A5'), + ('Sym','A1'), + ] + ), + 'hc3n': # special + OrderedDict([('J','I3'), + ('Ka','I3'), + ('Kc','I3'), + ('F','A5'), + ('Sym','A1'), + ] + ), + + + } + global_dict = {'class9': # non-linear tetratomic + OrderedDict([('v1','I5'), # preceded by 3x space + ('v2','I2'), + ('v3','I2'), + ('v4','I2'), + ('v5','I2'), + ('v6','I2'), + ] + ), + 'class10': + OrderedDict([('v1','I5'), # preceded by 3x space + ('v2','I2'), + ('v3','I2'), + ('v4','I2'), + ('n','A2'), + ('C','A2'), + ] + ), + 'hc3n': + OrderedDict([('v1','I3'), # preceded by 2x space + ('v2','I1'), + ('v3','I1'), + ('v4','I1'), + ('v5','I1'), + ('v6','I1'), + ('v7','I1'), + ('l5','I2'), + ('l6','I2'), + ('l7','I2'), + ] + ), + } + + + loc = OrderedDict() + for key,value in local_dict[group_local].items(): + loc[key] = {'format_str': value, 'length': int(value[1:]), + 'dtype': 'S'+value[1:] if dtype_dict[value[0]]=='s' else dtype_dict[value[0]], + 'formatter': fmt_dict[value[0]]} + + glob = OrderedDict() + for key,value in global_dict[group_global].items(): + glob[key] = {'format_str': value, 'length': int(value[1:]), + 'dtype': 'S'+value[1:] if dtype_dict[value[0]]=='s' else dtype_dict[value[0]], + 'formatter': fmt_dict[value[0]]} + + return loc,glob + +def read_hitran_file(filename, formats=None, + formatfile=os.path.join(DATA_DIR, 'readme.txt')): + if formats is None and formatfile is not None: + formats = parse_readme(formatfile) + elif formatfile is None: + raise ValueError("Must give a formatfilename or a format dict") + + dtypes = [entry['dtype'] for entry in formats.values()] + + with open(filename,'r') as f: + rows = [] + for line in f: + row = [] + start = 0 + for key,entry in formats.items(): + formatter = entry['formatter'] + length = entry['length'] + value = formatter(line[start:start+length]) + row.append(value) + start = start + length + rows.append(row) + + tbl = Table(rows=rows, names=formats.keys(), dtype=dtypes) + + return tbl + From 9bd22c176fc347282814aa59f724b851230f3555 Mon Sep 17 00:00:00 2001 From: Miguel de Val-Borro Date: Tue, 1 Nov 2016 18:43:04 -0400 Subject: [PATCH 02/12] Add __init__.py file for hitran subpackage --- astroquery/hitran/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 astroquery/hitran/__init__.py diff --git a/astroquery/hitran/__init__.py b/astroquery/hitran/__init__.py new file mode 100644 index 0000000000..3fd5c7ba0b --- /dev/null +++ b/astroquery/hitran/__init__.py @@ -0,0 +1,8 @@ +# Licensed under a 3-clause BSD style license - see LICENSE.rst +""" +HITRAN Catalog Query Tool +------------------------- + +:Author: Adam Ginsburg (adam.g.ginsburg@gmail.com) +""" +from .reader import read_hitran_file From 6e139bc75322a9d60976bfe03868d09a7c631016 Mon Sep 17 00:00:00 2001 From: Miguel de Val-Borro Date: Wed, 2 Nov 2016 11:16:28 -0400 Subject: [PATCH 03/12] remove unused numpy import --- astroquery/hitran/reader.py | 1 - 1 file changed, 1 deletion(-) diff --git a/astroquery/hitran/reader.py b/astroquery/hitran/reader.py index cce9459307..ecdf593d80 100644 --- a/astroquery/hitran/reader.py +++ b/astroquery/hitran/reader.py @@ -1,5 +1,4 @@ from collections import OrderedDict -import numpy as np from astropy.table import Table import os From 63d4e87ef063305f7788925045e964bdd964b0ce Mon Sep 17 00:00:00 2001 From: Miguel de Val-Borro Date: Wed, 2 Nov 2016 11:36:13 -0400 Subject: [PATCH 04/12] add hitran package data --- astroquery/hitran/setup_package.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 astroquery/hitran/setup_package.py diff --git a/astroquery/hitran/setup_package.py b/astroquery/hitran/setup_package.py new file mode 100644 index 0000000000..490464f100 --- /dev/null +++ b/astroquery/hitran/setup_package.py @@ -0,0 +1,12 @@ +# Licensed under a 3-clause BSD style license - see LICENSE.rst +from __future__ import absolute_import + +import os + + +def get_package_data(): + paths_data = [os.path.join('data', 'readme.txt'), + ] + + return {'astroquery.hitran': paths_data, + } From 3a9f592b6549c00a423557c4fedd7911461b8445 Mon Sep 17 00:00:00 2001 From: Miguel de Val-Borro Date: Wed, 2 Nov 2016 15:14:11 -0400 Subject: [PATCH 05/12] Function to download HITRAN data --- astroquery/hitran/__init__.py | 2 +- astroquery/hitran/reader.py | 178 +++++++++++++++++++++++++++++++++- 2 files changed, 177 insertions(+), 3 deletions(-) diff --git a/astroquery/hitran/__init__.py b/astroquery/hitran/__init__.py index 3fd5c7ba0b..307d1ed73d 100644 --- a/astroquery/hitran/__init__.py +++ b/astroquery/hitran/__init__.py @@ -5,4 +5,4 @@ :Author: Adam Ginsburg (adam.g.ginsburg@gmail.com) """ -from .reader import read_hitran_file +from .reader import download_hitran, read_hitran_file diff --git a/astroquery/hitran/reader.py b/astroquery/hitran/reader.py index ecdf593d80..4b1eef22c7 100644 --- a/astroquery/hitran/reader.py +++ b/astroquery/hitran/reader.py @@ -1,13 +1,151 @@ from collections import OrderedDict from astropy.table import Table +from astropy import log +from astropy.config import paths import os +try: + import urllib.request as urllib2 +except ImportError: + import urllib2 + DATA_DIR = os.path.join(os.path.dirname(__file__), 'data') +HITRAN_URL = 'http://hitran.org' +cache_location = os.path.join(paths.get_cache_dir(), 'astroquery', 'hitran') +if not os.path.exists(cache_location): + os.makedirs(cache_location) dtype_dict = {'f': 'f', 's':'s', 'd':'i', 'e':'f', 'F':'f', 'A':'s', 'I':'i'} fmt_dict = {'f': float, 's':str, 'd':int, 'e':float, 'A': str, 'I':int, 'F': float} +ISO_INDEX = { 'id':0, 'iso_name':1, 'abundance':2, 'mass':3, 'mol_name':4 } + +# Copied from hapi.py code +ISO = { + ( 1, 1): [ 1, 'H2(16O)', 0.997317, 18.010565, 'H2O' ], + ( 1, 2): [ 2, 'H2(18O)', 0.00199983, 20.014811, 'H2O' ], + ( 1, 3): [ 3, 'H2(17O)', 0.000372, 19.01478, 'H2O' ], + ( 1, 4): [ 4, 'HD(16O)', 0.00031069, 19.01674, 'H2O' ], + ( 1, 5): [ 5, 'HD(18O)', 0.000000623, 21.020985, 'H2O' ], + ( 1, 6): [ 6, 'HD(17O)', 0.000000116, 20.020956, 'H2O' ], + ( 2, 1): [ 7, '(12C)(16O)2', 0.9842, 43.98983, 'CO2' ], + ( 2, 2): [ 8, '(13C)(16O)2', 0.01106, 44.993185, 'CO2' ], + ( 2, 3): [ 9, '(16O)(12C)(18O)', 0.0039471, 45.994076, 'CO2' ], + ( 2, 4): [ 10, '(16O)(12C)(17O)', 0.000734, 44.994045, 'CO2' ], + ( 2, 5): [ 11, '(16O)(13C)(18O)', 0.00004434, 46.997431, 'CO2' ], + ( 2, 6): [ 12, '(16O)(13C)(17O)', 0.00000825, 45.9974, 'CO2' ], + ( 2, 7): [ 13, '(12C)(18O)2', 0.0000039573, 47.998322, 'CO2' ], + ( 2, 8): [ 14, '(17O)(12C)(18O)', 0.00000147, 46.998291, 'CO2' ], + ( 2, 0): [ 15, '(13C)(18O)2', 0.000000044967, 49.001675, 'CO2' ], + ( 2, 11):[120, '(18O)(13C)(17O)', 0.00000001654, 48.00165, 'CO2' ], + ( 2, 9): [121, '(12C)(17O)2', 0.0000001368, 45.998262, 'CO2' ], + ( 3, 1): [ 16, '(16O)3', 0.992901, 47.984745, 'O3' ], + ( 3, 2): [ 17, '(16O)(16O)(18O)', 0.00398194, 49.988991, 'O3' ], + ( 3, 3): [ 18, '(16O)(18O)(16O)', 0.00199097, 49.988991, 'O3' ], + ( 3, 4): [ 19, '(16O)(16O)(17O)', 0.00074, 48.98896, 'O3' ], + ( 3, 5): [ 20, '(16O)(17O)(16O)', 0.00037, 48.98896, 'O3' ], + ( 4, 1): [ 21, '(14N)2(16O)', 0.990333, 44.001062, 'N2O' ], + ( 4, 2): [ 22, '(14N)(15N)(16O)', 0.0036409, 44.998096, 'N2O' ], + ( 4, 3): [ 23, '(15N)(14N)(16O)', 0.0036409, 44.998096, 'N2O' ], + ( 4, 4): [ 24, '(14N)2(18O)', 0.00198582, 46.005308, 'N2O' ], + ( 4, 5): [ 25, '(14N)2(17O)', 0.000369, 45.005278, 'N2O' ], + ( 5, 1): [ 26, '(12C)(16O)', 0.98654, 27.994915, 'CO' ], + ( 5, 2): [ 27, '(13C)(16O)', 0.01108, 28.99827, 'CO' ], + ( 5, 3): [ 28, '(12C)(18O)', 0.0019782, 29.999161, 'CO' ], + ( 5, 4): [ 29, '(12C)(17O)', 0.000368, 28.99913, 'CO' ], + ( 5, 5): [ 30, '(13C)(18O)', 0.00002222, 31.002516, 'CO' ], + ( 5, 6): [ 31, '(13C)(17O)', 0.00000413, 30.002485, 'CO' ], + ( 6, 1): [ 32, '(12C)H4', 0.98827, 16.0313, 'CH4' ], + ( 6, 2): [ 33, '(13C)H4', 0.0111, 17.034655, 'CH4' ], + ( 6, 3): [ 34, '(12C)H3D', 0.00061575, 17.037475, 'CH4' ], + ( 6, 4): [ 35, '(13C)H3D', 0.0000049203, 18.04083, 'CH4' ], + ( 7, 1): [ 36, '(16O)2', 0.995262, 31.98983, 'O2' ], + ( 7, 2): [ 37, '(16O)(18O)', 0.00399141, 33.994076, 'O2' ], + ( 7, 3): [ 38, '(16O)(17O)', 0.000742, 32.994045, 'O2' ], + ( 8, 1): [ 39, '(14N)(16O)', 0.993974, 29.997989, 'NO' ], + ( 8, 2): [ 40, '(15N)(16O)', 0.0036543, 30.995023, 'NO' ], + ( 8, 3): [ 41, '(14N)(18O)', 0.00199312, 32.002234, 'NO' ], + ( 9, 1): [ 42, '(32S)(16O)2', 0.94568, 63.961901, 'SO2' ], + ( 9, 2): [ 43, '(34S)(16O)2', 0.04195, 65.957695, 'SO2' ], + ( 10, 1): [ 44, '(14N)(16O)2', 0.991616, 45.992904, 'NO2' ], + ( 11, 1): [ 45, '(14N)H3', 0.9958715, 17.026549, 'NH3' ], + ( 11, 2): [ 46, '(15N)H3', 0.0036613, 18.023583, 'NH3' ], + ( 12, 1): [ 47, 'H(14N)(16O)3', 0.98911, 62.995644, 'HNO3' ], + ( 12, 2): [117, 'H(15N)(16O)3', 0.003636, 63.99268, 'HNO3' ], + ( 13, 1): [ 48, '(16O)H', 0.997473, 17.00274, 'OH' ], + ( 13, 2): [ 49, '(18O)H', 0.00200014, 19.006986, 'OH' ], + ( 13, 3): [ 50, '(16O)D', 0.00015537, 18.008915, 'OH' ], + ( 14, 1): [ 51, 'H(19F)', 0.99984425, 20.006229, 'HF' ], + ( 14, 2): [110, 'D(19F)', 0.000115, 21.0125049978, 'HF' ], + ( 15, 1): [ 52, 'H(35Cl)', 0.757587, 35.976678, 'HCl' ], + ( 15, 2): [ 53, 'H(37Cl)', 0.242257, 37.973729, 'HCl' ], + ( 15, 3): [107, 'D(35Cl)', 0.000118005, 36.9829544578, 'HCl' ], + ( 15, 4): [108, 'D(37Cl)', 0.000037735, 38.9800043678, 'HCl' ], + ( 16, 1): [ 54, 'H(79Br)', 0.50678, 79.92616, 'HBr' ], + ( 16, 2): [ 55, 'H(81Br)', 0.49306, 81.924115, 'HBr' ], + ( 16, 3): [111, 'D(79Br)', 0.0000582935, 80.9324388778, 'HBr' ], + ( 16, 4): [112, 'D(81Br)', 0.0000567065, 82.9303923778, 'HBr' ], + ( 17, 1): [ 56, 'H(127I)', 0.99984425, 127.912297, 'HI' ], + ( 17, 2): [113, 'D(127I)', 0.000115, 128.918574778, 'HI' ], + ( 18, 1): [ 57, '(35Cl)(16O)', 0.75591, 50.963768, 'ClO' ], + ( 18, 2): [ 58, '(37Cl)(16O)', 0.24172, 52.960819, 'ClO' ], + ( 19, 1): [ 59, '(16O)(12C)(32S)', 0.93739, 59.966986, 'OCS' ], + ( 19, 2): [ 60, '(16O)(12C)(34S)', 0.04158, 61.96278, 'OCS' ], + ( 19, 3): [ 61, '(16O)(13C)(32S)', 0.01053, 60.970341, 'OCS' ], + ( 19, 4): [ 62, '(16O)(12C)(33S)', 0.01053, 60.966371, 'OCS' ], + ( 19, 5): [ 63, '(18O)(12C)(32S)', 0.00188, 61.971231, 'OCS' ], + ( 20, 1): [ 64, 'H2(12C)(16O)', 0.98624, 30.010565, 'H2CO' ], + ( 20, 2): [ 65, 'H2(13C)(16O)', 0.01108, 31.01392, 'H2CO' ], + ( 20, 3): [ 66, 'H2(12C)(18O)', 0.0019776, 32.014811, 'H2CO' ], + ( 21, 1): [ 67, 'H(16O)(35Cl)', 0.75579, 51.971593, 'HOCl' ], + ( 21, 2): [ 68, 'H(16O)(37Cl)', 0.24168, 53.968644, 'HOCl' ], + ( 22, 1): [ 69, '(14N)2', 0.9926874, 28.006147, 'N2' ], + ( 22, 2): [118, '(14N)(15N)', 0.0072535, 29.997989, 'N2' ], + ( 23, 1): [ 70, 'H(12C)(14N)', 0.98511, 27.010899, 'HCN' ], + ( 23, 2): [ 71, 'H(13C)(14N)', 0.01107, 28.014254, 'HCN' ], + ( 23, 3): [ 72, 'H(12C)(15N)', 0.0036217, 28.007933, 'HCN' ], + ( 24, 1): [ 73, '(12C)H3(35Cl)', 0.74894, 49.992328, 'CH3Cl'], + ( 24, 2): [ 74, '(12C)H3(37Cl)', 0.23949, 51.989379, 'CH3Cl'], + ( 25, 1): [ 75, 'H2(16O)2', 0.994952, 34.00548, 'H2O2' ], + ( 26, 1): [ 76, '(12C)2H2', 0.9776, 26.01565, 'C2H2' ], + ( 26, 2): [ 77, '(12C)(13C)H2', 0.02197, 27.019005, 'C2H2' ], + ( 26, 3): [105, '(12C)2HD', 0.00030455, 27.021825, 'C2H2' ], + ( 27, 1): [ 78, '(12C)2H6', 0.97699, 30.04695, 'C2H6' ], + ( 27, 2): [106, '(12C)H3(13C)H3', 0.021952611, 31.050305, 'C2H6' ], + ( 28, 1): [ 79, '(31P)H3', 0.99953283, 33.997238, 'PH3' ], + ( 29, 1): [ 80, '(12C)(16O)(19F)2', 0.98654, 65.991722, 'COF2' ], + ( 29, 2): [119, '(13C)(16O)(19F)2', 0.0110834, 66.995083, 'COF2' ], + ( 31, 1): [ 81, 'H2(32S)', 0.94988, 33.987721, 'H2S' ], + ( 31, 2): [ 82, 'H2(34S)', 0.04214, 35.983515, 'H2S' ], + ( 31, 3): [ 83, 'H2(33S)', 0.007498, 34.987105, 'H2S' ], + ( 32, 1): [ 84, 'H(12C)(16O)(16O)H', 0.983898, 46.00548, 'HCOOH'], + ( 33, 1): [ 85, 'H(16O)2', 0.995107, 32.997655, 'HO2' ], + ( 34, 1): [ 86, '(16O)', 0.997628, 15.994915, 'O' ], + ( 36, 1): [ 87, '(14N)(16O)+', 0.993974, 29.997989, 'NOp' ], + ( 37, 1): [ 88, 'H(16O)(79Br)', 0.5056, 95.921076, 'HOBr' ], + ( 37, 2): [ 89, 'H(16O)(81Br)', 0.4919, 97.919027, 'HOBr' ], + ( 38, 1): [ 90, '(12C)2H4', 0.9773, 28.0313, 'C2H4' ], + ( 38, 2): [ 91, '(12C)H2(13C)H2', 0.02196, 29.034655, 'C2H4' ], + ( 39, 1): [ 92, '(12C)H3(16O)H', 0.98593, 32.026215, 'CH3OH'], + ( 40, 1): [ 93, '(12C)H3(79Br)', 0.5013, 93.941811, 'CH3Br'], + ( 40, 2): [ 94, '(12C)H3(81Br)', 0.48766, 95.939764, 'CH3Br'], + ( 41, 1): [ 95, '(12C)H3(12C)(14N)', 0.97482, 41.026549, 'CH3CN'], + ( 42, 1): [ 96, '(12C)(19F)4', 0.9893, 87.993616, 'CF4' ], + ( 43, 1): [116, '(12C)4H2', 0.955998, 50.01565, 'C4H2' ], + ( 44, 1): [109, 'H(12C)3(14N)', 0.9646069, 51.01089903687, 'HC3N' ], + ( 45, 1): [103, 'H2', 0.999688, 2.01565, 'H2' ], + ( 45, 2): [115, 'HD', 0.00022997, 3.021825, 'H2' ], + ( 46, 1): [ 97, '(12C)(32S)', 0.939624, 43.971036, 'CS' ], + ( 46, 2): [ 98, '(12C)(34S)', 0.0416817, 45.966787, 'CS' ], + ( 46, 3): [ 99, '(13C)(32S)', 0.0105565, 44.974368, 'CS' ], + ( 46, 4): [100, '(12C)(33S)', 0.00741668, 44.970399, 'CS' ], + ( 47, 1): [114, '(32S)(16O)3', 0.9423964, 79.95682, 'SO3' ], + (1001, 1): [101, 'H', None, None, 'H' ], + (1002, 1): [102, 'He', None, None, 'He' ], + (1018, 1): [104, 'Ar', None, None, 'Ar' ], +} + def parse_readme(filename, group_global=None, group_local=None): with open(filename,'r') as f: @@ -72,9 +210,9 @@ def quanta_formatter(group_global='class1', group_local='group1'): ('Sym','A1'), ] ), + } - } global_dict = {'class9': # non-linear tetratomic OrderedDict([('v1','I5'), # preceded by 3x space ('v2','I2'), @@ -123,6 +261,43 @@ def quanta_formatter(group_global='class1', group_local='group1'): return loc,glob +def download_hitran(m, i, numin, numax): + """ + Download HITRAN data for a particular molecule. Based on fetch function from + hapi.py. + + Parameters + ---------- + m : int + HITRAN molecule number + i : int + HITRAN isotopologue number + numin : real + lower wavenumber bound + numax : real + upper wavenumber bound + """ + iso_id = str(ISO[(m,i)][ISO_INDEX['id']]) + mol_name = ISO[(m,i)][ISO_INDEX['mol_name']] + url = HITRAN_URL + '/lbl/api?' + \ + 'iso_ids_list=' + iso_id + '&' + \ + 'numin=' + str(numin) + '&' + \ + 'numax=' + str(numax) + try: + req = urllib2.urlopen(url) + except urllib2.HTTPError: + raise Exception('Failed to retrieve data for given parameters.') + except urllib2.URLError: + raise Exception('Cannot connect to {0}.'.format(HITRAN_URL)) + CHUNK = 64 * 1024 + filename = os.path.join(cache_location, '{0}.data'.format(mol_name)) + with open(filename, 'w') as fp: + while True: + chunk = req.read(CHUNK) + if not chunk: break + fp.write(chunk.decode('utf-8')) + log.info('{0} bytes written to {1}'.format(CHUNK, filename)) + def read_hitran_file(filename, formats=None, formatfile=os.path.join(DATA_DIR, 'readme.txt')): if formats is None and formatfile is not None: @@ -148,4 +323,3 @@ def read_hitran_file(filename, formats=None, tbl = Table(rows=rows, names=formats.keys(), dtype=dtypes) return tbl - From 7befdc47109f81cc58150190ce8f4d4321f0a2ec Mon Sep 17 00:00:00 2001 From: Miguel de Val-Borro Date: Wed, 2 Nov 2016 16:00:00 -0400 Subject: [PATCH 06/12] Added tests for the hitran package --- astroquery/hitran/setup_package.py | 5 +- astroquery/hitran/tests/__init__.py | 0 astroquery/hitran/tests/data/H2O.data | 122 +++++++++++++++++++++++++ astroquery/hitran/tests/test_hitran.py | 21 +++++ 4 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 astroquery/hitran/tests/__init__.py create mode 100644 astroquery/hitran/tests/data/H2O.data create mode 100644 astroquery/hitran/tests/test_hitran.py diff --git a/astroquery/hitran/setup_package.py b/astroquery/hitran/setup_package.py index 490464f100..a6372a48c7 100644 --- a/astroquery/hitran/setup_package.py +++ b/astroquery/hitran/setup_package.py @@ -5,8 +5,9 @@ def get_package_data(): - paths_data = [os.path.join('data', 'readme.txt'), - ] + paths_data = [os.path.join('data', 'readme.txt')] + paths_test = [os.path.join('data', 'H2O.data')] return {'astroquery.hitran': paths_data, + 'astroquery.hitran.tests': paths_test, } diff --git a/astroquery/hitran/tests/__init__.py b/astroquery/hitran/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/astroquery/hitran/tests/data/H2O.data b/astroquery/hitran/tests/data/H2O.data new file mode 100644 index 0000000000..d86f3e02ea --- /dev/null +++ b/astroquery/hitran/tests/data/H2O.data @@ -0,0 +1,122 @@ + 11 0.072059 2.043E-30 5.088E-12.09190.391 1922.82910.760.003700 0 1 0 0 1 0 4 2 2 5 1 5 5545533321287120 7 9.0 11.0 + 11 0.117133 2.956E-34 1.262E-11.08940.371 4095.80270.660.002000 1 0 0 1 0 0 5 2 3 6 1 6 4446534432287120 7 33.0 39.0 + 11 0.152768 7.836E-35 2.127E-11.08940.371 4195.81790.660.002000 0 0 1 0 0 1 5 2 3 6 1 6 4446534432287120 7 11.0 13.0 + 11 0.194652 9.864E-35 1.180E-11.07930.412 3977.26170.670.005300 1 0 0 0 0 1 5 1 5 4 1 4 5442434432257122 7 11.0 9.0 + 11 0.210927 1.663E-32 4.181E-10.08260.391 3598.51560.750.005300 0 2 0 0 2 0 4 3 1 5 2 4 5446534432257120 7 9.0 11.0 + 11 0.242095 9.157E-31 1.429E-10.07500.298 2904.42800.510.004900 0 1 0 0 1 0 9 3 6 10 2 9 5446834432287122 8 57.0 63.0 + 11 0.377306 8.133E-36 2.114E-11.06130.352 4563.98930.57-.000844 0 2 0 1 0 0 8 5 3 7 4 4 4342434432257122 7 17.0 15.0 + 11 0.388373 3.117E-34 1.722E-10.08550.391 4149.89890.670.006300 1 0 0 0 0 1 5 3 3 5 1 4 4442434432257122 7 11.0 11.0 + 11 0.400572 2.352E-28 1.009E-09.08690.434 1907.61580.65-.003100 0 1 0 0 1 0 4 2 3 3 3 0 5546633321287120 8 27.0 21.0 + 11 0.416028 1.956E-32 3.183E-10.03450.208 3623.76320.380.009500 0 0 0 0 0 0 15 7 9 16 4 12 34424344323171 511 31.0 33.0 + 11 0.511490 9.782E-36 3.244E-09.09830.434 5473.14450.780.005600 0 1 1 0 1 1 2 2 0 3 1 3 4346634432257120 7 15.0 21.0 + 11 0.537344 4.940E-37 1.430E-09.03020.298 5996.63770.48-.001100 0 2 0 0 2 0 11 8 4 10 9 1 3342434432297122 9 23.0 21.0 + 11 0.537824 1.484E-36 1.433E-09.03020.298 5996.63770.48-.001100 0 2 0 0 2 0 11 8 3 10 9 2 3342434432297122 9 69.0 63.0 + 11 0.537835 3.555E-36 1.351E-09.09230.412 5653.02640.73-.002000 0 1 1 0 1 1 5 1 5 4 2 2 4346534432287120 8 33.0 27.0 + 11 0.741691 4.394E-25 1.991E-09.09000.385 446.51070.60-.000800 0 0 0 0 0 0 6 1 6 5 2 3 5576533321836620 8 39.0 33.0 + 11 0.766500 1.393E-37 1.714E-08.05840.298 6655.62940.51-.009100 0 3 0 0 3 0 9 6 4 10 5 5 3342434432297122 9 19.0 21.0 + 11 0.768939 7.600E-37 1.894E-13.07820.434 4030.06980.690.000800 1 0 0 0 0 1 4 3 2 3 3 1 4342434432257122 7 27.0 21.0 + 11 0.865759 5.104E-35 2.755E-08.08180.352 5435.41210.680.005300 0 3 0 0 3 0 6 3 3 7 2 6 4445534432257120 7 13.0 15.0 + 11 0.895092 3.600E-28 8.314E-09.08010.412 2129.59910.75-.000300 0 1 0 0 1 0 5 3 2 4 4 1 5546633321287120 8 33.0 27.0 + 11 0.900086 5.783E-35 1.965E-08.07990.352 5613.36960.57-.002400 0 3 0 0 3 0 8 2 7 7 3 4 4442434432287122 8 51.0 45.0 + 11 0.940391 8.278E-34 4.584E-10.09190.434 3926.86230.690.003400 1 0 0 0 0 1 4 1 3 3 1 2 5442434432257122 7 9.0 7.0 + 11 1.166359 9.086E-36 1.721E-08.09190.391 5556.68510.760.003700 1 1 0 1 1 0 4 2 2 5 1 5 4345534432287120 7 9.0 11.0 + 11 1.389261 8.972E-34 8.139E-08.08870.412 5162.64211.010.000400 0 3 0 0 3 0 5 2 3 4 3 2 4447434432257120 7 33.0 27.0 + 11 1.542490 2.528E-36 5.884E-12.07130.371 4195.81790.620.005352 0 2 0 0 0 1 6 5 1 6 1 6 434243443230712210 13.0 13.0 + 11 1.547458 4.195E-34 6.329E-10.07920.434 4030.30590.69-.000400 1 0 0 0 0 1 4 3 1 3 3 0 4442434432257122 7 9.0 7.0 + 11 1.617166 3.709E-33 1.382E-07.09490.456 4855.29980.710.002000 0 3 0 0 3 0 3 1 2 2 2 1 4447834432257122 7 21.0 15.0 + 11 1.678415 1.915E-33 6.521E-10.08390.412 3974.62960.670.007200 1 0 0 0 0 1 5 0 5 4 0 4 4442434432257122 7 33.0 27.0 + 11 1.924093 1.165E-35 9.553E-08.07740.391 5754.74270.740.001500 1 1 0 1 1 0 4 4 0 5 3 3 4446434432257120 7 9.0 11.0 + 11 2.052196 6.816E-35 7.096E-11.07170.371 4197.33840.62-.009420 1 0 0 0 2 0 6 2 5 6 5 2 5442434432287122 8 39.0 39.0 + 11 2.153838 3.942E-33 6.786E-09.07790.371 4290.75680.620.006900 1 0 0 0 0 1 6 3 4 6 1 5 4442434432257122 7 39.0 39.0 + 11 2.261694 1.233E-26 1.953E-07.09510.434 1819.33510.69-.002900 0 1 0 0 1 0 4 1 4 3 2 1 5548633321287120 8 27.0 21.0 + 11 2.370644 1.712E-35 5.628E-10.07110.298 4750.36130.510.006168 0 2 0 1 0 0 10 3 7 10 0 10 4442434432287122 8 21.0 21.0 + 11 2.388433 7.025E-33 6.215E-08.01550.183 4606.16600.410.000000 0 0 0 0 0 0 19 4 16 18 5 13 34424044323271 5 0 39.0 37.0 + 11 2.585016 4.333E-35 7.275E-08.08330.412 5541.66360.690.003300 0 1 1 1 1 0 3 2 2 4 2 3 4442434432257122 7 21.0 27.0 + 11 2.604622 5.144E-34 5.683E-07.08110.371 5610.76510.730.001600 0 3 0 0 3 0 7 3 4 6 4 3 4446534432257120 7 45.0 39.0 + 11 2.729181 1.484E-35 6.870E-07.05630.333 6192.24460.69-.004300 0 3 0 0 3 0 9 4 6 8 5 3 3445434432287120 8 19.0 17.0 + 11 2.773758 3.753E-34 3.446E-07.09510.434 5454.59620.69-.002900 1 1 0 1 1 0 4 1 4 3 2 1 4448634432287120 8 27.0 21.0 + 11 2.861552 2.047E-34 2.921E-07.08690.434 5538.80220.65-.003100 1 1 0 1 1 0 4 2 3 3 3 0 4446634432287120 8 27.0 21.0 + 11 3.030769 2.501E-33 6.999E-08.07180.333 4622.90580.570.000600 0 0 1 1 0 0 8 2 7 8 2 6 4442434432257122 7 17.0 17.0 + 11 3.035947 8.888E-32 8.694E-08.08900.412 4027.80270.690.007500 1 0 0 0 0 1 4 3 2 4 1 3 4442434432257122 7 27.0 27.0 + 11 3.039201 1.449E-35 2.399E-07.06610.391 6106.29690.740.003200 0 1 1 0 1 1 6 4 2 5 5 1 4445534432297120 8 39.0 33.0 + 11 3.042006 2.058E-35 8.242E-09.06520.281 5439.05570.480.002500 0 0 1 1 0 0 10 5 5 11 3 8 444243443231712210 63.0 69.0 + 11 3.153107 1.864E-34 7.203E-07.09830.434 5376.78520.780.005600 1 1 0 1 1 0 2 2 0 3 1 3 3446634432257120 7 5.0 7.0 + 11 3.210930 1.532E-27 4.608E-07.07740.391 2126.40770.740.001500 0 1 0 0 1 0 4 4 0 5 3 3 5546433321257120 7 9.0 11.0 + 11 3.248006 3.445E-31 1.313E-07.03370.315 3994.25980.510.004600 0 1 0 0 1 0 10 8 3 9 9 0 5442434432297122 9 63.0 57.0 + 11 3.248211 1.149E-31 1.314E-07.03370.315 3994.25980.510.004600 0 1 0 0 1 0 10 8 2 9 9 1 4442434432297122 9 21.0 19.0 + 11 3.248742 3.513E-35 2.664E-07.08690.434 5630.14310.65-.003100 0 1 1 0 1 1 4 2 3 3 3 0 4446634432287120 8 9.0 7.0 + 11 3.275130 5.959E-35 3.081E-07.09510.434 5549.70170.69-.002900 0 1 1 0 1 1 4 1 4 3 2 1 4448634432287120 8 9.0 7.0 + 11 3.641201 1.422E-34 3.657E-10.08630.434 3962.91800.690.000600 1 0 0 0 0 1 4 2 2 3 2 1 5442434432257122 7 9.0 7.0 + 11 3.693225 8.266E-34 4.427E-09.08090.352 4186.56880.61-.010552 1 0 0 0 2 0 6 1 5 7 4 4 4442434432287122 8 13.0 15.0 + 11 3.708200 1.541E-35 7.506E-08.07930.412 5552.97660.670.005300 1 1 0 0 1 1 5 1 5 4 1 4 4442434432257122 7 11.0 9.0 + 11 3.796348 1.189E-35 5.818E-07.06900.371 6022.78420.62-.005500 1 1 0 1 1 0 5 5 1 6 4 2 4442434432287122 8 11.0 13.0 + 11 3.854359 1.317E-32 2.103E-07.01550.183 4606.16600.410.000000 0 0 0 0 0 0 17 8 10 18 5 13 34424044323271 5 0 35.0 37.0 + 11 3.913840 1.864E-33 3.684E-09.07270.371 4195.47710.620.003300 1 0 0 0 0 1 6 2 5 6 0 6 4442434432257122 7 39.0 39.0 + 11 4.002621 1.429E-26 1.473E-06.09830.434 1739.48360.780.005600 0 1 0 0 1 0 2 2 0 3 1 3 5546633321257120 7 5.0 7.0 + 11 4.021315 3.744E-30 1.803E-06.07490.371 3864.96560.620.002400 0 2 0 0 2 0 5 4 1 6 3 4 5446534432257120 7 33.0 39.0 + 11 4.035835 3.960E-35 6.864E-07.06710.371 6022.54590.68-.004600 1 1 0 1 1 0 5 5 0 6 4 3 4445534432287120 8 33.0 39.0 + 11 4.323122 3.632E-35 3.565E-10.06340.315 4559.70700.560.009368 0 2 0 1 0 0 8 5 4 9 0 9 4442434432287122 8 51.0 57.0 + 11 4.329670 6.288E-30 4.077E-07.03990.315 3526.62790.56-.010500 0 1 0 0 1 0 8 8 1 9 7 2 5442434432287122 8 51.0 57.0 + 11 4.331060 2.098E-30 4.082E-07.03990.315 3526.62670.56-.010500 0 1 0 0 1 0 8 8 0 9 7 3 5442434432297122 9 17.0 19.0 + 11 4.369783 1.895E-34 9.774E-07.08010.412 5756.65920.75-.000300 1 1 0 1 1 0 5 3 2 4 4 1 4446634432287120 8 33.0 27.0 + 11 4.483550 1.276E-34 1.022E-06.07500.412 5842.02830.71-.001000 0 1 1 0 1 1 5 3 3 4 4 0 4445534432287120 7 33.0 27.0 + 11 4.571618 5.024E-30 2.160E-06.08790.412 3495.93900.710.003000 0 2 0 0 2 0 3 3 1 4 2 2 5446534432257120 7 7.0 9.0 + 11 4.656998 1.168E-28 5.455E-07.04680.253 3080.17900.420.002600 0 0 0 0 0 0 14 6 9 15 3 12 555243332185641811 87.0 93.0 + 11 4.763938 8.776E-35 1.151E-08.05400.352 4846.77390.570.001300 0 0 1 1 0 0 8 4 5 7 6 2 444243443231712210 17.0 15.0 + 11 4.920466 1.825E-30 2.788E-06.08120.391 3868.87280.770.000300 0 2 0 0 2 0 6 3 3 5 4 2 5446534432287120 8 13.0 11.0 + 11 5.277974 2.118E-33 5.854E-07.07840.315 5022.28080.66-.005000 0 0 1 0 0 1 10 2 9 9 3 6 4446434432287120 8 21.0 19.0 + 11 5.330675 5.343E-33 1.071E-07.06750.391 4381.90380.620.003400 0 0 1 1 0 0 6 3 4 5 5 1 444243443231712210 13.0 11.0 + 11 5.351387 4.100E-32 6.302E-08.08330.412 3951.31450.690.003300 0 0 1 1 0 0 3 2 2 4 2 3 5442434432257122 7 21.0 27.0 + 11 5.555983 1.685E-32 1.389E-07.08020.371 4190.26220.620.004700 0 0 1 1 0 0 6 1 6 6 1 5 4442434432257122 7 13.0 13.0 + 11 5.914690 1.246E-29 1.180E-06.02150.208 3437.27510.380.000500 0 0 0 0 0 0 15 6 10 16 3 13 44424344323171 511 31.0 33.0 + 11 5.947272 2.926E-34 5.248E-06.08000.315 5812.38380.560.005300 0 3 0 0 3 0 8 3 5 9 2 8 3447834432287122 8 17.0 19.0 + 11 6.114567 7.785E-23 3.631E-06.09920.519 136.16390.68-.002700 0 0 0 0 0 0 3 1 3 2 2 0 5566633321836620 8 7.0 5.0 + 11 6.446024 1.310E-35 1.077E-06.04180.250 6444.63430.36-.023800 0 0 1 0 0 1 14 3 11 13 6 8 4442434432297122 9 87.0 81.0 + 11 6.570333 1.721E-30 4.462E-06.09900.456 3789.96920.68-.002700 1 0 0 1 0 0 3 1 3 2 2 0 5446634432287120 8 7.0 5.0 + 11 6.915385 2.210E-35 2.621E-06.06030.352 6340.33790.87-.007200 1 1 0 1 1 0 6 6 1 7 5 2 4446434432287120 8 39.0 45.0 + 11 6.915896 2.462E-33 1.827E-06.06670.298 5169.03860.510.000300 0 0 1 1 0 0 10 3 8 10 3 7 4442434432297122 8 21.0 21.0 + 11 6.975432 1.657E-27 3.366E-06.06900.371 2399.16550.62-.005500 0 1 0 0 1 0 5 5 1 6 4 2 5542433321287122 8 11.0 13.0 + 11 6.996459 2.258E-35 2.217E-07.08210.391 5749.66260.670.000800 1 1 0 0 1 1 4 4 1 5 2 4 444243443230712210 27.0 33.0 + 11 7.078452 1.365E-35 6.164E-09.00860.281 5062.00880.48-.001000 1 0 0 0 0 1 10 2 8 11 0 11 344243443230712210 21.0 23.0 + 11 7.082835 6.521E-35 2.271E-10.08260.352 4188.39400.61-.009852 0 0 1 0 2 0 6 0 6 7 4 3 4442434432287122 8 39.0 45.0 + 11 7.130356 9.983E-36 1.167E-09.06180.298 5027.25590.48-.001224 0 2 0 0 0 1 11 3 8 10 1 9 4442434432287122 8 69.0 63.0 + 11 7.272415 1.551E-35 6.520E-08.03360.281 5741.42580.48-.009972 0 0 1 0 2 0 10 7 3 11 7 4 4442434432297122 9 63.0 69.0 + 11 7.405549 2.419E-33 1.565E-05.06970.352 5782.70850.62-.005600 0 3 0 0 3 0 8 3 6 7 4 3 4445434432287120 8 51.0 45.0 + 11 7.529322 4.191E-35 1.662E-08.07720.315 5022.28080.510.018336 0 2 0 0 0 1 10 5 5 9 3 6 4442434432287122 7 21.0 19.0 + 11 7.596781 8.710E-34 3.367E-09.06850.333 4224.58740.57-.009724 1 0 0 0 2 0 7 0 7 8 3 6 4442434432287122 7 45.0 51.0 + 11 7.761580 6.153E-27 4.627E-06.06710.371 2398.38160.68-.004600 0 1 0 0 1 0 5 5 0 6 4 3 5545533321287120 8 33.0 39.0 + 11 7.841962 7.559E-33 8.554E-06.04040.315 5229.57760.510.000200 0 2 0 0 2 0 10 6 4 9 7 3 4442434432297122 9 21.0 19.0 + 11 7.898834 1.744E-35 2.114E-06.05710.250 6256.01950.36-.000800 0 0 1 0 0 1 14 3 12 13 4 9 3442434432297122 9 29.0 27.0 + 11 8.112253 2.899E-32 2.492E-06.07840.315 4918.23440.66-.005000 1 0 0 1 0 0 10 2 9 9 3 6 4446434432287120 8 63.0 57.0 + 11 8.149689 3.719E-34 4.841E-06.08630.434 5549.70170.690.000600 1 1 0 0 1 1 4 2 2 3 2 1 4442434432257122 7 9.0 7.0 + 11 8.253712 2.674E-28 2.442E-06.05990.300 2872.58080.50-.000900 0 0 0 0 0 0 14 4 10 15 3 13 555243332185641811 29.0 31.0 + 11 8.287542 2.987E-35 7.533E-10.05200.315 4661.44820.510.008340 0 2 0 0 0 1 10 3 8 9 1 9 4442434432257122 7 63.0 57.0 + 11 8.348342 2.110E-31 1.358E-06.09130.434 3926.86230.710.006200 1 0 0 0 0 1 3 3 1 3 1 2 4442434432257122 7 7.0 7.0 + 11 8.360701 7.548E-31 9.043E-06.08000.333 4259.87890.91-.002500 0 2 0 0 2 0 9 2 8 8 3 5 4446434432287120 8 19.0 17.0 + 11 8.415867 2.482E-32 5.545E-07.06190.333 4564.03030.570.001740 1 0 0 0 2 0 7 4 3 8 5 4 4446534432257120 7 45.0 51.0 + 11 8.473018 5.322E-30 9.552E-06.09900.456 3887.11430.68-.002700 0 0 1 0 0 1 3 1 3 2 2 0 5446634432287120 8 21.0 15.0 + 11 8.473649 1.561E-33 6.763E-06.05710.250 5781.95750.36-.000800 0 2 0 0 2 0 14 3 12 13 4 9 4442434432297122 9 87.0 81.0 + 11 8.480251 1.234E-35 2.059E-06.05990.371 6171.35550.610.001400 0 1 1 1 1 0 7 3 4 6 5 1 444243443230712210 15.0 13.0 + 11 8.552441 8.671E-32 1.300E-05.04790.333 4775.08790.80-.000700 0 2 0 0 2 0 9 5 5 8 6 2 4446434432287120 8 19.0 17.0 + 11 8.587987 1.088E-33 1.410E-09.09030.391 3868.98680.67-.007456 1 0 0 0 2 0 4 1 4 5 4 1 5442434432257122 7 27.0 33.0 + 11 8.671100 5.941E-28 3.208E-06.05250.268 2739.42870.460.005100 0 0 0 0 0 0 13 6 8 14 3 11 555243332185641811 27.0 29.0 + 11 8.758287 2.314E-35 9.206E-08.04990.281 5465.05220.480.005836 0 2 0 1 0 0 10 7 3 11 4 8 344243443231712210 21.0 23.0 + 11 8.769334 6.965E-29 3.973E-06.04700.333 3101.14230.57-.010300 0 1 0 0 1 0 7 7 1 8 6 2 5542433321287122 8 15.0 17.0 + 11 8.779495 1.456E-34 3.720E-08.07550.281 5144.40820.48-.010884 1 0 0 0 2 0 11 1 10 11 4 7 4442434432297122 8 69.0 69.0 + 11 8.787797 2.098E-28 3.998E-06.04600.333 3101.12380.57-.010200 0 1 0 0 1 0 7 7 0 8 6 3 5542433321287122 8 45.0 51.0 + 11 8.806541 3.194E-32 1.356E-05.04060.315 5229.57860.51-.000300 0 2 0 0 2 0 10 6 5 9 7 2 4442434432287122 8 63.0 57.0 + 11 8.848050 1.647E-33 6.638E-08.06900.352 4448.97070.610.006500 1 0 0 0 0 1 7 3 5 7 1 6 4442434432287122 8 15.0 15.0 + 11 8.891269 1.734E-33 4.324E-06.00750.161 5739.22460.410.000000 0 0 0 0 0 0 21 4 17 20 7 14 44424044323271 5 0 129.0 123.0 + 11 8.944479 3.459E-30 1.528E-05.07200.352 4188.39400.61-.002600 0 2 0 0 2 0 6 5 2 7 4 3 5445834432287122 7 39.0 45.0 + 11 9.266665 1.820E-34 9.150E-06.08010.412 5842.00200.75-.000300 0 1 1 0 1 1 5 3 2 4 4 1 4446634432287120 8 11.0 9.0 + 11 9.511897 2.027E-33 1.012E-05.03600.298 5473.81050.51-.007600 0 2 0 0 2 0 9 8 2 10 7 3 3442434432297122 9 19.0 21.0 + 11 9.520433 6.093E-33 1.015E-05.03600.298 5473.80220.51-.007500 0 2 0 0 2 0 9 8 1 10 7 4 3442434432297122 9 57.0 63.0 + 11 9.587702 3.647E-34 8.286E-06.07920.434 5630.14310.69-.000400 1 1 0 0 1 1 4 3 1 3 3 0 4442434432257122 7 9.0 7.0 + 11 9.638056 1.593E-34 3.462E-06.00750.161 6167.70850.410.000000 0 0 0 0 0 0 21 6 15 20 9 12 44424044323271 5 0 129.0 123.0 + 11 9.653410 1.745E-34 5.264E-06.05260.250 6139.02830.24-.000400 1 0 0 0 0 1 13 4 9 13 4 10 4442434432297122 9 81.0 81.0 + 11 9.656233 1.594E-34 1.021E-04.10040.480 6194.78760.74-.000200 0 4 0 0 4 0 2 0 2 1 1 1 3447334432257120 7 5.0 3.0 + 11 9.733177 4.758E-35 5.374E-05.09330.434 6430.62160.82-.002200 0 4 0 0 4 0 4 1 3 3 2 2 4447434432257120 7 9.0 7.0 + 11 9.795577 1.782E-27 7.007E-06.06030.352 2724.16720.87-.007200 0 1 0 0 1 0 6 6 1 7 5 2 5546433321287120 8 39.0 45.0 + 11 9.832807 1.969E-35 5.749E-06.00750.131 6707.33540.410.000000 0 0 0 0 0 0 22 7 16 23 4 19 34424044323271 5 0 135.0 141.0 + 11 9.857170 3.800E-31 2.194E-05.05020.333 4774.80470.560.002000 0 2 0 0 2 0 9 5 4 8 6 3 4445834432287122 8 57.0 51.0 + 11 9.921489 6.094E-28 7.279E-06.05630.352 2724.04150.61-.009300 0 1 0 0 1 0 6 6 0 7 5 3 5542433321287122 8 13.0 15.0 diff --git a/astroquery/hitran/tests/test_hitran.py b/astroquery/hitran/tests/test_hitran.py new file mode 100644 index 0000000000..6db6deb632 --- /dev/null +++ b/astroquery/hitran/tests/test_hitran.py @@ -0,0 +1,21 @@ +# Licensed under a 3-clause BSD style license - see LICENSE.rst +import os +from ...hitran import read_hitran_file + +def data_path(filename): + data_dir = os.path.join(os.path.dirname(__file__), 'data') + return os.path.join(data_dir, filename) + +def test_parser(): + tbl = read_hitran_file(data_path('H2O.data')) + + assert len(tbl) == 122 + assert set(tbl.keys()) == set(['molec_id', 'local_iso_id', 'nu', 'sw', 'a', + 'gamma_air', 'gamma_self', 'elower', 'n_air', + 'delta_air', 'global_upper_quanta', + 'global_lower_quanta', 'local_upper_quanta', + 'local_lower_quanta', 'ierr1', 'ierr2', + 'ierr3', 'ierr4', 'ierr5', 'ierr6', 'iref1', + 'iref2', 'iref3', 'iref4', 'iref5', 'iref6', + 'line_mixing_flag', 'gp', 'gpp']) + assert tbl['molec_id'][0] == 1 From b7fd1f36c04522d24e22e35a4820ab275000a39f Mon Sep 17 00:00:00 2001 From: Miguel de Val-Borro Date: Wed, 2 Nov 2016 16:58:38 -0400 Subject: [PATCH 07/12] Use requests module to download HITRAN data --- astroquery/hitran/reader.py | 38 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/astroquery/hitran/reader.py b/astroquery/hitran/reader.py index 4b1eef22c7..9129422bd9 100644 --- a/astroquery/hitran/reader.py +++ b/astroquery/hitran/reader.py @@ -1,16 +1,13 @@ from collections import OrderedDict from astropy.table import Table -from astropy import log from astropy.config import paths +from astropy.utils.console import ProgressBar +from ..utils import commons import os -try: - import urllib.request as urllib2 -except ImportError: - import urllib2 DATA_DIR = os.path.join(os.path.dirname(__file__), 'data') -HITRAN_URL = 'http://hitran.org' +HITRAN_URL = 'http://hitran.org/lbl/api' cache_location = os.path.join(paths.get_cache_dir(), 'astroquery', 'hitran') if not os.path.exists(cache_location): os.makedirs(cache_location) @@ -279,24 +276,21 @@ def download_hitran(m, i, numin, numax): """ iso_id = str(ISO[(m,i)][ISO_INDEX['id']]) mol_name = ISO[(m,i)][ISO_INDEX['mol_name']] - url = HITRAN_URL + '/lbl/api?' + \ - 'iso_ids_list=' + iso_id + '&' + \ - 'numin=' + str(numin) + '&' + \ - 'numax=' + str(numax) - try: - req = urllib2.urlopen(url) - except urllib2.HTTPError: - raise Exception('Failed to retrieve data for given parameters.') - except urllib2.URLError: - raise Exception('Cannot connect to {0}.'.format(HITRAN_URL)) - CHUNK = 64 * 1024 filename = os.path.join(cache_location, '{0}.data'.format(mol_name)) + CHUNK = 64 * 1024 + data = dict(iso_ids_list=iso_id, numin=numin, numax=numax) with open(filename, 'w') as fp: - while True: - chunk = req.read(CHUNK) - if not chunk: break - fp.write(chunk.decode('utf-8')) - log.info('{0} bytes written to {1}'.format(CHUNK, filename)) + response = commons.send_request(HITRAN_URL, data, 10, + request_type='GET') + if 'Content-Length' in response.headers: + total_length = response.headers.get('Content-Length') + pb = ProgressBar(int(total_length)) + for chunk in response.iter_content(chunk_size=CHUNK): + fp.write(chunk.decode('utf-8')) + try: + pb.update(CHUNK) + except NameError: + pass def read_hitran_file(filename, formats=None, formatfile=os.path.join(DATA_DIR, 'readme.txt')): From e5026737231bbca036a86ee5fdcf75d8c1d07278 Mon Sep 17 00:00:00 2001 From: Miguel de Val-Borro Date: Wed, 2 Nov 2016 17:41:22 -0400 Subject: [PATCH 08/12] Link to hapi.py code --- astroquery/hitran/reader.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/astroquery/hitran/reader.py b/astroquery/hitran/reader.py index 9129422bd9..806a8e3312 100644 --- a/astroquery/hitran/reader.py +++ b/astroquery/hitran/reader.py @@ -18,7 +18,8 @@ ISO_INDEX = { 'id':0, 'iso_name':1, 'abundance':2, 'mass':3, 'mol_name':4 } -# Copied from hapi.py code +# Copied from the hapi.py code (Academic Free License) +# http://hitran.org/static/hapi/hapi.py ISO = { ( 1, 1): [ 1, 'H2(16O)', 0.997317, 18.010565, 'H2O' ], ( 1, 2): [ 2, 'H2(18O)', 0.00199983, 20.014811, 'H2O' ], From 1760efdaf6fb9f4a453514806487b895d3900bda Mon Sep 17 00:00:00 2001 From: Miguel de Val-Borro Date: Thu, 3 Nov 2016 16:33:36 -0400 Subject: [PATCH 09/12] Add some documentation for HITRAN query --- astroquery/hitran/__init__.py | 2 +- docs/hitran/hitran.rst | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 docs/hitran/hitran.rst diff --git a/astroquery/hitran/__init__.py b/astroquery/hitran/__init__.py index 307d1ed73d..5999bae217 100644 --- a/astroquery/hitran/__init__.py +++ b/astroquery/hitran/__init__.py @@ -5,4 +5,4 @@ :Author: Adam Ginsburg (adam.g.ginsburg@gmail.com) """ -from .reader import download_hitran, read_hitran_file +from .reader import download_hitran, read_hitran_file, cache_location diff --git a/docs/hitran/hitran.rst b/docs/hitran/hitran.rst new file mode 100644 index 0000000000..98c80d2bf6 --- /dev/null +++ b/docs/hitran/hitran.rst @@ -0,0 +1,37 @@ +.. doctest-skip-all + +************************************ +HITRAN Queries (`astroquery.hitran`) +************************************ + +Getting started +=============== + +This module provides an interface to the `HITRAN`_ database API. It can +download a data file including transitions for a particular molecule in a given +wavenumber range. The file is downloaded in the `~hitran.cache_location` +directory and can be opened with a reader function that returns a table of +spectral lines including all accessible parameters. + +Examples +======== + +This will download all transitions of the main isotopologue of water between +the wavenumbers of 3400 and 4100 cm\ :sup:`-1`\ . + +.. code-block:: python + + >>> import os + >>> from astroquery.hitran import read_hitran_file, cache_location, download_hitran + >>> download_hitran(1, 1, 3400, 4100) + >>> tbl = read_hitran_file(os.path.join(cache_location, 'H2O.data')) + +Transitions are returned as an `~astropy.table.Table` instance. + +Reference/API +============= + +.. automodapi:: astroquery.hitran + :no-inheritance-diagram: + +.. _HITRAN: http://hitran.org From 05993e90c1a79a997435c5ae6870b3ded227c08f Mon Sep 17 00:00:00 2001 From: Miguel de Val-Borro Date: Fri, 4 Nov 2016 14:22:14 -0400 Subject: [PATCH 10/12] Use full path to API link Thanks to @bsipocz --- docs/hitran/hitran.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/hitran/hitran.rst b/docs/hitran/hitran.rst index 98c80d2bf6..4984586f80 100644 --- a/docs/hitran/hitran.rst +++ b/docs/hitran/hitran.rst @@ -9,7 +9,7 @@ Getting started This module provides an interface to the `HITRAN`_ database API. It can download a data file including transitions for a particular molecule in a given -wavenumber range. The file is downloaded in the `~hitran.cache_location` +wavenumber range. The file is downloaded in the `~astroquery.hitran.cache_location` directory and can be opened with a reader function that returns a table of spectral lines including all accessible parameters. From 45372e72bf7abee67991f5af5af5c99a05337e58 Mon Sep 17 00:00:00 2001 From: Miguel de Val-Borro Date: Fri, 4 Nov 2016 14:28:48 -0400 Subject: [PATCH 11/12] Add link to hitran.rst from the index and changelog entry --- CHANGES | 1 + docs/index.rst | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CHANGES b/CHANGES index 9765ff0b90..f34d23c9be 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,7 @@ 0.3.4 (unreleased) ------------------ +- Added basic HITRAN queries support (#617) - Fix #737, an issue with broken ALMA archive tables, via a hack (#775) - Add license statements to appropriate places (#776) - Correct HEASARC tool, which was sending incorrect data to the server (#774) diff --git a/docs/index.rst b/docs/index.rst index 15f31a1e7f..7bc3661965 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -170,6 +170,7 @@ These others are functional, but do not follow a common & consistent API: ogle/ogle.rst open_exoplanet_catalogue/open_exoplanet_catalogue.rst cosmosim/cosmosim.rst + hitran/hitran.rst Catalog, Archive, and Other =========================== @@ -254,6 +255,7 @@ above categories. splatalogue/splatalogue.rst nasa_ads/nasa_ads.rst vamdc/vamdc.rst + hitran/hitran.rst Developer documentation From 2481e369ed29c21a1e4ce48038fb080acb42566e Mon Sep 17 00:00:00 2001 From: Miguel de Val-Borro Date: Sat, 5 Nov 2016 22:02:32 -0400 Subject: [PATCH 12/12] Give cache directory path in HITRAN docs This fixes a sphinx warning --- docs/hitran/hitran.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/hitran/hitran.rst b/docs/hitran/hitran.rst index 4984586f80..6b9aa921c2 100644 --- a/docs/hitran/hitran.rst +++ b/docs/hitran/hitran.rst @@ -9,9 +9,9 @@ Getting started This module provides an interface to the `HITRAN`_ database API. It can download a data file including transitions for a particular molecule in a given -wavenumber range. The file is downloaded in the `~astroquery.hitran.cache_location` -directory and can be opened with a reader function that returns a table of -spectral lines including all accessible parameters. +wavenumber range. The file is downloaded in the default cache directory +``~/.astropy/cache/astroquery/hitran`` and can be opened with a reader function +that returns a table of spectral lines including all accessible parameters. Examples ========