From 564c4762944d3288097eb4ef761bdbdb0f9d4d9f Mon Sep 17 00:00:00 2001 From: David Hensle <51132108+dhensle@users.noreply.github.com> Date: Tue, 14 May 2024 10:03:01 -0700 Subject: [PATCH] Trip destination alts preprocessor for both sample and simulate steps (#869) * trip_destination alts preprocessor * non_hh_veh cat, drop unused cols for alts * blacken * adding missed alts columns used in xborder model * remove unneeded addition to categorical * revert change to drop size terms * creating separate sample and simulate preprocessors --------- Co-authored-by: Jeffrey Newman --- activitysim/abm/models/trip_destination.py | 31 ++++++++++++++-------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/activitysim/abm/models/trip_destination.py b/activitysim/abm/models/trip_destination.py index 8a3320a20..e214d56fd 100644 --- a/activitysim/abm/models/trip_destination.py +++ b/activitysim/abm/models/trip_destination.py @@ -60,7 +60,8 @@ class TripDestinationSettings(LocationComponentSettings, extra="forbid"): PRIMARY_DEST: str = "tour_leg_dest" # must be created in preprocessor REDUNDANT_TOURS_MERGED_CHOOSER_COLUMNS: list[str] | None = None preprocessor: PreprocessorSettings | None = None - alts_preprocessor: PreprocessorSettings | None = None + alts_preprocessor_sample: PreprocessorSettings | None = None + alts_preprocessor_simulate: PreprocessorSettings | None = None CLEANUP: bool fail_some_trips_for_testing: bool = False """This setting is used by testing code to force failed trip_destination.""" @@ -202,6 +203,15 @@ def _destination_sample( log_alt_losers = state.settings.log_alt_losers + if model_settings.alts_preprocessor_sample: + expressions.assign_columns( + state, + df=alternatives, + model_settings=model_settings.alts_preprocessor_sample, + locals_dict=locals_dict, + trace_label=tracing.extend_trace_label(trace_label, "alts"), + ) + choices = interaction_sample( state, choosers=trips, @@ -936,6 +946,15 @@ def trip_destination_simulate( ) locals_dict.update(skims) + if model_settings.alts_preprocessor_simulate: + expressions.assign_columns( + state, + df=destination_sample, + model_settings=model_settings.alts_preprocessor_simulate, + locals_dict=locals_dict, + trace_label=tracing.extend_trace_label(trace_label, "alts"), + ) + log_alt_losers = state.settings.log_alt_losers destinations = interaction_sample_simulate( state, @@ -1246,7 +1265,6 @@ def run_trip_destination( state.filesystem, model_settings_file_name ) preprocessor_settings = model_settings.preprocessor - alts_preprocessor_settings = model_settings.alts_preprocessor logsum_settings = state.filesystem.read_model_settings( model_settings.LOGSUM_SETTINGS ) @@ -1369,15 +1387,6 @@ def run_trip_destination( trace_label=nth_trace_label, ) - if alts_preprocessor_settings: - expressions.assign_columns( - state, - df=alternatives, - model_settings=alts_preprocessor_settings, - locals_dict=locals_dict, - trace_label=tracing.extend_trace_label(nth_trace_label, "alts"), - ) - if isinstance( nth_trips["trip_period"].dtype, pd.api.types.CategoricalDtype ):