-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathplotall.py
More file actions
executable file
·63 lines (51 loc) · 1.93 KB
/
Copy pathplotall.py
File metadata and controls
executable file
·63 lines (51 loc) · 1.93 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
#!/usr/bin/env python
import oct2py # pip install oct2py
from argparse import ArgumentParser
import concurrent.futures
from pathlib import Path
from copy import deepcopy
import itertools
"""
Python >= 3.5 required
Oct2Py is thread-safe: https://blink1073.github.io/oct2py/source/info.html#threading
see docs:
https://blink1073.github.io/oct2py/source/api.html
to do things like set path to octave.exe etc.
"""
def frame(direc: Path, ymd, UTsec, saveplots):
with oct2py.Oct2Py() as octave:
octave.plotframe(str(direc), ymd, UTsec, saveplots)
def main():
p = ArgumentParser()
p.add_argument('direc', help='directory to plot')
p.add_argument('max_threads', help='maximum number of threads to use (large grids use lots of RAM)',
nargs='?', type=int, default=5)
p.add_argument('-s', '--saveplots', help='plot type to save (png, eps) [default png]',
nargs='+', default=['png'])
p = p.parse_args()
direc = Path(p.direc).expanduser()
config = direc / 'inputs/config.ini'
# works single-threaded, was just a first test
# with oct2py.Oct2Py() as octave:
# octave.plotall(p.direc, p.saveplots)
# %% setup
with oct2py.Oct2Py() as octave:
octave.addpath('../script_utils')
ymd0, UTsec0, tdur, dtout = octave.readconfig(str(config), nout=4)
Nt = int((UTsec0+tdur - UTsec0) // dtout) + 1
ymd = deepcopy(ymd0)
UTsec = deepcopy(UTsec0)
# %% setup threading
ymds = []
UTsecs = []
for _ in range(Nt):
ymd, UTsec = octave.dateinc(dtout, ymd, UTsec, nout=2)
ymds.append(ymd)
UTsecs.append(UTsec)
# %% threading
# set max_workers as high as your PC can handle
with concurrent.futures.ThreadPoolExecutor(max_workers=p.max_threads) as exc:
exc.map(frame,
itertools.repeat(direc), ymds, UTsecs, itertools.repeat(p.saveplots))
if __name__ == '__main__':
main()