def households_transition(households, annual_household_control_totals, year): ct = annual_household_control_totals.to_frame() tran = transition.TabularTotalsTransition(ct, 'total_number_of_households') model = transition.TransitionModel(tran) hh = households.to_frame(households.local_columns + ['activity_id']) new, added_hh_idx, empty_dict = \ model.transition(hh, year,) new.loc[added_hh_idx, "building_id"] = -1 orca.add_table("households", new)
def full_transition(agents, agent_controls, year, settings, location_fname, linked_tables=None): """ Run a transition model based on control totals specified in the usual UrbanSim way Parameters ---------- agents : DataFrameWrapper Table to be transitioned agent_controls : DataFrameWrapper Table of control totals year : int The year, which will index into the controls settings : dict Contains the configuration for the transition model - is specified down to the yaml level with a "total_column" which specifies the control total and an "add_columns" param which specified which columns to add when calling to_frame (should be a list of the columns needed to do the transition location_fname : str The field name in the resulting dataframe to set to -1 (to unplace new agents) linked_tables : dict of tuple, optional Dictionary of table_name: (table, 'column name') pairs. The column name should match the index of `agents`. Indexes in `agents` that are copied or removed will also be copied and removed in linked tables. Returns ------- Nothing """ ct = agent_controls.to_frame() hh = agents.to_frame(agents.local_columns + settings.get('add_columns', [])) print "Total agents before transition: {}".format(len(hh)) linked_tables = linked_tables or {} for table_name, (table, col) in linked_tables.iteritems(): print "Total %s before transition: %s" % (table_name, len(table)) tran = transition.TabularTotalsTransition(ct, settings['total_column']) model = transition.TransitionModel(tran) new, added_hh_idx, new_linked = model.transition( hh, year, linked_tables=linked_tables) new.loc[added_hh_idx, location_fname] = -1 print "Total agents after transition: {}".format(len(new)) orca.add_table(agents.name, new) for table_name, table in new_linked.iteritems(): print "Total %s after transition: %s" % (table_name, len(table)) orca.add_table(table_name, table)
def full_transition(agents, agent_controls, year, settings, location_fname): """ Run a transition model based on control totals specified in the usual UrbanSim way Parameters ---------- agents : DataFrameWrapper Table to be transitioned agent_controls : DataFrameWrapper Table of control totals year : int The year, which will index into the controls settings : dict Contains the configuration for the transition model - is specified down to the yaml level with a "total_column" which specifies the control total and an "add_columns" param which specified which columns to add when calling to_frame (should be a list of the columns needed to do the transition location_fname : str The field name in the resulting dataframe to set to -1 (to unplace new agents) Returns ------- Nothing """ ct = agent_controls.to_frame() hh = agents.to_frame(agents.local_columns + settings['add_columns']) print "Total agents before transition: {}".format(len(hh)) tran = transition.TabularTotalsTransition(ct, settings['total_column']) model = transition.TransitionModel(tran) new, added_hh_idx, new_linked = model.transition(hh, year) new.loc[added_hh_idx, location_fname] = -1 print "Total agents after transition: {}".format(len(new)) orca.add_table(agents.name, new)