Skip to content

Commit f44f965

Browse files
committed
Merge pull request #50 from synthicity/orca
Switch from UrbanSim to Orca
2 parents 003d69d + 66a2257 commit f44f965

25 files changed

+347
-269
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ install:
2121
cytoolz ipython-notebook jinja2 matplotlib numpy pandas pandana patsy pip
2222
pytables pytest pyyaml scipy statsmodels toolz
2323
- source activate test-environment
24-
- pip install bottle prettytable simplejson zbox
25-
- pip install https://github.com/synthicity/urbansim/archive/master.zip
24+
- pip install bottle orca prettytable simplejson zbox
2625
- pip install openmatrix
2726
- pip install pytest-cov coveralls pep8
2827
- pip install .

activitysim/defaults/misc.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
1-
import urbansim.sim.simulation as sim
2-
import warnings
31
import os
4-
import yaml
5-
import pandas as pd
2+
import warnings
3+
64
import numpy as np
5+
import orca
6+
import pandas as pd
7+
import yaml
78

89

910
warnings.filterwarnings('ignore', category=pd.io.pytables.PerformanceWarning)
1011
pd.options.mode.chained_assignment = None
1112

1213

13-
@sim.injectable()
14+
@orca.injectable()
1415
def set_random_seed():
1516
pass
1617

1718

18-
@sim.injectable()
19+
@orca.injectable()
1920
def configs_dir():
2021
return '.'
2122

2223

23-
@sim.injectable()
24+
@orca.injectable()
2425
def data_dir():
2526
return '.'
2627

2728

28-
@sim.injectable()
29+
@orca.injectable()
2930
def settings(configs_dir):
3031
with open(os.path.join(configs_dir, "configs", "settings.yaml")) as f:
3132
return yaml.load(f)
3233

3334

34-
@sim.injectable(cache=True)
35+
@orca.injectable(cache=True)
3536
def store(data_dir, settings):
3637
return pd.HDFStore(os.path.join(data_dir, "data", settings["store"]),
3738
mode='r')
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import os
2-
import urbansim.sim.simulation as sim
2+
3+
import orca
4+
35
from activitysim import activitysim as asim
46

57
"""
@@ -8,18 +10,18 @@
810
"""
911

1012

11-
@sim.injectable()
13+
@orca.injectable()
1214
def auto_ownership_spec(configs_dir):
1315
f = os.path.join(configs_dir, 'configs', "auto_ownership.csv")
1416
return asim.read_model_spec(f).fillna(0)
1517

1618

17-
@sim.model()
19+
@orca.step()
1820
def auto_ownership_simulate(set_random_seed, households_merged,
1921
auto_ownership_spec):
2022

2123
choices, _ = asim.simple_simulate(
2224
households_merged.to_frame(), auto_ownership_spec)
2325

2426
print "Choices:\n", choices.value_counts()
25-
sim.add_column("households", "auto_ownership", choices)
27+
orca.add_column("households", "auto_ownership", choices)

activitysim/defaults/models/cdap.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import os
2+
3+
import orca
24
import pandas as pd
3-
import urbansim.sim.simulation as sim
5+
46
from activitysim import activitysim as asim
57
from activitysim.cdap import cdap
68

