Skip to content

Commit

Permalink
blacken
Browse files Browse the repository at this point in the history
  • Loading branch information
dhensle committed Jul 27, 2023
1 parent a25c891 commit 851ba21
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 20 deletions.
2 changes: 1 addition & 1 deletion activitysim/abm/models/cdap.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def cdap_simulate(persons_merged, persons, households, chunk_size, trace_hh_id):
estimator.write_choices(choices)
choices = estimator.get_survey_values(choices, "persons", "cdap_activity")
if add_joint_tour_utility:
hh_joint.index.name = 'household_id'
hh_joint.index.name = "household_id"
hh_joint = estimator.get_survey_values(
hh_joint, "households", "has_joint_tour"
)
Expand Down
33 changes: 21 additions & 12 deletions activitysim/abm/models/location_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _location_sample(

sample_size = model_settings["SAMPLE_SIZE"]
if estimator:
sample_size = model_settings.get('ESTIMATION_SAMPLE_SIZE', 0)
sample_size = model_settings.get("ESTIMATION_SAMPLE_SIZE", 0)

locals_d = {
"skims": skims,
Expand Down Expand Up @@ -471,23 +471,32 @@ def run_location_sample(
if estimator:
# grabbing survey values
survey_persons = estimation.manager.get_survey_table("persons")
if 'school_location' in trace_label:
survey_choices = survey_persons['school_zone_id'].reset_index()
elif ('workplace_location' in trace_label) and ('external' not in trace_label):
survey_choices = survey_persons['workplace_zone_id'].reset_index()
if "school_location" in trace_label:
survey_choices = survey_persons["school_zone_id"].reset_index()
elif ("workplace_location" in trace_label) and ("external" not in trace_label):
survey_choices = survey_persons["workplace_zone_id"].reset_index()
else:
return choices
survey_choices.columns = ['person_id', 'alt_dest']
survey_choices = survey_choices[survey_choices['person_id'].isin(choices.index) & (survey_choices.alt_dest > 0)]
survey_choices.columns = ["person_id", "alt_dest"]
survey_choices = survey_choices[
survey_choices["person_id"].isin(choices.index)
& (survey_choices.alt_dest > 0)
]
# merging survey destination into table if not available
joined_data = survey_choices.merge(choices, on=['person_id', 'alt_dest'], how='left', indicator=True)
missing_rows = joined_data[joined_data['_merge'] == 'left_only']
missing_rows['pick_count'] = 1
joined_data = survey_choices.merge(
choices, on=["person_id", "alt_dest"], how="left", indicator=True
)
missing_rows = joined_data[joined_data["_merge"] == "left_only"]
missing_rows["pick_count"] = 1
if len(missing_rows) > 0:
new_choices = missing_rows[['person_id', 'alt_dest', 'prob', 'pick_count']].set_index('person_id')
new_choices = missing_rows[
["person_id", "alt_dest", "prob", "pick_count"]
].set_index("person_id")
choices = choices.append(new_choices, ignore_index=False).sort_index()
# making probability the mean of all other sampled destinations by person
choices['prob'] = choices['prob'].fillna(choices.groupby('person_id')['prob'].transform('mean'))
choices["prob"] = choices["prob"].fillna(
choices.groupby("person_id")["prob"].transform("mean")
)

return choices

Expand Down
1 change: 1 addition & 0 deletions activitysim/estimation/larch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from .stop_frequency import *
from .external_worker_identification import *


def component_model(name, *args, **kwargs):
if isinstance(name, str):
m = globals().get(f"{name}_model")
Expand Down
2 changes: 2 additions & 0 deletions activitysim/estimation/larch/location_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,15 @@ def workplace_location_model(**kwargs):
**kwargs,
)


def external_workplace_location_model(**kwargs):
unused = kwargs.pop("name", None)
return location_choice_model(
name="external_workplace_location",
**kwargs,
)


def school_location_model(**kwargs):
unused = kwargs.pop("name", None)
return location_choice_model(
Expand Down
17 changes: 10 additions & 7 deletions activitysim/estimation/larch/simple_simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def free_parking_model(
}, # True is free parking, False is paid parking, names match spec positions
)


def work_from_home_model(
name="work_from_home",
edb_directory="output/estimation_data_bundle/{name}/",
Expand Down Expand Up @@ -311,6 +312,7 @@ def joint_tour_participation_model(
},
)


def external_non_mandatory_identification_model(
name="external_non_mandatory_identification",
edb_directory="output/estimation_data_bundle/{name}/",
Expand Down Expand Up @@ -339,8 +341,8 @@ def transit_pass_subsidy_model(
edb_directory=edb_directory,
return_data=return_data,
choices={
0: 1, # 0 means no subsidy, alternative 1
1: 2, # 1 means subsidy, alternative 2
0: 1, # 0 means no subsidy, alternative 1
1: 2, # 1 means subsidy, alternative 2
},
)

Expand All @@ -355,11 +357,12 @@ def transit_pass_ownership_model(
edb_directory=edb_directory,
return_data=return_data,
choices={
0: 1, # 0 means no pass, alternative 1
1: 2, # 1 means pass, alternative 2
0: 1, # 0 means no pass, alternative 1
1: 2, # 1 means pass, alternative 2
},
)


def transponder_ownership_model(
name="transponder_ownership",
edb_directory="output/estimation_data_bundle/{name}/",
Expand All @@ -370,7 +373,7 @@ def transponder_ownership_model(
edb_directory=edb_directory,
return_data=return_data,
choices={
0: 1, # 0 means no pass, alternative 1
1: 2, # 1 means pass, alternative 2
0: 1, # 0 means no pass, alternative 1
1: 2, # 1 means pass, alternative 2
},
)
)

0 comments on commit 851ba21

Please sign in to comment.