Skip to content

Commit

Permalink
Merge pull request #55 from UDST/trip-mode-choice
Browse files Browse the repository at this point in the history
Trip mode choice running on tours table for eatout purpose only
  • Loading branch information
bstabler committed Apr 8, 2016
2 parents cf1942c + 5d8bedb commit 1a01d02
Show file tree
Hide file tree
Showing 11 changed files with 1,568 additions and 624 deletions.
86 changes: 71 additions & 15 deletions activitysim/defaults/models/mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,69 @@


@orca.injectable()
def mode_choice_settings(configs_dir):
def tour_mode_choice_settings(configs_dir):
with open(os.path.join(configs_dir,
"configs",
"tour_mode_choice.yaml")) as f:
return yaml.load(f)


@orca.injectable()
def mode_choice_spec_df(configs_dir):
def tour_mode_choice_spec_df(configs_dir):
with open(os.path.join(configs_dir,
"configs",
"tour_mode_choice.csv")) as f:
return asim.read_model_spec(f)


@orca.injectable()
def mode_choice_coeffs(configs_dir):
def tour_mode_choice_coeffs(configs_dir):
with open(os.path.join(configs_dir,
"configs",
"tour_mode_choice_coeffs.csv")) as f:
return pd.read_csv(f, index_col='Expression')


@orca.injectable()
def mode_choice_spec(mode_choice_spec_df, mode_choice_coeffs,
mode_choice_settings):
return _mode_choice_spec(mode_choice_spec_df, mode_choice_coeffs,
mode_choice_settings)
def tour_mode_choice_spec(tour_mode_choice_spec_df,
tour_mode_choice_coeffs,
tour_mode_choice_settings):
return _mode_choice_spec(tour_mode_choice_spec_df,
tour_mode_choice_coeffs,
tour_mode_choice_settings)


@orca.injectable()
def trip_mode_choice_settings(configs_dir):
with open(os.path.join(configs_dir,
"configs",
"trip_mode_choice.yaml")) as f:
return yaml.load(f)


@orca.injectable()
def trip_mode_choice_spec_df(configs_dir):
with open(os.path.join(configs_dir,
"configs",
"trip_mode_choice.csv")) as f:
return asim.read_model_spec(f)


@orca.injectable()
def trip_mode_choice_coeffs(configs_dir):
with open(os.path.join(configs_dir,
"configs",
"trip_mode_choice_coeffs.csv")) as f:
return pd.read_csv(f, index_col='Expression')


@orca.injectable()
def trip_mode_choice_spec(trip_mode_choice_spec_df,
trip_mode_choice_coeffs,
trip_mode_choice_settings):
return _mode_choice_spec(trip_mode_choice_spec_df,
trip_mode_choice_coeffs,
trip_mode_choice_settings)


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


@orca.step()
def mode_choice_simulate(tours_merged,
mode_choice_spec,
mode_choice_settings,
skims, omx_file):
def tour_mode_choice_simulate(tours_merged,
tour_mode_choice_spec,
tour_mode_choice_settings,
skims, omx_file):

tours = tours_merged.to_frame()

print mode_choice_spec.eatout

# FIXME this only runs eatout
choices = _mode_choice_simulate(
tours[tours.tour_type == "eatout"],
skims,
get_segment_and_unstack(mode_choice_spec, 'eatout'),
mode_choice_settings['CONSTANTS'],
get_segment_and_unstack(tour_mode_choice_spec, 'eatout'),
tour_mode_choice_settings['CONSTANTS'],
omx=omx_file)

print "Choices:\n", choices.value_counts()
orca.add_column("tours", "mode", choices)


@orca.step()
def trip_mode_choice_simulate(tours_merged,
trip_mode_choice_spec,
trip_mode_choice_settings,
skims, omx_file):

# FIXME running the trips model on tours
trips = tours_merged.to_frame()

print trip_mode_choice_spec.eatout

# FIXME this only runs eatout
choices = _mode_choice_simulate(
trips[trips.tour_type == "eatout"],
skims,
get_segment_and_unstack(trip_mode_choice_spec, 'eatout'),
trip_mode_choice_settings['CONSTANTS'],
omx=omx_file)

print "Choices:\n", choices.value_counts()
orca.add_column("trips", "mode", choices)
6 changes: 6 additions & 0 deletions activitysim/defaults/tables/tours.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ def is_joint(tours):
return pd.Series(False, index=tours.index)


@orca.column("tours")
def is_not_joint(tours):
# FIXME
return pd.Series(True, index=tours.index)


@orca.column("tours")
def number_of_participants(tours):
# FIXME
Expand Down
8 changes: 4 additions & 4 deletions activitysim/defaults/test/test_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,13 @@ def test_mini_run(store, random_seed):
# this is a regression test so that we know if these numbers change
auto_choice = orca.get_table('households').get_column('auto_ownership')
print auto_choice[[2306822, 652072, 651907]]
print pd.Series(
[2, 1, 1], index=[2306822, 652072, 651907], name="HHID")

pdt.assert_series_equal(
auto_choice[[2306822, 652072, 651907]],
pd.Series(
[2, 1, 1], index=pd.Index([2306822, 652072, 651907], name='HHID')))

[2, 1, 1], index=pd.Index([2306822, 652072, 651907], name="HHID")))
orca.run(["cdap_simulate"])

orca.run(['mandatory_tour_frequency'])
Expand All @@ -99,7 +100,6 @@ def test_mini_run(store, random_seed):
pd.Series(
['school1', 'work1', 'school2'],
index=pd.Index([146642, 642922, 642921], name='PERID')))

orca.clear_cache()


Expand Down Expand Up @@ -138,7 +138,7 @@ def test_full_run(store):
orca.run(["destination_choice"])
orca.run(["mandatory_scheduling"])
orca.run(["non_mandatory_scheduling"])
orca.run(["mode_choice_simulate"])
orca.run(["tour_mode_choice_simulate"])

orca.clear_cache()
tmp.close()
Expand Down
3 changes: 2 additions & 1 deletion activitysim/tests/test_skim.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,6 @@ def test_3dskims(data):
pd.Series(
[12, 93, 47],
index=[0, 1, 2]
)
),
check_dtype=False
)

0 comments on commit 1a01d02

Please sign in to comment.