Skip to content

Commit 5d8bedb

Browse files
committed
revisions from trip-mode-choice before master merge
1 parent 532d986 commit 5d8bedb

File tree

5 files changed

+985
-623
lines changed

5 files changed

+985
-623
lines changed

activitysim/defaults/models/mode.py

Lines changed: 71 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,69 @@
1616

1717

1818
@orca.injectable()
19-
def mode_choice_settings(configs_dir):
19+
def tour_mode_choice_settings(configs_dir):
2020
with open(os.path.join(configs_dir,
2121
"configs",
2222
"tour_mode_choice.yaml")) as f:
2323
return yaml.load(f)
2424

2525

2626
@orca.injectable()
27-
def mode_choice_spec_df(configs_dir):
27+
def tour_mode_choice_spec_df(configs_dir):
2828
with open(os.path.join(configs_dir,
2929
"configs",
3030
"tour_mode_choice.csv")) as f:
3131
return asim.read_model_spec(f)
3232

3333

3434
@orca.injectable()
35-
def mode_choice_coeffs(configs_dir):
35+
def tour_mode_choice_coeffs(configs_dir):
3636
with open(os.path.join(configs_dir,
3737
"configs",
3838
"tour_mode_choice_coeffs.csv")) as f:
3939
return pd.read_csv(f, index_col='Expression')
4040

4141

4242
@orca.injectable()
43-
def mode_choice_spec(mode_choice_spec_df, mode_choice_coeffs,
44-
mode_choice_settings):
45-
return _mode_choice_spec(mode_choice_spec_df, mode_choice_coeffs,
46-
mode_choice_settings)
43+
def tour_mode_choice_spec(tour_mode_choice_spec_df,
44+
tour_mode_choice_coeffs,
45+
tour_mode_choice_settings):
46+
return _mode_choice_spec(tour_mode_choice_spec_df,
47+
tour_mode_choice_coeffs,
48+
tour_mode_choice_settings)
49+
50+
51+
@orca.injectable()
52+
def trip_mode_choice_settings(configs_dir):
53+
with open(os.path.join(configs_dir,
54+
"configs",
55+
"trip_mode_choice.yaml")) as f:
56+
return yaml.load(f)
57+
58+
59+
@orca.injectable()
60+
def trip_mode_choice_spec_df(configs_dir):
61+
with open(os.path.join(configs_dir,
62+
"configs",
63+
"trip_mode_choice.csv")) as f:
64+
return asim.read_model_spec(f)
65+
66+
67+
@orca.injectable()
68+
def trip_mode_choice_coeffs(configs_dir):
69+
with open(os.path.join(configs_dir,
70+
"configs",
71+
"trip_mode_choice_coeffs.csv")) as f:
72+
return pd.read_csv(f, index_col='Expression')
73+
74+
75+
@orca.injectable()
76+
def trip_mode_choice_spec(trip_mode_choice_spec_df,
77+
trip_mode_choice_coeffs,
78+
trip_mode_choice_settings):
79+
return _mode_choice_spec(trip_mode_choice_spec_df,
80+
trip_mode_choice_coeffs,
81+
trip_mode_choice_settings)
4782

4883

4984
def _mode_choice_simulate(tours, skims, spec, additional_constants, omx=None):
@@ -100,22 +135,43 @@ def get_segment_and_unstack(spec, segment):
100135

101136

102137
@orca.step()
103-
def mode_choice_simulate(tours_merged,
104-
mode_choice_spec,
105-
mode_choice_settings,
106-
skims, omx_file):
138+
def tour_mode_choice_simulate(tours_merged,
139+
tour_mode_choice_spec,
140+
tour_mode_choice_settings,
141+
skims, omx_file):
107142

108143
tours = tours_merged.to_frame()
109144

110-
print mode_choice_spec.eatout
111-
112145
# FIXME this only runs eatout
113146
choices = _mode_choice_simulate(
114147
tours[tours.tour_type == "eatout"],
115148
skims,
116-
get_segment_and_unstack(mode_choice_spec, 'eatout'),
117-
mode_choice_settings['CONSTANTS'],
149+
get_segment_and_unstack(tour_mode_choice_spec, 'eatout'),
150+
tour_mode_choice_settings['CONSTANTS'],
118151
omx=omx_file)
119152

120153
print "Choices:\n", choices.value_counts()
121154
orca.add_column("tours", "mode", choices)
155+
156+
157+
@orca.step()
158+
def trip_mode_choice_simulate(tours_merged,
159+
trip_mode_choice_spec,
160+
trip_mode_choice_settings,
161+
skims, omx_file):
162+
163+
# FIXME running the trips model on tours
164+
trips = tours_merged.to_frame()
165+
166+
print trip_mode_choice_spec.eatout
167+
168+
# FIXME this only runs eatout
169+
choices = _mode_choice_simulate(
170+
trips[trips.tour_type == "eatout"],
171+
skims,
172+
get_segment_and_unstack(trip_mode_choice_spec, 'eatout'),
173+
trip_mode_choice_settings['CONSTANTS'],
174+
omx=omx_file)
175+
176+
print "Choices:\n", choices.value_counts()
177+
orca.add_column("trips", "mode", choices)

activitysim/defaults/tables/tours.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ def is_joint(tours):
137137
return pd.Series(False, index=tours.index)
138138

139139

140+
@orca.column("tours")
141+
def is_not_joint(tours):
142+
# FIXME
143+
return pd.Series(True, index=tours.index)
144+
145+
140146
@orca.column("tours")
141147
def number_of_participants(tours):
142148
# FIXME

activitysim/defaults/test/test_defaults.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,13 @@ def test_mini_run(store, random_seed):
8181
# this is a regression test so that we know if these numbers change
8282
auto_choice = orca.get_table('households').get_column('auto_ownership')
8383
print auto_choice[[2306822, 652072, 651907]]
84+
print pd.Series(
85+
[2, 1, 1], index=[2306822, 652072, 651907], name="HHID")
8486

8587
pdt.assert_series_equal(
8688
auto_choice[[2306822, 652072, 651907]],
8789
pd.Series(
88-
[2, 1, 1], index=pd.Index([2306822, 652072, 651907], name='HHID')))
89-
90+
[2, 1, 1], index=pd.Index([2306822, 652072, 651907], name="HHID")))
9091
orca.run(["cdap_simulate"])
9192

9293
orca.run(['mandatory_tour_frequency'])
@@ -99,7 +100,6 @@ def test_mini_run(store, random_seed):
99100
pd.Series(
100101
['school1', 'work1', 'school2'],
101102
index=pd.Index([146642, 642922, 642921], name='PERID')))
102-
103103
orca.clear_cache()
104104

105105

@@ -138,7 +138,7 @@ def test_full_run(store):
138138
orca.run(["destination_choice"])
139139
orca.run(["mandatory_scheduling"])
140140
orca.run(["non_mandatory_scheduling"])
141-
orca.run(["mode_choice_simulate"])
141+
orca.run(["tour_mode_choice_simulate"])
142142

143143
orca.clear_cache()
144144
tmp.close()

0 commit comments

Comments
 (0)