synthicity/urbansim — pull request #48 by jiffyclub (2014-07-15 21:11:10+00:00)
Title: High level simulation framework

This adds the ability to register tables, computed columns, and models with table injection into functions. The best illustration is probably a sample from the unit tests:

```python
import pandas as pd
import urbansim.simulation as sim

df = pd.DataFrame(
{'a': [1, 2, 3],
'b': [4, 5, 6]},
index=['x', 'y', 'z'])

sim.add_table('test_table', df)

@sim.table('table_func')
def table_func(test_table):
tt = test_table.to_frame()
tt['c'] = [7, 8, 9]
return tt

@sim.column('table_func', 'new_col')
def new_col(test_table, table_func):
tt = test_table.to_frame()
tf = table_func.to_frame(columns=['c'])
return tt['a'] + tt['b'] + tf['c']

@sim.model('test_model1')
def test_model1(year, test_table, table_func):
tf = table_func.to_frame(columns=['new_col'])
test_table[year] = tf['new_col'] + year

@sim.model('test_model2')
def test_model2(test_table):
tt = test_table.to_frame()
test_table['a'] = tt['a'] ** 2

sim.run(models=['test_model1', 'test_model2'], years=[2000, 3000])

test_table = sim.get_table('test_table')
assert_frames_equal(
test_table.to_frame(),
pd.DataFrame(
{'a': [1, 16, 81],
'b': [4, 5, 6],
2000: [2012, 2015, 2018],
3000: [3012, 3017, 3024]},
index=['x', 'y', 'z']))
```