Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linked tables option to Simple Transition Model #36

Open
cvanoli opened this issue Jan 4, 2021 · 3 comments
Open

Add linked tables option to Simple Transition Model #36

cvanoli opened this issue Jan 4, 2021 · 3 comments
Assignees

Comments

@cvanoli
Copy link
Contributor

cvanoli commented Jan 4, 2021

Right now, the utils.simple_transition model does not allow for linked tables to be changed as the transition model changes the main table. We use this specifically when the households are transitioning, the persons table should change as well. Though we have that option in the full_transition model in a parameter called linked_tables, we don't have the same possibility when running a simple transition model with a growth rate.

@cvanoli
Copy link
Contributor Author

cvanoli commented Jan 4, 2021

To solve this, I created the linked_tables_addin branch, where I add a parameter called linked_tables, which default is None, so nothing would happen if you do not choose to use this.
def simple_transition(tbl, rate, location_fname, linked_tables=None):
Equally as in the full transition model,

    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.

After the transition itself, these lines are added to take care of the linked tables that should be changed:

    linked_tables = linked_tables or {}
    updated_links = {}
    for table_name, (table, col) in linked_tables.items():
        print('updating linked table {}'.format(table_name))
        updated_links[table_name] = \
            transition._update_linked_table(table, col, added, copied, removed)
    for table_name, table in updated_links.items():
        print("Total {} after transition: {:,}".format(table_name, len(table)))
        orca.add_table(table_name, table)

if linked_tables is None nothing different from the original state, happens.

This is the improved simple_transition model in the linked_tables_addin branch

@smmaurer
Copy link
Member

smmaurer commented Jan 4, 2021

This looks great to me! @janowicz should take a quick look as well when convenient, because I think he wrote the original code.

@cvanoli
Copy link
Contributor Author

cvanoli commented Jan 4, 2021

Okay thanks @smmaurer , I'll be performing some tests meanwhile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants