forked from aflaxman/bednet_stock_and_flow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_all.py
99 lines (76 loc) · 2.9 KB
/
run_all.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
"""
notes on how to do this:
1a. create a new folder for data,
1b. create a subfolder for traces
2. modify local_settings.py to point to the new data folder
3. copy all the input csv files to the new data folder
4. generate the initial empirical priors::
$ python emp_priors.py
5. adjust empirical priors based on expert priors, if desired
6. generate posteriors
$ python run_all.py
"""
import optparse
import os
import subprocess
import settings
def run_all(fit_empirical_priors=False):
""" Enqueues all jobs necessary to fit model
Example
-------
>>> import run_all
>>> run_all.run_all()
"""
if fit_empirical_priors:
# fit empirical priors (by pooling data from all regions)
import emp_priors, graphics
emp_priors.admin_err_and_bias(recompute=True)
emp_priors.llin_discard_rate(recompute=True)
emp_priors.neg_binom(recompute=True)
emp_priors.survey_design(recompute=True)
graphics.plot_neg_binom_fits()
#fit each region individually for this model
from data import Data
data = Data()
post_names = []
dir = settings.PATH
for ii, r in enumerate(sorted(data.countries)):
o = '%s/%s-stdout.txt' % (dir, r[0:3])
e = '%s/%s-stderr.txt' % (dir, r[0:3])
name_str = 'ITN%s-%d' % (r[0:3].strip(), ii)
post_names.append(name_str)
call_str = 'qsub -cwd -o %s -e %s ' % (o,e) \
+ '-N %s ' % name_str \
+ 'fit.sh %d' % ii
subprocess.call(call_str, shell=True)
# TODO: after all posteriors have finished running, notify me via email
hold_str = '-hold_jid %s ' % ','.join(post_names)
o = '%s/summarize.stdout' % dir
e = '%s/summarize.stderr' % dir
call_str = 'qsub -cwd -o %s -e %s ' % (o,e) \
+ hold_str \
+ '-N netsdone ' \
+ 'fit.sh summarize'
subprocess.call(call_str, shell=True)
def main():
usage = 'usage: %prog [options]'
parser = optparse.OptionParser(usage)
(options, args) = parser.parse_args()
if len(args) != 0:
parser.error('incorrect number of arguments')
# make a directory for the output traces
try:
#settings.PATH = args[0]
# TODO: create new dir if necessary
#os.mkdir(settings.PATH)
#os.mkdir(settings.PATH + 'traces')
# TODO: somehow copy csv files into new dir
#for fname in 'pop.csv reten.csv design.csv manuitns.csv adminllins_itns.csv stock_llins.csv flow_llins.csv llincc.csv itncc.csv numllins.csv'.split(' '):
#cp pop.csv reten.csv design.csv manuitns.csv adminllins_itns.csv stock_llins.csv flow_llins.csv llincc.csv itncc.csv numllins.csv ../2010_07_26
#cp *.json ../2010_07_26
pass
except IOError, e:
parser.error('failed to create data/output directory: %s' % e)
run_all()
if __name__ == '__main__':
main()