-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathreaddata.py
More file actions
109 lines (64 loc) · 2.67 KB
/
Copy pathreaddata.py
File metadata and controls
109 lines (64 loc) · 2.67 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import numpy as np
from pathlib import Path
from argparse import ArgumentParser
from datetime import datetime, timedelta
from typing import Tuple, Dict
LSP = 7
def readsimsize(fn: Path):
with fn.open('rb') as f:
return np.fromfile(f, np.int32, 3)
def readdata(P: dict, fn: Path) -> Dict[str, np.ndarray]:
dat = {}
with fn.open('rb') as f:
t = np.fromfile(f, np.float64, 4)
dat['t'] = datetime(int(t[0]), int(t[1]), int(t[2])) + timedelta(hours=t[3])
dat['ne'] = read3D(f, P['lxs'])
dat['v1'] = read3D(f, P['lxs'])
dat['Ti'] = read3D(f, P['lxs'])
dat['Te'] = read3D(f, P['lxs'])
dat['J1'] = read3D(f, P['lxs'])
dat['J2'] = read3D(f, P['lxs'])
dat['J3'] = read3D(f, P['lxs'])
dat['Phitop'] = read2D(f, P['lxs'])
if P['lxs'][1] == 1 or P['lxs'][2] == 1:
dat['Ti'] = dat['Ti'].squeeze()
dat['Te'] = dat['Te'].squeeze()
return dat
def read4D(f, lsp: Tuple[int, int, int], lxs: int) -> np.ndarray:
return np.fromfile(f, np.float64, np.prod(lxs)*lsp).reshape((lxs, lsp), order='F')
def read3D(f, lxs: Tuple[int, int, int]) -> np.ndarray:
return np.fromfile(f, np.float64, np.prod(lxs)).reshape(*lxs, order='F')
def read2D(f, lxs: Tuple[int, int]) -> np.ndarray:
return np.fromfile(f, np.float64, np.prod(lxs[1:])).reshape(*lxs[1:], order='F')
def readconfig(inifn: Path) -> dict:
inifn = Path(inifn).expanduser()
P = {}
with inifn.open('r') as f:
date = list(map(int, f.readline().split()[0].split(',')))[::-1]
sec = float(f.readline().split()[0])
P['t0'] = datetime(*date) + timedelta(seconds=sec)
P['tdur'] = float(f.readline().split()[0])
P['dtout'] = float(f.readline().split()[0])
P['f107a'], P['f107'], P['Ap'] = map(float, f.readline().split()[0].split(','))
P['tcfl'] = float(f.readline().split()[0])
P['Teinf'] = float(f.readline().split()[0])
P['flagpot'] = int(f.readline().split()[0])
P['flagperiodic'] = int(f.readline().split()[0])
P['flagoutput'] = int(f.readline().split()[0])
P['flagcap'] = int(f.readline().split()[0])
return P
def loadframe(simdir: Path):
simdir = Path(simdir).expanduser()
P = readconfig(simdir/'inputs/config.ini')
sizefn = simdir / 'inputs/simsize.dat'
P['lxs'] = readsimsize(sizefn)
# %% datfn
t = P['t0'].timetuple()
datfn = simdir / f'{t[0]}{t[1]:02d}{t[2]:02d}_{t[3]*3600+t[4]*60+t[5]}.000001.dat'
dat = readdata(P, datfn)
return dat
if __name__ == '__main__':
p = ArgumentParser()
p.add_argument('simdir')
p = p.parse_args()
dat = loadframe(p.simdir)