Skip to content

Commit

Permalink
p3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
toliwaga committed Oct 16, 2018
1 parent 2d6fc31 commit 5c769a0
Show file tree
Hide file tree
Showing 48 changed files with 342 additions and 260 deletions.
8 changes: 5 additions & 3 deletions activitysim/abm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# ActivitySim
# See full license in LICENSE.txt.

import misc
import tables
import models
from __future__ import absolute_import

from . import misc
from . import tables
from . import models
8 changes: 5 additions & 3 deletions activitysim/abm/misc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# ActivitySim
# See full license in LICENSE.txt.

from __future__ import (absolute_import, division, print_function, unicode_literals)

import os
import warnings
import logging
Expand All @@ -13,7 +15,7 @@
from activitysim.core import inject

# FIXME
warnings.filterwarnings('ignore', category=pd.io.pytables.PerformanceWarning)
# warnings.filterwarnings('ignore', category=pd.io.pytables.PerformanceWarning)
pd.options.mode.chained_assignment = None

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -64,7 +66,7 @@ def trace_hh_id(settings):
id = settings.get('trace_hh_id', None)

if id and not isinstance(id, int):
logger.warn("setting trace_hh_id is wrong type, should be an int, but was %s" % type(id))
logger.warning("setting trace_hh_id is wrong type, should be an int, but was %s" % type(id))
id = None

return id
Expand All @@ -76,7 +78,7 @@ def trace_od(settings):
od = settings.get('trace_od', None)

if od and not (isinstance(od, list) and len(od) == 2 and all(isinstance(x, int) for x in od)):
logger.warn("setting trace_od is wrong type, should be a list of length 2, but was %s" % od)
logger.warning("setting trace_od should be a list of length 2, but was %s" % od)
od = None

return od
Expand Down
8 changes: 4 additions & 4 deletions activitysim/abm/models/accessibility.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# ActivitySim
# See full license in LICENSE.txt.

from builtins import range
from builtins import object
from __future__ import (absolute_import, division, print_function, unicode_literals)
from builtins import *

import logging
import os

import pandas as pd
import numpy as np
Expand Down Expand Up @@ -183,7 +183,7 @@ def compute_accessibility(accessibility, skim_dict, land_use, trace_od):
if trace_od:

if not trace_od_rows.any():
logger.warn("trace_od not found origin = %s, dest = %s" % (trace_orig, trace_dest))
logger.warning("trace_od not found origin = %s, dest = %s" % (trace_orig, trace_dest))
else:

# add OD columns to trace results
Expand Down
2 changes: 1 addition & 1 deletion activitysim/abm/models/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def annotate_tables(model_settings, trace_label):
annotate_tables = model_settings.get('annotate_tables', [])

if not annotate_tables:
logger.warn("annotate_tables setting is empty - nothing to do!")
logger.warning("annotate_tables setting is empty - nothing to do!")

t0 = tracing.print_elapsed_time()

Expand Down
7 changes: 4 additions & 3 deletions activitysim/abm/models/joint_tour_composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

def add_null_results(trace_label, tours):
logger.info("Skipping %s: add_null_results" % trace_label)
tours['composition'] = np.nan
tours['composition'] = ''
pipeline.replace_table("tours", tours)


