-
Notifications
You must be signed in to change notification settings - Fork 2
/
parse_acedata.py
83 lines (63 loc) · 1.92 KB
/
parse_acedata.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from datetime import datetime, timedelta
def parse_from_web(filename):
data={
'time':[],
'bx':[],
'by':[],
'bz':[],
'x':[],
'y':[],
'z':[],
}
with open(filename) as fh:
while True:
line=fh.readline()
if line.startswith('BEGIN DATA'):
break
while True:
line=fh.readline()
if line=='':
break
tokens=line.split()
year,doy,h,m=[int(tok) for tok in tokens[:4]]
s,bx,by,bz,fraction_good=[float(tok) for tok in tokens[4:9]]
n_vectors,quality=[int(tok) for tok in tokens[9:11]]
x,y,z=[float(tok) for tok in tokens[11:]]
time=datetime(year,1,1)+timedelta(doy-1)+timedelta(seconds=h*3600+m*60+s)
data['time'].append(time)
data['bx'].append(bx)
data['by'].append(by)
data['bz'].append(bz)
data['x'].append(x)
data['y'].append(y)
data['z'].append(z)
return data
def parse_from_ruth(filename):
data={
'time':[],
'rho':[],
'T':[],
'ux':[],
'uy':[],
'uz':[],
}
with open(filename) as fh:
while True:
line=fh.readline()
if line=='': break
tokens=line.split()
try:
int(tokens[0])
except (ValueError,IndexError):
continue
year=int(tokens[0])
doy=int(tokens[1])
dayfrac,rho,T,speed,ux,uy,uz=[float(s) for s in tokens[2:]]
time=datetime(year,1,1)+timedelta(doy-1)+timedelta(seconds=dayfrac*3600*24)
data['time'].append(time)
data['rho'].append(rho)
data['T'].append(T)
data['ux'].append(ux)
data['uy'].append(uy)
data['uz'].append(uz)
return data