-
Notifications
You must be signed in to change notification settings - Fork 0
/
setupruns.py
executable file
·175 lines (155 loc) · 5.2 KB
/
setupruns.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import sys
import os
import logging
from optparse import OptionParser
import sverify
from sverify import options_process
#from sverify import options_vmix
#from sverify import options_obs
from sverify import svconfig
from sverify.options_run import options_run_main
# import cartopy.crs as ccrs
# import cartopy.feature as cfeature
"""
Functions
-----------
INPUTS:
inputs are detailed in the attributes of the ConfigFile class.
STEPS
"""
logger = logging.getLogger(__name__)
def main():
parser = OptionParser()
# parser.add_option(
# "-a", type="string", dest="state", default="ND", help="two letter state code (ND)"
# )
parser.add_option(
"-i",
type="string",
dest="configfile",
default="CONFIG.S",
help="Name of configuration file",
)
parser.add_option(
"-p",
action="store_true",
dest="print_help",
default=False,
help="Print help for configuration file",
)
parser.add_option(
"--defaults",
action="store_true",
dest="defaults",
default=False,
help="Write CONTROL.0 and SETUP.0 files in top level directory",
)
parser.add_option(
"--vmix",
action="store_true",
dest="vmix",
default=False,
help="Write CONTROL and SETUP files for vmixing, \
Locations are where there are AQS stations. \
CONTROL.suffix, suffix is V+AQS station id.",
)
parser.add_option(
"--nei",
action="store_true",
dest="nei",
default=False,
help="Write CONTROL and SETUP files for sources found in \
the CONFIG.nei file.",
)
parser.add_option(
"--debug",
action="store_true",
dest="debug",
default=False,
help="Print messages for debugging",
)
parser.add_option(
"--quiet",
action="store_false",
dest="verbose",
default=True,
help="Don't print messages"
)
(opts, args) = parser.parse_args()
options = svconfig.ConfigFile(opts.configfile)
if opts.print_help:
print("-------------------------------------------------------------")
print("Configuration file options (key words are not case sensitive)")
print("-------------------------------------------------------------")
print(options.print_help(order=options.lorder))
sys.exit()
#options = svconfig.ConfigFile(opts.configfile)
# options.fileread is a boolean attribute of ConfigFile class.
if not options.fileread:
print("configuration file " + opts.configfile + " not found.\ngoodbye")
sys.exit()
##------------------------------------------------------##
##------------------------------------------------------##
# Process some of the options to create new parameters.
##------------------------------------------------------##
##------------------------------------------------------##
svp = options_process.main(options)
# TO DO - may pass svp rather than individual attributes to functions.
d1 = svp.d1
d2 = svp.d2
area = svp.area
#logfile = svp.logfile
source_chunks = svp.source_chunks
datem_chunks = svp.datem_chunks
tcmrun = svp.tcmrun
run_duration = svp.run_duration
rfignum = 1
# create an instance of the MetObs class.
# vmet = MetObs()
##------------------------------------------------------##
# Run a test
##------------------------------------------------------##
runtest=False
if runtest:
print('No test available')
rval = 1
##------------------------------------------------------##
# Create default CONTROL.0 and SETUP.0 files
##------------------------------------------------------##
elif opts.defaults and not svp.ensemble:
#with open(logfile, 'a') as fid:
# fid.write('Running defaults\n')
from sverify.svhy import default_setup
from sverify.svhy import default_control
logger.info("writing CONTROL.0 and SETUP.0")
# if units='ppb' then ichem=6 is set to output mixing ratios.
default_setup("SETUP.0", options.tdir, units=options.cunits)
default_control("CONTROL.0", options.tdir, run_duration, d1, area=area)
# if ensemble then copy CONTROL.0 and SETUP.0 to ensemble directories
elif opts.defaults and svp.ensemble:
from sverify.svens import ensemble_defaults
ensemble_defaults(options.tdir)
##------------------------------------------------------##
# Create CONTROL and SETUP files in subdirectories.
##------------------------------------------------------##
# FILES created
# CONTROL and SETUP and ASCDATA.CFG files in each subdirectory.
# CONTROL files for vmixing.
elif not opts.defaults:
tcmrun=False
main = False
vmix = opts.vmix
neibool = opts.nei
if not vmix and not neibool: main = True
#logger.info('writing control files')
options_run_main(options, d1, d2, source_chunks,
tcmrun, main, vmix, neibool)
return 1
if __name__ == "__main__":
if sys.argv.count("--debug") > 0:
log_level = logging.DEBUG
elif sys.argv.count("--quiet") == 0:
log_level = logging.INFO
else:
log_level = logging.WARNING
sverify.run(main, 'setupruns.py', log_level = log_level)