@@ -15,37 +17,37 @@
1517
"""
1618

1719

18-
@sim.injectable()
20+
@orca.injectable()
1921
def cdap_1_person_spec(configs_dir):
2022
f = os.path.join(configs_dir, 'configs', "cdap_1_person.csv")
2123
return asim.read_model_spec(f).fillna(0)
2224

2325

24-
@sim.injectable()
26+
@orca.injectable()
2527
def cdap_2_person_spec(configs_dir):
2628
f = os.path.join(configs_dir, 'configs', "cdap_2_person.csv")
2729
return asim.read_model_spec(f).fillna(0)
2830

2931

30-
@sim.injectable()
32+
@orca.injectable()
3133
def cdap_3_person_spec(configs_dir):
3234
f = os.path.join(configs_dir, 'configs', "cdap_3_person.csv")
3335
return asim.read_model_spec(f).fillna(0)
3436

3537

36-
@sim.injectable()
38+
@orca.injectable()
3739
def cdap_final_rules(configs_dir):
3840
f = os.path.join(configs_dir, 'configs', "cdap_final_rules.csv")
3941
return asim.read_model_spec(f).fillna(0)
4042

4143

42-
@sim.injectable()
44+
@orca.injectable()
4345
def cdap_all_people(configs_dir):
4446
f = os.path.join(configs_dir, 'configs', "cdap_all_people.csv")
4547
return asim.read_model_spec(f).fillna(0)
4648

4749

48-
@sim.model()
50+
@orca.step()
4951
def cdap_simulate(set_random_seed, persons_merged,
5052
cdap_1_person_spec, cdap_2_person_spec, cdap_3_person_spec,
5153
cdap_final_rules, cdap_all_people):
@@ -60,4 +62,4 @@ def cdap_simulate(set_random_seed, persons_merged,
6062
cdap_all_people)
6163

6264
print "Choices:\n", choices.value_counts()
63-
sim.add_column("persons", "cdap_activity", choices)
65+
orca.add_column("persons", "cdap_activity", choices)

activitysim/defaults/models/destination.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
import urbansim.sim.simulation as sim
2-
from activitysim import activitysim as asim
31
import os
2+
3+
import orca
44
import pandas as pd
55

6+
from activitysim import activitysim as asim
7+
68
"""
79
Given the tour generation from the above, each tour needs to have a
810
destination, so in this case tours are the choosers (with the associated
911
person that's making the tour)
1012
"""
1113

1214

13-
@sim.table()
15+
@orca.table()
1416
def destination_choice_spec(configs_dir):
1517
f = os.path.join(configs_dir, 'configs', 'destination_choice.csv')
1618
return asim.read_model_spec(f).fillna(0)
1719

1820

19-
@sim.model()
21+
@orca.step()
2022
def destination_choice(set_random_seed,
2123
non_mandatory_tours_merged,
2224
skims,
@@ -64,4 +66,4 @@ def destination_choice(set_random_seed,
6466
print "Choices:\n", choices.describe()
6567
# every trip now has a destination which is the index from the
6668
# alternatives table - in this case it's the destination taz
67-
sim.add_column("non_mandatory_tours", "destination", choices)
69+
orca.add_column("non_mandatory_tours", "destination", choices)

activitysim/defaults/models/mandatory_scheduling.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import os
2+
3+
import orca
24
import pandas as pd
3-
import urbansim.sim.simulation as sim
5+
46
from activitysim import activitysim as asim
57
from .util.vectorize_tour_scheduling import vectorize_tour_scheduling
68

@@ -10,7 +12,7 @@
1012
"""
1113

1214

13-
@sim.table()
15+
@orca.table()
1416
def tdd_alts(configs_dir):
1517
# right now this file just contains the start and end hour
1618
f = os.path.join(configs_dir, "configs",
@@ -20,19 +22,19 @@ def tdd_alts(configs_dir):
2022

2123
# used to have duration in the actual alternative csv file,
2224
# but this is probably better as a computed column like this
23-
@sim.column("tdd_alts")
25+
@orca.column("tdd_alts")
2426
def duration(tdd_alts):
2527
return tdd_alts.end - tdd_alts.start
2628

2729

28-
@sim.table()
30+
@orca.table()
2931
def tdd_work_spec(configs_dir):
3032
f = os.path.join(configs_dir, 'configs',
3133
'tour_departure_and_duration_work.csv')
3234
return asim.read_model_spec(f).fillna(0)
3335

3436

35-
@sim.table()
37+
@orca.table()
3638
def tdd_school_spec(configs_dir):
3739
f = os.path.join(configs_dir, 'configs',
3840
'tour_departure_and_duration_school.csv')
@@ -41,7 +43,7 @@ def tdd_school_spec(configs_dir):
4143

4244
# I think it's easier to do this in one model so you can merge the two
4345
# resulting series together right away
44-
@sim.model()
46+
@orca.step()
4547
def mandatory_scheduling(set_random_seed,
4648
mandatory_tours_merged,
4749
tdd_alts,
@@ -69,6 +71,5 @@ def mandatory_scheduling(set_random_seed,
6971

7072
print "Choices:\n", choices.describe()
7173

72-
sim.add_column("mandatory_tours",
73-
"tour_departure_and_duration",
74-
choices)
74+
orca.add_column(
75+
"mandatory_tours", "tour_departure_and_duration", choices)

activitysim/defaults/models/mandatory_tour_frequency.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import os
2+
3+
import orca
24
import pandas as pd
3-
import urbansim.sim.simulation as sim
5+
46
from activitysim import activitysim as asim
57
from .util.mandatory_tour_frequency import process_mandatory_tours
68

@@ -10,13 +12,13 @@
1012
"""
1113

1214

13-
@sim.injectable()
15+
@orca.injectable()
1416
def mandatory_tour_frequency_spec(configs_dir):
1517
f = os.path.join(configs_dir, 'configs', "mandatory_tour_frequency.csv")
1618
return asim.read_model_spec(f).fillna(0)
1719

1820

19-
@sim.model()
21+
@orca.step()
2022
def mandatory_tour_frequency(set_random_seed,
2123
persons_merged,
2224
mandatory_tour_frequency_spec):
@@ -36,7 +38,7 @@ def mandatory_tour_frequency(set_random_seed,
3638
index=choices.index).reindex(persons_merged.local.index)
3739

3840
print "Choices:\n", choices.value_counts()
39-
sim.add_column("persons", "mandatory_tour_frequency", choices)
41+
orca.add_column("persons", "mandatory_tour_frequency", choices)
4042

4143

4244
"""
@@ -46,7 +48,7 @@ def mandatory_tour_frequency(set_random_seed,
4648
"""
4749

4850

49-
@sim.table()
51+
@orca.table()
5052
def mandatory_tours(persons):
5153
persons = persons.to_frame(columns=["mandatory_tour_frequency",
5254
"is_worker"])
@@ -55,7 +57,7 @@ def mandatory_tours(persons):
5557

5658

5759
# broadcast mandatory_tours on to persons using the person_id foreign key
58-
sim.broadcast('persons', 'mandatory_tours',
59-
cast_index=True, onto_on='person_id')
60-
sim.broadcast('persons_merged', 'mandatory_tours',
61-
cast_index=True, onto_on='person_id')
60+
orca.broadcast('persons', 'mandatory_tours',
61+
cast_index=True, onto_on='person_id')
62+
orca.broadcast('persons_merged', 'mandatory_tours',
63+
cast_index=True, onto_on='person_id')

activitysim/defaults/models/mode.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import os
21
import copy
3-
import yaml
2+
import os
3+
4+
import orca
45
import pandas as pd
5-
import urbansim.sim.simulation as sim
6+
import yaml
7+
68
from activitysim import activitysim as asim
79
from activitysim import skim as askim
810

@@ -12,7 +14,7 @@
1214
"""
1315

1416

15-
@sim.injectable()
17+
@orca.injectable()
1618
def mode_choice_settings(configs_dir):
1719
with open(os.path.join(configs_dir, "configs", "mode_choice.yaml")) as f:
1820
return yaml.load(f)
@@ -45,7 +47,7 @@ def evaluate_expression_list(expressions, locals_d):
4547
return pd.Series(d)
4648

4749

48-
@sim.injectable()
50+
@orca.injectable()
4951
def mode_choice_coefficients(mode_choice_settings):
5052
# coefficients comes as a list of dicts and needs to be tuples
5153
coeffs = [x.items()[0] for x in mode_choice_settings['COEFFICIENTS']]
@@ -54,7 +56,7 @@ def mode_choice_coefficients(mode_choice_settings):
5456
return evaluate_expression_list(expressions, locals_d=constants)
5557

5658

57-
@sim.injectable()
59+
@orca.injectable()
5860
def mode_choice_spec(configs_dir, mode_choice_coefficients):
5961
f = os.path.join(configs_dir, 'configs', "mode_choice_work.csv")
6062
df = asim.read_model_spec(f)
@@ -67,7 +69,7 @@ def get_segment_and_unstack(spec, segment):
6769
return spec[segment].unstack().fillna(0)
6870

6971

70-
@sim.model()
72+
@orca.step()
7173
def mode_choice_simulate(tours_merged,
7274
mode_choice_spec,
7375
mode_choice_settings,
@@ -100,4 +102,4 @@ def mode_choice_simulate(tours_merged,
100102
locals_d=locals_d)
101103

102104
print "Choices:\n", choices.value_counts()
103-
sim.add_column("tours", "mode", choices)
105+
orca.add_column("tours", "mode", choices)

activitysim/defaults/models/non_mandatory_scheduling.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import os
2+
3+
import orca
24
import pandas as pd
3-
import urbansim.sim.simulation as sim
5+
46
from activitysim import activitysim as asim
57
from .util.vectorize_tour_scheduling import vectorize_tour_scheduling
68

@@ -11,14 +13,14 @@
1113
"""
1214

1315

14-
@sim.table()
16+
@orca.table()
1517
def tdd_non_mandatory_spec(configs_dir):
1618
f = os.path.join(configs_dir, 'configs',
1719
'tour_departure_and_duration_nonmandatory.csv')
1820
return asim.read_model_spec(f).fillna(0)
1921

2022

21-
@sim.model()
23+
@orca.step()
2224
def non_mandatory_scheduling(set_random_seed,
2325
non_mandatory_tours_merged,
2426
tdd_alts,
@@ -35,6 +37,5 @@ def non_mandatory_scheduling(set_random_seed,
3537

3638
print "Choices:\n", choices.describe()
3739

38-
sim.add_column("non_mandatory_tours",
39-
"tour_departure_and_duration",
40-
choices)
40+
orca.add_column(
41+
"non_mandatory_tours", "tour_departure_and_duration", choices)

0 commit comments

Comments
 (0)