forked from NREL/ReEDS-2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaugurbatch.py
115 lines (97 loc) · 3.84 KB
/
augurbatch.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
# import necessary packages
import os
import sys
import queue
import threading
import csv
import subprocess
def createCurtCCThreads(case, ccworkers, yearset, restartfile, startyear,
endyear, distpv, csp, dr, timetype, waterswitch,
iteration):
q = queue.Queue()
num_worker_threads = int(ccworkers)
def ccworker():
while True:
ThreadInit = q.get()
if ThreadInit is None:
break
case = ThreadInit['case']
cur_year = ThreadInit['cur_year']
# call the reflow script with appropriate options
if os.name != 'posix':
os.system('start /wait cmd /c python ' + os.path.join(
'ReEDS_Augur', 'ReEDS_Augur.py') + ' ' + case + ' '
+ str(cur_year) + ' ' + str(cur_year) + ' ' + timetype
+ ' ' + str(csp) + ' ' + str(dr) + ' ' + str(waterswitch) + ' '
+ str(iteration) + ' ' + str(marg_vre) + ' ' + str(marg_dr) + ' '
+ str(marg_stor) + ' ' + str(marg_dr))
if os.name == 'posix':
shellscript = subprocess.Popen(
['python ' + os.path.join('ReEDS_Augur', 'ReEDS_Augur.py')
+ ' ' + case + ' ' + str(cur_year) + ' ' + str(cur_year)
+ ' ' + timetype + ' ' + str(csp) + ' ' + str(dr) + ' ' + str(waterswitch)
+ ' ' + str(iteration) + ' ' + str(marg_vre) + ' ' + str(marg_dr) + ' '
+ str(marg_stor) + ' ' + str(marg_dr) + ' >/dev/null'],
stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL, shell=True)
# wait for it to finish before killing the thread
shellscript.wait()
q.task_done()
threads = []
for i in range(num_worker_threads):
t = threading.Thread(target=ccworker)
t.start()
threads.append(t)
for i in range(len(yearset[0])):
idx1 = int(yearset[0][i]) <= int(endyear)
idx2 = int(yearset[0][i]) >= int(startyear)
if idx1 and idx2:
q.put({'case': case,
'cur_year': yearset[0][i],
'restartfile': restartfile})
# block until all tasks are done
q.join()
# stop workers
for i in range(num_worker_threads):
q.put(None)
for t in threads:
t.join()
def main():
case = sys.argv[1]
ccworkers = sys.argv[2]
yearfile = sys.argv[3]
yearset = list(csv.reader(open(os.path.join(yearfile), 'r'),
delimiter=','))
restartfile = sys.argv[4]
startyear = sys.argv[5]
endyear = sys.argv[6]
distpv = sys.argv[7]
csp = sys.argv[8]
dr = sys.argv[9]
timetype = sys.argv[10]
waterswitch = sys.argv[11]
iteration = sys.argv[12]
marg_vre = sys.argv[13]
marg_stor = sys.argv[14]
marg_dr = sys.argv[15]
print('Beginning batch run of Augur calls using options: ')
print('Case: '+case)
print('Number of threads: '+str(ccworkers))
print('Year file: ' + yearfile)
print('Restart file: ' + restartfile)
print('Start year: ' + str(startyear))
print('End year: ' + str(endyear))
print('distpv switch setting: ' + distpv)
print('calc_csp_cc setting: ' + csp)
print('calc_dr_cc setting: ' + dr)
print('timetype: ' + timetype)
print('waterswitch' + waterswitch)
print('iteration: ' + str(iteration))
print('marg_vre: ' + str(marg_vre))
print('marg_stor: ' + str(marg_stor))
print('marg_dr: ' + str(marg_dr))
createCurtCCThreads(case, ccworkers, yearset, restartfile, startyear,
endyear, distpv, csp, dr, timetype, waterswitch,
iteration, marg_vre, marg_stor, marg_dr)
if __name__ == '__main__':
main()