Skip to content

Commit 62c3523

Browse files
authored
Merge pull request #661 from JoeJimFlood/tot_tours
Moved 'tot_tours' from nm tour frequency script to alternatives file
2 parents fc06d62 + 3d4dc35 commit 62c3523

File tree

8 files changed

+602
-589
lines changed

8 files changed

+602
-589
lines changed

activitysim/abm/models/non_mandatory_tour_frequency.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import logging
6+
import warnings
67
from pathlib import Path
78
from typing import Any
89

@@ -200,12 +201,24 @@ def non_mandatory_tour_frequency(
200201
model_settings_file_name,
201202
)
202203

203-
# FIXME kind of tacky both that we know to add this here and del it below
204-
# 'tot_tours' is used in model_spec expressions
205204
alternatives = simulate.read_model_alts(
206205
state, "non_mandatory_tour_frequency_alternatives.csv", set_index=None
207206
)
208-
alternatives["tot_tours"] = alternatives.sum(axis=1)
207+
if "tot_tours" not in alternatives.columns:
208+
# add a column for total tours
209+
alternatives["tot_tours"] = alternatives.sum(axis=1)
210+
warnings.warn(
211+
"The 'tot_tours' column may not be automatically added in the future.",
212+
FutureWarning,
213+
)
214+
else:
215+
# tot_tours already exists, check if it is consistent with legacy behavior
216+
if not (alternatives["tot_tours"] == alternatives.sum(axis=1)).all():
217+
warnings.warn(
218+
"The 'tot_tours' column in non_mandatory_tour_frequency_alternatives.csv "
219+
"does not match the sum of the other columns.",
220+
RuntimeWarning,
221+
)
209222

210223
# filter based on results of CDAP
211224
choosers = persons_merged

activitysim/abm/models/util/canonical_ids.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def determine_flavors_from_alts_file(
182182
flavors = {
183183
c: int(alts[c].max() + max_extension)
184184
for c in alts.columns
185-
if all(alts[c].astype(str).str.isnumeric())
185+
if all(alts[c].astype(str).str.isnumeric()) and (c != "tot_tours")
186186
}
187187
valid_flavors = all(
188188
[(isinstance(flavor, str) & (num >= 0)) for flavor, num in flavors.items()]
Lines changed: 97 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,97 @@
1-
escort,shopping,othmaint,othdiscr,eatout,social
2-
0,0,0,0,0,0
3-
0,0,0,1,0,0
4-
0,0,0,0,0,1
5-
0,0,0,1,0,1
6-
0,0,0,0,1,0
7-
0,0,0,1,1,0
8-
0,0,0,0,1,1
9-
0,0,0,1,1,1
10-
0,0,1,0,0,0
11-
0,0,1,1,0,0
12-
0,0,1,0,0,1
13-
0,0,1,1,0,1
14-
0,0,1,0,1,0
15-
0,0,1,1,1,0
16-
0,0,1,0,1,1
17-
0,0,1,1,1,1
18-
0,1,0,0,0,0
19-
0,1,0,1,0,0
20-
0,1,0,0,0,1
21-
0,1,0,1,0,1
22-
0,1,0,0,1,0
23-
0,1,0,1,1,0
24-
0,1,0,0,1,1
25-
0,1,0,1,1,1
26-
0,1,1,0,0,0
27-
0,1,1,1,0,0
28-
0,1,1,0,0,1
29-
0,1,1,1,0,1
30-
0,1,1,0,1,0
31-
0,1,1,1,1,0
32-
0,1,1,0,1,1
33-
0,1,1,1,1,1
34-
1,0,0,0,0,0
35-
1,0,0,1,0,0
36-
1,0,0,0,0,1
37-
1,0,0,1,0,1
38-
1,0,0,0,1,0
39-
1,0,0,1,1,0
40-
1,0,0,0,1,1
41-
1,0,0,1,1,1
42-
1,0,1,0,0,0
43-
1,0,1,1,0,0
44-
1,0,1,0,0,1
45-
1,0,1,1,0,1
46-
1,0,1,0,1,0
47-
1,0,1,1,1,0
48-
1,0,1,0,1,1
49-
1,0,1,1,1,1
50-
1,1,0,0,0,0
51-
1,1,0,1,0,0
52-
1,1,0,0,0,1
53-
1,1,0,1,0,1
54-
1,1,0,0,1,0
55-
1,1,0,1,1,0
56-
1,1,0,0,1,1
57-
1,1,0,1,1,1
58-
1,1,1,0,0,0
59-
1,1,1,1,0,0
60-
1,1,1,0,0,1
61-
1,1,1,1,0,1
62-
1,1,1,0,1,0
63-
1,1,1,1,1,0
64-
1,1,1,0,1,1
65-
1,1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