Skip to content

Commit 35adea3

Browse files
1) added a script that can be called from command line to run popgen; accordingly modified .gitignore file, and the setup,py file, 2) cleaned configuration elements, 3) altered the way input files are specified, now, input files are to be specified in the project folder, 4) deleted any references to configuration elements that are not used, 5) commented out a print statement in the reweighting procedure
1 parent 15bf688 commit 35adea3

File tree

8 files changed

+61
-24
lines changed

8 files changed

+61
-24
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ dist
1010
build
1111
eggs
1212
parts
13-
bin
1413
var
1514
sdist
1615
develop-eggs
@@ -39,4 +38,4 @@ output/*.html
3938
output/*/index.html
4039

4140
# Sphinx
42-
docs/_build
41+
docs/_build

bin/popgen_run

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python
2+
3+
import sys
4+
import time
5+
6+
from popgen import Project
7+
8+
9+
class ArgumentsError(Exception):
10+
pass
11+
12+
13+
def run():
14+
"""
15+
Runs the PopGen program to generate a synthetic population.
16+
Please refer to PopGen documentation on the GitHub site
17+
for guidance on setting up the configuration file.
18+
"""
19+
args = sys.argv[1:]
20+
21+
print args
22+
23+
if len(args) != 1:
24+
raise ArgumentsError(
25+
"""The module accepts only one argument which is the location of
26+
the configuration file.
27+
28+
Example usage on linux or Mac:
29+
popgen_run /location/of/file.yaml
30+
31+
Example usage on Windows:
32+
popgen_run c:/location/of/file.yaml""")
33+
34+
t = time.time()
35+
p_obj = Project(config_loc=args[0])
36+
p_obj.load_project()
37+
p_obj.run_scenarios()
38+
print "Time it took: %.4f" % (time.time() - t)
39+
40+
run()

popgen/data.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def __init__(self, config):
3030
self.region_ids = None
3131
self.sample_geo_ids = None
3232
self._inputs_config = self.config.project.inputs
33+
self.location = os.path.abspath(self.config.project.location)
3334

3435
def load_data(self):
3536

@@ -54,7 +55,8 @@ def get_data(self, config, header=0):
5455
# print config_dict, type(config_dict)
5556
data_dict = {}
5657
for item in config_dict:
57-
full_location = os.path.abspath(config_dict[item])
58+
filename = config_dict[item]
59+
full_location = os.path.join(self.location, filename)
5860
data_dict[item] = pd.read_csv(full_location, index_col=0,
5961
header=header)
6062
data_dict[item].loc[:,

popgen/project.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ def _load_config(self):
3838

3939
def _populate_project_properties(self):
4040
self.name = self._config.project.name
41-
self.synthesize = self._config.project.synthesize
4241
self.location = os.path.abspath(self._config.project.location)
4342

4443
def _load_data(self):

popgen/reweighting.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ def run_reweighting(self, region_constraints, geo_constraints):
157157
geo_constraints.loc[geo_id])
158158
pass
159159
# raw_input("Geo done %s" %geo_id)
160-
# raw_input ("One outer iteration complete in %.4f" %
161-
# (time.time() - t))
160+
# print ("\t\t\tOne outer iteration complete in %.4f" %
161+
# (time.time() - t))
162162
self._populate_sample_weights(sample_weights, region_id, geo_ids)
163163
# print self.average_deviations
164164
print "\tsample_weights sum:", sample_weights.sum()
@@ -262,6 +262,7 @@ def _calculate_populate_average_deviation(
262262
self, geo_id, iter, sample_weights, constraints):
263263
diff_sum = 0
264264

265+
sample_weights = np.array(sample_weights, order="C")
265266
for column in constraints.index:
266267
weighted_sum = sample_weights.dot(self.geo_contrib[column])
267268
diff_sum += (np.abs(weighted_sum - constraints[column]) /

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
package_data={'popgen': [
3939
'../tutorials/1_basic_popgen_setup/*.csv',
4040
'../tutorials/1_basic_popgen_setup/*.yaml']},
41+
scripts=['bin/popgen_run'],
4142
include_package_data=True,
4243
setup_requires=['numpy==1.9.2'],
4344
install_requires=[

tutorials/1_basic_popgen_setup/configuration.yaml

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
project:
2-
synthesize: True
32
name: example
4-
location: ../tutorials/1_basic_popgen_setup/
3+
location: ./tutorials/1_basic_popgen_setup/
54
inputs:
65
entities: [household, person]
76
housing_entities: [household]
@@ -14,23 +13,21 @@ project:
1413
sample_geo: sample_geo
1514
location:
1615
geo_corr_mapping:
17-
geo_to_sample: ../tutorials/1_basic_popgen_setup/geo_sample_mapping.csv
18-
region_to_sample: ../tutorials/1_basic_popgen_setup/region_sample_mapping.csv
19-
region_to_geo: ../tutorials/1_basic_popgen_setup/region_geo_mapping.csv
16+
geo_to_sample: geo_sample_mapping.csv
17+
region_to_sample: region_sample_mapping.csv
18+
region_to_geo: region_geo_mapping.csv
2019
sample:
21-
household: ../tutorials/1_basic_popgen_setup/household_sample.csv
22-
person: ../tutorials/1_basic_popgen_setup/person_sample.csv
20+
household: household_sample.csv
21+
person: person_sample.csv
2322
marginals:
24-
geo:
25-
household: ../tutorials/1_basic_popgen_setup/household_marginals.csv
26-
person: ../tutorials/1_basic_popgen_setup/person_marginals.csv
2723
region:
28-
household: ../tutorials/1_basic_popgen_setup/region_household_marginals.csv
29-
person: ../tutorials/1_basic_popgen_setup/region_person_marginals.csv
30-
24+
household: region_household_marginals.csv
25+
person: region_person_marginals.csv
26+
geo:
27+
household: household_marginals.csv
28+
person: person_marginals.csv
3129
scenario:
32-
- description: all_controls_entropy
33-
apply_region_controls: True
30+
- description: all_controls_ipu
3431
control_variables:
3532
region:
3633
household: [rhhldtype]
@@ -46,7 +43,7 @@ project:
4643
rounding_procedure: bucket
4744
archive_performance_frequency: 1
4845
reweighting:
49-
procedure: entropy
46+
procedure: ipu
5047
tolerance: 0.0001
5148
inner_iterations: 1
5249
outer_iterations: 1000

tutorials/1_basic_popgen_setup/configuration_multiple_scenarios.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
project:
2-
synthesize: True
32
name: example
43
location: ../demo/example/
54
inputs:
@@ -27,7 +26,6 @@ project:
2726
region:
2827
household: ../demo/example/region_household_marginals.csv
2928
person: ../demo/example/region_person_marginals.csv
30-
3129
scenario:
3230
- description: derived_2_entropy
3331
apply_region_controls: True

0 commit comments

Comments
 (0)