1
2
3 """
4 A class for reading Lamda molecular data files. See:
5 http://home.strw.leidenuniv.nl/~moldata/
6
7 Author: R. Lombaert
8
9 """
10
11 import os
12 import numpy as np
13
14 from cc.tools.readers.CollisReader import CollisReader
15 from cc.tools.readers.MolReader import MolReader
16 from cc.tools.io import DataIO
17
18
19
21
22 '''
23 A Reader for Lamda molecular data files.
24
25 For more information on the Lamda molecular data files, see:
26 http://home.strw.leidenuniv.nl/~moldata/
27 Lamda files are the input spectroscopic and collisional data files for
28 MCP/ALI.
29
30 Provides methods to manage molecular spectroscopic data (excitation
31 levels, Einstein A coefficients, transitions, etc) through inheritance from
32 the MolReader class, and methods to manage collisional rate data through
33 inheritance from the CollisReader class.
34
35 Note that both parents have methods getTI, getTUpper, getTLower. It
36 functions the same, and the default will be MolReader's method. If you want
37 to retrieve trans indices for the collision rates, specify the itype as
38 'coll_trans'.
39
40 '''
41
43
44 '''
45 Creating a LamdaReader object ready for reading Lamda molecular data.
46
47 A full filename is required.
48
49 Additional args/kwargs are used for the dict creation of the parent of
50 Reader.
51
52 @param fn: The lamda data filename, including filepath.
53 @type fn: string
54
55 '''
56
57 super(LamdaReader, self).__init__(fn=fn,*args,**kwargs)
58 self.read()
59
60
61
63
64 '''
65 Read the Lamda file, including molecular spectroscopy and collision
66 rates.
67
68 Each level and transition is stored as an index, following the
69 prescription of MolReader and CollisReader.
70
71 '''
72
73
74 d = DataIO.readFile(self.fn)
75 self['pars'] = dict()
76 pars = ['molecule','mol_weight','ny']
77 dtypes = [str,float,int]
78 indices = [1,3,5]
79 for i,p,dt in zip(indices,pars,dtypes):
80 self['pars'][p] = dt(d[i].split()[0])
81
82
83
84 d1 = np.genfromtxt(self.fn,skip_header=7,max_rows=self['pars']['ny'],\
85 dtype='i8,f8,f8',usecols=(0,2,1),\
86 names=['index','weight','energy'])
87 self['level'] = d1
88
89
90 index = 7 + self['pars']['ny'] + 1
91 self['pars']['nline'] = int(d[index].split()[0])
92
93
94
95 d2 = np.genfromtxt(self.fn,usecols=[0,1,2,4,3],dtype='i8,i8,i8,f8,f8',\
96 skip_header=index+2,max_rows=self['pars']['nline'],\
97 names=['index','lup','llow','frequency','einsteinA'])
98 self['trans'] = d2
99
100
101 index += 1 + self['pars']['nline'] + 2
102 self['pars']['npartners'] = int(d[index].split()[0])
103 index += 2
104 self['pars']['partners'] = d[index:index+self['pars']['npartners']]
105 index += self['pars']['npartners'] + 1
106 self['pars']['ncoll_trans'] = int(d[index].split()[0])
107 index += 2
108 self['pars']['ncoll_temp'] = int(d[index].split()[0])
109 index += 2
110 self['coll_temp'] = np.array(d[index].split(),dtype=float)
111
112
113 d3 = np.genfromtxt(self.fn,usecols=[0,1,2],dtype='i8,i8,i8',\
114 skip_header=index+2,names=['index','lup','llow'])
115 d4 = np.genfromtxt(self.fn,skip_header=index+2,\
116 usecols=range(3,3+self['pars']['ncoll_temp']))
117 dtype = [('index',int),('lup',int),('llow',int),('rates',np.ndarray)]
118 self['coll_trans'] = np.empty(shape=(self['pars']['ncoll_trans'],),\
119 dtype=dtype)
120 self['coll_trans']['index'] = d3['index']
121 self['coll_trans']['lup'] = d3['lup']
122 self['coll_trans']['llow'] = d3['llow']
123 for i in range(self['pars']['ncoll_trans']):
124 self['coll_trans']['rates'][i] = d4[i,:]
125