@@ -569,14 +569,13 @@ def merge_persons(self):
569569 inject .add_table ("proto_persons_merged" , persons_merged )
570570
571571
572- def get_disaggregate_logsums (network_los , chunk_size , trace_hh_id ):
572+ def get_disaggregate_logsums (
573+ network_los , chunk_size , trace_hh_id , disagg_model_settings
574+ ):
573575 logsums = {}
574576 persons_merged = pipeline .get_table ("proto_persons_merged" ).sort_index (
575577 inplace = False
576578 )
577- disagg_model_settings = read_disaggregate_accessibility_yaml (
578- "disaggregate_accessibility.yaml"
579- )
580579
581580 for model_name in [
582581 "workplace_location" ,
@@ -696,8 +695,14 @@ def compute_disaggregate_accessibility(network_los, chunk_size, trace_hh_id):
696695 tracing .register_traceable_table (tablename , df )
697696 del df
698697
698+ disagg_model_settings = read_disaggregate_accessibility_yaml (
699+ "disaggregate_accessibility.yaml"
700+ )
701+
699702 # Run location choice
700- logsums = get_disaggregate_logsums (network_los , chunk_size , trace_hh_id )
703+ logsums = get_disaggregate_logsums (
704+ network_los , chunk_size , trace_hh_id , disagg_model_settings
705+ )
701706 logsums = {k + "_accessibility" : v for k , v in logsums .items ()}
702707
703708 # Combined accessibility table
@@ -736,20 +741,20 @@ def compute_disaggregate_accessibility(network_los, chunk_size, trace_hh_id):
736741 logsums ["proto_disaggregate_accessibility" ] = access_df
737742
738743 # Drop any tables prematurely created
739- for tablename in [
740- "school_destination_size" ,
741- "workplace_destination_size" ,
742- ]:
743- pipeline .drop_table (tablename )
744+ # FIXME: dropping size tables breaks restart functionality for location choice models.
745+ # hopefully this pipeline mess just goes away with move away from orca....
746+ # for tablename in [
747+ # "school_destination_size",
748+ # "workplace_destination_size",
749+ # ]:
750+ # pipeline.drop_table(tablename)
744751
745752 for ch in list (pipeline .get_rn_generator ().channels .keys ()):
746753 pipeline .get_rn_generator ().drop_channel (ch )
747754
748- # Drop any prematurely added traceables
749- for trace in [
750- x for x in inject .get_injectable ("traceable_tables" ) if "proto_" not in x
751- ]:
752- tracing .deregister_traceable_table (trace )
755+ # Dropping all traceable tables
756+ for table in inject .get_injectable ("traceable_tables" ):
757+ tracing .deregister_traceable_table (table )
753758
754759 # need to clear any premature tables that were added during the previous run
755760 orca ._TABLES .clear ()
@@ -760,4 +765,22 @@ def compute_disaggregate_accessibility(network_los, chunk_size, trace_hh_id):
760765 # Inject accessibility results into pipeline
761766 [inject .add_table (k , df ) for k , df in logsums .items ()]
762767
768+ # available post-processing
769+ for annotations in disagg_model_settings .get ("postprocess_proto_tables" , []):
770+ tablename = annotations ["tablename" ]
771+ df = pipeline .get_table (tablename )
772+ assert df is not None
773+ assert annotations is not None
774+ assign_columns (
775+ df = df ,
776+ model_settings = {
777+ ** annotations ["annotate" ],
778+ ** disagg_model_settings ["suffixes" ],
779+ },
780+ trace_label = tracing .extend_trace_label (
781+ "disaggregate_accessibility.postprocess" , tablename
782+ ),
783+ )
784+ pipeline .replace_table (tablename , df )
785+
763786 return
0 commit comments