Skip to content

Commit cc1944c

Browse files
bwentldhensle
andauthored
exposing network_los to annotator and preprocessor (#1134)
Co-authored-by: David Hensle <51132108+dhensle@users.noreply.github.com>
1 parent 1921121 commit cc1944c

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

‎activitysim/core/expressions.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ def compute_columns(
130130
_locals_dict["skim_dict"] = state.get_injectable("skim_dataset_dict")
131131
else:
132132
_locals_dict["skim_dict"] = state.get_injectable("skim_dict")
133+
134+
_locals_dict["network_los"] = state.get_injectable("network_los")
133135
except FileNotFoundError:
134136
pass # maybe we don't even need the skims
135137

‎activitysim/core/test/configs/preprocessor.csv‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ skim dict test,od_distance,"skim_dict.lookup(df.origin, df.destination, 'DIST')"
66
skim wrapper test,od_distance_wrapper,skims2d['DIST']
77
sov time,od_sov_time,skims3d['SOV_TIME']
88
testing constant from locals_dict,constant_test,test_constant / 2
9-
testing global constant,global_constant_test,global_test_constant / 2
9+
testing global constant,global_constant_test,global_test_constant / 2
10+
network los period label test,los_period,network_los.skim_time_period_label(df.depart)

‎activitysim/core/test/test_preprocessing.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def state() -> workflow.State:
3434
state = add_canonical_dirs("configs_1z").load_settings()
3535
network_los = los.Network_LOS(state)
3636
network_los.load_data()
37+
state.set("network_los", network_los)
3738
state.set("skim_dict", network_los.get_default_skim_dict())
3839
return state
3940

@@ -71,6 +72,7 @@ def tours():
7172
"origin": [1, 2, 3],
7273
"destination": [2, 3, 1],
7374
"period": ["AM", "PM", "AM"],
75+
"depart": [8, 18, 8],
7476
}
7577
).set_index("tour_id")
7678

@@ -88,6 +90,7 @@ def check_outputs(tours):
8890
"od_sov_time",
8991
"constant_test",
9092
"global_constant_test",
93+
"los_period",
9194
]
9295

9396
# check all new columns are added
@@ -101,7 +104,7 @@ def check_outputs(tours):
101104
), f"Unexpected column found: _hh_income in {tours.columns}"
102105

103106
# check the values in the new columns
104-
exppected_output = pd.DataFrame(
107+
expected_output = pd.DataFrame(
105108
{
106109
"tour_id": [1, 2, 3],
107110
"is_high_income": [False, True, True],
@@ -111,9 +114,11 @@ def check_outputs(tours):
111114
"od_sov_time": [0.78, 0.89, 1.76],
112115
"constant_test": [21, 21, 21],
113116
"global_constant_test": [21, 21, 21],
117+
"los_period": ["AM", "PM", "AM"],
114118
}
115119
).set_index("tour_id")
116-
pd.testing.assert_frame_equal(tours[new_cols], exppected_output, check_dtype=False)
120+
expected_output["los_period"] = expected_output["los_period"].astype("category")
121+
pd.testing.assert_frame_equal(tours[new_cols], expected_output, check_dtype=False)
117122

118123

119124
def setup_skims(state: workflow.State):

0 commit comments

Comments
 (0)