-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_sims.py
85 lines (52 loc) · 1.98 KB
/
create_sims.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
84
85
import os
import numpy as np
from shutil import copyfile
## load functions
from py_functions import render_template
debug = False
if debug:
path_sims = os.path.join('..','..','data','4-output')
path_template = os.path.join('..','..','config','template')
else:
path_sims = snakemake.output.path_sims
path_template = snakemake.input.path_template
print(path_sims)
# =============================================================================
# 1. input
# =============================================================================
## template path
## if file exists overwrite
overwrite = False
swan_template = 'swan_template_final.swn'
# =============================================================================
# 2. wave conditions
# =============================================================================
## complete range
wind_speed_list = [30, 20]
# =============================================================================
# 4. create sims
# =============================================================================
string = ''
## template file
template = os.path.join(path_template,swan_template)
## make combinations
for ii, item in enumerate(wind_speed_list):
## get conditions
wind_speed = item
fname = 'U{}'.format(wind_speed)
## data for template
data = {'output_path':os.path.dirname(path_sims[ii]),
'extension':'swn',
'variant':'A',
'fname':fname,
'wind_speed': wind_speed,
'wind_dir': 180,
'water_level': 0}
## skip if file already exists
if os.path.exists(os.path.join(path_sims[ii], '{}.swn'.format(fname))) and overwrite:
print('skipped {}'.format(fname))
continue
## render template
render_template(data,template)
## copy swan_run
copyfile(os.path.join(path_template,'run_SWAN.sh'), os.path.join(os.path.dirname(path_sims[ii]),'run_SWAN.sh'))