-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathawsm_docker
executable file
·73 lines (61 loc) · 2.29 KB
/
awsm_docker
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
#!/usr/bin/env python
import argparse
import os
import sys
import shutil
from subprocess import call
def run():
parser = argparse.ArgumentParser(description='Run AWSM example cases')
parser.add_argument('--case', metavar='C', type=str,
help='Test case to run, either tuol, brb, or rme',
default='tuol')
args = parser.parse_args()
case = args.case
# set variables to run Tuol case
if case == 'tuol':
cfg = 'config_tuol_docker.ini'
fpc = 'tuolumne'
topo = 'tuolx_dem_50m.ipw'
# set variables to run BRB case
elif case == 'brb':
cfg = 'awsm_config_0401_0630.ini'
fpc = 'brb'
topo = 'topo.nc'
# set variables to run rme
elif case == 'rme':
cfg = 'config_rme_docker.ini'
fpc = 'rme'
topo = 'topo.nc'
else:
raise IOError('Not a valid test case')
# create maxus if needed
maxus_call = None
if not os.path.isfile('./{}/topo/maxus.nc'.format(fpc)):
# if rme, also create the tbreak for precip redistribution
tbreak = ''
if case == 'rme':
tbreak = '--make_tbreak=1 --out_tbreak=/data/input/topo/tbreak.nc --sv_global=100 --sv_local=30'
# format command to generate maxus
maxus_call = ('docker-compose -f {}/docker-compose.yml'
' run awsm gen_maxus --window=30 {}'
' --out_maxus=/data/input/topo/maxus.nc'
' /data/input/topo/{}').format(fpc, tbreak, topo)
# run command
call(maxus_call, shell=True, universal_newlines=True)
# rename windowed maxus as maxus
os.remove('./{}/topo/maxus.nc'.format(fpc))
shutil.move('./{}/topo/maxus_30window.nc'.format(fpc),
'./{}/topo/maxus.nc'.format(fpc))
print(maxus_call)
# run system
run_call = ('docker-compose'
' -f ./{}/docker-compose.yml'
' run awsm /data/input/{}').format(fpc, cfg)
call(run_call, shell=True, universal_newlines=True)
# give user the commands used
print('If you want to run this outside of the Python script, the commands were: ')
if maxus_call is not None:
print(maxus_call)
print(run_call)
if __name__ == '__main__':
run()