@@ -36,12 +36,17 @@ class CdapSettings(PydanticReadable, extra="forbid"):
3636 JOINT_TOUR_COEFFICIENTS : str = "cdap_joint_tour_coefficients.csv"
3737 JOINT_TOUR_USEFUL_COLUMNS : list [str ] | None = None
3838 """Columns to include from the persons table that will be need to calculate household joint tour utility."""
39- annotate_persons : PreprocessorSettings | None = None
40- annotate_households : PreprocessorSettings | None = None
4139 COEFFICIENTS : Path
4240 CONSTANTS : dict [str , Any ] = {}
4341 compute_settings : ComputeSettings | None = None
4442
43+ preprocessor : PreprocessorSettings | None = None
44+ """Preprocess choosers tables before running the model."""
45+ annotate_persons : PreprocessorSettings | None = None
46+ """Postprocess persons table after model completion."""
47+ annotate_households : PreprocessorSettings | None = None
48+ """Postprocess households table after model completion."""
49+
4550
4651@workflow .step
4752def cdap_simulate (
@@ -171,6 +176,16 @@ def cdap_simulate(
171176 index = True ,
172177 )
173178
179+ # preprocess choosers
180+ expressions .annotate_preprocessors (
181+ state ,
182+ df = persons_merged ,
183+ locals_dict = constants ,
184+ skims = None ,
185+ model_settings = model_settings ,
186+ trace_label = trace_label ,
187+ )
188+
174189 if estimator :
175190 estimator .write_model_settings (model_settings , "cdap.yaml" )
176191 estimator .write_spec (model_settings , tag = "INDIV_AND_HHSIZE1_SPEC" )
@@ -241,31 +256,25 @@ def cdap_simulate(
241256 cap_cat_type = pd .api .types .CategoricalDtype (["" , "M" , "N" , "H" ], ordered = False )
242257 choices = choices .astype (cap_cat_type )
243258 persons ["cdap_activity" ] = choices
244-
245- expressions .assign_columns (
246- state ,
247- df = persons ,
248- model_settings = model_settings .annotate_persons ,
249- trace_label = tracing .extend_trace_label (trace_label , "annotate_persons" ),
250- )
251-
252259 state .add_table ("persons" , persons )
253260
254261 # - annotate households table
255262 if add_joint_tour_utility :
256263 hh_joint = hh_joint .reindex (households .index )
257264 households ["has_joint_tour" ] = hh_joint
258265
259- expressions .assign_columns (
260- state ,
261- df = households ,
262- model_settings = model_settings .annotate_households ,
263- trace_label = tracing .extend_trace_label (trace_label , "annotate_households" ),
264- )
265266 state .add_table ("households" , households )
266267
267268 tracing .print_summary ("cdap_activity" , persons .cdap_activity , value_counts = True )
268269 logger .info (
269270 "cdap crosstabs:\n %s"
270271 % pd .crosstab (persons .ptype , persons .cdap_activity , margins = True )
271272 )
273+
274+ expressions .annotate_tables (
275+ state ,
276+ locals_dict = constants ,
277+ skims = None ,
278+ model_settings = model_settings ,
279+ trace_label = trace_label ,
280+ )
0 commit comments