-
Notifications
You must be signed in to change notification settings - Fork 0
/
explore_multiple_runs.py
89 lines (75 loc) · 3.55 KB
/
explore_multiple_runs.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
import os
import pandana
import pandas as pd
from optparse import OptionParser
from urbansim.maps import dframe_explorer
# set data file to explore
#data_file = "conversion/out2010run_113.h5"
data_file = "conversion/run_142.run_2015_07_15_13_392041.h5"
#data_file2 = "conversion/run_133ref_with_school_models2041.h5" # for computing differences between runs
data_file2 = "conversion/run_138.run_2015_05_28_14_572041.h5"
# Correspondence between the data and the shape files.
allgeo = {"zones": ("TAZ", "zone_id"),
"parcels": ("NEW_USIMPI", "parcel_id"),
"fazes": ("FAZ10", "faz_id"),
"tractcity": ("ID", "tractcity_id")}
# Which tables will appear in the menu in the upper right corner.
common_tables = ['buildings', 'parcels', 'households', 'persons', 'jobs']
tables = {"zones": common_tables + ["zones"],
"parcels": common_tables,
"fazes": common_tables + ["zones", "fazes"],
"tractcity": common_tables + ["tractcity"]}
# Which variables should be taken out of the second run
common_vars2 = ["number_of_households", "number_of_jobs"]
variables2 = {"parcels": common_vars2
}
# the eplorer will not work with text columns, therefore remove those
columns_to_remove = {
"tractcity": ["juris_d", "tract", "trctjuris"]
}
if __name__ == "__main__":
parser = OptionParser()
parser.add_option("-g", "--geo", dest="geo",
help="Geography for the display, e.g. 'zones' (default) or 'fazes'", default="zones")
parser.add_option("-p", "--port", dest="port", default=8765,
help="Port for the display. Default is 8765.")
(options, args) = parser.parse_args()
geo = options.geo
port = options.port
for tbl in ["zones", "fazes", "tractcity"]:
if tbl in tables[geo]:
variables2[tbl] = common_vars2
import psrc_urbansim.models
import urbansim.sim.simulation as sim
from psrc_urbansim.utils import change_store
change_store(data_file)
#import psrc_urbansim.accessibility.variables
# create a dictionary of pandas frames
d = {tbl: sim.get_table(tbl).to_frame() for tbl in tables[geo]}
# remove unwanted columns
for tbl, cols in columns_to_remove.iteritems():
if tbl in d.keys():
d[tbl].drop(cols, axis=1, inplace=True)
change_store(data_file2)
sim.clear_cache()
#import urbansim.sim.simulation as sim
#import psrc_urbansim.accessibility.variables
for tbl in variables2.keys():
d2 = sim.get_table(tbl).to_frame(columns=variables2[tbl])
d2.columns = map(lambda x: x + "_2", d2.columns)
d[tbl] = pd.merge(d[tbl], d2, left_index=True, right_index=True)
# add the id column since the join does not work if the id is an index
d[geo][allgeo[geo][1]] = d[geo].index.values
dframe_explorer.start(d,
center=[47.614848,-122.3359058],
zoom=11,
#shape_json=os.path.join(os.getenv("DATA_HOME", "."), 'data', '%s.geojson' % geo),
shape_json=os.path.join('data/', '%s.geojson' % geo),
geom_name=allgeo[geo][0], # from JSON file
join_name=allgeo[geo][1], # from data frames
precision=2,
port=int(port)
)
# In the browser, the fifth field is a filter, e.g. number_of_households > 1000,
# and the sixth field is a simple computation, e.g. number_of_jobs / 1000
# I believe the attribute must be on the displayed geography (i.e. geo above).