Expand Down Expand Up @@ -94,10 +94,11 @@ def joint_tour_composition(
# convert indexes to alternative names
choices = pd.Series(model_spec.columns[choices.values], index=choices.index)

# add composition column to tours
# add composition column to tours for tracing
joint_tours['composition'] = choices

assign_in_place(tours, joint_tours[['composition']])
# reindex since we ran model on a subset of households
tours['composition'] = choices.reindex(tours.index).fillna('').astype(str)
pipeline.replace_table("tours", tours)

tracing.print_summary('joint_tour_composition', joint_tours.composition,
Expand Down
2 changes: 1 addition & 1 deletion activitysim/abm/models/joint_tour_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def joint_tour_frequency(
# - annotate households
# add joint_tour_frequency and num_hh_joint_tours columns to households
# reindex since we ran model on a subset of households
households['joint_tour_frequency'] = choices.reindex(households.index)
households['joint_tour_frequency'] = choices.reindex(households.index).fillna('').astype(str)

households['num_hh_joint_tours'] = joint_tours.groupby('household_id').size().\
reindex(households.index).fillna(0).astype(np.int8)
Expand Down
4 changes: 2 additions & 2 deletions activitysim/abm/models/joint_tour_participation.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def joint_tour_participation_candidates(joint_tours, persons_merged):
MAX_PNUM = 100
if candidates.PNUM.max() > MAX_PNUM:
# if this happens, channel random seeds will overlap at MAX_PNUM (not probably a big deal)
logger.warn("max persons.PNUM (%s) > MAX_PNUM (%s)" % (candidates.PNUM.max(), MAX_PNUM))
logger.warning("max persons.PNUM (%s) > MAX_PNUM (%s)" % (candidates.PNUM.max(), MAX_PNUM))

candidates['participant_id'] = (candidates[joint_tours.index.name] * MAX_PNUM) + candidates.PNUM
candidates.set_index('participant_id', drop=True, inplace=True, verify_integrity=True)
Expand Down Expand Up @@ -154,7 +154,7 @@ def participants_chooser(probs, choosers, spec, trace_label):
iter += 1

if iter > MAX_ITERATIONS:
logger.warn('%s max iterations exceeded (%s).' % (trace_label, MAX_ITERATIONS))
logger.warning('%s max iterations exceeded (%s).' % (trace_label, MAX_ITERATIONS))
diagnostic_cols = ['tour_id', 'household_id', 'composition', 'adult']
unsatisfied_candidates = candidates[diagnostic_cols].join(probs)
tracing.write_csv(unsatisfied_candidates,
Expand Down
2 changes: 1 addition & 1 deletion activitysim/abm/models/mandatory_tour_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def mandatory_tour_frequency(persons_merged,
persons = inject.get_table('persons').to_frame()

# need to reindex as we only handled persons with cdap_activity == 'M'
persons['mandatory_tour_frequency'] = choices.reindex(persons.index)
persons['mandatory_tour_frequency'] = choices.reindex(persons.index).fillna('').astype(str)

expressions.assign_columns(
df=persons,
Expand Down
10 changes: 8 additions & 2 deletions activitysim/abm/models/non_mandatory_tour_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import logging

import numpy as np
import pandas as pd

from activitysim.core.interaction_simulate import interaction_simulate
Expand Down Expand Up @@ -47,8 +48,11 @@ def non_mandatory_tour_frequency(persons, persons_merged,
choosers = persons_merged.to_frame()

# FIXME kind of tacky both that we know to add this here and del it below
# 'tot_tours' is used in model_spec expressions
alternatives['tot_tours'] = alternatives.sum(axis=1)

no_tours_alt = list((alternatives.sum(axis=1) == 0).values).index(True)

# - preprocessor
preprocessor_settings = model_settings.get('preprocessor', None)
if preprocessor_settings:
Expand Down Expand Up @@ -103,7 +107,8 @@ def non_mandatory_tour_frequency(persons, persons_merged,
persons = persons.to_frame()

# need to reindex as we only handled persons with cdap_activity in ['M', 'N']
persons['non_mandatory_tour_frequency'] = choices.reindex(persons.index)
persons['non_mandatory_tour_frequency'] = \
choices.reindex(persons.index).fillna(no_tours_alt).astype(np.int8)

"""
We have now generated non-mandatory tours, but they are attributes of the person table
Expand All @@ -112,11 +117,12 @@ def non_mandatory_tour_frequency(persons, persons_merged,
"""
del alternatives['tot_tours'] # del tot_tours column we added above
non_mandatory_tours = process_non_mandatory_tours(
persons[~persons.mandatory_tour_frequency.isnull()],
persons[persons.mandatory_tour_frequency != no_tours_alt],
alternatives,
)

tours = pipeline.extend_table("tours", non_mandatory_tours)

tracing.register_traceable_table('tours', tours)
pipeline.get_rn_generator().add_channel(non_mandatory_tours, 'tours')

Expand Down
19 changes: 11 additions & 8 deletions activitysim/abm/models/trip_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,9 @@ def choose_trip_destination(

dropped_trips = ~trips.index.isin(destination_sample.index.unique())
if dropped_trips.any():
logger.warn("%s trip_destination_ample %s trips without viable destination alternatives"
% (trace_label, dropped_trips.sum()))
logger.warning("%s trip_destination_ample %s trips "
"without viable destination alternatives" %
(trace_label, dropped_trips.sum()))
trips = trips[~dropped_trips]

t0 = print_elapsed_time("%s.trip_destination_sample" % trace_label, t0)
Expand Down Expand Up @@ -340,8 +341,9 @@ def choose_trip_destination(

dropped_trips = ~trips.index.isin(destinations.index)
if dropped_trips.any():
logger.warn("%s trip_destination_simulate %s trips without viable destination alternatives"
% (trace_label, dropped_trips.sum()))
logger.warning("%s trip_destination_simulate %s trips "
"without viable destination alternatives" %
(trace_label, dropped_trips.sum()))

t0 = print_elapsed_time("%s.trip_destination_simulate" % trace_label, t0)

Expand Down Expand Up @@ -503,8 +505,8 @@ def run_trip_destination(

failed_trip_ids = nth_trips.index.difference(destinations.index)
if failed_trip_ids.any():
logger.warn("%s sidelining %s trips without viable destination alternatives"
% (nth_trace_label, failed_trip_ids.shape[0]))
logger.warning("%s sidelining %s trips without viable destination alternatives" %
(nth_trace_label, failed_trip_ids.shape[0]))
next_trip_ids = nth_trips.next_trip_id.reindex(failed_trip_ids)
trips.loc[failed_trip_ids, 'failed'] = True
trips.loc[failed_trip_ids, 'destination'] = -1
Expand Down Expand Up @@ -549,15 +551,16 @@ def trip_destination(
trace_label)

if trips_df.failed.any():
logger.warn("%s %s failed trips" % (trace_label, trips_df.failed.sum()))
logger.warning("%s %s failed trips" % (trace_label, trips_df.failed.sum()))
file_name = "%s_failed_trips" % trace_label
logger.info("writing failed trips to %s" % file_name)
tracing.write_csv(trips_df[trips_df.failed], file_name=file_name, transpose=False)

if CLEANUP:
trips_df = cleanup_failed_trips(trips_df)
elif trips_df.failed.any():
logger.warn("%s keeping %s sidelined failed trips" % (trace_label, trips_df.failed.sum()))
logger.warning("%s keeping %s sidelined failed trips" %
(trace_label, trips_df.failed.sum()))

pipeline.replace_table("trips", trips_df)

Expand Down
7 changes: 4 additions & 3 deletions activitysim/abm/models/trip_purpose_and_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ def trip_purpose_and_destination(
results.append(trips_df[RESULT_COLUMNS])
break

logger.warn("%s %s failed trips in iteration %s" % (trace_label, num_failed_trips, i))
logger.warning("%s %s failed trips in iteration %s" % (trace_label, num_failed_trips, i))
file_name = "%s_i%s_failed_trips" % (trace_label, i)
logger.info("writing failed trips to %s" % file_name)
tracing.write_csv(trips_df[trips_df.failed], file_name=file_name, transpose=False)

# if max iterations reached, add remaining trips to results and give up
# note that we do this BEFORE failing leg_mates so resulting trip legs are complete
if i >= MAX_ITERATIONS:
logger.warn("%s too many iterations %s" % (trace_label, i))
logger.warning("%s too many iterations %s" % (trace_label, i))
results.append(trips_df[RESULT_COLUMNS])
break

Expand All @@ -142,7 +142,8 @@ def trip_purpose_and_destination(
if CLEANUP:
trips_df = cleanup_failed_trips(trips_df)
elif trips_df.failed.any():
logger.warn("%s keeping %s sidelined failed trips" % (trace_label, trips_df.failed.sum()))
logger.warning("%s keeping %s sidelined failed trips" %
(trace_label, trips_df.failed.sum()))

pipeline.replace_table("trips", trips_df)

Expand Down
8 changes: 4 additions & 4 deletions activitysim/abm/models/trip_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ def schedule_trips_in_leg(
# most initial departure (when no choice was made because all probs were zero)
if last_iteration and (failfix == FAILFIX_CHOOSE_MOST_INITIAL):
choices = choices.reindex(nth_trips.index)
logger.warn("%s coercing %s depart choices to most initial" %
(nth_trace_label, choices.isna().sum()))
logger.warning("%s coercing %s depart choices to most initial" %
(nth_trace_label, choices.isna().sum()))
choices = choices.fillna(trips[ADJUST_NEXT_DEPART_COL])

# adjust allowed depart range of next trip
Expand Down Expand Up @@ -552,8 +552,8 @@ def trip_scheduling(
choices = pd.concat(choices_list)
choices = choices.reindex(trips_df.index)
if choices.isnull().any():
logger.warn("%s of %s trips could not be scheduled after %s iterations" %
(choices.isnull().sum(), trips_df.shape[0], i))
logger.warning("%s of %s trips could not be scheduled after %s iterations" %
(choices.isnull().sum(), trips_df.shape[0], i))

if failfix != FAILFIX_DROP_AND_CLEANUP:
raise RuntimeError("%s setting '%' not enabled in settings" %
Expand Down
6 changes: 3 additions & 3 deletions activitysim/abm/models/util/tour_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def size_term(land_use, destination_choice_coeffs):
missing = coeffs[~coeffs.index.isin(land_use.columns)]

if len(missing) > 0:
logger.warn("%s missing columns in land use" % len(missing.index))
logger.warning("%s missing columns in land use" % len(missing.index))
for v in missing.index.values:
logger.warn("missing: %s" % v)
logger.warning("missing: %s" % v)

return land_use[coeffs.index].dot(coeffs)

Expand Down Expand Up @@ -84,7 +84,7 @@ def tour_destination_size_terms(land_use, size_terms, selector):
df.index.name = 'TAZ'

if not (df.dtypes == 'float64').all():
logger.warn('Surprised to find that not all size_terms were float64!')
logger.warning('Surprised to find that not all size_terms were float64!')

# - #NARROW
# float16 has 3.3 decimal digits of precision, float32 has 7.2
Expand Down
2 changes: 1 addition & 1 deletion activitysim/abm/test/configs/annotate_households_cdap.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Description,Target,Expression
#,, annotate households table after cdap model has run
num_under16_not_at_school,num_under16_not_at_school,"persons.under16_not_at_school.groupby(persons.household_id).sum().reindex(households.index).fillna(0)"
num_under16_not_at_school,num_under16_not_at_school,"persons.under16_not_at_school.astype(int).groupby(persons.household_id).sum().reindex(households.index).fillna(0)"
num_travel_active,num_travel_active,"persons.travel_active.groupby(persons.household_id).sum().reindex(households.index).fillna(0)"
num_travel_active_adults,num_travel_active_adults,"(persons.adult & persons.travel_active).groupby(persons.household_id).sum().reindex(households.index).fillna(0)"
num_travel_active_children,num_travel_active_children,"num_travel_active - num_travel_active_adults"
1 change: 1 addition & 0 deletions activitysim/abm/test/output/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.csv
*.log
*.prof
*.h5
*.txt
*.yaml
1 change: 1 addition & 0 deletions activitysim/abm/test/test_misc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ActivitySim
# See full license in LICENSE.txt.
from __future__ import (absolute_import, division, print_function, unicode_literals)

from builtins import str
import os
Expand Down
Loading

1 comment on commit 5c769a0

@bstabler
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.