-
Notifications
You must be signed in to change notification settings - Fork 0
/
adsre.py
60 lines (44 loc) · 1.89 KB
/
adsre.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#regex the ads data for
import re
import scipy
import scipy.interpolate
class lineInfo(object):
def __init__(self, name='data_to_Ian.txt'):
txtobj = open(name,'r')
self.z = []
self.charge = []
self.transition = []
self.te = []
self.pec = []
self.parse(txtobj)
self.te = scipy.vstack(self.te)
#if (len(scipy.unique(self.te)) == self.te.shape[1]):
# self.te = scipy.unique(self.te) #same te base, drop it like its hot
self.pec = scipy.vstack(self.pec)
self._splines = {}
def parse(self,txtobj):
data = []
go = 2
for text in txtobj:
temp = re.findall('\d{2} ',text)
if temp and go == 2:
go -= 1
self.z += [int(temp[0])]
self.charge += [int(temp[1])]
self.transition += [re.findall('\(.*?\)',text)]
elif go == 1:
go -= 1
self.te += [scipy.array(re.findall('\d\.\d*[eE][-+]\d{2}',text)).astype(float)]
elif go == 0:
self.pec += [scipy.array(re.findall('\d\.\d*[eE][-+]\d{2}',text)).astype(float)]
go = 2
def __call__(self, te, i):
try:
return scipy.exp(self._splines[i](scipy.log(te)))
except KeyError:
self._splines[i] = scipy.interpolate.interp1d(scipy.log(self.te[i]),
scipy.log(self.pec[i]),
bounds_error=False,
kind='cubic',
fill_value=(scipy.NINF,scipy.log(self.pec[i,-1])))
return scipy.exp(self._splines[i](scipy.log(te)))