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

Write Number of Participants to Trip List Output #372

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions activitysim/abm/models/stop_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,24 @@ def process_trips(tours, stop_frequency_alts):

trips['person_id'] = reindex(tours.person_id, trips.tour_id)
trips['household_id'] = reindex(tours.household_id, trips.tour_id)
trips['number_of_participants'] = reindex(tours.number_of_participants, trips.tour_id)

trips['primary_purpose'] = reindex(tours.primary_purpose, trips.tour_id)

# reorder columns and drop 'direction'
trips = trips[['person_id', 'household_id', 'tour_id', 'primary_purpose',
'trip_num', 'outbound', 'trip_count']]
'trip_num', 'outbound', 'trip_count', 'number_of_participants']]

"""
person_id household_id tour_id primary_purpose trip_num outbound trip_count
0 32927 32927 954910 work 1 True 2
1 32927 32927 954910 work 2 True 2
2 32927 32927 954910 work 1 False 2
3 32927 32927 954910 work 2 False 2
4 33993 33993 985824 univ 1 True 1
5 33993 33993 985824 univ 1 False 2
6 33993 33993 985824 univ 2 False 2

person_id household_id tour_id primary_purpose trip_num outbound trip_count number_of_participants
0 32927 32927 954910 work 1 True 2 1
1 32927 32927 954910 work 2 True 2 1
2 32927 32927 954910 work 1 False 2 1
3 32927 32927 954910 work 2 False 2 1
4 33993 33993 985824 univ 1 True 1 1
5 33993 33993 985824 univ 1 False 2 1
6 33993 33993 985824 univ 2 False 2 1
7 53993 53993 785824 joint 1 True 2 3
"""

# canonical_trip_num: 1st trip out = 1, 2nd trip out = 2, 1st in = 5, etc.
Expand Down
9 changes: 8 additions & 1 deletion activitysim/abm/models/trip_mode_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ def trip_mode_choice(
logger.info("Running %s with %d trips", trace_label, trips_df.shape[0])

tours_merged = tours_merged.to_frame()
tours_merged = tours_merged[model_settings['TOURS_MERGED_CHOOSER_COLUMNS']]

# - filter tours_merged (AFTER copying destination and origin columns to trips)
# tours_merged is used for logsums, we filter it here upfront to save space and time
tours_merged_cols = model_settings['TOURS_MERGED_CHOOSER_COLUMNS']
if 'REDUNDANT_TOURS_MERGED_CHOOSER_COLUMNS' in model_settings:
redundant_cols = model_settings['REDUNDANT_TOURS_MERGED_CHOOSER_COLUMNS']
tours_merged_cols = [c for c in tours_merged_cols if c not in redundant_cols]
tours_merged = tours_merged[tours_merged_cols]

nest_spec = config.get_logit_model_settings(model_settings)

Expand Down
4 changes: 1 addition & 3 deletions activitysim/core/assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@

from activitysim.core import util
from activitysim.core import config
from activitysim.core import expressions
from activitysim.core import los
from activitysim.core import pipeline
from activitysim.core import inject

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -151,7 +150,6 @@ def local_utilities():
'reindex_i': util.reindex_i,
'setting': config.setting,
'other_than': util.other_than,
'skim_time_period_label': expressions.skim_time_period_label,
'rng': pipeline.get_rn_generator(),
}

Expand Down
51 changes: 0 additions & 51 deletions activitysim/core/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,57 +125,6 @@ def assign_columns(df, model_settings, locals_dict={}, trace_label=None):
assign_in_place(df, results)


# ##################################################################################################
# helpers
# ##################################################################################################

def skim_time_period_label(time_period):
"""
convert time period times to skim time period labels (e.g. 9 -> 'AM')

Parameters
----------
time_period : pandas Series

Returns
-------
pandas Series
string time period labels
"""

skim_time_periods = config.setting('skim_time_periods')

# Default to 60 minute time periods
period_minutes = 60
if 'period_minutes' in skim_time_periods.keys():
period_minutes = skim_time_periods['period_minutes']

# Default to a day
model_time_window_min = 1440
if ('time_window') in skim_time_periods.keys():
model_time_window_min = skim_time_periods['time_window']

# Check to make sure the intervals result in no remainder time throught 24 hour day
assert 0 == model_time_window_min % period_minutes
total_periods = model_time_window_min / period_minutes

# FIXME - eventually test and use np version always?
period_label = 'periods'
if 'hours' in skim_time_periods.keys():
period_label = 'hours'
warnings.warn('`skim_time_periods` key `hours` in settings.yml will be removed in '
'future verions. Use `periods` instead',
FutureWarning)

if np.isscalar(time_period):
bin = np.digitize([time_period % total_periods],
skim_time_periods[period_label], right=True)[0] - 1
return skim_time_periods['labels'][bin]

return pd.cut(time_period, skim_time_periods[period_label],
labels=skim_time_periods['labels'], ordered=False).astype(str)


def annotate_preprocessors(
tours_df, locals_dict, skims,
model_settings, trace_label):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ PRIMARY_DEST: destination

REDUNDANT_TOURS_MERGED_CHOOSER_COLUMNS:
- tour_mode
- number_of_participants

CONSTANTS:
max_walk_distance: 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,7 @@ TOURS_MERGED_CHOOSER_COLUMNS:
- tour_type
- free_parking_at_work

REDUNDANT_TOURS_MERGED_CHOOSER_COLUMNS:
- number_of_participants

MODE_CHOICE_LOGSUM_COLUMN_NAME: mode_choice_logsum
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,7 @@ TOURS_MERGED_CHOOSER_COLUMNS:
- income_segment
# - demographic_segment

REDUNDANT_TOURS_MERGED_CHOOSER_COLUMNS:
- number_of_participants

MODE_CHOICE_LOGSUM_COLUMN_NAME: mode_choice_logsum