-
Notifications
You must be signed in to change notification settings - Fork 7
/
run_init.py
executable file
·59 lines (41 loc) · 1.68 KB
/
run_init.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
import os
import sys
import glob
import datetime as dt
import multiprocessing as mp
scripts_dir = os.path.dirname(os.path.abspath(__file__))
def list_dirs(path):
return [a for a in os.listdir(path) if os.path.isdir(os.path.join(path, a))]
def fun(filein):
cmd = 'python '+scripts_dir+'/rttov_wrf.py '+filein+' both'
os.system(cmd)
print(cmd)
if __name__ == '__main__':
init = sys.argv[1]
force = False
if len(sys.argv) >= 3:
if sys.argv[2] == 'force':
force = True
if init[-1] == '/':
init = init[:-1] # remove trailing /
print ('got folder', init)
init_time = dt.datetime.strptime(os.path.basename(init), '%Y-%m-%d_%H:%M')
files = sorted(glob.glob(init+'/*/wrfout_d01_20??-??-??_??:??:00'))
format = 'wrfout_d01_%Y-%m-%d_%H:%M:00'
times = [dt.datetime.strptime(os.path.basename(a), format) for a in files]
pool = mp.Pool(processes=10)
for file, time in zip(files, times):
# save time by running only 1, 5, 10, 20, 30, 45 files
delta_t = time - init_time
#if int(delta_t.seconds/60) in [1, 5, 10, 20, 30, 45, 60, 75]:
#if int(delta_t.seconds/60) % 10 == 0 or int(delta_t.seconds/60) in [1, 5]:
#if ((int(time.minute) in [5, 10, 15, 20, 30, 35, 40, 45, 50])
# or (int(time.minute) == 0 and int(delta_t.seconds) > 0)):
if True:
# save time, dont rerun existing files
p = os.path.dirname(file)+'/RT_'+os.path.basename(file)+'.nc'
if not os.path.isfile(p) or force:
print(p, 'does not yet exist', flush=True)
pool.apply_async(fun, args=(file,))
pool.close()
pool.join()